ovl: skip checking lower file's i_writecount on truncate
authorChengguang Xu <cgxu519@mykernel.net>
Sat, 24 Apr 2021 14:03:15 +0000 (22:03 +0800)
committerMiklos Szeredi <mszeredi@redhat.com>
Tue, 17 Aug 2021 09:47:44 +0000 (11:47 +0200)
It is possible that a directory tree is shared between multiple overlay
instances as a lower layer.  In this case when one instance executes a file
residing on the lower layer, the other instance denies a truncate(2) call
on this file.

This only happens for truncate(2) and not for open(2) with the O_TRUNC
flag.

Fix this interference and inconsistency by removing the preliminary
i_writecount check before copy-up.

This means that unlike on normal filesystems truncate(argv[0]) will now
succeed.  If this ever causes a regression in a real world use case this
needs to be revisited.

One way to fix this properly would be to keep a correct i_writecount in the
overlay inode, but that is difficult due to memory mapping code only
dealing with the real file/inode.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Documentation/filesystems/overlayfs.rst
fs/overlayfs/inode.c

index 455ca86eb4fcea115a28bfdf648ad73ab973504d..7da6c30ed596ad72a446b5dc81b52b305b77b069 100644 (file)
@@ -427,6 +427,9 @@ b) If a file residing on a lower layer is opened for read-only and then
 memory mapped with MAP_SHARED, then subsequent changes to the file are not
 reflected in the memory mapping.
 
+c) If a file residing on a lower layer is being executed, then opening that
+file for write or truncating the file will not be denied with ETXTBSY.
+
 The following options allow overlayfs to act more like a standards
 compliant filesystem:
 
index 37300e972a398c416b48435e6c3c4f2305298bf1..8aa370e8143a750dcc241535bd92a6d48550d60e 100644 (file)
@@ -33,12 +33,6 @@ int ovl_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
                goto out;
 
        if (attr->ia_valid & ATTR_SIZE) {
-               struct inode *realinode = d_inode(ovl_dentry_real(dentry));
-
-               err = -ETXTBSY;
-               if (atomic_read(&realinode->i_writecount) < 0)
-                       goto out_drop_write;
-
                /* Truncate should trigger data copy up as well */
                full_copy_up = true;
        }