]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
fuse: don't truncate cached, mutated symlink
authorMiklos Szeredi <mszeredi@redhat.com>
Thu, 20 Feb 2025 10:02:58 +0000 (11:02 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Apr 2025 12:31:51 +0000 (14:31 +0200)
[ Upstream commit b4c173dfbb6c78568578ff18f9e8822d7bd0e31b ]

Fuse allows the value of a symlink to change and this property is exploited
by some filesystems (e.g. CVMFS).

It has been observed, that sometimes after changing the symlink contents,
the value is truncated to the old size.

This is caused by fuse_getattr() racing with fuse_reverse_inval_inode().
fuse_reverse_inval_inode() updates the fuse_inode's attr_version, which
results in fuse_change_attributes() exiting before updating the cached
attributes

This is okay, as the cached attributes remain invalid and the next call to
fuse_change_attributes() will likely update the inode with the correct
values.

The reason this causes problems is that cached symlinks will be
returned through page_get_link(), which truncates the symlink to
inode->i_size.  This is correct for filesystems that don't mutate
symlinks, but in this case it causes bad behavior.

The solution is to just remove this truncation.  This can cause a
regression in a filesystem that relies on supplying a symlink larger than
the file size, but this is unlikely.  If that happens we'd need to make
this behavior conditional.

Reported-by: Laura Promberger <laura.promberger@cern.ch>
Tested-by: Sam Lewis <samclewis@google.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Link: https://lore.kernel.org/r/20250220100258.793363-1-mszeredi@redhat.com
Reviewed-by: Bernd Schubert <bschubert@ddn.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/fuse/dir.c
fs/namei.c
include/linux/fs.h

index 44d1c8cc58a42e36ee1b40deb635c276dce8e6e2..03dadc44e9b1cccadc62fb60486d70860a8fd347 100644 (file)
@@ -1333,7 +1333,7 @@ static const char *fuse_get_link(struct dentry *dentry, struct inode *inode,
                goto out_err;
 
        if (fc->cache_symlinks)
-               return page_get_link(dentry, inode, callback);
+               return page_get_link_raw(dentry, inode, callback);
 
        err = -ECHILD;
        if (!dentry)
index 05d45b9b59cb4150e1cfc5c5bb76a6d8491b104c..c188d525300d15ad21994f206d6a27274f1d787f 100644 (file)
@@ -5114,10 +5114,9 @@ const char *vfs_get_link(struct dentry *dentry, struct delayed_call *done)
 EXPORT_SYMBOL(vfs_get_link);
 
 /* get the link contents into pagecache */
-const char *page_get_link(struct dentry *dentry, struct inode *inode,
-                         struct delayed_call *callback)
+static char *__page_get_link(struct dentry *dentry, struct inode *inode,
+                            struct delayed_call *callback)
 {
-       char *kaddr;
        struct page *page;
        struct address_space *mapping = inode->i_mapping;
 
@@ -5136,8 +5135,23 @@ const char *page_get_link(struct dentry *dentry, struct inode *inode,
        }
        set_delayed_call(callback, page_put_link, page);
        BUG_ON(mapping_gfp_mask(mapping) & __GFP_HIGHMEM);
-       kaddr = page_address(page);
-       nd_terminate_link(kaddr, inode->i_size, PAGE_SIZE - 1);
+       return page_address(page);
+}
+
+const char *page_get_link_raw(struct dentry *dentry, struct inode *inode,
+                             struct delayed_call *callback)
+{
+       return __page_get_link(dentry, inode, callback);
+}
+EXPORT_SYMBOL_GPL(page_get_link_raw);
+
+const char *page_get_link(struct dentry *dentry, struct inode *inode,
+                                       struct delayed_call *callback)
+{
+       char *kaddr = __page_get_link(dentry, inode, callback);
+
+       if (!IS_ERR(kaddr))
+               nd_terminate_link(kaddr, inode->i_size, PAGE_SIZE - 1);
        return kaddr;
 }
 
index d011dc742e3ef66fc22a97b70321d6268b44d1e0..a111724982795beec8502acbe48f79de4512a409 100644 (file)
@@ -3387,6 +3387,8 @@ extern const struct file_operations generic_ro_fops;
 
 extern int readlink_copy(char __user *, int, const char *);
 extern int page_readlink(struct dentry *, char __user *, int);
+extern const char *page_get_link_raw(struct dentry *, struct inode *,
+                                    struct delayed_call *);
 extern const char *page_get_link(struct dentry *, struct inode *,
                                 struct delayed_call *);
 extern void page_put_link(void *);