linux-brain/fs/overlayfs
Amir Goldstein e506ac1dab ovl: hash directory inodes for fsnotify
commit 31747eda41 upstream.

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: Niklas Cassel <niklas.cassel@axis.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Tested-by: Niklas Cassel <niklas.cassel@axis.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-02-22 15:42:33 +01:00
..
Kconfig ovl: introduce the inodes index dir feature 2017-07-04 22:03:17 +02:00
Makefile ovl: split super.c 2016-12-16 11:02:56 +01:00
copy_up.c ovl: fix missing unlock_rename() in ovl_do_copy_up() 2017-10-05 15:53:18 +02:00
dir.c ovl: fix missing unlock_rename() in ovl_do_copy_up() 2017-10-05 15:53:18 +02:00
inode.c ovl: hash directory inodes for fsnotify 2018-02-22 15:42:33 +01:00
namei.c ovl: Pass ovl_get_nlink() parameters in right order 2017-12-20 10:10:18 +01:00
overlayfs.h ovl: fix EIO from lookup of non-indexed upper 2017-10-24 16:06:16 +02:00
ovl_entry.h locking/barriers: Convert users of lockless_dereference() to READ_ONCE() 2017-12-25 14:26:21 +01:00
readdir.c ovl: take mnt_want_write() for removing impure xattr 2018-02-16 20:23:10 +01:00
super.c ovl: hash directory inodes for fsnotify 2018-02-22 15:42:33 +01:00
util.c ovl: hash directory inodes for fsnotify 2018-02-22 15:42:33 +01:00