Skip to content

Commit d295b66

Browse files
committed
Merge tag 'fsnotify_for_v6.4-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
Pull inotify fix from Jan Kara: "A fix for possibly reporting invalid watch descriptor with inotify event" * tag 'fsnotify_for_v6.4-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: inotify: Avoid reporting event with invalid wd
2 parents 2a78769 + c915d8f commit d295b66

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

fs/notify/inotify/inotify_fsnotify.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int inotify_handle_inode_event(struct fsnotify_mark *inode_mark, u32 mask,
6565
struct fsnotify_event *fsn_event;
6666
struct fsnotify_group *group = inode_mark->group;
6767
int ret;
68-
int len = 0;
68+
int len = 0, wd;
6969
int alloc_len = sizeof(struct inotify_event_info);
7070
struct mem_cgroup *old_memcg;
7171

@@ -80,6 +80,13 @@ int inotify_handle_inode_event(struct fsnotify_mark *inode_mark, u32 mask,
8080
i_mark = container_of(inode_mark, struct inotify_inode_mark,
8181
fsn_mark);
8282

83+
/*
84+
* We can be racing with mark being detached. Don't report event with
85+
* invalid wd.
86+
*/
87+
wd = READ_ONCE(i_mark->wd);
88+
if (wd == -1)
89+
return 0;
8390
/*
8491
* Whoever is interested in the event, pays for the allocation. Do not
8592
* trigger OOM killer in the target monitoring memcg as it may have
@@ -110,7 +117,7 @@ int inotify_handle_inode_event(struct fsnotify_mark *inode_mark, u32 mask,
110117
fsn_event = &event->fse;
111118
fsnotify_init_event(fsn_event);
112119
event->mask = mask;
113-
event->wd = i_mark->wd;
120+
event->wd = wd;
114121
event->sync_cookie = cookie;
115122
event->name_len = len;
116123
if (len)

0 commit comments

Comments
 (0)