fsnotify: fix UAF from FS_ERROR event on a shutting down filesystem
authorAmir Goldstein <amir73il@gmail.com>
Tue, 16 Apr 2024 18:14:52 +0000 (21:14 +0300)
committerJan Kara <jack@suse.cz>
Wed, 17 Apr 2024 13:06:50 +0000 (15:06 +0200)
commit795bb82d12a16a4cee42845b0e4c7e3276574e5d
treee82347600c4058d7e4c08ca42d7afd9af065405a
parenta5e57b4d370c6d320e5bfb0c919fe00aee29e039
fsnotify: fix UAF from FS_ERROR event on a shutting down filesystem

Protect against use after free when filesystem calls fsnotify_sb_error()
during fs shutdown.

Move freeing of sb->s_fsnotify_info to destroy_super_work(), because it
may be accessed from fs shutdown context.

Reported-by: syzbot+5e3f9b2a67b45f16d4e6@syzkaller.appspotmail.com
Suggested-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/linux-fsdevel/20240416173211.4lnmgctyo4jn5fha@quack3/
Fixes: 07a3b8d0bf72 ("fsnotify: lazy attach fsnotify_sb_info state to sb")
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Message-Id: <20240416181452.567070-1-amir73il@gmail.com>
fs/notify/fsnotify.c
fs/super.c
include/linux/fsnotify_backend.h