Skip to content

Commit 676a067

Browse files
jsomervitorvalds
authored andcommitted
inotify: remove broken mask checks causing unmount to be EINVAL
Running the command: inotifywait -e unmount /mnt/disk immediately aborts with a -EINVAL return code. This is however a valid parameter. This abort occurs only if unmount is the sole event parameter. If other event parameters are supplied, then the unmount event wait will work. The problem was introduced by commit 44b350f ("inotify: Fix mask checks"). In that commit, it states: The mask checks in inotify_update_existing_watch() and inotify_new_watch() are useless because inotify_arg_to_mask() sets FS_IN_IGNORED and FS_EVENT_ON_CHILD bits anyway. But instead of removing the useless checks, it did this: mask = inotify_arg_to_mask(arg); - if (unlikely(!mask)) + if (unlikely(!(mask & IN_ALL_EVENTS))) return -EINVAL; The problem is that IN_ALL_EVENTS doesn't include IN_UNMOUNT, and other parts of the code keep IN_UNMOUNT separate from IN_ALL_EVENTS. So the check should be: if (unlikely(!(mask & (IN_ALL_EVENTS | IN_UNMOUNT)))) But inotify_arg_to_mask(arg) always sets the IN_UNMOUNT bit in the mask anyway, so the check is always going to pass and thus should simply be removed. Also note that inotify_arg_to_mask completely controls what mask bits get set from arg, there's no way for invalid bits to get enabled there. Lets fix it by simply removing the useless broken checks. Signed-off-by: Jim Somerville <[email protected]> Signed-off-by: Paul Gortmaker <[email protected]> Cc: Jerome Marchand <[email protected]> Cc: John McCutchan <[email protected]> Cc: Robert Love <[email protected]> Cc: Eric Paris <[email protected]> Cc: <[email protected]> [2.6.37+] Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent bffea77 commit 676a067

File tree

1 file changed

+0
-4
lines changed

1 file changed

+0
-4
lines changed

fs/notify/inotify/inotify_user.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,6 @@ static int inotify_update_existing_watch(struct fsnotify_group *group,
576576

577577
/* don't allow invalid bits: we don't want flags set */
578578
mask = inotify_arg_to_mask(arg);
579-
if (unlikely(!(mask & IN_ALL_EVENTS)))
580-
return -EINVAL;
581579

582580
fsn_mark = fsnotify_find_inode_mark(group, inode);
583581
if (!fsn_mark)
@@ -629,8 +627,6 @@ static int inotify_new_watch(struct fsnotify_group *group,
629627

630628
/* don't allow invalid bits: we don't want flags set */
631629
mask = inotify_arg_to_mask(arg);
632-
if (unlikely(!(mask & IN_ALL_EVENTS)))
633-
return -EINVAL;
634630

635631
tmp_i_mark = kmem_cache_alloc(inotify_inode_mark_cachep, GFP_KERNEL);
636632
if (unlikely(!tmp_i_mark))

0 commit comments

Comments
 (0)