Skip to contentSkip to conversation

inotify: actually check for invalid bits in sys_inotify_add_watch()

PATCH Superseded Dave Hansen 5 participants 7 messages Jun 30, 2015 – Sep 21, 2015

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 inotify: actually check for invalid bits in sys_inotify_add_watch()

From: Dave Hansen <[email protected]>

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.

Add the actual check which was intended. Retain the existing check because it actually does something useful: ensure that some 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'.

Cc John McCutchan <[email protected]> (maintainer:INOTIFY)
Cc Robert Love <[email protected]> (maintainer:INOTIFY)
Cc Eric Paris <[email protected]> (maintainer:INOTIFY)
Cc [email protected] (open list)

---

 b/fs/notify/inotify/inotify_user.c |    3 +++
 1 file changed, 3 insertions(+)
fs/notify/inotify/inotify_user.c renamed from fs/notify/inotify/inotify_user.c~inotify-EINVAL-on-invalid-bit +3 -0
diff -puN fs/notify/inotify/inotify_user.c~inotify-EINVAL-on-invalid-bit fs/notify/inotify/inotify_user.c
@@ -707,6 +707,9 @@ SYSCALL_DEFINE3(inotify_add_watch, int,
 	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;
 

_

#1 lore raw
Quoted 6 lines · Dave Hansen

From: Dave Hansen <[email protected]>

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.

Quoted 7 lines

Add the actual check which was intended. Retain the existing check because it actually does something useful: ensure that some 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'.

Did anybody have any comments on this patch? Who picks up inotify patches?

Quoted 18 lines
 b/fs/notify/inotify/inotify_user.c |    3 +++
 1 file changed, 3 insertions(+)

diff -puN fs/notify/inotify/inotify_user.c~inotify-EINVAL-on-invalid-bit fs/notify/inotify/inotify_user.c

fs/notify/inotify/inotify_user.c renamed from fs/notify/inotify/inotify_user.c~inotify-EINVAL-on-invalid-bit +3 -0
@@ -707,6 +707,9 @@ SYSCALL_DEFINE3(inotify_add_watch, int,
 	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;
 

_

#2 lore raw
Quoted 12 lines · Dave Hansen
Quoted 11 lines · Dave Hansen

From: Dave Hansen <[email protected]>

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.

Add the actual check which was intended. Retain the existing check because it actually does something useful: ensure that some inotify bits are being added to the watch. Plus, this is existing behavior which would be nice to preserve.

Quoted 4 lines
Quoted 2 lines

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

Did anybody have any comments on this patch? Who picks up inotify patches?

Theoretically the people you have CC'd pick them up. However it seems for quite some time Andrew has been shepherding them along.

josh

Quoted 23 lines
Quoted 16 lines
 b/fs/notify/inotify/inotify_user.c |    3 +++
 1 file changed, 3 insertions(+)

diff -puN fs/notify/inotify/inotify_user.c~inotify-EINVAL-on-invalid-bit fs/notify/inotify/inotify_user.c

fs/notify/inotify/inotify_user.c 2015-06-26 13:35:19.026122033 -0700 renamed from fs/notify/inotify/inotify_user.c~inotify-EINVAL-on-invalid-bit 2015-06-26 13:33:30.277219285 -0700 +3 -0
@@ -707,6 +707,9 @@ SYSCALL_DEFINE3(inotify_add_watch, int,
      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;
 
Quoted 2 lines

_

--
To unsubscribe from this list: send the line "unsubscribe stable" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Dave Hansen

Looks fine to me. And usually akpm picks them up these days.

Quoted 40 lines · Dave Hansen
Quoted 6 lines · Dave Hansen

From: Dave Hansen <[email protected]>

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.

Quoted 7 lines

Add the actual check which was intended. Retain the existing check because it actually does something useful: ensure that some 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'.

Did anybody have any comments on this patch? Who picks up inotify patches?

Quoted 21 lines
 b/fs/notify/inotify/inotify_user.c |    3 +++
 1 file changed, 3 insertions(+)

diff -puN fs/notify/inotify/inotify_user.c~inotify-EINVAL-on

(quoted diff) +1 -3
-invalid-bit fs/notify/inotify/inotify_user.c
--- a/fs/notify/inotify/inotify_user.c~inotify-EINVAL-on-invalid
-bit	2015-06-26 13:33:30.277219285 -0700
+++ b/fs/notify/inotify/inotify_user.c	2015-06-26

13:35:19.026122033 -0700

fs/notify/inotify/inotify_user.c renamed from fs/notify/inotify/inotify_user.c~inotify-EINVAL-on-invalid-bit +3 -0
@@ -707,6 +707,9 @@ SYSCALL_DEFINE3(inotify_add_watch, int,
 	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;
 

_

#4 lore raw
Quoted 1 line · Eric Paris

Looks fine to me. And usually akpm picks them up these days.

Is that an Acked-by? :)

#5 lore raw
Quoted 4 lines · On Wed, 9 Sep 2015 16:32:37 -0700 Dave Hansen <[email protected]> wrote:
Quoted 1 line · Eric Paris

Looks fine to me. And usually akpm picks them up these days.

Is that an Acked-by? :)

I grabbed it for 4.3.

I removed your cc:stable. I don't see anything in here which warrants a backport. If there *is* a reason for backporting then your changelogological skills are sorely wanting!

The changelog is pretty sucky really. What are the reasons for this change, apart from "do what the comment said"? What's the benefit?

And the code comment sucks. "don't allow invalid bits": well duh. And "we don't want flags set" is also useless: it doesn't explain *why* we don't want those flags set.

And given that there is potential to break existing userspace, we need some decent reasons for making this change.

From: Dave Hansen <[email protected]>
Subject: inotify: actually check for invalid bits in sys_inotify_add_watch()

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.

Add the actual check which was intended. Retain the existing check because it actually does something useful: ensure that some 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'.

Cc John McCutchan <[email protected]>
Cc Robert Love <[email protected]>
Cc Eric Paris <[email protected]>

---

 fs/notify/inotify/inotify_user.c |    3 +++
 1 file changed, 3 insertions(+)
fs/notify/inotify/inotify_user.c renamed from fs/notify/inotify/inotify_user.c~inotify-actually-check-for-invalid-bits-in-sys_inotify_add_watch +3 -0
diff -puN fs/notify/inotify/inotify_user.c~inotify-actually-check-for-invalid-bits-in-sys_inotify_add_watch fs/notify/inotify/inotify_user.c
@@ -707,6 +707,9 @@ SYSCALL_DEFINE3(inotify_add_watch, int,
 	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;
 

_

#6 lore raw

2015-09-10 23:49 GMT+03:00 Andrew Morton <[email protected]>:

Quoted 8 lines · On Wed, 9 Sep 2015 16:32:37 -0700 Dave Hansen <[email protected]> wrote:
Quoted 5 lines · Eric Paris
Quoted 1 line

Looks fine to me. And usually akpm picks them up these days.

Is that an Acked-by? :)

I grabbed it for 4.3.

This patch breaks CRIU. When we are dumping an inotify file descriptors, we read event masks from /proc/self/fdinfo.

[root@fc22-vm criu]# cat /proc/1065/fdinfo/3
pos: 0
flags: 04000
mnt_id: 11
inotify wd:1 ino:101d5c sdev:fc00002 mask:800a708 ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:5c1d10003996cda2

Here the mask contains the 0x8000000 (FS_EVENT_ON_CHILD) flag, which is set for all inotify and dnotify watchers. On restore, we call inotify_add_watch() with this mask, and it fails with this patch:

1375 inotify_add_watch(3, "/proc/self/fd/5", IN_CLOSE_WRITE|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_UNMOUNT|IN_IGNORED|0x8000000) = -1 EINVAL (Invalid argument)

I am not sure that we have to save backward compatibility here. Maybe we should not show FS_EVENT_ON_CHILD in fdinfo.

Quoted 64 lines

I removed your cc:stable. I don't see anything in here which warrants a backport. If there *is* a reason for backporting then your changelogological skills are sorely wanting!

The changelog is pretty sucky really. What are the reasons for this change, apart from "do what the comment said"? What's the benefit?

And the code comment sucks. "don't allow invalid bits": well duh. And "we don't want flags set" is also useless: it doesn't explain *why* we don't want those flags set.

And given that there is potential to break existing userspace, we need some decent reasons for making this change.

From: Dave Hansen <[email protected]>
Subject: inotify: actually check for invalid bits in sys_inotify_add_watch()

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.

Add the actual check which was intended. Retain the existing check because it actually does something useful: ensure that some 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'.

Cc John McCutchan <[email protected]>
Cc Robert Love <[email protected]>
Cc Eric Paris <[email protected]>

---

 fs/notify/inotify/inotify_user.c |    3 +++
 1 file changed, 3 insertions(+)

diff -puN fs/notify/inotify/inotify_user.c~inotify-actually-check-for-invalid-bits-in-sys_inotify_add_watch fs/notify/inotify/inotify_user.c

fs/notify/inotify/inotify_user.c renamed from fs/notify/inotify/inotify_user.c~inotify-actually-check-for-invalid-bits-in-sys_inotify_add_watch +3 -0
@@ -707,6 +707,9 @@ SYSCALL_DEFINE3(inotify_add_watch, int,
        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;
 

_

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/