Re: [PATCH -next] fanotify: Fix the checks in fanotify_fsid_equal

From: Amir Goldstein
Date: Sat Mar 28 2020 - 05:15:31 EST


On Fri, Mar 27, 2020 at 8:10 PM Nathan Chancellor
<natechancellor@xxxxxxxxx> 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@xxxxxxxxx>
> ---

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.