Skip to content

Commit b3a0066

Browse files
committed
dnotify: Handle errors from fsnotify_add_mark_locked() in fcntl_dirnotify()
fsnotify_add_mark_locked() can fail but we do not check its return value. This didn't matter before commit 9dd813c "fsnotify: Move mark list head from object into dedicated structure" as none of possible failures could happen for dnotify but after that commit -ENOMEM can be returned. Handle this error properly in fcntl_dirnotify() as otherwise we just hit BUG_ON(dn_mark->dn) in dnotify_free_mark(). Reviewed-by: Amir Goldstein <amir73il@gmail.com> Reported-by: syzkaller Fixes: 9dd813c Signed-off-by: Jan Kara <jack@suse.cz>
1 parent ff5abbe commit b3a0066

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎fs/notify/dnotify/dnotify.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,11 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
319319
dn_mark = container_of(fsn_mark, struct dnotify_mark, fsn_mark);
320320
spin_lock(&fsn_mark->lock);
321321
} else {
322-
fsnotify_add_mark_locked(new_fsn_mark, inode, NULL, 0);
322+
error = fsnotify_add_mark_locked(new_fsn_mark, inode, NULL, 0);
323+
if (error) {
324+
mutex_unlock(&dnotify_group->mark_mutex);
325+
goto out_err;
326+
}
323327
spin_lock(&new_fsn_mark->lock);
324328
fsn_mark = new_fsn_mark;
325329
dn_mark = new_dn_mark;
@@ -345,6 +349,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
345349
*/
346350
if (dn_mark == new_dn_mark)
347351
destroy = 1;
352+
error = 0;
348353
goto out;
349354
}
350355

0 commit comments

Comments
 (0)