From: Dominique Martinet Date: Wed, 3 Nov 2021 08:34:05 +0000 (+0900) Subject: fscache_cookie_enabled: check cookie is valid before accessing it X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=ef3047fca111b6f3ef5d63dd8eb177df94dc2997;p=linux.git fscache_cookie_enabled: check cookie is valid before accessing it 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 Acked-by: David Howells Signed-off-by: Dominique Martinet Cc: Jeffrey E Altman Signed-off-by: Greg Kroah-Hartman --- diff --git a/include/linux/fscache.h b/include/linux/fscache.h index a4dab59986137..3b2282c157f79 100644 --- a/include/linux/fscache.h +++ b/include/linux/fscache.h @@ -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); } /*