29 Nov, 2016

1 commit

  • Handling of recursion in d_real() is completely broken. Recursion is only
    done in the 'inode != NULL' case. But when opening the file we have
    'inode == NULL' hence d_real() will return an overlay dentry. This won't
    work since overlayfs doesn't define its own file operations, so all file
    ops will fail.

    Fix by doing the recursion first and the check against the inode second.

    Bash script to reproduce the issue written by Quentin:

    - 8< - - - - - 8< - - - - - 8< - - - - - 8< - - - -
    tmpdir=$(mktemp -d)
    pushd ${tmpdir}

    mkdir -p {upper,lower,work}
    echo -n 'rocks' > lower/ksplice
    mount -t overlay level_zero upper -o lowerdir=lower,upperdir=upper,workdir=work
    cat upper/ksplice

    tmpdir2=$(mktemp -d)
    pushd ${tmpdir2}

    mkdir -p {upper,work}
    mount -t overlay level_one upper -o lowerdir=${tmpdir}/upper,upperdir=upper,workdir=work
    ls -l upper/ksplice
    cat upper/ksplice
    - 8< - - - - - 8< - - - - - 8< - - - - - 8< - - - -

    Reported-by: Quentin Casasnovas
    Signed-off-by: Miklos Szeredi
    Fixes: 2d902671ce1c ("vfs: merge .d_select_inode() into .d_real()")
    Cc: # v4.8+

    Miklos Szeredi
     

31 Oct, 2016

3 commits

  • Make sure the copied up file hits the disk before renaming to the final
    destination. If this is not done then the copy-up may corrupt the data in
    the file in case of a crash.

    Signed-off-by: Miklos Szeredi
    Cc:

    Miklos Szeredi
     
  • tmpfs doesn't have ->get_acl() because it only uses cached acls.

    This fixes the acl tests in pjdfstest when tmpfs is used as the upper layer
    of the overlay.

    Reported-by: Amir Goldstein
    Signed-off-by: Miklos Szeredi
    Fixes: 39a25b2b3762 ("ovl: define ->get_acl() for overlay inodes")
    Cc: # v4.8

    Miklos Szeredi
     
  • This change fixes xfstest generic/375, which failed to clear the
    setgid bit in the following test case on overlayfs:

    touch $testfile
    chown 100:100 $testfile
    chmod 2755 $testfile
    _runas -u 100 -g 101 -- setfacl -m u::rwx,g::rwx,o::rwx $testfile

    Reported-by: Amir Goldstein
    Signed-off-by: Miklos Szeredi
    Tested-by: Amir Goldstein
    Fixes: d837a49bd57f ("ovl: fix POSIX ACL setting")
    Cc: # v4.8

    Miklos Szeredi
     

15 Oct, 2016

3 commits

  • Pull more misc uaccess and vfs updates from Al Viro:
    "The rest of the stuff from -next (more uaccess work) + assorted fixes"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    score: traps: Add missing include file to fix build error
    fs/super.c: don't fool lockdep in freeze_super() and thaw_super() paths
    fs/super.c: fix race between freeze_super() and thaw_super()
    overlayfs: Fix setting IOP_XATTR flag
    iov_iter: kernel-doc import_iovec() and rw_copy_check_uvector()
    blackfin: no access_ok() for __copy_{to,from}_user()
    arm64: don't zero in __copy_from_user{,_inatomic}
    arm: don't zero in __copy_from_user_inatomic()/__copy_from_user()
    arc: don't leak bits of kernel stack into coredump
    alpha: get rid of tail-zeroing in __copy_user()

    Linus Torvalds
     
  • Pull overlayfs updates from Miklos Szeredi:
    "This update contains fixes to the "use mounter's permission to access
    underlying layers" area, and miscellaneous other fixes and cleanups.

    No new features this time"

    * 'overlayfs-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs:
    ovl: use vfs_get_link()
    vfs: add vfs_get_link() helper
    ovl: use generic_readlink
    ovl: explain error values when removing acl from workdir
    ovl: Fix info leak in ovl_lookup_temp()
    ovl: during copy up, switch to mounter's creds early
    ovl: lookup: do getxattr with mounter's permission
    ovl: copy_up_xattr(): use strnlen

    Linus Torvalds
     
  • ovl_fill_super calls ovl_new_inode to create a root inode for the new
    superblock before initializing sb->s_xattr. This wrongly causes
    IOP_XATTR to be cleared in i_opflags of the new inode, causing SELinux
    to log the following message:

    SELinux: (dev overlay, type overlay) has no xattr support

    Fix this by initializing sb->s_xattr and similar fields before calling
    ovl_new_inode.

    Signed-off-by: Andreas Gruenbacher
    Signed-off-by: Al Viro

    Vivek Goyal
     

