]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
inotify: actually check for invalid bits in sys_inotify_add_watch()
authorDave Hansen <dave.hansen@linux.intel.com>
Wed, 21 Oct 2015 22:02:42 +0000 (09:02 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 21 Oct 2015 22:02:42 +0000 (09:02 +1100)
The comment here says that it is checking for invalid bits.  But, the mask
is *actually* checking to ensure that _any_ valid bit is set, which is
quite different.

Without this check, an unexpected bit could get set on an inotify object.
Since these bits are also interpreted by the fsnotify/dnotify code, there
is the potential for an object to be mishandled inside the kernel.  For
instance, can we be sure that setting the dnotify flag FS_DN_RENAME on an
inotify watch is harmless?

Add the actual check which was intended.  Retain the existing inotify bits
are being added to the watch.  Plus, this is existing behavior which would
be nice to preserve.

I did a quick sniff test that inotify functions and that my
'inotify-tools' package passes 'make check'.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: John McCutchan <john@johnmccutchan.com>
Cc: Robert Love <rlove@rlove.org>
Cc: Eric Paris <eparis@parisplace.org>
Cc: Josh Boyer <jwboyer@fedoraproject.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/notify/inotify/inotify_user.c

index 5b1e2a497e5114c26e556830f9f891c36130ffc7..5923f408e08b478f191eefd2e8fb7a92b292cfe4 100644 (file)
@@ -707,6 +707,9 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,
        unsigned flags = 0;
 
        /* don't allow invalid bits: we don't want flags set */
+       if (unlikely(mask & ~ALL_INOTIFY_BITS))
+               return -EINVAL;
+       /* require at least one valid bit set in the mask */
        if (unlikely(!(mask & ALL_INOTIFY_BITS)))
                return -EINVAL;