* [PATCH -next] fanotify: Fix the checks in fanotify_fsid_equal
@ 2020-03-27 17:10 Nathan Chancellor
2020-03-27 17:26 ` Nick Desaulniers
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Nathan Chancellor @ 2020-03-27 17:10 UTC (permalink / raw)
To: Jan Kara
Cc: Amir Goldstein, linux-fsdevel, linux-kernel, clang-built-linux,
Nathan Chancellor
Clang warns:
fs/notify/fanotify/fanotify.c:28:23: warning: self-comparison always
evaluates to true [-Wtautological-compare]
return fsid1->val[0] == fsid1->val[0] && fsid2->val[1] == fsid2->val[1];
^
fs/notify/fanotify/fanotify.c:28:57: warning: self-comparison always
evaluates to true [-Wtautological-compare]
return fsid1->val[0] == fsid1->val[0] && fsid2->val[1] == fsid2->val[1];
^
2 warnings generated.
The intention was clearly to compare val[0] and val[1] in the two
different fsid structs. Fix it otherwise this function always returns
true.
Fixes: afc894c784c8 ("fanotify: Store fanotify handles differently")
Link: https://github.com/ClangBuiltLinux/linux/issues/952
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
fs/notify/fanotify/fanotify.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index 7a889da1ee12..cb54ecdb3fb9 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -25,7 +25,7 @@ static bool fanotify_path_equal(struct path *p1, struct path *p2)
static inline bool fanotify_fsid_equal(__kernel_fsid_t *fsid1,
__kernel_fsid_t *fsid2)
{
- return fsid1->val[0] == fsid1->val[0] && fsid2->val[1] == fsid2->val[1];
+ return fsid1->val[0] == fsid2->val[0] && fsid1->val[1] == fsid2->val[1];
}
static bool fanotify_fh_equal(struct fanotify_fh *fh1,
--
2.26.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH -next] fanotify: Fix the checks in fanotify_fsid_equal
2020-03-27 17:10 [PATCH -next] fanotify: Fix the checks in fanotify_fsid_equal Nathan Chancellor
@ 2020-03-27 17:26 ` Nick Desaulniers
2020-03-28 9:15 ` Amir Goldstein
2020-03-30 10:40 ` Jan Kara
2 siblings, 0 replies; 4+ messages in thread
From: Nick Desaulniers @ 2020-03-27 17:26 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Jan Kara, Amir Goldstein, linux-fsdevel, LKML, clang-built-linux
On Fri, Mar 27, 2020 at 10:10 AM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> Clang warns:
>
> fs/notify/fanotify/fanotify.c:28:23: warning: self-comparison always
> evaluates to true [-Wtautological-compare]
> return fsid1->val[0] == fsid1->val[0] && fsid2->val[1] == fsid2->val[1];
> ^
> fs/notify/fanotify/fanotify.c:28:57: warning: self-comparison always
> evaluates to true [-Wtautological-compare]
> return fsid1->val[0] == fsid1->val[0] && fsid2->val[1] == fsid2->val[1];
> ^
> 2 warnings generated.
>
> The intention was clearly to compare val[0] and val[1] in the two
> different fsid structs. Fix it otherwise this function always returns
> true.
>
> Fixes: afc894c784c8 ("fanotify: Store fanotify handles differently")
> Link: https://github.com/ClangBuiltLinux/linux/issues/952
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Thanks for the patch. Subtle bugs that are off by one character have
always been hard for me to spot!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
> fs/notify/fanotify/fanotify.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
> index 7a889da1ee12..cb54ecdb3fb9 100644
> --- a/fs/notify/fanotify/fanotify.c
> +++ b/fs/notify/fanotify/fanotify.c
> @@ -25,7 +25,7 @@ static bool fanotify_path_equal(struct path *p1, struct path *p2)
> static inline bool fanotify_fsid_equal(__kernel_fsid_t *fsid1,
> __kernel_fsid_t *fsid2)
> {
> - return fsid1->val[0] == fsid1->val[0] && fsid2->val[1] == fsid2->val[1];
> + return fsid1->val[0] == fsid2->val[0] && fsid1->val[1] == fsid2->val[1];
> }
>
> static bool fanotify_fh_equal(struct fanotify_fh *fh1,
> --
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next] fanotify: Fix the checks in fanotify_fsid_equal
2020-03-27 17:10 [PATCH -next] fanotify: Fix the checks in fanotify_fsid_equal Nathan Chancellor
2020-03-27 17:26 ` Nick Desaulniers
@ 2020-03-28 9:15 ` Amir Goldstein
2020-03-30 10:40 ` Jan Kara
2 siblings, 0 replies; 4+ messages in thread
From: Amir Goldstein @ 2020-03-28 9:15 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Jan Kara, linux-fsdevel, linux-kernel, clang-built-linux
On Fri, Mar 27, 2020 at 8:10 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> Clang warns:
>
> fs/notify/fanotify/fanotify.c:28:23: warning: self-comparison always
> evaluates to true [-Wtautological-compare]
> return fsid1->val[0] == fsid1->val[0] && fsid2->val[1] == fsid2->val[1];
> ^
> fs/notify/fanotify/fanotify.c:28:57: warning: self-comparison always
> evaluates to true [-Wtautological-compare]
> return fsid1->val[0] == fsid1->val[0] && fsid2->val[1] == fsid2->val[1];
> ^
> 2 warnings generated.
>
> The intention was clearly to compare val[0] and val[1] in the two
> different fsid structs. Fix it otherwise this function always returns
> true.
>
> Fixes: afc894c784c8 ("fanotify: Store fanotify handles differently")
> Link: https://github.com/ClangBuiltLinux/linux/issues/952
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---
Ouch! Good catch!
It would have been quite hard to catch this with tests as
non equal fsid and equal fid are quite rare in the wild.
I will try to write some test with mounts of cloned loop devs.
Thanks,
Amir.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next] fanotify: Fix the checks in fanotify_fsid_equal
2020-03-27 17:10 [PATCH -next] fanotify: Fix the checks in fanotify_fsid_equal Nathan Chancellor
2020-03-27 17:26 ` Nick Desaulniers
2020-03-28 9:15 ` Amir Goldstein
@ 2020-03-30 10:40 ` Jan Kara
2 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2020-03-30 10:40 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Jan Kara, Amir Goldstein, linux-fsdevel, linux-kernel, clang-built-linux
On Fri 27-03-20 10:10:30, Nathan Chancellor wrote:
> Clang warns:
>
> fs/notify/fanotify/fanotify.c:28:23: warning: self-comparison always
> evaluates to true [-Wtautological-compare]
> return fsid1->val[0] == fsid1->val[0] && fsid2->val[1] == fsid2->val[1];
> ^
> fs/notify/fanotify/fanotify.c:28:57: warning: self-comparison always
> evaluates to true [-Wtautological-compare]
> return fsid1->val[0] == fsid1->val[0] && fsid2->val[1] == fsid2->val[1];
> ^
> 2 warnings generated.
>
> The intention was clearly to compare val[0] and val[1] in the two
> different fsid structs. Fix it otherwise this function always returns
> true.
>
> Fixes: afc894c784c8 ("fanotify: Store fanotify handles differently")
> Link: https://github.com/ClangBuiltLinux/linux/issues/952
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Thanks for the fix! That's a good catch that would have been pain to debug!
I've applied it to my tree.
Honza
> ---
> fs/notify/fanotify/fanotify.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
> index 7a889da1ee12..cb54ecdb3fb9 100644
> --- a/fs/notify/fanotify/fanotify.c
> +++ b/fs/notify/fanotify/fanotify.c
> @@ -25,7 +25,7 @@ static bool fanotify_path_equal(struct path *p1, struct path *p2)
> static inline bool fanotify_fsid_equal(__kernel_fsid_t *fsid1,
> __kernel_fsid_t *fsid2)
> {
> - return fsid1->val[0] == fsid1->val[0] && fsid2->val[1] == fsid2->val[1];
> + return fsid1->val[0] == fsid2->val[0] && fsid1->val[1] == fsid2->val[1];
> }
>
> static bool fanotify_fh_equal(struct fanotify_fh *fh1,
> --
> 2.26.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-03-30 10:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-27 17:10 [PATCH -next] fanotify: Fix the checks in fanotify_fsid_equal Nathan Chancellor
2020-03-27 17:26 ` Nick Desaulniers
2020-03-28 9:15 ` Amir Goldstein
2020-03-30 10:40 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).