1. 31 5月, 2018 2 次提交
    • A
      ovl: use inode_insert5() to hash a newly created inode · 01b39dcc
      Amir Goldstein 提交于
      Currently, there is a small window where ovl_obtain_alias() can
      race with ovl_instantiate() and create two different overlay inodes
      with the same underlying real non-dir non-hardlink inode.
      
      The race requires an adversary to guess the file handle of the
      yet to be created upper inode and decode the guessed file handle
      after ovl_creat_real(), but before ovl_instantiate().
      This race does not affect overlay directory inodes, because those
      are decoded via ovl_lookup_real() and not with ovl_obtain_alias().
      
      This patch fixes the race, by using inode_insert5() to add a newly
      created inode to cache.
      
      If the newly created inode apears to already exist in cache (hashed
      by the same real upper inode), we instantiate the dentry with the old
      inode and drop the new inode, instead of silently not hashing the new
      inode.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      01b39dcc
    • V
      ovl: Pass argument to ovl_get_inode() in a structure · ac6a52eb
      Vivek Goyal 提交于
      ovl_get_inode() right now has 5 parameters. Soon this patch series will
      add 2 more and suddenly argument list starts looking too long.
      
      Hence pass arguments to ovl_get_inode() in a structure and it looks
      little cleaner.
      Signed-off-by: NVivek Goyal <vgoyal@redhat.com>
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      ac6a52eb
  2. 12 4月, 2018 8 次提交
  3. 16 2月, 2018 1 次提交
    • A
      ovl: hash non-dir by lower inode for fsnotify · 764baba8
      Amir Goldstein 提交于
      Commit 31747eda ("ovl: hash directory inodes for fsnotify")
      fixed an issue of inotify watch on directory that stops getting
      events after dropping dentry caches.
      
      A similar issue exists for non-dir non-upper files, for example:
      
      $ mkdir -p lower upper work merged
      $ touch lower/foo
      $ mount -t overlay -o
      lowerdir=lower,workdir=work,upperdir=upper none merged
      $ inotifywait merged/foo &
      $ echo 2 > /proc/sys/vm/drop_caches
      $ cat merged/foo
      
      inotifywait doesn't get the OPEN event, because ovl_lookup() called
      from 'cat' allocates a new overlay inode and does not reuse the
      watched inode.
      
      Fix this by hashing non-dir overlay inodes by lower real inode in
      the following cases that were not hashed before this change:
       - A non-upper overlay mount
       - A lower non-hardlink when index=off
      
      A helper ovl_hash_bylower() was added to put all the logic and
      documentation about which real inode an overlay inode is hashed by
      into one place.
      
      The issue dates back to initial version of overlayfs, but this
      patch depends on ovl_inode code that was introduced in kernel v4.13.
      
      Cc: <stable@vger.kernel.org> #v4.13
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      764baba8
  4. 24 1月, 2018 6 次提交
  5. 19 1月, 2018 1 次提交
    • A
      ovl: hash directory inodes for fsnotify · 31747eda
      Amir Goldstein 提交于
      fsnotify pins a watched directory inode in cache, but if directory dentry
      is released, new lookup will allocate a new dentry and a new inode.
      Directory events will be notified on the new inode, while fsnotify listener
      is watching the old pinned inode.
      
      Hash all directory inodes to reuse the pinned inode on lookup. Pure upper
      dirs are hashes by real upper inode, merge and lower dirs are hashed by
      real lower inode.
      
      The reference to lower inode was being held by the lower dentry object
      in the overlay dentry (oe->lowerstack[0]). Releasing the overlay dentry
      may drop lower inode refcount to zero. Add a refcount on behalf of the
      overlay inode to prevent that.
      
      As a by-product, hashing directory inodes also detects multiple
      redirected dirs to the same lower dir and uncovered redirected dir
      target on and returns -ESTALE on lookup.
      
      The reported issue dates back to initial version of overlayfs, but this
      patch depends on ovl_inode code that was introduced in kernel v4.13.
      
      Cc: <stable@vger.kernel.org> #v4.13
      Reported-by: NNiklas Cassel <niklas.cassel@axis.com>
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      Tested-by: NNiklas Cassel <niklas.cassel@axis.com>
      31747eda
  6. 09 11月, 2017 5 次提交
  7. 24 10月, 2017 1 次提交
    • A
      ovl: fix EIO from lookup of non-indexed upper · 6eaf0111
      Amir Goldstein 提交于
      Commit fbaf94ee ("ovl: don't set origin on broken lower hardlink")
      attempt to avoid the condition of non-indexed upper inode with lower
      hardlink as origin. If this condition is found, lookup returns EIO.
      
      The protection of commit mentioned above does not cover the case of lower
      that is not a hardlink when it is copied up (with either index=off/on)
      and then lower is hardlinked while overlay is offline.
      
      Changes to lower layer while overlayfs is offline should not result in
      unexpected behavior, so a permanent EIO error after creating a link in
      lower layer should not be considered as correct behavior.
      
      This fix replaces EIO error with success in cases where upper has origin
      but no index is found, or index is found that does not match upper
      inode. In those cases, lookup will not fail and the returned overlay inode
      will be hashed by upper inode instead of by lower origin inode.
      
      Fixes: 359f392c ("ovl: lookup index entry for copy up origin")
      Cc: <stable@vger.kernel.org> # v4.13
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      6eaf0111
  8. 12 9月, 2017 1 次提交
    • A
      ovl: fix false positive ESTALE on lookup · 939ae4ef
      Amir Goldstein 提交于
      Commit b9ac5c27 ("ovl: hash overlay non-dir inodes by copy up origin")
      verifies that the origin lower inode stored in the overlayfs inode matched
      the inode of a copy up origin dentry found by lookup.
      
      There is a false positive result in that check when lower fs does not
      support file handles and copy up origin cannot be followed by file handle
      at lookup time.
      
      The false negative happens when finding an overlay inode in cache on a
      copied up overlay dentry lookup. The overlay inode still 'remembers' the
      copy up origin inode, but the copy up origin dentry is not available for
      verification.
      
      Relax the check in case copy up origin dentry is not available.
      
      Fixes: b9ac5c27 ("ovl: hash overlay non-dir inodes by copy up...")
      Cc: <stable@vger.kernel.org> # v4.13
      Reported-by: NJordi Pujol <jordipujolp@gmail.com>
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      939ae4ef
  9. 28 7月, 2017 1 次提交
  10. 20 7月, 2017 1 次提交
  11. 05 7月, 2017 9 次提交
    • A
      ovl: cleanup orphan index entries · caf70cb2
      Amir Goldstein 提交于
      index entry should live only as long as there are upper or lower
      hardlinks.
      
      Cleanup orphan index entries on mount and when dropping the last
      overlay inode nlink.
      
      When about to cleanup or link up to orphan index and the index inode
      nlink > 1, admit that something went wrong and adjust overlay nlink
      to index inode nlink - 1 to prevent it from dropping below zero.
      This could happen when adding lower hardlinks underneath a mounted
      overlay and then trying to unlink them.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      caf70cb2
    • A
      ovl: persistent overlay inode nlink for indexed inodes · 5f8415d6
      Amir Goldstein 提交于
      With inodes index enabled, an overlay inode nlink counts the union of upper
      and non-covered lower hardlinks. During the lifetime of a non-pure upper
      inode, the following nlink modifying operations can happen:
      
      1. Lower hardlink copy up
      2. Upper hardlink created, unlinked or renamed over
      3. Lower hardlink whiteout or renamed over
      
      For the first, copy up case, the union nlink does not change, whether the
      operation succeeds or fails, but the upper inode nlink may change.
      Therefore, before copy up, we store the union nlink value relative to the
      lower inode nlink in the index inode xattr trusted.overlay.nlink.
      
      For the second, upper hardlink case, the union nlink should be incremented
      or decremented IFF the operation succeeds, aligned with nlink change of the
      upper inode. Therefore, before link/unlink/rename, we store the union nlink
      value relative to the upper inode nlink in the index inode.
      
      For the last, lower cover up case, we simplify things by preceding the
      whiteout or cover up with copy up. This makes sure that there is an index
      upper inode where the nlink xattr can be stored before the copied up upper
      entry is unlink.
      
      Return the overlay inode nlinks for indexed upper inodes on stat(2).
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      5f8415d6
    • A
      ovl: implement index dir copy up · 59be0971
      Amir Goldstein 提交于
      Implement a copy up method for non-dir objects using index dir to
      prevent breaking lower hardlinks on copy up.
      
      This method requires that the inodes index dir feature was enabled and
      that all underlying fs support file handle encoding/decoding.
      
      On the first lower hardlink copy up, upper file is created in index dir,
      named after the hex representation of the lower origin inode file handle.
      On the second lower hardlink copy up, upper file is found in index dir,
      by the same lower handle key.
      On either case, the upper indexed inode is then linked to the copy up
      upper path.
      
      The index entry remains linked for future lower hardlink copy up and for
      lower to upper inode map, that is needed for exporting overlayfs to NFS.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      59be0971
    • M
      b9ac5c27
    • A
      ovl: lookup index entry for copy up origin · 359f392c
      Amir Goldstein 提交于
      When inodes index feature is enabled, lookup in indexdir for the index
      entry of lower real inode or copy up origin inode. The index entry name
      is the hex representation of the lower inode file handle.
      
      If the index dentry in negative, then either no lower aliases have been
      copied up yet, or aliases have been copied up in older kernels and are
      not indexed.
      
      If the index dentry for a copy up origin inode is positive, but points
      to an inode different than the upper inode, then either the upper inode
      has been copied up and not indexed or it was indexed, but since then
      index dir was cleared. Either way, that index cannot be used to indentify
      the overlay inode.
      
      If a positive dentry that matches the upper inode was found, then it is
      safe to use the copy up origin st_ino for upper hardlinks, because all
      indexed upper hardlinks are represented by the same overlay inode as the
      copy up origin.
      
      Set the INDEX type flag on an indexed upper dentry. A non-upper dentry
      may also have a positive index from copy up of another lower hardlink.
      This situation will be handled by following patches.
      
      Index lookup is going to be used to prevent breaking hardlinks on copy up.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      359f392c
    • M
      ovl: move impure to ovl_inode · 13c72075
      Miklos Szeredi 提交于
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      13c72075
    • M
      ovl: move __upperdentry to ovl_inode · 09d8b586
      Miklos Szeredi 提交于
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      09d8b586
    • M
      ovl: use i_private only as a key · 25b7713a
      Miklos Szeredi 提交于
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      25b7713a
    • M
      ovl: simplify getting inode · e6d2ebdd
      Miklos Szeredi 提交于
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      e6d2ebdd
  12. 29 5月, 2017 1 次提交
  13. 05 5月, 2017 2 次提交
  14. 08 3月, 2017 1 次提交
    • A
      ovl: lockdep annotate of nested stacked overlayfs inode lock · b1eaa950
      Amir Goldstein 提交于
      An overlayfs instance can be the lower layer of another overlayfs
      instance. This setup triggers a lockdep splat of possible recursive
      locking of sb->s_type->i_mutex_key in iterate_dir(). Trimmed snip:
      
       [ INFO: possible recursive locking detected ]
       bash/2468 is trying to acquire lock:
        &sb->s_type->i_mutex_key#14, at: iterate_dir+0x7d/0x15c
       but task is already holding lock:
        &sb->s_type->i_mutex_key#14, at: iterate_dir+0x7d/0x15c
      
      One problem observed with this splat is that ovl_new_inode()
      does not call lockdep_annotate_inode_mutex_key() to annotate
      the dir inode lock as &sb->s_type->i_mutex_dir_key like other
      fs do.
      
      The other problem is that the 2 nested levels of overlayfs inode
      lock are annotated using the same key, which is the cause of the
      false positive lockdep warning.
      
      Fix this by annotating overlayfs inode lock in ovl_fill_inode()
      according to stack level of the super block instance and use
      different key for dir vs. non-dir like other fs do.
      
      Here is an edited snip from /proc/lockdep_chains after
      iterate_dir() of nested overlayfs:
      
       [...] &ovl_i_mutex_dir_key[depth]   (stack_depth=2)
       [...] &ovl_i_mutex_dir_key[depth]#2 (stack_depth=1)
       [...] &type->i_mutex_dir_key        (stack_depth=0)
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      b1eaa950