1. 16 5月, 2023 1 次提交
  2. 14 1月, 2022 1 次提交
  3. 03 6月, 2021 1 次提交
  4. 09 3月, 2021 1 次提交
    • S
      ovl: implement volatile-specific fsync error behaviour · 05fd80bb
      Sargun Dhillon 提交于
      stable inclusion
      from stable-5.10.15
      commit 8ccf963c6227ff1feb2db6b1bdcb5243f7f38067
      bugzilla: 48167
      
      --------------------------------
      
      commit 335d3fc5 upstream.
      
      Overlayfs's volatile option allows the user to bypass all forced sync calls
      to the upperdir filesystem. This comes at the cost of safety. We can never
      ensure that the user's data is intact, but we can make a best effort to
      expose whether or not the data is likely to be in a bad state.
      
      The best way to handle this in the time being is that if an overlayfs's
      upperdir experiences an error after a volatile mount occurs, that error
      will be returned on fsync, fdatasync, sync, and syncfs. This is
      contradictory to the traditional behaviour of VFS which fails the call
      once, and only raises an error if a subsequent fsync error has occurred,
      and been raised by the filesystem.
      
      One awkward aspect of the patch is that we have to manually set the
      superblock's errseq_t after the sync_fs callback as opposed to just
      returning an error from syncfs. This is because the call chain looks
      something like this:
      
      sys_syncfs ->
      	sync_filesystem ->
      		__sync_filesystem ->
      			/* The return value is ignored here
      			sb->s_op->sync_fs(sb)
      			_sync_blockdev
      		/* Where the VFS fetches the error to raise to userspace */
      		errseq_check_and_advance
      
      Because of this we call errseq_set every time the sync_fs callback occurs.
      Due to the nature of this seen / unseen dichotomy, if the upperdir is an
      inconsistent state at the initial mount time, overlayfs will refuse to
      mount, as overlayfs cannot get a snapshot of the upperdir's errseq that
      will increment on error until the user calls syncfs.
      Signed-off-by: NSargun Dhillon <sargun@sargun.me>
      Suggested-by: NAmir Goldstein <amir73il@gmail.com>
      Reviewed-by: NAmir Goldstein <amir73il@gmail.com>
      Fixes: c86243b0 ("ovl: provide a mount option "volatile"")
      Cc: stable@vger.kernel.org
      Reviewed-by: NVivek Goyal <vgoyal@redhat.com>
      Reviewed-by: NJeff Layton <jlayton@kernel.org>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      05fd80bb
  5. 06 10月, 2020 1 次提交
  6. 02 9月, 2020 5 次提交
  7. 16 7月, 2020 1 次提交
  8. 04 6月, 2020 1 次提交
  9. 03 6月, 2020 1 次提交
    • A
      ovl: fix out of bounds access warning in ovl_check_fb_len() · 522f6e6c
      Amir Goldstein 提交于
      syzbot reported out of bounds memory access from open_by_handle_at()
      with a crafted file handle that looks like this:
      
        { .handle_bytes = 2, .handle_type = OVL_FILEID_V1 }
      
      handle_bytes gets rounded down to 0 and we end up calling:
        ovl_check_fh_len(fh, 0) => ovl_check_fb_len(fh + 3, -3)
      
      But fh buffer is only 2 bytes long, so accessing struct ovl_fb at
      fh + 3 is illegal.
      
      Fixes: cbe7fba8 ("ovl: make sure that real fid is 32bit aligned in memory")
      Reported-and-tested-by: syzbot+61958888b1c60361a791@syzkaller.appspotmail.com
      Cc: <stable@vger.kernel.org> # v5.5
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      522f6e6c
  10. 13 5月, 2020 2 次提交
  11. 27 3月, 2020 1 次提交
    • A
      ovl: enable xino automatically in more cases · 926e94d7
      Amir Goldstein 提交于
      So far, with xino=auto, we only enable xino if we know that all
      underlying filesystem use 32bit inode numbers.
      
      When users configure overlay with xino=auto, they already declare that
      they are ready to handle 64bit inode number from overlay.
      
      It is a very common case, that underlying filesystem uses 64bit ino,
      but rarely or never uses the high inode number bits (e.g. tmpfs, xfs).
      Leaving it for the users to declare high ino bits are unused with
      xino=on is not a recipe for many users to enjoy the benefits of xino.
      
      There appears to be very little reason not to enable xino when users
      declare xino=auto even if we do not know how many bits underlying
      filesystem uses for inode numbers.
      
      In the worst case of xino bits overflow by real inode number, we
      already fall back to the non-xino behavior - real inode number with
      unique pseudo dev or to non persistent inode number and overlay st_dev
      (for directories).
      
      The only annoyance from auto enabling xino is that xino bits overflow
      emits a warning to kmsg. Suppress those warnings unless users explicitly
      asked for xino=on, suggesting that they expected high ino bits to be
      unused by underlying filesystem.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      926e94d7
  12. 17 3月, 2020 4 次提交
  13. 12 3月, 2020 1 次提交
  14. 24 1月, 2020 3 次提交
    • J
      ovl: implement async IO routines · 2406a307
      Jiufei Xue 提交于
      A performance regression was observed since linux v4.19 with aio test using
      fio with iodepth 128 on overlayfs.  The queue depth of the device was
      always 1 which is unexpected.
      
      After investigation, it was found that commit 16914e6f ("ovl: add
      ovl_read_iter()") and commit 2a92e07e ("ovl: add ovl_write_iter()")
      resulted in vfs_iter_{read,write} being called on underlying filesystem,
      which always results in syncronous IO.
      
      Implement async IO for stacked reading and writing.  This resolves the
      performance regresion.
      
      This is implemented by allocating a new kiocb for submitting the AIO
      request on the underlying filesystem.  When the request is completed, the
      new kiocb is freed and the completion callback is called on the original
      iocb.
      Signed-off-by: NJiufei Xue <jiufei.xue@linux.alibaba.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      2406a307
    • M
      ovl: layer is const · 13464165
      Miklos Szeredi 提交于
      The ovl_layer struct is never modified except at initialization.
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      13464165
    • A
      ovl: simplify ovl_same_sb() helper · 0f831ec8
      Amir Goldstein 提交于
      No code uses the sb returned from this helper, so make it retrun a boolean
      and rename it to ovl_same_fs().
      
      The xino mode is irrelevant when all layers are on same fs, so instead of
      describing samefs with mode OVL_XINO_OFF, use a new xino_mode state, which
      is 0 in the case of samefs, -1 in the case of xino=off and > 0 with xino
      enabled.
      
      Create a new helper ovl_same_dev(), to use instead of the common check for
      (ovl_same_fs() || xinobits).
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      0f831ec8
  15. 23 1月, 2020 1 次提交
  16. 10 12月, 2019 1 次提交
    • A
      ovl: make sure that real fid is 32bit aligned in memory · cbe7fba8
      Amir Goldstein 提交于
      Seprate on-disk encoding from in-memory and on-wire resresentation
      of overlay file handle.
      
      In-memory and on-wire we only ever pass around pointers to struct
      ovl_fh, which encapsulates at offset 3 the on-disk format struct
      ovl_fb. struct ovl_fb encapsulates at offset 21 the real file handle.
      That makes sure that the real file handle is always 32bit aligned
      in-memory when passed down to the underlying filesystem.
      
      On-disk format remains the same and store/load are done into
      correctly aligned buffer.
      
      New nfs exported file handles are exported with aligned real fid.
      Old nfs file handles are copied to an aligned buffer before being
      decoded.
      Reported-by: NAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      cbe7fba8
  17. 19 6月, 2019 1 次提交
  18. 29 5月, 2019 1 次提交
    • A
      ovl: detect overlapping layers · 146d62e5
      Amir Goldstein 提交于
      Overlapping overlay layers are not supported and can cause unexpected
      behavior, but overlayfs does not currently check or warn about these
      configurations.
      
      User is not supposed to specify the same directory for upper and
      lower dirs or for different lower layers and user is not supposed to
      specify directories that are descendants of each other for overlay
      layers, but that is exactly what this zysbot repro did:
      
          https://syzkaller.appspot.com/x/repro.syz?x=12c7a94f400000
      
      Moving layer root directories into other layers while overlayfs
      is mounted could also result in unexpected behavior.
      
      This commit places "traps" in the overlay inode hash table.
      Those traps are dummy overlay inodes that are hashed by the layers
      root inodes.
      
      On mount, the hash table trap entries are used to verify that overlay
      layers are not overlapping.  While at it, we also verify that overlay
      layers are not overlapping with directories "in-use" by other overlay
      instances as upperdir/workdir.
      
      On lookup, the trap entries are used to verify that overlay layers
      root inodes have not been moved into other layers after mount.
      
      Some examples:
      
      $ ./run --ov --samefs -s
      ...
      ( mkdir -p base/upper/0/u base/upper/0/w base/lower lower upper mnt
        mount -o bind base/lower lower
        mount -o bind base/upper upper
        mount -t overlay none mnt ...
              -o lowerdir=lower,upperdir=upper/0/u,workdir=upper/0/w)
      
      $ umount mnt
      $ mount -t overlay none mnt ...
              -o lowerdir=base,upperdir=upper/0/u,workdir=upper/0/w
      
        [   94.434900] overlayfs: overlapping upperdir path
        mount: mount overlay on mnt failed: Too many levels of symbolic links
      
      $ mount -t overlay none mnt ...
              -o lowerdir=upper/0/u,upperdir=upper/0/u,workdir=upper/0/w
      
        [  151.350132] overlayfs: conflicting lowerdir path
        mount: none is already mounted or mnt busy
      
      $ mount -t overlay none mnt ...
              -o lowerdir=lower:lower/a,upperdir=upper/0/u,workdir=upper/0/w
      
        [  201.205045] overlayfs: overlapping lowerdir path
        mount: mount overlay on mnt failed: Too many levels of symbolic links
      
      $ mount -t overlay none mnt ...
              -o lowerdir=lower,upperdir=upper/0/u,workdir=upper/0/w
      $ mv base/upper/0/ base/lower/
      $ find mnt/0
        mnt/0
        mnt/0/w
        find: 'mnt/0/w/work': Too many levels of symbolic links
        find: 'mnt/0/u': Too many levels of symbolic links
      
      Reported-by: syzbot+9c69c282adc4edd2b540@syzkaller.appspotmail.com
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      146d62e5
  19. 06 5月, 2019 1 次提交
    • A
      ovl: fix missing upper fs freeze protection on copy up for ioctl · 3428030d
      Amir Goldstein 提交于
      Generalize the helper ovl_open_maybe_copy_up() and use it to copy up file
      with data before FS_IOC_SETFLAGS ioctl.
      
      The FS_IOC_SETFLAGS ioctl is a bit of an odd ball in vfs, which probably
      caused the confusion.  File may be open O_RDONLY, but ioctl modifies the
      file.  VFS does not call mnt_want_write_file() nor lock inode mutex, but
      fs-specific code for FS_IOC_SETFLAGS does.  So ovl_ioctl() calls
      mnt_want_write_file() for the overlay file, and fs-specific code calls
      mnt_want_write_file() for upper fs file, but there was no call for
      ovl_want_write() for copy up duration which prevents overlayfs from copying
      up on a frozen upper fs.
      
      Fixes: dab5ca8f ("ovl: add lsattr/chattr support")
      Cc: <stable@vger.kernel.org> # v4.19
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Acked-by: NVivek Goyal <vgoyal@redhat.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      3428030d
  20. 13 2月, 2019 1 次提交
  21. 27 10月, 2018 2 次提交
  22. 04 10月, 2018 1 次提交
  23. 20 7月, 2018 7 次提交
    • V
      ovl: add helper to force data copy-up · d1e6f6a9
      Vivek Goyal 提交于
      Signed-off-by: NVivek Goyal <vgoyal@redhat.com>
      Reviewed-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      d1e6f6a9
    • V
      ovl: Check redirect on index as well · 0a2d0d3f
      Vivek Goyal 提交于
      Right now we seem to check redirect only if upperdentry is found.  But it
      is possible that there is no upperdentry but later we found an index.
      
      We need to check redirect on index as well and set it in
      ovl_inode->redirect.  Otherwise link code can assume that dentry does not
      have redirect and place a new one which breaks things.  In my testing
      overlay/033 test started failing in xfstests.  Following are the details.
      
      For example do following.
      
      $ mkdir lower upper work merged
      
       - Make lower dir with 4 links.
        $ echo "foo" > lower/l0.txt
        $ ln  lower/l0.txt lower/l1.txt
        $ ln  lower/l0.txt lower/l2.txt
        $ ln  lower/l0.txt lower/l3.txt
      
       - Mount with index on and metacopy on.
      
        $ mount -t overlay -o lowerdir=lower,upperdir=upper,workdir=work,\
                              index=on,metacopy=on none merged
      
       - Link lower
      
        $ ln merged/l0.txt merged/l4.txt
          (This will metadata copy up of l0.txt and put an absolute redirect
           /l0.txt)
      
        $ echo 2 > /proc/sys/vm/drop/caches
      
        $ ls merged/l1.txt
        (Now l1.txt will be looked up.  There is no upper dentry but there is
         lower dentry and index will be found.  We don't check for redirect on
         index, hence ovl_inode->redirect will be NULL.)
      
       - Link Upper
      
        $ ln merged/l4.txt merged/l5.txt
        (Lookup of l4.txt will use inode from l1.txt lookup which is still in
         cache.  It has ovl_inode->redirect NULL, hence link will put a new
         redirect and replace /l0.txt with /l4.txt
      
       - Drop caches.
        echo 2 > /proc/sys/vm/drop_caches
      
       - List l1.txt and it returns -ESTALE
      
        $ ls merged/l0.txt
      
        (It returns stale because, we found a metacopy of l0.txt in upper and it
         has redirect l4.txt but there is no file named l4.txt in lower layer.
         So lower data copy is not found and -ESTALE is returned.)
      
      So problem here is that we did not process redirect on index.  Check
      redirect on index as well and then problem is fixed.
      Signed-off-by: NVivek Goyal <vgoyal@redhat.com>
      Reviewed-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      0a2d0d3f
    • V
      ovl: Add an inode flag OVL_CONST_INO · a00c2d59
      Vivek Goyal 提交于
      Add an ovl_inode flag OVL_CONST_INO.  This flag signifies if inode number
      will remain constant over copy up or not.  This flag does not get updated
      over copy up and remains unmodifed after setting once.
      
      Next patch in the series will make use of this flag.  It will basically
      figure out if dentry is of type ORIGIN or not.  And this can be derived by
      this flag.
      
      ORIGIN = (upperdentry && ovl_test_flag(OVL_CONST_INO, inode)).
      Suggested-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NVivek Goyal <vgoyal@redhat.com>
      Reviewed-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      a00c2d59
    • V
      ovl: Add helper ovl_inode_realdata() · 4823d49c
      Vivek Goyal 提交于
      Add an helper to retrieve real data inode associated with overlay inode.
      This helper will ignore all metacopy inodes and will return only the real
      inode which has data.
      Signed-off-by: NVivek Goyal <vgoyal@redhat.com>
      Reviewed-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      4823d49c
    • V
      ovl: Store lower data inode in ovl_inode · 2664bd08
      Vivek Goyal 提交于
      Right now ovl_inode stores inode pointer for lower inode.  This helps with
      quickly getting lower inode given overlay inode (ovl_inode_lower()).
      
      Now with metadata only copy-up, we can have metacopy inode in middle layer
      as well and inode containing data can be different from ->lower.  I need to
      be able to open the real file in ovl_open_realfile() and for that I need to
      quickly find the lower data inode.
      
      Hence store lower data inode also in ovl_inode.  Also provide an helper
      ovl_inode_lowerdata() to access this field.
      Signed-off-by: NVivek Goyal <vgoyal@redhat.com>
      Reviewed-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      2664bd08
    • V
      ovl: Fix ovl_getattr() to get number of blocks from lower · 67d756c2
      Vivek Goyal 提交于
      If an inode has been copied up metadata only, then we need to query the
      number of blocks from lower and fill up the stat->st_blocks.
      
      We need to be careful about races where we are doing stat on one cpu and
      data copy up is taking place on other cpu.  We want to return
      stat->st_blocks either from lower or stable upper and not something in
      between.  Hence, ovl_has_upperdata() is called first to figure out whether
      block reporting will take place from lower or upper.
      
      We now support metacopy dentries in middle layer.  That means number of
      blocks reporting needs to come from lowest data dentry and this could be
      different from lower dentry.  Hence we end up making a separate
      vfs_getxattr() call for metacopy dentries to get number of blocks.
      Signed-off-by: NVivek Goyal <vgoyal@redhat.com>
      Reviewed-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      67d756c2
    • V
      ovl: Add helper ovl_dentry_lowerdata() to get lower data dentry · 647d253f
      Vivek Goyal 提交于
      Now we have the notion of data dentry and metacopy dentry.
      ovl_dentry_lower() will return uppermost lower dentry, but it could be
      either data or metacopy dentry.  Now we support metacopy dentries in lower
      layers so it is possible that lowerstack[0] is metacopy dentry while
      lowerstack[1] is actual data dentry.
      
      So add an helper which returns lowest most dentry which is supposed to be
      data dentry.
      Signed-off-by: NVivek Goyal <vgoyal@redhat.com>
      Reviewed-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      647d253f