Skip to contentSkip to conversation

SUNRPC: fix delayed cache cleanup in write_flush

PATCH In review Jakub Klus 2 participants 2 messages Oct 23 – Oct 25

Subsystems (3)
lore
Share & tools
lore

Jakub Klus

author
#0 lore raw

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.

Fixes 3b68e6ee3cbd ("SUNRPC: cache: ignore timestamp written to 'flush' file.")
---
 net/sunrpc/cache.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/sunrpc/cache.c +3 -3
index 1bc04109d213d..871ba95626849 100644
@@ -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
maintainer
#1 lore raw
Quoted 11 lines · Jakub Klus

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.

[...]

Applied to nfsd-testing, thanks!

[1/1] SUNRPC: fix delayed cache cleanup in write_flush

      commit: fa5ce71d54eee315c5cdc95ca85bb1eae5336d4e

--
Chuck Lever