14 Oct, 2016

3 commits


11 Oct, 2016

3 commits

  • Pull more vfs updates from Al Viro:
    ">rename2() work from Miklos + current_time() from Deepa"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    fs: Replace current_fs_time() with current_time()
    fs: Replace CURRENT_TIME_SEC with current_time() for inode timestamps
    fs: Replace CURRENT_TIME with current_time() for inode timestamps
    fs: proc: Delete inode time initializations in proc_alloc_inode()
    vfs: Add current_time() api
    vfs: add note about i_op->rename changes to porting
    fs: rename "rename2" i_op to "rename"
    vfs: remove unused i_op->rename
    fs: make remaining filesystems use .rename2
    libfs: support RENAME_NOREPLACE in simple_rename()
    fs: support RENAME_NOREPLACE for local filesystems
    ncpfs: fix unused variable warning

    Linus Torvalds
     
  • Pull vfs xattr updates from Al Viro:
    "xattr stuff from Andreas

    This completes the switch to xattr_handler ->get()/->set() from
    ->getxattr/->setxattr/->removexattr"

    * 'work.xattr' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    vfs: Remove {get,set,remove}xattr inode operations
    xattr: Stop calling {get,set,remove}xattr inode operations
    vfs: Check for the IOP_XATTR flag in listxattr
    xattr: Add __vfs_{get,set,remove}xattr helpers
    libfs: Use IOP_XATTR flag for empty directory handling
    vfs: Use IOP_XATTR flag for bad-inode handling
    vfs: Add IOP_XATTR inode operations flag
    vfs: Move xattr_resolve_name to the front of fs/xattr.c
    ecryptfs: Switch to generic xattr handlers
    sockfs: Get rid of getxattr iop
    sockfs: getxattr: Fail with -EOPNOTSUPP for invalid attribute names
    kernfs: Switch to generic xattr handlers
    hfs: Switch to generic xattr handlers
    jffs2: Remove jffs2_{get,set,remove}xattr macros
    xattr: Remove unnecessary NULL attribute name check

    Linus Torvalds
     
  • Pull misc vfs updates from Al Viro:
    "Assorted misc bits and pieces.

    There are several single-topic branches left after this (rename2
    series from Miklos, current_time series from Deepa Dinamani, xattr
    series from Andreas, uaccess stuff from from me) and I'd prefer to
    send those separately"

    * 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (39 commits)
    proc: switch auxv to use of __mem_open()
    hpfs: support FIEMAP
    cifs: get rid of unused arguments of CIFSSMBWrite()
    posix_acl: uapi header split
    posix_acl: xattr representation cleanups
    fs/aio.c: eliminate redundant loads in put_aio_ring_file
    fs/internal.h: add const to ns_dentry_operations declaration
    compat: remove compat_printk()
    fs/buffer.c: make __getblk_slow() static
    proc: unsigned file descriptors
    fs/file: more unsigned file descriptors
    fs: compat: remove redundant check of nr_segs
    cachefiles: Fix attempt to read i_blocks after deleting file [ver #2]
    cifs: don't use memcpy() to copy struct iov_iter
    get rid of separate multipage fault-in primitives
    fs: Avoid premature clearing of capabilities
    fs: Give dentry to inode_change_ok() instead of inode
    fuse: Propagate dentry down to inode_change_ok()
    ceph: Propagate dentry down to inode_change_ok()
    xfs: Propagate dentry down to inode_change_ok()
    ...

    Linus Torvalds
     

08 Oct, 2016

3 commits


05 Oct, 2016

1 commit

  • Pull security subsystem updates from James Morris:

    SELinux/LSM:
    - overlayfs support, necessary for container filesystems

    LSM:
    - finally remove the kernel_module_from_file hook

    Smack:
    - treat signal delivery as an 'append' operation

    TPM:
    - lots of bugfixes & updates

    Audit:
    - new audit data type: LSM_AUDIT_DATA_FILE

    * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (47 commits)
    Revert "tpm/tpm_crb: implement tpm crb idle state"
    Revert "tmp/tpm_crb: fix Intel PTT hw bug during idle state"
    Revert "tpm/tpm_crb: open code the crb_init into acpi_add"
    Revert "tmp/tpm_crb: implement runtime pm for tpm_crb"
    lsm,audit,selinux: Introduce a new audit data type LSM_AUDIT_DATA_FILE
    tmp/tpm_crb: implement runtime pm for tpm_crb
    tpm/tpm_crb: open code the crb_init into acpi_add
    tmp/tpm_crb: fix Intel PTT hw bug during idle state
    tpm/tpm_crb: implement tpm crb idle state
    tpm: add check for minimum buffer size in tpm_transmit()
    tpm: constify TPM 1.x header structures
    tpm/tpm_crb: fix the over 80 characters checkpatch warring
    tpm/tpm_crb: drop useless cpu_to_le32 when writing to registers
    tpm/tpm_crb: cache cmd_size register value.
    tmp/tpm_crb: drop include to platform_device
    tpm/tpm_tis: remove unused itpm variable
    tpm_crb: fix incorrect values of cmdReady and goIdle bits
    tpm_crb: refine the naming of constants
    tpm_crb: remove wmb()'s
    tpm_crb: fix crb_req_canceled behavior
    ...

    Linus Torvalds
     

27 Sep, 2016

1 commit


22 Sep, 2016

1 commit

  • inode_change_ok() will be resposible for clearing capabilities and IMA
    extended attributes and as such will need dentry. Give it as an argument
    to inode_change_ok() instead of an inode. Also rename inode_change_ok()
    to setattr_prepare() to better relect that it does also some
    modifications in addition to checks.

    Reviewed-by: Christoph Hellwig
    Signed-off-by: Jan Kara

    Jan Kara
     

21 Sep, 2016

1 commit

  • The function uses the memory address of a struct dentry as unique id.
    While the address-based directory entry is only visible to root it is IMHO
    still worth fixing since the temporary name does not have to be a kernel
    address. It can be any unique number. Replace it by an atomic integer
    which is allowed to wrap around.

    Signed-off-by: Richard Weinberger
    Reviewed-by: Kees Cook
    Signed-off-by: Miklos Szeredi
    Cc: # v3.18+
    Fixes: e9be9d5e76e3 ("overlay filesystem")

    Richard Weinberger
     

19 Sep, 2016

1 commit

  • Now, we have the notion that copy up of a file is done with the creds
    of mounter of overlay filesystem (as opposed to task). Right now before
    we switch creds, we do some vfs_getattr() operations in the context of
    task and that itself can fail. We should do that getattr() using the
    creds of mounter instead.

    So this patch switches to mounter's creds early during copy up process so
    that even vfs_getattr() is done with mounter's creds.

    Do not call revert_creds() unless we have already called
    ovl_override_creds(). [Reported by Arnd Bergmann]

    Signed-off-by: Vivek Goyal
    Signed-off-by: Miklos Szeredi

    Vivek Goyal
     

16 Sep, 2016

3 commits

  • The getxattr() in ovl_is_opaquedir() was missed when converting all
    operations on underlying fs to be done under mounter's permission.

    This patch fixes this by moving the ovl_override_creds()/revert_creds() out
    from ovl_lookup_real() to ovl_lookup().

    Also convert to using vfs_getxattr() instead of directly calling
    i_op->getxattr().

    Signed-off-by: Miklos Szeredi

    Miklos Szeredi
     
  • Be defensive about what underlying fs provides us in the returned xattr
    list buffer. strlen() may overrun the buffer, so use strnlen() and WARN if
    the contents are not properly null terminated.

    Signed-off-by: Miklos Szeredi
    Cc:

    Miklos Szeredi
     
  • This patch allows flock, posix locks, ofd locks and leases to work
    correctly on overlayfs.

    Instead of using the underlying inode for storing lock context use the
    overlay inode. This allows locks to be persistent across copy-up.

    This is done by introducing locks_inode() helper and using it instead of
    file_inode() to get the inode in locking code. For non-overlayfs the two
    are equivalent, except for an extra pointer dereference in locks_inode().

    Since lock operations are in "struct file_operations" we must also make
    sure not to call underlying filesystem's lock operations. Introcude a
    super block flag MS_NOREMOTELOCK to this effect.

    Signed-off-by: Miklos Szeredi
    Acked-by: Jeff Layton
    Cc: "J. Bruce Fields"

    Miklos Szeredi
     

05 Sep, 2016

1 commit

  • Workdir creation fails in latest kernel.

    Fix by allowing EOPNOTSUPP as a valid return value from
    vfs_removexattr(XATTR_NAME_POSIX_ACL_*). Upper filesystem may not support
    ACL and still be perfectly able to support overlayfs.

    Reported-by: Martin Ziegler
    Signed-off-by: Miklos Szeredi
    Fixes: c11b9fdd6a61 ("ovl: remove posix_acl_default from workdir")
    Cc:

    Miklos Szeredi
     

01 Sep, 2016

12 commits

  • Be defensive about what underlying fs provides us in the returned xattr
    list buffer. If it's not properly null terminated, bail out with a warning
    insead of BUG.

    Signed-off-by: Miklos Szeredi
    Cc:

    Miklos Szeredi
     
  • Now that overlayfs has xattr handlers for iop->{set,remove}xattr, use
    those same handlers for iop->getxattr as well.

    Signed-off-by: Andreas Gruenbacher
    Signed-off-by: Miklos Szeredi

    Andreas Gruenbacher
     
  • Setting POSIX acl may also modify the file mode, so need to copy that up to
    the overlay inode.

    Reported-by: Eryu Guan
    Fixes: d837a49bd57f ("ovl: fix POSIX ACL setting")
    Signed-off-by: Miklos Szeredi

    Miklos Szeredi
     
  • Commit d837a49bd57f ("ovl: fix POSIX ACL setting") switches from
    iop->setxattr from ovl_setxattr to generic_setxattr, so switch from
    ovl_removexattr to generic_removexattr as well. As far as permission
    checking goes, the same rules should apply in either case.

    While doing that, rename ovl_setxattr to ovl_xattr_set to indicate that
    this is not an iop->setxattr implementation and remove the unused inode
    argument.

    Move ovl_other_xattr_set above ovl_own_xattr_set so that they match the
    order of handlers in ovl_xattr_handlers.

    Signed-off-by: Andreas Gruenbacher
    Fixes: d837a49bd57f ("ovl: fix POSIX ACL setting")
    Signed-off-by: Miklos Szeredi

    Andreas Gruenbacher
     
  • Use an ordinary #ifdef to conditionally include the POSIX ACL handlers
    in ovl_xattr_handlers, like the other filesystems do. Flag the code
    that is now only used conditionally with __maybe_unused.

    Signed-off-by: Andreas Gruenbacher
    Signed-off-by: Miklos Szeredi

    Andreas Gruenbacher
     
  • Make sure ovl_own_xattr_handler only matches attribute names starting
    with "overlay.", not "overlayXXX".

    Signed-off-by: Andreas Gruenbacher
    Fixes: d837a49bd57f ("ovl: fix POSIX ACL setting")
    Signed-off-by: Miklos Szeredi

    Andreas Gruenbacher
     
  • Trivial fix to spelling mistake in pr_err message.

    Signed-off-by: Colin Ian King
    Signed-off-by: Miklos Szeredi

    Colin Ian King
     
  • Some operations (setxattr/chmod) can make the cached acl stale. We either
    need to clear overlay's acl cache for the affected inode or prevent acl
    caching on the overlay altogether. Preventing caching has the following
    advantages:

    - no double caching, less memory used

    - overlay cache doesn't go stale when fs clears it's own cache

    Possible disadvantage is performance loss. If that becomes a problem
    get_acl() can be optimized for overlayfs.

    This patch disables caching by pre setting i_*acl to a value that

    - has bit 0 set, so is_uncached_acl() will return true

    - is not equal to ACL_NOT_CACHED, so get_acl() will not overwrite it

    The constant -3 was chosen for this purpose.

    Fixes: 39a25b2b3762 ("ovl: define ->get_acl() for overlay inodes")
    Signed-off-by: Miklos Szeredi

    Miklos Szeredi
     
  • Instead of calling ->get_acl() directly, use get_acl() to get the cached
    value.

    We will have the acl cached on the underlying inode anyway, because we do
    permission checking on the both the overlay and the underlying fs.

    So, since we already have double caching, this improves performance without
    any cost.

    Signed-off-by: Miklos Szeredi

    Miklos Szeredi
     
  • When mounting overlayfs it needs a clean "work" directory under the
    supplied workdir.

    Previously the mount code removed this directory if it already existed and
    created a new one. If the removal failed (e.g. directory was not empty)
    then it fell back to a read-only mount not using the workdir.

    While this has never been reported, it is possible to get a non-empty
    "work" dir from a previous mount of overlayfs in case of crash in the
    middle of an operation using the work directory.

    In this case the left over state should be discarded and the overlay
    filesystem will be consistent, guaranteed by the atomicity of operations on
    moving to/from the workdir to the upper layer.

    This patch implements cleaning out any files left in workdir. It is
    implemented using real recursion for simplicity, but the depth is limited
    to 2, because the worst case is that of a directory containing whiteouts
    under "work".

    Signed-off-by: Miklos Szeredi
    Cc:

    Miklos Szeredi
     
  • Clear out posix acl xattrs on workdir and also reset the mode after
    creation so that an inherited sgid bit is cleared.

    Signed-off-by: Miklos Szeredi
    Cc:

    Miklos Szeredi
     
  • Setting MS_POSIXACL in sb->s_flags has the side effect of passing mode to
    create functions without masking against umask.

    Another problem when creating over a whiteout is that the default posix acl
    is not inherited from the parent dir (because the real parent dir at the
    time of creation is the work directory).

    Fix these problems by:

    a) If upper fs does not have MS_POSIXACL, then mask mode with umask.

    b) If creating over a whiteout, call posix_acl_create() to get the
    inherited acls. After creation (but before moving to the final
    destination) set these acls on the created file. posix_acl_create() also
    updates the file creation mode as appropriate.

    Fixes: 39a25b2b3762 ("ovl: define ->get_acl() for overlay inodes")
    Signed-off-by: Miklos Szeredi

    Miklos Szeredi
     

