Skip to contentSkip to conversation

fanotify: Fix the checks in fanotify_fsid_equal

PATCH In review Nathan Chancellor 4 participants 4 messages Mar 27, 2020 – Mar 30, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fanotify: Fix the checks in fanotify_fsid_equal

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")
---
 fs/notify/fanotify/fanotify.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/notify/fanotify/fanotify.c +1 -1
index 7a889da1ee12..cb54ecdb3fb9 100644
@@ -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,
Signature · 1 line
2.26.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · 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.

Quoted 7 lines

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")

Thanks for the patch. Subtle bugs that are off by one character have always been hard for me to spot!

Quoted 18 lines
---
 fs/notify/fanotify/fanotify.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/notify/fanotify/fanotify.c +1 -2
index 7a889da1ee12..cb54ecdb3fb9 100644
@@ -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,
--
Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw
In reply to Nathan Chancellor
Quoted 13 lines · 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.

Quoted 8 lines

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")

---

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.

maintainer
#3 lore raw
In reply to Nathan Chancellor
Quoted 12 lines · 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.

Quoted 7 lines

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")

Thanks for the fix! That's a good catch that would have been pain to debug! I've applied it to my tree.

Honza

Quoted 20 lines
---
 fs/notify/fanotify/fanotify.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/notify/fanotify/fanotify.c +1 -1
index 7a889da1ee12..cb54ecdb3fb9 100644
@@ -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,
Signature · 1 line
2.26.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR