diff mbox series

afs: Fix afs_dynroot_readdir() to not use the RCU read lock

Message ID 1638014.1744145189@warthog.procyon.org.uk (mailing list archive)
State New
Headers show
Series afs: Fix afs_dynroot_readdir() to not use the RCU read lock | expand

Commit Message

David Howells April 8, 2025, 8:46 p.m. UTC
afs_dynroot_readdir() uses the RCU read lock to walk the cell list whilst
emitting cell automount entries - but dir_emit() may write to a userspace
buffer, thereby causing a fault to occur and waits to happen.

Fix afs_dynroot_readdir() to get a shared lock on net->cells_lock instead.

This can be triggered by enabling lockdep, preconfiguring a number of
cells, doing "mount -t afs none /afs -o dyn" (or using the kafs-client
package with afs.mount systemd unit enabled) and then doing "ls /afs".

Fixes: 1d0b929fc070 ("afs: Change dynroot to create contents on demand")
Reported-by: syzbot+3b6c5c6a1d0119b687a1@syzkaller.appspotmail.com
Reported-by: syzbot+8245611446194a52150d@syzkaller.appspotmail.com
Reported-by: syzbot+1aa62e6852a6ad1c7944@syzkaller.appspotmail.com
Reported-by: syzbot+54e6c2176ba76c56217e@syzkaller.appspotmail.com
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
cc: linux-fsdevel@vger.kernel.org
---
 fs/afs/dynroot.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Christian Brauner April 9, 2025, 10:13 a.m. UTC | #1
On Tue, 08 Apr 2025 21:46:29 +0100, David Howells wrote:
> afs_dynroot_readdir() uses the RCU read lock to walk the cell list whilst
> emitting cell automount entries - but dir_emit() may write to a userspace
> buffer, thereby causing a fault to occur and waits to happen.
> 
> Fix afs_dynroot_readdir() to get a shared lock on net->cells_lock instead.
> 
> This can be triggered by enabling lockdep, preconfiguring a number of
> cells, doing "mount -t afs none /afs -o dyn" (or using the kafs-client
> package with afs.mount systemd unit enabled) and then doing "ls /afs".
> 
> [...]

Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] afs: Fix afs_dynroot_readdir() to not use the RCU read lock
      https://git.kernel.org/vfs/vfs/c/7571ebd29ff2
diff mbox series

Patch

diff --git a/fs/afs/dynroot.c b/fs/afs/dynroot.c
index 691e0ae607a1..8c6130789fde 100644
--- a/fs/afs/dynroot.c
+++ b/fs/afs/dynroot.c
@@ -348,9 +348,9 @@  static int afs_dynroot_readdir(struct file *file, struct dir_context *ctx)
 	}
 
 	if ((unsigned long long)ctx->pos <= AFS_MAX_DYNROOT_CELL_INO) {
-		rcu_read_lock();
+		down_read(&net->cells_lock);
 		ret = afs_dynroot_readdir_cells(net, ctx);
-		rcu_read_unlock();
+		up_read(&net->cells_lock);
 	}
 	return ret;
 }