alistair23-linux/fs/ocfs2
Jeff Liu 32918dd9f1 ocfs2: fix ocfs2_init_security_and_acl() to initialize acl correctly
We need to re-initialize the security for a new reflinked inode with its
parent dirs if it isn't specified to be preserved for ocfs2_reflink().
However, the code logic is broken at ocfs2_init_security_and_acl()
although ocfs2_init_security_get() succeed.  As a result,
ocfs2_acl_init() does not involked and therefore the default ACL of
parent dir was missing on the new inode.

Note this was introduced by 9d8f13ba3 ("security: new
security_inode_init_security API adds function callback")

To reproduce:

    set default ACL for the parent dir(ocfs2 in this case):
    $ setfacl -m default:user:jeff:rwx ../ocfs2/
    $ getfacl ../ocfs2/
    # file: ../ocfs2/
    # owner: jeff
    # group: jeff
    user::rwx
    group::r-x
    other::r-x
    default:user::rwx
    default:user:jeff:rwx
    default:group::r-x
    default😷:rwx
    default:other::r-x

    $ touch a
    $ getfacl a
    # file: a
    # owner: jeff
    # group: jeff
    user::rw-
    group::rw-
    other::r--

Before patching, create reflink file b from a, the user
default ACL entry(user:jeff:rwx)was missing:

    $ ./ocfs2_reflink a b
    $ getfacl b
    # file: b
    # owner: jeff
    # group: jeff
    user::rw-
    group::rw-
    other::r--

In this case, the end user can also observed an error message at syslog:

  (ocfs2_reflink,3229,2):ocfs2_init_security_and_acl:7193 ERROR: status = 0

After applying this patch, create reflink file c from a:

    $ ./ocfs2_reflink a c
    $ getfacl c
    # file: c
    # owner: jeff
    # group: jeff
    user::rw-
    user:jeff:rwx			#effective:rw-
    group::r-x			#effective:r--
    mask::rw-
    other::r--

Test program:
/* Usage: reflink <source> <dest> */
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>

static int
reflink_file(char const *src_name, char const *dst_name,
	     bool preserve_attrs)
{
	int fd;

#ifndef REFLINK_ATTR_NONE
#  define REFLINK_ATTR_NONE 0
#endif
#ifndef REFLINK_ATTR_PRESERVE
#  define REFLINK_ATTR_PRESERVE 1
#endif
#ifndef OCFS2_IOC_REFLINK
	struct reflink_arguments {
		uint64_t old_path;
		uint64_t new_path;
		uint64_t preserve;
	};

#  define OCFS2_IOC_REFLINK _IOW ('o', 4, struct reflink_arguments)
#endif
	struct reflink_arguments args = {
		.old_path = (unsigned long) src_name,
		.new_path = (unsigned long) dst_name,
		.preserve = preserve_attrs ? REFLINK_ATTR_PRESERVE :
					     REFLINK_ATTR_NONE,
	};

	fd = open(src_name, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "Failed to open %s: %s\n",
			src_name, strerror(errno));
		return -1;
	}

	if (ioctl(fd, OCFS2_IOC_REFLINK, &args) < 0) {
		fprintf(stderr, "Failed to reflink %s to %s: %s\n",
			src_name, dst_name, strerror(errno));
		return -1;
	}
}

int
main(int argc, char *argv[])
{
	if (argc != 3) {
		fprintf(stdout, "Usage: %s source dest\n", argv[0]);
		return 1;
	}

	return reflink_file(argv[1], argv[2], 0);
}

