Skip to content

Commit

Permalink
netfs, fscache: Prevent Oops in fscache_put_cache()
Browse files Browse the repository at this point in the history
[ Upstream commit 3be0b3e ]

This function dereferences "cache" and then checks if it's
IS_ERR_OR_NULL().  Check first, then dereference.

Fixes: 9549332 ("fscache: Implement cache registration")
Signed-off-by: Dan Carpenter <[email protected]>
Signed-off-by: David Howells <[email protected]>
Link: https://lore.kernel.org/r/[email protected]/ # v2
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Dan Carpenter authored and gregkh committed Feb 1, 2024
1 parent 7a73190 commit 1c45256
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fs/fscache/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,14 @@ EXPORT_SYMBOL(fscache_acquire_cache);
void fscache_put_cache(struct fscache_cache *cache,
enum fscache_cache_trace where)
{
unsigned int debug_id = cache->debug_id;
unsigned int debug_id;
bool zero;
int ref;

if (IS_ERR_OR_NULL(cache))
return;

debug_id = cache->debug_id;
zero = __refcount_dec_and_test(&cache->ref, &ref);
trace_fscache_cache(debug_id, ref - 1, where);

Expand Down

0 comments on commit 1c45256

Please sign in to comment.