1 From 04df32fa10ab9a6f0643db2949d42efc966bc844 Mon Sep 17 00:00:00 2001
2 From: Zhao Hongjiang <zhaohongjiang@huawei.com>
3 Date: Tue, 30 Apr 2013 15:26:46 -0700
4 Subject: inotify: invalid mask should return a error number but not set it
6 From: Zhao Hongjiang <zhaohongjiang@huawei.com>
8 commit 04df32fa10ab9a6f0643db2949d42efc966bc844 upstream.
10 When we run the crackerjack testsuite, the inotify_add_watch test is
13 This is caused by the invalid mask 0 - the task is waiting for the event
14 but it never comes. inotify_add_watch() should return -EINVAL as it did
15 before commit 676a0675cf92 ("inotify: remove broken mask checks causing
16 unmount to be EINVAL"). That commit removes the invalid mask check, but
19 Check the mask's ALL_INOTIFY_BITS before the inotify_arg_to_mask() call.
20 If none are set, just return -EINVAL.
22 Because IN_UNMOUNT is in ALL_INOTIFY_BITS, this change will not trigger
23 the problem that above commit fixed.
25 [akpm@linux-foundation.org: fix build]
26 Signed-off-by: Zhao Hongjiang <zhaohongjiang@huawei.com>
27 Acked-by: Jim Somerville <Jim.Somerville@windriver.com>
28 Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
29 Cc: Jerome Marchand <jmarchan@redhat.com>
30 Cc: Eric Paris <eparis@parisplace.org>
31 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
32 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
33 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
37 fs/notify/inotify/inotify_user.c | 6 ++++--
38 1 file changed, 4 insertions(+), 2 deletions(-)
40 --- a/fs/notify/inotify/inotify_user.c
41 +++ b/fs/notify/inotify/inotify_user.c
42 @@ -577,7 +577,6 @@ static int inotify_update_existing_watch
43 int add = (arg & IN_MASK_ADD);
46 - /* don't allow invalid bits: we don't want flags set */
47 mask = inotify_arg_to_mask(arg);
49 fsn_mark = fsnotify_find_inode_mark(group, inode);
50 @@ -628,7 +627,6 @@ static int inotify_new_watch(struct fsno
51 struct idr *idr = &group->inotify_data.idr;
52 spinlock_t *idr_lock = &group->inotify_data.idr_lock;
54 - /* don't allow invalid bits: we don't want flags set */
55 mask = inotify_arg_to_mask(arg);
57 tmp_i_mark = kmem_cache_alloc(inotify_inode_mark_cachep, GFP_KERNEL);
58 @@ -757,6 +755,10 @@ SYSCALL_DEFINE3(inotify_add_watch, int,
62 + /* don't allow invalid bits: we don't want flags set */
63 + if (unlikely(!(mask & ALL_INOTIFY_BITS)))
66 filp = fget_light(fd, &fput_needed);