]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
afs: Fix the locking used by afs_get_link()
authorDavid Howells <dhowells@redhat.com>
Tue, 12 May 2026 12:34:01 +0000 (13:34 +0100)
committerChristian Brauner <brauner@kernel.org>
Tue, 12 May 2026 12:42:33 +0000 (14:42 +0200)
commitc0410adf3da6db46f3513411fcf95e63c2f1d1ad
tree71d1c59b9aba1dfda3d10b71a75b3d301e71bdab
parent9871938f99cc6cb266a77265491660e2375271f5
afs: Fix the locking used by afs_get_link()

The afs filesystem in the kernel doesn't do locking correctly for symbolic
links.  There are a number of problems:

 (1) It doesn't do any locking around afs_read_single() to prevent races
     between multiple ->get_link() calls, thereby allowing the possibility
     of leaks.

 (2) It doesn't use RCU barriering when accessing the buffer pointers
     during RCU pathwalk.

 (3) It can race with another thread updating the contents of the symlink
     if a third party updated it on the server.

Fix this by the following means:

 (0) Move symlink handling into its own file as this makes it more
     complicated.

 (1) Take the validate_lock around afs_read_single() to prevent races
     between multiple ->get_link() calls.

 (2) Keep a separate copy of the symlink contents with an rcu_head.  This
     is always going to be a lot smaller than a page, so it can be
     kmalloc'd and save quite a bit of memory.  It also needs a refcount
     for non-RCU pathwalk.

 (3) Split the symlink read and write-to-cache routines in afs from those
     for directories.

 (4) Discard the I/O buffer as soon as the write-to-cache completes as this
     is a full page (plus a folio_queue).

 (5) If there's no cache, discard the I/O buffer immediately after reading
     and copying if there is no cache.

Fixes: eae9e78951bb ("afs: Use netfslib for symlinks, allowing them to be cached")
Fixes: 6698c02d64b2 ("afs: Locally initialise the contents of a new symlink on creation")
Closes: https://sashiko.dev/#/patchset/20260326104544.509518-1-dhowells%40redhat.com
Signed-off-by: David Howells <dhowells@redhat.com>
Link: https://patch.msgid.link/20260512123404.719402-25-dhowells@redhat.com
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/afs/Makefile
fs/afs/dir.c
fs/afs/fsclient.c
fs/afs/inode.c
fs/afs/internal.h
fs/afs/symlink.c [new file with mode: 0644]
fs/afs/validation.c
fs/afs/yfsclient.c