Skip to content

Commit 583340d

Browse files
author
Al Viro
committed
fs/super.c: don't drop ->s_user_ns until we free struct super_block itself
Avoids fun races in RCU pathwalk... Same goes for freeing LSM shite hanging off super_block's arse. Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 6613476 commit 583340d

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

fs/super.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,10 @@ static void destroy_super_work(struct work_struct *work)
274274
{
275275
struct super_block *s = container_of(work, struct super_block,
276276
destroy_work);
277-
int i;
278-
279-
for (i = 0; i < SB_FREEZE_LEVELS; i++)
277+
security_sb_free(s);
278+
put_user_ns(s->s_user_ns);
279+
kfree(s->s_subtype);
280+
for (int i = 0; i < SB_FREEZE_LEVELS; i++)
280281
percpu_free_rwsem(&s->s_writers.rw_sem[i]);
281282
kfree(s);
282283
}
@@ -296,9 +297,6 @@ static void destroy_unused_super(struct super_block *s)
296297
super_unlock_excl(s);
297298
list_lru_destroy(&s->s_dentry_lru);
298299
list_lru_destroy(&s->s_inode_lru);
299-
security_sb_free(s);
300-
put_user_ns(s->s_user_ns);
301-
kfree(s->s_subtype);
302300
shrinker_free(s->s_shrink);
303301
/* no delays needed */
304302
destroy_super_work(&s->destroy_work);
@@ -409,9 +407,6 @@ static void __put_super(struct super_block *s)
409407
WARN_ON(s->s_dentry_lru.node);
410408
WARN_ON(s->s_inode_lru.node);
411409
WARN_ON(!list_empty(&s->s_mounts));
412-
security_sb_free(s);
413-
put_user_ns(s->s_user_ns);
414-
kfree(s->s_subtype);
415410
call_rcu(&s->rcu, destroy_super_rcu);
416411
}
417412
}

0 commit comments

Comments
 (0)