Signed-off-by: Jie Liu <jeff.liu@oracle.com>
Reviewed-by: Tao Ma <boyu.mt@taobao.com>
Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-27 19:10:09 -08:00
..
cluster Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial 2013-02-21 17:40:58 -08:00
dlm Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
dlmfs new helper: file_inode(file) 2013-02-22 23:31:31 -05:00
acl.c ocfs2: Handle kuids and kgids in acl/xattr conversions. 2013-02-13 06:00:56 -08:00
acl.h fs: take the ACL checks to common code 2011-07-25 14:30:23 -04:00
alloc.c ocfs2: remove kfree() redundant null checks 2013-02-21 17:22:19 -08:00
alloc.h ocfs2: Add ocfs2_trim_fs for SSD trim support. 2011-05-23 23:37:18 -07:00
aops.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
aops.h ocfs2: serialize unaligned aio 2011-07-28 02:07:16 -07:00
blockcheck.c ocfs2: kill endianness abuses in blockcheck.c 2012-05-29 23:28:35 -04:00
blockcheck.h
buffer_head_io.c ocfs2: Remove masklog ML_UPTODATE. 2011-02-24 16:22:20 +08:00
buffer_head_io.h ocfs2: Take the inode out of the metadata read/write paths. 2009-09-04 16:07:48 -07:00
dcache.c stop passing nameidata * to ->d_revalidate() 2012-07-14 16:34:14 +04:00
dcache.h Track negative entries v3 2010-09-10 09:18:15 -07:00
dir.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
dir.h
dlmglue.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace 2013-02-25 16:00:49 -08:00
dlmglue.h ocfs2: Fix lockdep warning in reflink. 2010-09-10 09:19:06 -07:00
export.c fs: encode_fh: return FILEID_INVALID if invalid fid_type 2013-02-26 02:46:10 -05:00
export.h
extent_map.c ocfs2: remove kfree() redundant null checks 2013-02-21 17:22:19 -08:00
extent_map.h ocfs2: Implement llseek() 2011-07-25 14:58:15 -07:00
file.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
file.h ->permission() sanitizing: don't pass flags to ->permission() 2011-07-20 01:43:24 -04:00
heartbeat.c ocfs2: Remove mlog(0) from fs/ocfs2/heartbeat.c 2011-02-23 21:17:39 +08:00
heartbeat.h
inode.c ocfs2: Convert uid and gids between in core and on disk inodes 2013-02-13 06:00:58 -08:00
inode.h ocfs2: serialize unaligned aio 2011-07-28 02:07:16 -07:00
ioctl.c new helper: file_inode(file) 2013-02-22 23:31:31 -05:00
ioctl.h Ocfs2: Move ocfs2 ioctl definitions from ocfs2_fs.h to newly added ocfs2_ioctl.h 2010-03-02 14:10:20 -08:00
journal.c ocfs2: remove kfree() redundant null checks 2013-02-21 17:22:19 -08:00
journal.h ocfs2: Add a missing journal credit in ocfs2_link_credits() -v2 2011-11-17 01:46:48 -08:00
Kconfig ocfs2: Make OCFS2_FS depend on CONFIGFS_FS 2011-01-16 21:22:40 +00:00
localalloc.c ocfs2: remove kfree() redundant null checks 2013-02-21 17:22:19 -08:00
localalloc.h ocfs2: increase the default size of local alloc windows 2010-05-05 18:18:07 -07:00
locks.c ocfs2: remove INODE from unused files. 2011-02-21 11:18:23 +08:00
locks.h
Makefile Ocfs2/move_extents: Add basic framework and source files for extent moving. 2011-05-25 15:17:08 +08:00
mmap.c kill f_vfsmnt 2013-02-26 02:46:10 -05:00
mmap.h
move_extents.c new helper: file_inode(file) 2013-02-22 23:31:31 -05:00
move_extents.h Ocfs2/move_extents: move/defrag extents within a certain range. 2011-05-25 15:17:12 +08:00
namei.c ocfs2: Convert uid and gids between in core and on disk inodes 2013-02-13 06:00:58 -08:00
namei.h ocfs2: Create reflinked file in orphan dir. 2009-09-22 20:09:48 -07:00
ocfs1_fs_compat.h
ocfs2.h ocfs2: avoid unaligned access to dqc_bitmap 2011-12-01 14:39:32 -08:00
ocfs2_fs.h Revert wrong fixes for common misspellings 2011-04-26 23:31:11 -07:00
ocfs2_ioctl.h Ocfs2/move_extents: Adding new ioctl code 'OCFS2_IOC_MOVE_EXT' to ocfs2. 2011-05-25 15:17:08 +08:00
ocfs2_lockid.h ocfs2: Add new refcount tree lock resource in dlmglue. 2009-09-22 20:09:28 -07:00
ocfs2_lockingver.h ocfs2_dlmfs: Enable the use of user cluster stacks. 2010-02-26 15:41:18 -08:00
ocfs2_trace.h ocfs2: Add trace event for trim. 2011-05-23 23:37:20 -07:00
quota.h ocfs2: use system_wq instead of ocfs2_quota_wq 2011-02-01 11:42:42 +01:00
quota_global.c userns: Convert struct dquot dq_id to be a struct kqid 2012-09-18 01:01:41 -07:00
quota_local.c userns: Convert struct dquot dq_id to be a struct kqid 2012-09-18 01:01:41 -07:00
refcounttree.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
refcounttree.h Ocfs2/refcounttree: Publicize couple of funcs from refcounttree.c 2011-05-25 15:17:08 +08:00
reservations.c ocfs2: Remove masklog ML_RESERVATIONS. 2011-02-23 22:10:56 +08:00
reservations.h Fix common misspellings 2011-03-31 11:26:23 -03:00
resize.c ocfs2: Remove mlog(0) from fs/ocfs2/suballoc.c 2011-02-22 08:24:01 +08:00
resize.h
slot_map.c ocfs2: Clean up messages in the fs 2011-07-24 10:34:54 -07:00
slot_map.h
stack_o2cb.c ocfs2: remove kfree() redundant null checks 2013-02-21 17:22:19 -08:00
stack_user.c dlm: add recovery callbacks 2012-01-04 08:56:31 -06:00
stackglue.c ocfs2_dlmfs: Enable the use of user cluster stacks. 2010-02-26 15:41:18 -08:00
stackglue.h Fix common misspellings 2011-03-31 11:26:23 -03:00
suballoc.c ocfs2: ->e_leaf_clusters endianness breakage 2012-04-13 12:31:43 -04:00
suballoc.h ocfs2: allow return of new inode block location before allocation of the inode 2010-09-08 14:25:59 +08:00
super.c ocfs2: remove kfree() redundant null checks 2013-02-21 17:22:19 -08:00
super.h treewide: use __printf not __attribute__((format(printf,...))) 2011-10-31 17:30:54 -07:00
symlink.c ocfs2: Fix oops in ocfs2_fast_symlink_readpage() code path 2013-02-26 02:46:12 -05:00
symlink.h ocfs: simplify symlink handling 2012-05-29 23:28:40 -04:00
sysfile.c ocfs2: remove kfree() redundant null checks 2013-02-21 17:22:19 -08:00
sysfile.h
uptodate.c ocfs2: Remove masklog ML_UPTODATE. 2011-02-24 16:22:20 +08:00
uptodate.h ocfs2: Pass struct ocfs2_caching_info to the journal functions. 2009-09-04 16:07:50 -07:00
ver.c
ver.h
xattr.c ocfs2: fix ocfs2_init_security_and_acl() to initialize acl correctly 2013-02-27 19:10:09 -08:00
xattr.h ocfs2: propagate umode_t 2012-01-03 22:55:02 -05:00