Commits on Dec 14, 2017
  1. ovl: fix overlay: warning prefix

    amir73il committed with Miklos Szeredi Nov 22, 2017
    Conform two stray warning messages to the standard overlayfs: prefix.
    
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Commits on Dec 11, 2017
  1. ovl: Use PTR_ERR_OR_ZERO()

    gomonovych committed with Miklos Szeredi Nov 27, 2017
    Fix ptr_ret.cocci warnings:
    fs/overlayfs/overlayfs.h:179:11-17: WARNING: PTR_ERR_OR_ZERO can be used
    
    Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR
    
    Generated by: scripts/coccinelle/api/ptr_ret.cocci
    
    Signed-off-by: Vasyl Gomonovych <gomonovych@gmail.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  2. ovl: Sync upper dirty data when syncing overlayfs

    Chengguang Xu committed with Miklos Szeredi Nov 29, 2017
    When executing filesystem sync or umount on overlayfs,
    dirty data does not get synced as expected on upper filesystem.
    This patch fixes sync filesystem method to keep data consistency
    for overlayfs.
    
    Signed-off-by: Chengguang Xu <cgxu@mykernel.net>
    Fixes: e593b2b ("ovl: properly implement sync_filesystem()")
    Cc: <stable@vger.kernel.org> #4.11
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  3. ovl: update ctx->pos on impure dir iteration

    amir73il committed with Miklos Szeredi Nov 29, 2017
    This fixes a regression with readdir of impure dir in overlayfs
    that is shared to VM via 9p fs.
    
    Reported-by: Miguel Bernal Marin <miguel.bernal.marin@linux.intel.com>
    Fixes: 4edb83b ("ovl: constant d_ino for non-merge dirs")
    Cc: <stable@vger.kernel.org> #4.14
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Tested-by: Miguel Bernal Marin <miguel.bernal.marin@linux.intel.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  4. ovl: Pass ovl_get_nlink() parameters in right order

    rhvgoyal committed with Miklos Szeredi Nov 27, 2017
    Right now we seem to be passing index as "lowerdentry" and origin.dentry
    as "upperdentry". IIUC, we should pass these parameters in reversed order
    and this looks like a bug.
    
    Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
    Acked-by: Amir Goldstein <amir73il@gmail.com>
    Fixes: caf70cb ("ovl: cleanup orphan index entries")
    Cc: <stable@vger.kernel.org> #v4.13
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  5. ovl: don't follow redirects if redirect_dir=off

    Miklos Szeredi committed Dec 11, 2017
    Overlayfs is following redirects even when redirects are disabled. If this
    is unintentional (probably the majority of cases) then this can be a
    problem.  E.g. upper layer comes from untrusted USB drive, and attacker
    crafts a redirect to enable read access to otherwise unreadable
    directories.
    
    If "redirect_dir=off", then turn off following as well as creation of
    redirects.  If "redirect_dir=follow", then turn on following, but turn off
    creation of redirects (which is what "redirect_dir=off" does now).
    
    This is a backward incompatible change, so make it dependent on a config
    option.
    
    Reported-by: David Howells <dhowells@redhat.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Commits on Nov 27, 2017
  1. Rename superblock flags (MS_xyz -> SB_xyz)

    torvalds committed Nov 27, 2017
    This is a pure automated search-and-replace of the internal kernel
    superblock flags.
    
    The s_flags are now called SB_*, with the names and the values for the
    moment mirroring the MS_* flags that they're equivalent to.
    
    Note how the MS_xyz flags are the ones passed to the mount system call,
    while the SB_xyz flags are what we then use in sb->s_flags.
    
    The script to do this was:
    
        # places to look in; re security/*: it generally should *not* be
        # touched (that stuff parses mount(2) arguments directly), but
        # there are two places where we really deal with superblock flags.
        FILES="drivers/mtd drivers/staging/lustre fs ipc mm \
                include/linux/fs.h include/uapi/linux/bfs_fs.h \
                security/apparmor/apparmorfs.c security/apparmor/include/lib.h"
        # the list of MS_... constants
        SYMS="RDONLY NOSUID NODEV NOEXEC SYNCHRONOUS REMOUNT MANDLOCK \
              DIRSYNC NOATIME NODIRATIME BIND MOVE REC VERBOSE SILENT \
              POSIXACL UNBINDABLE PRIVATE SLAVE SHARED RELATIME KERNMOUNT \
              I_VERSION STRICTATIME LAZYTIME SUBMOUNT NOREMOTELOCK NOSEC BORN \
              ACTIVE NOUSER"
    
        SED_PROG=
        for i in $SYMS; do SED_PROG="$SED_PROG -e s/MS_$i/SB_$i/g"; done
    
        # we want files that contain at least one of MS_...,
        # with fs/namespace.c and fs/pnode.c excluded.
        L=$(for i in $SYMS; do git grep -w -l MS_$i $FILES; done| sort|uniq|grep -v '^fs/namespace.c'|grep -v '^fs/pnode.c')
    
        for f in $L; do sed -i $f $SED_PROG; done
    
    Requested-by: Al Viro <viro@zeniv.linux.org.uk>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Commits on Nov 17, 2017
  1. Merge branch 'overlayfs-linus' of git://git.kernel.org/pub/scm/linux/…

    torvalds committed Nov 17, 2017
    …kernel/git/mszeredi/vfs
    
    Pull overlayfs updates from Miklos Szeredi:
    
     - Report constant st_ino values across copy-up even if underlying
       layers are on different filesystems, but using different st_dev
       values for each layer.
    
       Ideally we'd report the same st_dev across the overlay, and it's
       possible to do for filesystems that use only 32bits for st_ino by
       unifying the inum space. It would be nice if it wasn't a choice of 32
       or 64, rather filesystems could report their current maximum (that
       could change on resize, so it wouldn't be set in stone).
    
     - miscellaneus fixes and a cleanup of ovl_fill_super(), that was long
       overdue.
    
     - created a path_put_init() helper that clears out the pointers after
       putting the ref.
    
       I think this could be useful elsewhere, so added it to <linux/path.h>
    
    * 'overlayfs-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs: (30 commits)
      ovl: remove unneeded arg from ovl_verify_origin()
      ovl: Put upperdentry if ovl_check_origin() fails
      ovl: rename ufs to ofs
      ovl: clean up getting lower layers
      ovl: clean up workdir creation
      ovl: clean up getting upper layer
      ovl: move ovl_get_workdir() and ovl_get_lower_layers()
      ovl: reduce the number of arguments for ovl_workdir_create()
      ovl: change order of setup in ovl_fill_super()
      ovl: factor out ovl_free_fs() helper
      ovl: grab reference to workbasedir early
      ovl: split out ovl_get_indexdir() from ovl_fill_super()
      ovl: split out ovl_get_lower_layers() from ovl_fill_super()
      ovl: split out ovl_get_workdir() from ovl_fill_super()
      ovl: split out ovl_get_upper() from ovl_fill_super()
      ovl: split out ovl_get_lowerstack() from ovl_fill_super()
      ovl: split out ovl_get_workpath() from ovl_fill_super()
      ovl: split out ovl_get_upperpath() from ovl_fill_super()
      ovl: use path_put_init() in error paths for ovl_fill_super()
      vfs: add path_put_init()
      ...
Commits on Nov 10, 2017
  1. ovl: remove unneeded arg from ovl_verify_origin()

    amir73il committed with Miklos Szeredi Sep 24, 2017
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  2. ovl: Put upperdentry if ovl_check_origin() fails

    rhvgoyal committed with Miklos Szeredi Nov 1, 2017
    If ovl_check_origin() fails, we should put upperdentry. We have a reference
    on it by now. So goto out_put_upper instead of out.
    
    Fixes: a9d0195 ("ovl: lookup non-dir copy-up-origin by file handle")
    Cc: <stable@vger.kernel.org> #4.12
    Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  3. ovl: rename ufs to ofs

    Miklos Szeredi committed Nov 10, 2017
    Rename all "struct ovl_fs" pointers to "ofs".  The "ufs" name is historical
    and can only be found in overlayfs/super.c.
    
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  4. ovl: clean up getting lower layers

    Miklos Szeredi committed Nov 10, 2017
    Move calling ovl_get_lower_layers() into ovl_get_lowerstack().
    
    ovl_get_lowerstack() now returns the root dentry's filled in ovl_entry.
    
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  5. ovl: clean up workdir creation

    Miklos Szeredi committed Nov 10, 2017
    Move calling ovl_get_workdir() into ovl_get_workpath().
    
    Rename ovl_get_workdir() to ovl_make_workdir() and ovl_get_workpath() to
    ovl_get_workdir().
    
    Workpath is now not needed outside ovl_get_workdir().
    
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  6. ovl: clean up getting upper layer

    Miklos Szeredi committed Nov 10, 2017
    Merge ovl_get_upper() and ovl_get_upperpath().
    
    The resulting function is named ovl_get_upper(), though it still returns
    upperpath as well.
    
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  7. ovl: move ovl_get_workdir() and ovl_get_lower_layers()

    Miklos Szeredi committed Nov 10, 2017
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  8. ovl: reduce the number of arguments for ovl_workdir_create()

    Miklos Szeredi committed Nov 10, 2017
    Remove "sb" and "dentry" arguments of ovl_workdir_create() and related
    functions.  Move setting MS_RDONLY flag to callers.
    
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  9. ovl: change order of setup in ovl_fill_super()

    Miklos Szeredi committed Nov 10, 2017
    Move ovl_get_upper() immediately after ovl_get_upperpath(),
    ovl_get_workdir() immediately after ovl_get_workdir() and
    ovl_get_lower_layers() immediately after ovl_get_lowerstack().
    
    Also move prepare_creds() up to where other allocations are happening.
    
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  10. ovl: factor out ovl_free_fs() helper

    Miklos Szeredi committed Nov 10, 2017
    This can be called both from ovl_put_super() and in the error cleanup path
    from ovl_fill_super().
    
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Commits on Nov 9, 2017
  1. ovl: grab reference to workbasedir early

    Miklos Szeredi committed Nov 9, 2017
    and related cleanups.
    
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  2. ovl: split out ovl_get_indexdir() from ovl_fill_super()

    Miklos Szeredi committed Nov 9, 2017
    It's okay to get rid of the intermediate error label due to ufs being
    zeroed on allocation.
    
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  3. ovl: split out ovl_get_lower_layers() from ovl_fill_super()

    Miklos Szeredi committed Nov 9, 2017
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  4. ovl: split out ovl_get_workdir() from ovl_fill_super()

    Miklos Szeredi committed Nov 9, 2017
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  5. ovl: split out ovl_get_upper() from ovl_fill_super()

    Miklos Szeredi committed Nov 9, 2017
    And don't clobber ufs->upper_mnt on error.
    
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  6. ovl: split out ovl_get_lowerstack() from ovl_fill_super()

    Miklos Szeredi committed Nov 9, 2017
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  7. ovl: split out ovl_get_workpath() from ovl_fill_super()

    Miklos Szeredi committed Nov 9, 2017
    It's okay to get rid of the intermediate error label due to ufs being
    zeroed on allocation.
    
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  8. ovl: split out ovl_get_upperpath() from ovl_fill_super()

    Miklos Szeredi committed Nov 9, 2017
    It's okay to get rid of the intermediate error label due to ufs being
    zeroed on allocation.
    
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  9. ovl: use path_put_init() in error paths for ovl_fill_super()

    Miklos Szeredi committed Nov 9, 2017
    This allows simplifying the error cleanup later.
    
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  10. ovl: update cache version of impure parent on rename

    amir73il committed with Miklos Szeredi Nov 1, 2017
    ovl_rename() updates dir cache version for impure old parent if an entry
    with copy up origin is moved into old parent, but it did not update
    cache version if the entry moved out of old parent has a copy up origin.
    
    [SzM] Same for new dir: we updated the version if an entry with origin was
    moved in, but not if an entry with origin was moved out.
    
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  11. ovl: relax same fs constraint for constant st_ino

    amir73il committed with Miklos Szeredi Oct 31, 2017
    For the case of all layers not on the same fs, return the copy up origin
    inode st_dev/st_ino for non-dir from stat(2).
    
    This guaranties constant st_dev/st_ino for non-dir across copy up.
    Like the same fs case, st_ino of non-dir is also persistent.
    
    If the st_dev/st_ino for copied up object would have been the same as
    that of the real underlying lower file, running diff on underlying lower
    file and overlay copied up file would result in diff reporting that the
    two files are equal when in fact, they may have different content.
    
    Therefore, unlike the same fs case, st_dev is not persistent because it
    uses the unique anonymous bdev allocated for the lower layer.
    
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  12. ovl: return anonymous st_dev for lower inodes

    chandanr committed with Miklos Szeredi Jul 24, 2017
    For non-samefs setup, to make sure that st_dev/st_ino pair is unique
    across the system, we return a unique anonymous st_dev for stat(2)
    of lower layer inode.
    
    A following patch is going to fix constant st_dev/st_ino across copy up
    by returning origin st_dev/st_ino for copied up objects.
    
    If the st_dev/st_ino for copied up object would have been the same as
    that of the real underlying lower file, running diff on underlying lower
    file and overlay copied up file would result in diff reporting that the
    2 files are equal when in fact, they may have different content.
    
    [amir: simplify ovl_get_pseudo_dev()
           split from allocate anonymous bdev patch]
    
    Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  13. ovl: allocate anonymous devs for lowerdirs

    chandanr committed with Miklos Szeredi Nov 1, 2017
    Generate unique values of st_dev per lower layer for non-samefs
    overlay mount. The unique values are obtained by allocating anonymous
    bdevs for each of the lowerdirs in the overlayfs instance.
    
    The anonymous bdev is going to be returned by stat(2) for lowerdir
    non-dir entries in non-samefs case.
    
    [amir: split from ovl_getattr() and re-structure patches]
    
    Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  14. ovl: re-structure overlay lower layers in-memory

    chandanr committed with Miklos Szeredi Jul 24, 2017
    Define new structures to represent overlay instance lower layers and
    overlay merge dir lower layers to make room for storing more per layer
    information in-memory.
    
    Instead of keeping the fs instance lower layers in an array of struct
    vfsmount, keep them in an array of new struct ovl_layer, that has a
    pointer to struct vfsmount.
    
    Instead of keeping the dentry lower layers in an array of struct path,
    keep them in an array of new struct ovl_path, that has a pointer to
    struct dentry and to struct ovl_layer.
    
    Add a small helper to find the fs layer id that correspopnds to a lower
    struct ovl_path and use it in ovl_lookup().
    
    [amir: split re-structure from anonymous bdev patch]
    
    Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  15. ovl: move include of ovl_entry.h into overlayfs.h

    amir73il committed with Miklos Szeredi Oct 30, 2017
    Most overlayfs c files already explicitly include ovl_entry.h
    to use overlay entry struct definitions and upcoming changes
    are going to require even more c files to include this header.
    
    All overlayfs c files include overlayfs.h and overlayfs.h itself
    refers to some structs defined in ovl_entry.h, so it seems more
    logic to include ovl_entry.h from overlayfs.h than from c files.
    
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  16. ovl: fix rmdir problem on non-merge dir with origin xattr

    zhangyi (F) committed with Miklos Szeredi Jul 4, 2017
    An "origin && non-merge" upper dir may have leftover whiteouts that
    were created in past mount. overlayfs does no clear this dir when we
    delete it, which may lead to rmdir fail or temp file left in workdir.
    
    Simple reproducer:
      mkdir lower upper work merge
      mkdir -p lower/dir
      touch lower/dir/a
      mount -t overlay overlay -olowerdir=lower,upperdir=upper,\
        workdir=work merge
      rm merge/dir/a
      umount merge
      rm -rf lower/*
      touch lower/dir  (*)
      mount -t overlay overlay -olowerdir=lower,upperdir=upper,\
        workdir=work merge
      rm -rf merge/dir
    
    Syslog dump:
      overlayfs: cleanup of 'work/#7' failed (-39)
    
    (*): if we do not create the regular file, the result is different:
      rm: cannot remove "dir/": Directory not empty
    
    This patch adds a check for the case of non-merge dir that may contain
    whiteouts, and calls ovl_check_empty_dir() to check and clear whiteouts
    from upper dir when an empty dir is being deleted.
    
    [amir: split patch from ovl_check_empty_dir() cleanup
           rename ovl_is_origin() to ovl_may_have_whiteouts()
           check OVL_WHITEOUTS flag instead of checking origin xattr]
    
    Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  17. ovl: simplify ovl_check_empty_and_clear()

    zhangyi (F) committed with Miklos Szeredi Oct 31, 2017
    Filter out non-whiteout non-upper entries from list of merge dir entries
    while checking if merge dir is empty in ovl_check_empty_dir().
    The remaining work for ovl_clear_empty() is to clear all entries on the
    list.
    
    [amir: split patch from rmdir bug fix]
    
    Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>