]> www.infradead.org Git - users/hch/misc.git/commitdiff
afs: Fix afs_dynroot_readdir() to not use the RCU read lock
authorDavid Howells <dhowells@redhat.com>
Tue, 8 Apr 2025 20:46:29 +0000 (21:46 +0100)
committerChristian Brauner <brauner@kernel.org>
Fri, 11 Apr 2025 13:24:29 +0000 (15:24 +0200)
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>
Link: https://lore.kernel.org/1638014.1744145189@warthog.procyon.org.uk
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/dynroot.c

index 691e0ae607a167b91abd836ccb05562662638096..8c6130789fde3ae9cf41b5cd2f57dbe578e1ef08 100644 (file)
@@ -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;
 }