fscache_cookie_enabled: check cookie is valid before accessing it
authorDominique Martinet <asmadeus@codewreck.org>
Wed, 3 Nov 2021 08:34:05 +0000 (17:34 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 Jan 2022 14:35:11 +0000 (15:35 +0100)
commit 0dc54bd4d6e03be1f0b678c4297170b79f1a44ab upstream.

fscache_cookie_enabled() could be called on NULL cookies and cause a
null pointer dereference when accessing cookie flags: just make sure
the cookie is valid first

Suggested-by: David Howells <dhowells@redhat.com>
Acked-by: David Howells <dhowells@redhat.com>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
Cc: Jeffrey E Altman <jaltman@auristor.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/fscache.h

index a4dab599861373b75e4231e66ca9a640680a0a0e..3b2282c157f797de6d3b7a39aced1d61d7526eb9 100644 (file)
@@ -167,7 +167,7 @@ struct fscache_cookie {
 
 static inline bool fscache_cookie_enabled(struct fscache_cookie *cookie)
 {
-       return test_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
+       return fscache_cookie_valid(cookie) && test_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
 }
 
 /*