]> git.baikalelectronics.ru Git - kernel.git/commit
fscache: Fix invalidation/lookup race
authorDavid Howells <dhowells@redhat.com>
Wed, 20 Apr 2022 13:27:17 +0000 (14:27 +0100)
committerDavid Howells <dhowells@redhat.com>
Tue, 5 Jul 2022 15:12:55 +0000 (16:12 +0100)
commit031884e80c1848d5450caf28041d8b5713dfe9a1
treef9ee0ccef90f4ee18ded974f90bbbecd3dd42466
parent59142d1bb95e2794682ec0e46788bfe562c2f7bd
fscache: Fix invalidation/lookup race

If an NFS file is opened for writing and closed, fscache_invalidate() will
be asked to invalidate the file - however, if the cookie is in the
LOOKING_UP state (or the CREATING state), then request to invalidate
doesn't get recorded for fscache_cookie_state_machine() to do something
with.

Fix this by making __fscache_invalidate() set a flag if it sees the cookie
is in the LOOKING_UP state to indicate that we need to go to invalidation.
Note that this requires a count on the n_accesses counter for the state
machine, which that will release when it's done.

fscache_cookie_state_machine() then shifts to the INVALIDATING state if it
sees the flag.

Without this, an nfs file can get corrupted if it gets modified locally and
then read locally as the cache contents may not get updated.

Fixes: 5de8fa09a284 ("fscache: Implement cookie invalidation")
Reported-by: Max Kellermann <mk@cm4all.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Tested-by: Max Kellermann <mk@cm4all.com>
Link: https://lore.kernel.org/r/YlWWbpW5Foynjllo@rabbit.intern.cm-ag
fs/fscache/cookie.c
include/linux/fscache.h