Skip to content

Commit

Permalink
fsnotify: do not handle events on a shutting down filesystem
Browse files Browse the repository at this point in the history
Protect against use after free when filesystem calls fsnotify_sb_error()
after calling fsnotify_sb_delete().

Reported-by: syzbot+5e3f9b2a67b45f16d4e6@syzkaller.appspotmail.com
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
  • Loading branch information
amir73il committed Apr 12, 2024
1 parent d122efd commit a4170c0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/linux/fsnotify.h
Expand Up @@ -23,6 +23,9 @@ static inline bool fsnotify_sb_has_priority_watchers(struct super_block *sb,
{
struct fsnotify_sb_info *sbinfo = fsnotify_sb_info(sb);

if (unlikely(!(sb->s_flags & SB_ACTIVE)))
return 0;

/* Were any marks ever added to any object on this sb? */
if (!sbinfo)
return false;
Expand Down Expand Up @@ -453,6 +456,9 @@ static inline int fsnotify_sb_error(struct super_block *sb, struct inode *inode,
.sb = sb,
};

if (!fsnotify_sb_has_watchers(sb))
return 0;

return fsnotify(FS_ERROR, &report, FSNOTIFY_EVENT_ERROR,
NULL, NULL, NULL, 0);
}
Expand Down

0 comments on commit a4170c0

Please sign in to comment.