afs: Fix afs_dynroot_readdir() to not use the RCU read lock
Subsystems (2)
David Howells
maintainerPATCH 1/1 afs: Fix afs_dynroot_readdir() to not use the RCU read lock
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".
--- fs/afs/dynroot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/afs/dynroot.c +2 -2
@@ -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; }
Quoted 11 lines · David Howells
afs_dynroot_readdir()uses the RCU read lock to walk the cell list whilst emitting cell automount entries - butdir_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 onnet->cells_lockinstead.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