hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/fs/notify/inotify/inotify_fsnotify.c
....@@ -64,7 +64,7 @@
6464 struct fsnotify_event *fsn_event;
6565 struct fsnotify_group *group = inode_mark->group;
6666 int ret;
67
- int len = 0;
67
+ int len = 0, wd;
6868 int alloc_len = sizeof(struct inotify_event_info);
6969 struct mem_cgroup *old_memcg;
7070
....@@ -79,6 +79,13 @@
7979 i_mark = container_of(inode_mark, struct inotify_inode_mark,
8080 fsn_mark);
8181
82
+ /*
83
+ * We can be racing with mark being detached. Don't report event with
84
+ * invalid wd.
85
+ */
86
+ wd = READ_ONCE(i_mark->wd);
87
+ if (wd == -1)
88
+ return 0;
8289 /*
8390 * Whoever is interested in the event, pays for the allocation. Do not
8491 * trigger OOM killer in the target monitoring memcg as it may have
....@@ -109,7 +116,7 @@
109116 fsn_event = &event->fse;
110117 fsnotify_init_event(fsn_event, 0);
111118 event->mask = mask;
112
- event->wd = i_mark->wd;
119
+ event->wd = wd;
113120 event->sync_cookie = cookie;
114121 event->name_len = len;
115122 if (len)