Skip to content

Commit fb24771

Browse files
jtlaytondhowells
authored andcommitted
fscache: don't leak cookie access refs if invalidation is in progress 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 <[email protected]> Signed-off-by: Jeff Layton <[email protected]> Signed-off-by: David Howells <[email protected]>
1 parent 3d7cb6b commit fb24771

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/fscache/cookie.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,9 @@ static void fscache_cookie_state_machine(struct fscache_cookie *cookie)
739739
fallthrough;
740740

741741
case FSCACHE_COOKIE_STATE_FAILED:
742+
if (test_and_clear_bit(FSCACHE_COOKIE_DO_INVALIDATE, &cookie->flags))
743+
fscache_end_cookie_access(cookie, fscache_access_invalidate_cookie_end);
744+
742745
if (atomic_read(&cookie->n_accesses) != 0)
743746
break;
744747
if (test_bit(FSCACHE_COOKIE_DO_RELINQUISH, &cookie->flags)) {
@@ -1063,8 +1066,8 @@ void __fscache_invalidate(struct fscache_cookie *cookie,
10631066
return;
10641067

10651068
case FSCACHE_COOKIE_STATE_LOOKING_UP:
1066-
__fscache_begin_cookie_access(cookie, fscache_access_invalidate_cookie);
1067-
set_bit(FSCACHE_COOKIE_DO_INVALIDATE, &cookie->flags);
1069+
if (!test_and_set_bit(FSCACHE_COOKIE_DO_INVALIDATE, &cookie->flags))
1070+
__fscache_begin_cookie_access(cookie, fscache_access_invalidate_cookie);
10681071
fallthrough;
10691072
case FSCACHE_COOKIE_STATE_CREATING:
10701073
spin_unlock(&cookie->lock);

0 commit comments

Comments
 (0)