Skip to content

Commit

Permalink
inotify: invalid mask should return a error number but not set it
Browse files Browse the repository at this point in the history
When we run the crackerjack testsuite, the inotify_add_watch test is
stalled.

This is caused by the invalid mask 0 - the task is waiting for the event
but it never comes.  inotify_add_watch() should return -EINVAL as it did
before commit 676a067 ("inotify: remove broken mask checks causing
unmount to be EINVAL").  That commit removes the invalid mask check, but
that check is needed.

Check the mask's ALL_INOTIFY_BITS before the inotify_arg_to_mask() call.
If none are set, just return -EINVAL.

Because IN_UNMOUNT is in ALL_INOTIFY_BITS, this change will not trigger
the problem that above commit fixed.

[[email protected]: fix build]
Signed-off-by: Zhao Hongjiang <[email protected]>
Acked-by: Jim Somerville <[email protected]>
Cc: Paul Gortmaker <[email protected]>
Cc: Jerome Marchand <[email protected]>
Cc: Eric Paris <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Zhao Hongjiang authored and torvalds committed May 1, 2013
1 parent ace6128 commit 04df32f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fs/notify/inotify/inotify_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ static int inotify_update_existing_watch(struct fsnotify_group *group,
int add = (arg & IN_MASK_ADD);
int ret;

/* don't allow invalid bits: we don't want flags set */
mask = inotify_arg_to_mask(arg);

fsn_mark = fsnotify_find_inode_mark(group, inode);
Expand Down Expand Up @@ -621,7 +620,6 @@ static int inotify_new_watch(struct fsnotify_group *group,
struct idr *idr = &group->inotify_data.idr;
spinlock_t *idr_lock = &group->inotify_data.idr_lock;

/* don't allow invalid bits: we don't want flags set */
mask = inotify_arg_to_mask(arg);

tmp_i_mark = kmem_cache_alloc(inotify_inode_mark_cachep, GFP_KERNEL);
Expand Down Expand Up @@ -747,6 +745,10 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,
int ret;
unsigned flags = 0;

/* don't allow invalid bits: we don't want flags set */
if (unlikely(!(mask & ALL_INOTIFY_BITS)))
return -EINVAL;

f = fdget(fd);
if (unlikely(!f.file))
return -EBADF;
Expand Down

0 comments on commit 04df32f

Please sign in to comment.