09 Aug, 2016

3 commits

  • During a new file creation we need to make sure new file is created with the
    right label. New file is created in upper/ so effectively file should get
    label as if task had created file in upper/.

    We switched to mounter's creds for actual file creation. Also if there is a
    whiteout present, then file will be created in work/ dir first and then
    renamed in upper. In none of the cases file will be labeled as we want it to
    be.

    This patch introduces a new hook dentry_create_files_as(), which determines
    the label/context dentry will get if it had been created by task in upper
    and modify passed set of creds appropriately. Caller makes use of these new
    creds for file creation.

    Signed-off-by: Vivek Goyal
    Acked-by: Stephen Smalley
    [PM: fix whitespace issues found with checkpatch.pl]
    [PM: changes to use stat->mode in ovl_create_or_link()]
    Signed-off-by: Paul Moore

    Vivek Goyal
     
  • Provide a security hook which is called when xattrs of a file are being
    copied up. This hook is called once for each xattr and LSM can return
    0 if the security module wants the xattr to be copied up, 1 if the
    security module wants the xattr to be discarded on the copy, -EOPNOTSUPP
    if the security module does not handle/manage the xattr, or a -errno
    upon an error.

    Signed-off-by: David Howells
    Signed-off-by: Vivek Goyal
    Acked-by: Stephen Smalley
    [PM: whitespace cleanup for checkpatch.pl]
    Signed-off-by: Paul Moore

    Vivek Goyal
     
  • Provide a security hook to label new file correctly when a file is copied
    up from lower layer to upper layer of a overlay/union mount.

    This hook can prepare a new set of creds which are suitable for new file
    creation during copy up. Caller will use new creds to create file and then
    revert back to old creds and release new creds.

    Signed-off-by: Vivek Goyal
    Acked-by: Stephen Smalley
    [PM: whitespace cleanup to appease checkpatch.pl]
    Signed-off-by: Paul Moore

    Vivek Goyal