Revert "fanotify: remove unneeded sub-zero check for unsigned value"
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 20 May 2024 19:43:58 +0000 (12:43 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 20 May 2024 19:43:58 +0000 (12:43 -0700)
This reverts commit e6595224464b692ddae193d783402130d1625147.

These kinds of patches are only making the code worse.

Compilers don't care about the unnecessary check, but removing it makes
the code less obvious to a human.  The declaration of 'len' is more than
80 lines earlier, so a human won't easily see that 'len' is of an
unsigned type, so to a human the range check that checks against zero is
much more explicit and obvious.

Any tool that complains about a range check like this just because the
variable is unsigned is actively detrimental, and should be ignored.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/notify/fanotify/fanotify_user.c

index 483a6a1255fb2cdda97238388d14fb268cd0ced6..9ec313e9f6e199f8cc8aa8127022cc9e53aa6e2e 100644 (file)
@@ -502,7 +502,7 @@ static int copy_fid_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh,
        }
 
        /* Pad with 0's */
-       WARN_ON_ONCE(len >= FANOTIFY_EVENT_ALIGN);
+       WARN_ON_ONCE(len < 0 || len >= FANOTIFY_EVENT_ALIGN);
        if (len > 0 && clear_user(buf, len))
                return -EFAULT;