Skip to content

Commit 38c0324

Browse files
authored
Linux: Fix zfs_prune panics
by protecting against sb->s_shrink eviction on umount with newer kernels deactivate_locked_super calls shrinker_free and only then sops->kill_sb cb, resulting in UAF on umount when trying to reach for the shrinker functions in zpl_prune_sb of in-umount dataset Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Adam Moss <[email protected]> Signed-off-by: Pavel Snajdr <[email protected]> Closes #16770
1 parent ae1d118 commit 38c0324

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

module/os/linux/zfs/zpl_super.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,18 @@ zpl_prune_sb(uint64_t nr_to_scan, void *arg)
375375
struct super_block *sb = (struct super_block *)arg;
376376
int objects = 0;
377377

378-
(void) -zfs_prune(sb, nr_to_scan, &objects);
378+
/*
379+
* deactivate_locked_super calls shrinker_free and only then
380+
* sops->kill_sb cb, resulting in UAF on umount when trying to reach
381+
* for the shrinker functions in zpl_prune_sb of in-umount dataset.
382+
* Increment if s_active is not zero, but don't prune if it is -
383+
* umount could be underway.
384+
*/
385+
if (atomic_inc_not_zero(&sb->s_active)) {
386+
(void) -zfs_prune(sb, nr_to_scan, &objects);
387+
atomic_dec(&sb->s_active);
388+
}
389+
379390
}
380391

381392
const struct super_operations zpl_super_operations = {

0 commit comments

Comments
 (0)