SUNRPC: fix delayed cache cleanup in write_flush
Subsystems (3)
PATCH 1/1 SUNRPC: fix delayed cache cleanup in write_flush
When writing to the cache flush control file, write_flush() advances cd->flush_time so newly added entries aren't prematurely invalidated.
However, write_flush() was also assigning this future timestamp to cd->nextcheck. When cache_clean() runs, it sees that cd->nextcheck is in the future and skips cleaning the cache buckets. Rapid flushes (such as running exportfs -ua followed by exportfs -r, which can happen during systemctl restart nfs-server on RHEL) push cd->nextcheck further out, leaving old tombstone entries stuck in RAM.
Fix this by anchoring cd->nextcheck to current boot time (now), allowing cache_clean() to sweep deleted entries immediately.
This delay causes a subtle SELinux label loss failure in nfs-utils:
1. exportfs -ua && exportfs -r invalidates cache records but leaves the '-test-client-' tombstone in RAM due to the nextcheck delay.
2. During mount setup, rpc.mountd calls export_test(), which uses auth_domain_find() to verify if path probing succeeds.
3. Because auth_domain_find() does an RCU lookup without checking cache entry expiry, it hits the lingering tombstone (whose kref > 0) and erroneously returns success instead of -ENOENT.
4. This causes rpc.mountd to assign a physical UUID to a pseudo-root, collapsing the fsid boundary and causing the client to drop SELinux labels.
Note: The export_test() in rpc.mountd is scheduled to be removed from nfs-utils.
Tested on RHEL 10.3.
--- net/sunrpc/cache.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/sunrpc/cache.c +3 -3
@@ -1532,9 +1532,9 @@ static ssize_t write_flush(struct file *file, const char __user *buf,*/ if (cd->flush_time >= now) - now = cd->flush_time +1 ; - - cd->flush_time = now; + cd->flush_time++; +else + cd->flush_time = now; cd->nextcheck = now;cache_flush ();
Signature · 1 line
2.56.0
Chuck Lever
maintainerQuoted 11 lines · Jakub Klus
When writing to the cache flush control file,
write_flush()advancescd->flush_timeso newly added entries aren't prematurely invalidated.However,
write_flush()was also assigning this future timestamp tocd->nextcheck. Whencache_clean()runs, it sees thatcd->nextcheckis in the future and skips cleaning the cache buckets. Rapid flushes (such as runningexportfs -uafollowed byexportfs -r, which can happen during systemctl restart nfs-server on RHEL) pushcd->nextcheckfurther out, leaving old tombstone entries stuck in RAM.[...]
Applied to nfsd-testing, thanks!
[1/1] SUNRPC: fix delayed cache cleanup in write_flush
commit: fa5ce71d54eee315c5cdc95ca85bb1eae5336d4e
--
Chuck Lever