Skip to content

Commit

Permalink
fscache: don't leak cookie access refs if invalidation is in progress…
Browse files Browse the repository at this point in the history
… or failed

It's possible for a request to invalidate a fscache_cookie will come in
while we're already processing an invalidation. If that happens we
currently take an extra access reference that will leak. Only call
__fscache_begin_cookie_access if the FSCACHE_COOKIE_DO_INVALIDATE bit
was previously clear.

Also, ensure that we attempt to clear the bit when the cookie is
"FAILED" and put the reference to avoid an access leak.

Fixes: 85e4ea1 ("fscache: Fix invalidation/lookup race")
Suggested-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: David Howells <dhowells@redhat.com>
  • Loading branch information
Jeff Layton authored and David Howells committed Aug 9, 2022
1 parent 3d7cb6b commit fb24771
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fs/fscache/cookie.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,9 @@ static void fscache_cookie_state_machine(struct fscache_cookie *cookie)
fallthrough;

case FSCACHE_COOKIE_STATE_FAILED:
if (test_and_clear_bit(FSCACHE_COOKIE_DO_INVALIDATE, &cookie->flags))
fscache_end_cookie_access(cookie, fscache_access_invalidate_cookie_end);

if (atomic_read(&cookie->n_accesses) != 0)
break;
if (test_bit(FSCACHE_COOKIE_DO_RELINQUISH, &cookie->flags)) {
Expand Down Expand Up @@ -1063,8 +1066,8 @@ void __fscache_invalidate(struct fscache_cookie *cookie,
return;

case FSCACHE_COOKIE_STATE_LOOKING_UP:
__fscache_begin_cookie_access(cookie, fscache_access_invalidate_cookie);
set_bit(FSCACHE_COOKIE_DO_INVALIDATE, &cookie->flags);
if (!test_and_set_bit(FSCACHE_COOKIE_DO_INVALIDATE, &cookie->flags))
__fscache_begin_cookie_access(cookie, fscache_access_invalidate_cookie);
fallthrough;
case FSCACHE_COOKIE_STATE_CREATING:
spin_unlock(&cookie->lock);
Expand Down

0 comments on commit fb24771

Please sign in to comment.