OSDN Git Service

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)
committerDominique Martinet <asmadeus@codewreck.org>
Wed, 3 Nov 2021 08:44:29 +0000 (17:44 +0900)
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>
include/linux/fscache.h

index a4dab59..3b2282c 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);
 }
 
 /*