* [PATCH 1/6] SUNRPC: Move cache_initialize() declaration to sunrpc-private header
2026-05-01 14:51 [PATCH 0/6] SUNRPC: Address remaining cache_check_rcu() UAF in cache content files Chuck Lever
@ 2026-05-01 14:51 ` Chuck Lever
2026-05-01 14:51 ` [PATCH 2/6] SUNRPC: Provide a shared workqueue for cache release callbacks Chuck Lever
` (6 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Chuck Lever @ 2026-05-01 14:51 UTC (permalink / raw)
To: Misbah Anjum N, Jeff Layton, NeilBrown, Olga Kornievskaia,
Dai Ngo, Tom Talpey, Trond Myklebust, Anna Schumaker,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Yang Erkun
Cc: linux-nfs, linux-kernel, netdev, Chuck Lever
From: Chuck Lever <chuck.lever@oracle.com>
cache_initialize() was introduced by commit 8eab945c5616 ("sunrpc:
make the cache cleaner workqueue deferrable", 2010) and placed in
the public include/linux/sunrpc/cache.h from the start, but it
has never been EXPORT_SYMBOL_GPL'd. The only caller, init_sunrpc()
in net/sunrpc/sunrpc_syms.c, is built into the same module that
defines the function, so external modules could not link against
the symbol even if they tried. The public declaration has been a
stale-public hygiene leak ever since.
Relocate the declaration to net/sunrpc/sunrpc.h alongside other
sunrpc-internal helpers and include that header from
net/sunrpc/cache.c so the compiler enforces prototype consistency
at the definition site. The public include/linux/sunrpc/cache.h
now reflects the actual external API surface.
No functional change.
Assisted-by: Claude:claude-opus-4-7[1m]
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
include/linux/sunrpc/cache.h | 1 -
net/sunrpc/cache.c | 1 +
net/sunrpc/sunrpc.h | 1 +
3 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
index 2735c332ddb7..83c88dc82e69 100644
--- a/include/linux/sunrpc/cache.h
+++ b/include/linux/sunrpc/cache.h
@@ -237,7 +237,6 @@ extern int cache_check(struct cache_detail *detail,
extern void cache_flush(void);
extern void cache_purge(struct cache_detail *detail);
#define NEVER (0x7FFFFFFF)
-extern void __init cache_initialize(void);
extern int cache_register_net(struct cache_detail *cd, struct net *net);
extern void cache_unregister_net(struct cache_detail *cd, struct net *net);
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 391037f15292..488a14961b19 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -39,6 +39,7 @@
#include "netns.h"
#include "netlink.h"
#include "fail.h"
+#include "sunrpc.h"
#define RPCDBG_FACILITY RPCDBG_CACHE
diff --git a/net/sunrpc/sunrpc.h b/net/sunrpc/sunrpc.h
index e3c6e3b63f0b..7fa35ee8f9a4 100644
--- a/net/sunrpc/sunrpc.h
+++ b/net/sunrpc/sunrpc.h
@@ -41,6 +41,7 @@ struct svc_rqst;
int rpc_clients_notifier_register(void);
void rpc_clients_notifier_unregister(void);
void auth_domain_cleanup(void);
+void __init cache_initialize(void);
void svc_sock_update_bufs(struct svc_serv *serv);
enum svc_auth_status svc_authenticate(struct svc_rqst *rqstp);
#endif /* _NET_SUNRPC_SUNRPC_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 2/6] SUNRPC: Provide a shared workqueue for cache release callbacks
2026-05-01 14:51 [PATCH 0/6] SUNRPC: Address remaining cache_check_rcu() UAF in cache content files Chuck Lever
2026-05-01 14:51 ` [PATCH 1/6] SUNRPC: Move cache_initialize() declaration to sunrpc-private header Chuck Lever
@ 2026-05-01 14:51 ` Chuck Lever
2026-05-01 14:51 ` [PATCH 3/6] SUNRPC: Defer ip_map sub-object cleanup past RCU grace period Chuck Lever
` (5 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Chuck Lever @ 2026-05-01 14:51 UTC (permalink / raw)
To: Misbah Anjum N, Jeff Layton, NeilBrown, Olga Kornievskaia,
Dai Ngo, Tom Talpey, Trond Myklebust, Anna Schumaker,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Yang Erkun
Cc: linux-nfs, linux-kernel, netdev, Chuck Lever
From: Chuck Lever <chuck.lever@oracle.com>
Cache .put callbacks may need to release sub-objects whose
cleanup sleeps (path_put, auth_domain_put, put_group_info), which
precludes running the release from a call_rcu() softirq callback.
Commit 48db892356d6 ("NFSD: Defer sub-object cleanup in export
put callbacks") introduced nfsd_export_wq for that purpose, with
a dedicated workqueue chosen so that flush_workqueue() in the
per-namespace teardown path drains only NFSD export release work
rather than blocking on unrelated work queued to system_unbound_wq.
Subsequent patches in this series convert the sunrpc ip_map and
unix_gid put callbacks to the same queue_rcu_work() pattern, and
those would otherwise need their own per-cache workqueue for the
same reason. Hoist the workqueue up to the sunrpc layer so that
all four cache_detail put callbacks share a single workqueue,
managed entirely within net/sunrpc/cache.c.
Expose the workqueue through three helpers.
sunrpc_cache_queue_release() schedules a deferred release after
the next RCU grace period. sunrpc_cache_destroy_net()
encapsulates the cache_unregister_net() + drain +
cache_destroy_net() sequence that single-cache teardowns
otherwise have to open-code, putting the ordering rule in one
place. sunrpc_cache_drain() exposes the underlying
rcu_barrier() + flush_workqueue() primitive for the rare caller
that drains multiple cache_details together, such as
nfsd_export_shutdown(). Allocate the workqueue in
cache_initialize() and destroy it in a new cache_destroy()
called from cleanup_sunrpc(). Replace the local nfsd_export_wq
with the shared sunrpc helpers and drop the
nfsd_export_wq_init/shutdown helpers and their callers.
Assisted-by: Claude:claude-opus-4-7[1m]
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfsd/export.c | 41 +++-----------------------
fs/nfsd/export.h | 2 --
fs/nfsd/nfsctl.c | 8 +----
include/linux/sunrpc/cache.h | 3 ++
net/sunrpc/cache.c | 70 +++++++++++++++++++++++++++++++++++++++++++-
net/sunrpc/sunrpc.h | 3 +-
net/sunrpc/sunrpc_syms.c | 23 +++++++++------
7 files changed, 93 insertions(+), 57 deletions(-)
diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index 15972919e1e9..3c4340e743fa 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -39,8 +39,6 @@
* second map contains a reference to the entry in the first map.
*/
-static struct workqueue_struct *nfsd_export_wq;
-
#define EXPKEY_HASHBITS 8
#define EXPKEY_HASHMAX (1 << EXPKEY_HASHBITS)
#define EXPKEY_HASHMASK (EXPKEY_HASHMAX -1)
@@ -62,7 +60,7 @@ static void expkey_put(struct kref *ref)
struct svc_expkey *key = container_of(ref, struct svc_expkey, h.ref);
INIT_RCU_WORK(&key->ek_rwork, expkey_release);
- queue_rcu_work(nfsd_export_wq, &key->ek_rwork);
+ sunrpc_cache_queue_release(&key->ek_rwork);
}
static int expkey_upcall(struct cache_detail *cd, struct cache_head *h)
@@ -652,7 +650,7 @@ static void svc_export_put(struct kref *ref)
struct svc_export *exp = container_of(ref, struct svc_export, h.ref);
INIT_RCU_WORK(&exp->ex_rwork, svc_export_release);
- queue_rcu_work(nfsd_export_wq, &exp->ex_rwork);
+ sunrpc_cache_queue_release(&exp->ex_rwork);
}
/**
@@ -2193,36 +2191,6 @@ const struct seq_operations nfs_exports_op = {
.show = e_show,
};
-/**
- * nfsd_export_wq_init - allocate the export release workqueue
- *
- * Called once at module load. The workqueue runs deferred svc_export and
- * svc_expkey release work scheduled by queue_rcu_work() in the cache put
- * callbacks.
- *
- * Return values:
- * %0: workqueue allocated
- * %-ENOMEM: allocation failed
- */
-int nfsd_export_wq_init(void)
-{
- nfsd_export_wq = alloc_workqueue("nfsd_export", WQ_UNBOUND, 0);
- if (!nfsd_export_wq)
- return -ENOMEM;
- return 0;
-}
-
-/**
- * nfsd_export_wq_shutdown - drain and free the export release workqueue
- *
- * Called once at module unload. Per-namespace teardown in
- * nfsd_export_shutdown() has already drained all deferred work.
- */
-void nfsd_export_wq_shutdown(void)
-{
- destroy_workqueue(nfsd_export_wq);
-}
-
/*
* Initialize the exports module.
*/
@@ -2284,9 +2252,8 @@ nfsd_export_shutdown(struct net *net)
cache_unregister_net(nn->svc_expkey_cache, net);
cache_unregister_net(nn->svc_export_cache, net);
- /* Drain deferred export and expkey release work. */
- rcu_barrier();
- flush_workqueue(nfsd_export_wq);
+ /* One drain covers both caches' deferred release work. */
+ sunrpc_cache_drain();
cache_destroy_net(nn->svc_expkey_cache, net);
cache_destroy_net(nn->svc_export_cache, net);
svcauth_unix_purge(net);
diff --git a/fs/nfsd/export.h b/fs/nfsd/export.h
index b05399374574..8969e81de448 100644
--- a/fs/nfsd/export.h
+++ b/fs/nfsd/export.h
@@ -111,8 +111,6 @@ __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp,
/*
* Function declarations
*/
-int nfsd_export_wq_init(void);
-void nfsd_export_wq_shutdown(void);
int nfsd_export_init(struct net *);
void nfsd_export_shutdown(struct net *);
void nfsd_export_flush(struct net *);
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index 064a2e749bc9..468aad8c3af9 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -2536,12 +2536,9 @@ static int __init init_nfsd(void)
if (retval)
goto out_free_pnfs;
nfsd_lockd_init(); /* lockd->nfsd callbacks */
- retval = nfsd_export_wq_init();
- if (retval)
- goto out_free_lockd;
retval = register_pernet_subsys(&nfsd_net_ops);
if (retval < 0)
- goto out_free_export_wq;
+ goto out_free_lockd;
retval = register_cld_notifier();
if (retval)
goto out_free_subsys;
@@ -2570,8 +2567,6 @@ static int __init init_nfsd(void)
unregister_cld_notifier();
out_free_subsys:
unregister_pernet_subsys(&nfsd_net_ops);
-out_free_export_wq:
- nfsd_export_wq_shutdown();
out_free_lockd:
nfsd_lockd_shutdown();
nfsd_drc_slab_free();
@@ -2592,7 +2587,6 @@ static void __exit exit_nfsd(void)
nfsd4_destroy_laundry_wq();
unregister_cld_notifier();
unregister_pernet_subsys(&nfsd_net_ops);
- nfsd_export_wq_shutdown();
nfsd_drc_slab_free();
nfsd_lockd_shutdown();
nfsd4_free_slabs();
diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
index 83c88dc82e69..84802438a5fc 100644
--- a/include/linux/sunrpc/cache.h
+++ b/include/linux/sunrpc/cache.h
@@ -237,11 +237,14 @@ extern int cache_check(struct cache_detail *detail,
extern void cache_flush(void);
extern void cache_purge(struct cache_detail *detail);
#define NEVER (0x7FFFFFFF)
+extern void sunrpc_cache_queue_release(struct rcu_work *rwork);
+extern void sunrpc_cache_drain(void);
extern int cache_register_net(struct cache_detail *cd, struct net *net);
extern void cache_unregister_net(struct cache_detail *cd, struct net *net);
extern struct cache_detail *cache_create_net(const struct cache_detail *tmpl, struct net *net);
extern void cache_destroy_net(struct cache_detail *cd, struct net *net);
+extern void sunrpc_cache_destroy_net(struct cache_detail *cd, struct net *net);
extern void sunrpc_init_cache_detail(struct cache_detail *cd);
extern void sunrpc_destroy_cache_detail(struct cache_detail *cd);
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 488a14961b19..733bcd3daa46 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -1705,9 +1705,77 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
return -ENOMEM;
}
-void __init cache_initialize(void)
+static struct workqueue_struct *sunrpc_cache_wq;
+
+/**
+ * sunrpc_cache_queue_release - schedule deferred cache release work
+ * @rwork: caller-initialized rcu_work to queue
+ *
+ * Run @rwork in process context after the next RCU grace period.
+ * Use this for cache .put callbacks whose cleanup may sleep
+ * (path_put(), auth_domain_put()).
+ */
+void sunrpc_cache_queue_release(struct rcu_work *rwork)
{
+ queue_rcu_work(sunrpc_cache_wq, rwork);
+}
+EXPORT_SYMBOL_GPL(sunrpc_cache_queue_release);
+
+/**
+ * sunrpc_cache_drain - drain pending cache release work
+ *
+ * Wait for outstanding RCU callbacks to enqueue their release
+ * work, then flush that work to completion.
+ */
+void sunrpc_cache_drain(void)
+{
+ rcu_barrier();
+ flush_workqueue(sunrpc_cache_wq);
+}
+EXPORT_SYMBOL_GPL(sunrpc_cache_drain);
+
+/**
+ * sunrpc_cache_destroy_net - quiesce and tear down a per-net cache
+ * @cd: the cache_detail to release
+ * @net: the network namespace owning @cd
+ *
+ * Canonical teardown for caches whose .put callbacks use
+ * sunrpc_cache_queue_release(). Unregister @cd to stop new
+ * lookups, drain in-flight RCU callbacks and queued release
+ * work, then free @cd and its hash table. The drain ensures
+ * release workers complete while the cache_detail is still
+ * valid.
+ */
+void sunrpc_cache_destroy_net(struct cache_detail *cd, struct net *net)
+{
+ cache_unregister_net(cd, net);
+ sunrpc_cache_drain();
+ cache_destroy_net(cd, net);
+}
+EXPORT_SYMBOL_GPL(sunrpc_cache_destroy_net);
+
+/**
+ * cache_initialize - allocate sunrpc cache subsystem resources
+ */
+int __init cache_initialize(void)
+{
+ sunrpc_cache_wq = alloc_workqueue("sunrpc_cache",
+ WQ_UNBOUND | WQ_MEM_RECLAIM, 0);
+ if (!sunrpc_cache_wq)
+ return -ENOMEM;
INIT_DEFERRABLE_WORK(&cache_cleaner, do_cache_clean);
+ return 0;
+}
+
+/**
+ * cache_destroy - release sunrpc cache subsystem resources
+ *
+ * Caller must ensure no further sunrpc_cache_queue_release()
+ * calls can be scheduled before invoking this.
+ */
+void cache_destroy(void)
+{
+ destroy_workqueue(sunrpc_cache_wq);
}
int cache_register_net(struct cache_detail *cd, struct net *net)
diff --git a/net/sunrpc/sunrpc.h b/net/sunrpc/sunrpc.h
index 7fa35ee8f9a4..75ee201e4800 100644
--- a/net/sunrpc/sunrpc.h
+++ b/net/sunrpc/sunrpc.h
@@ -41,7 +41,8 @@ struct svc_rqst;
int rpc_clients_notifier_register(void);
void rpc_clients_notifier_unregister(void);
void auth_domain_cleanup(void);
-void __init cache_initialize(void);
+int __init cache_initialize(void);
+void cache_destroy(void);
void svc_sock_update_bufs(struct svc_serv *serv);
enum svc_auth_status svc_authenticate(struct svc_rqst *rqstp);
#endif /* _NET_SUNRPC_SUNRPC_H */
diff --git a/net/sunrpc/sunrpc_syms.c b/net/sunrpc/sunrpc_syms.c
index ab88ce46afb5..d75ff1e592f2 100644
--- a/net/sunrpc/sunrpc_syms.c
+++ b/net/sunrpc/sunrpc_syms.c
@@ -97,24 +97,26 @@ init_sunrpc(void)
if (err)
goto out2;
- cache_initialize();
-
- err = register_pernet_subsys(&sunrpc_net_ops);
+ err = cache_initialize();
if (err)
goto out3;
- err = register_rpc_pipefs();
+ err = register_pernet_subsys(&sunrpc_net_ops);
if (err)
goto out4;
- err = rpc_sysfs_init();
+ err = register_rpc_pipefs();
if (err)
goto out5;
- err = genl_register_family(&sunrpc_nl_family);
+ err = rpc_sysfs_init();
if (err)
goto out6;
+ err = genl_register_family(&sunrpc_nl_family);
+ if (err)
+ goto out7;
+
sunrpc_debugfs_init();
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
rpc_register_sysctl();
@@ -123,12 +125,14 @@ init_sunrpc(void)
init_socket_xprt(); /* clnt sock transport */
return 0;
-out6:
+out7:
rpc_sysfs_exit();
-out5:
+out6:
unregister_rpc_pipefs();
-out4:
+out5:
unregister_pernet_subsys(&sunrpc_net_ops);
+out4:
+ cache_destroy();
out3:
rpcauth_remove_module();
out2:
@@ -157,6 +161,7 @@ cleanup_sunrpc(void)
rpc_unregister_sysctl();
#endif
rcu_barrier(); /* Wait for completion of call_rcu()'s */
+ cache_destroy();
}
MODULE_DESCRIPTION("Sun RPC core");
MODULE_LICENSE("GPL");
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 3/6] SUNRPC: Defer ip_map sub-object cleanup past RCU grace period
2026-05-01 14:51 [PATCH 0/6] SUNRPC: Address remaining cache_check_rcu() UAF in cache content files Chuck Lever
2026-05-01 14:51 ` [PATCH 1/6] SUNRPC: Move cache_initialize() declaration to sunrpc-private header Chuck Lever
2026-05-01 14:51 ` [PATCH 2/6] SUNRPC: Provide a shared workqueue for cache release callbacks Chuck Lever
@ 2026-05-01 14:51 ` Chuck Lever
2026-05-01 14:51 ` [PATCH 4/6] SUNRPC: Use shared release pattern for the unix_gid cache Chuck Lever
` (4 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Chuck Lever @ 2026-05-01 14:51 UTC (permalink / raw)
To: Misbah Anjum N, Jeff Layton, NeilBrown, Olga Kornievskaia,
Dai Ngo, Tom Talpey, Trond Myklebust, Anna Schumaker,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Yang Erkun
Cc: linux-nfs, linux-kernel, netdev, Chuck Lever
From: Chuck Lever <chuck.lever@oracle.com>
ip_map_put() is already correct in that auth_domain_put() of
im->m_client reaches svcauth_unix_domain_release(), which defers
the actual kfree() of the unix_domain with call_rcu(); the ip_map
itself is freed via kfree_rcu(). Readers in c_show() under
cache_seq_start_rcu() therefore observe both objects until the
next RCU grace period.
This patch is a consistency change rather than a bug fix. The
svc_export and svc_expkey caches were converted to the
queue_rcu_work() pattern in commit 48db892356d6 ("NFSD: Defer
sub-object cleanup in export put callbacks") because path_put()
and auth_domain_put() must run in process context after the RCU
grace period. The next patch routes unix_gid through the same
mechanism. Sending ip_map through sunrpc_cache_queue_release()
unifies all four cache_detail .put callbacks on a single release
path and removes the implicit reliance on every current and
future auth_ops .domain_release implementation deferring its own
kfree() behind call_rcu().
Replace the rcu_head field with an rcu_work, move the kfree() and
auth_domain_put() into a new ip_map_release() taking a
work_struct, and have ip_map_put() invoke INIT_RCU_WORK() and
sunrpc_cache_queue_release() in place of kfree_rcu(). Switch
ip_map_cache_destroy() to sunrpc_cache_destroy_net() so
per-namespace teardown waits for outstanding release work
before freeing the cache_detail.
Assisted-by: Claude:claude-opus-4-7[1m]
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
net/sunrpc/svcauth_unix.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 64a2658faddb..14688813c242 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -103,18 +103,26 @@ struct ip_map {
char m_class[8]; /* e.g. "nfsd" */
struct in6_addr m_addr;
struct unix_domain *m_client;
- struct rcu_head m_rcu;
+ struct rcu_work m_rwork;
};
+static void ip_map_release(struct work_struct *work)
+{
+ struct ip_map *im = container_of(to_rcu_work(work),
+ struct ip_map, m_rwork);
+
+ if (test_bit(CACHE_VALID, &im->h.flags) &&
+ !test_bit(CACHE_NEGATIVE, &im->h.flags))
+ auth_domain_put(&im->m_client->h);
+ kfree(im);
+}
+
static void ip_map_put(struct kref *kref)
{
- struct cache_head *item = container_of(kref, struct cache_head, ref);
- struct ip_map *im = container_of(item, struct ip_map,h);
+ struct ip_map *im = container_of(kref, struct ip_map, h.ref);
- if (test_bit(CACHE_VALID, &item->flags) &&
- !test_bit(CACHE_NEGATIVE, &item->flags))
- auth_domain_put(&im->m_client->h);
- kfree_rcu(im, m_rcu);
+ INIT_RCU_WORK(&im->m_rwork, ip_map_release);
+ sunrpc_cache_queue_release(&im->m_rwork);
}
static inline int hash_ip6(const struct in6_addr *ip)
@@ -1569,6 +1577,5 @@ void ip_map_cache_destroy(struct net *net)
sn->ip_map_cache = NULL;
cache_purge(cd);
- cache_unregister_net(cd, net);
- cache_destroy_net(cd, net);
+ sunrpc_cache_destroy_net(cd, net);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 4/6] SUNRPC: Use shared release pattern for the unix_gid cache
2026-05-01 14:51 [PATCH 0/6] SUNRPC: Address remaining cache_check_rcu() UAF in cache content files Chuck Lever
` (2 preceding siblings ...)
2026-05-01 14:51 ` [PATCH 3/6] SUNRPC: Defer ip_map sub-object cleanup past RCU grace period Chuck Lever
@ 2026-05-01 14:51 ` Chuck Lever
2026-05-01 14:51 ` [PATCH 5/6] SUNRPC: Hold cd->net for the lifetime of cache files Chuck Lever
` (3 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Chuck Lever @ 2026-05-01 14:51 UTC (permalink / raw)
To: Misbah Anjum N, Jeff Layton, NeilBrown, Olga Kornievskaia,
Dai Ngo, Tom Talpey, Trond Myklebust, Anna Schumaker,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Yang Erkun
Cc: linux-nfs, linux-kernel, netdev, Chuck Lever
From: Chuck Lever <chuck.lever@oracle.com>
unix_gid_put() is already correct in that put_group_info() runs
inside its call_rcu() callback, after the RCU grace period.
This patch is a consistency change rather than a bug fix:
the three other cache_detail .put callbacks (svc_export,
svc_expkey, ip_map) now use the queue_rcu_work() pattern via
sunrpc_cache_queue_release(), and routing unix_gid through the same
path keeps a single release mechanism for all four caches.
Replace the rcu_head field with an rcu_work, rename
unix_gid_free() to unix_gid_release() and convert it to take
a work_struct, and have unix_gid_put() invoke INIT_RCU_WORK()
and sunrpc_cache_queue_release() in place of call_rcu().
Switch unix_gid_cache_destroy() to sunrpc_cache_destroy_net()
so per-namespace teardown waits for outstanding release work
before freeing the cache_detail.
Assisted-by: Claude:claude-opus-4-7[1m]
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
net/sunrpc/svcauth_unix.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 14688813c242..762cf03574b4 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -420,7 +420,7 @@ struct unix_gid {
struct cache_head h;
kuid_t uid;
struct group_info *gi;
- struct rcu_head rcu;
+ struct rcu_work rwork;
};
static int unix_gid_hash(kuid_t uid)
@@ -428,23 +428,23 @@ static int unix_gid_hash(kuid_t uid)
return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
}
-static void unix_gid_free(struct rcu_head *rcu)
+static void unix_gid_release(struct work_struct *work)
{
- struct unix_gid *ug = container_of(rcu, struct unix_gid, rcu);
- struct cache_head *item = &ug->h;
+ struct unix_gid *ug = container_of(to_rcu_work(work),
+ struct unix_gid, rwork);
- if (test_bit(CACHE_VALID, &item->flags) &&
- !test_bit(CACHE_NEGATIVE, &item->flags))
+ if (test_bit(CACHE_VALID, &ug->h.flags) &&
+ !test_bit(CACHE_NEGATIVE, &ug->h.flags))
put_group_info(ug->gi);
kfree(ug);
}
static void unix_gid_put(struct kref *kref)
{
- struct cache_head *item = container_of(kref, struct cache_head, ref);
- struct unix_gid *ug = container_of(item, struct unix_gid, h);
+ struct unix_gid *ug = container_of(kref, struct unix_gid, h.ref);
- call_rcu(&ug->rcu, unix_gid_free);
+ INIT_RCU_WORK(&ug->rwork, unix_gid_release);
+ sunrpc_cache_queue_release(&ug->rwork);
}
static int unix_gid_match(struct cache_head *corig, struct cache_head *cnew)
@@ -899,8 +899,7 @@ void unix_gid_cache_destroy(struct net *net)
sn->unix_gid_cache = NULL;
cache_purge(cd);
- cache_unregister_net(cd, net);
- cache_destroy_net(cd, net);
+ sunrpc_cache_destroy_net(cd, net);
}
static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid)
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 5/6] SUNRPC: Hold cd->net for the lifetime of cache files
2026-05-01 14:51 [PATCH 0/6] SUNRPC: Address remaining cache_check_rcu() UAF in cache content files Chuck Lever
` (3 preceding siblings ...)
2026-05-01 14:51 ` [PATCH 4/6] SUNRPC: Use shared release pattern for the unix_gid cache Chuck Lever
@ 2026-05-01 14:51 ` Chuck Lever
2026-05-01 14:51 ` [PATCH 6/6] NFSD: Convert nfsd_export_shutdown() to sunrpc_cache_destroy_net() Chuck Lever
` (2 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Chuck Lever @ 2026-05-01 14:51 UTC (permalink / raw)
To: Misbah Anjum N, Jeff Layton, NeilBrown, Olga Kornievskaia,
Dai Ngo, Tom Talpey, Trond Myklebust, Anna Schumaker,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Yang Erkun
Cc: linux-nfs, linux-kernel, netdev, Chuck Lever
From: Chuck Lever <chuck.lever@oracle.com>
Each per-net sunrpc cache exposes three files under
/proc/net/rpc/<cachename>/: content, channel, and flush.
Their open helpers (content_open, cache_open, open_flush) take a
reference on cd->owner via try_module_get() but no reference on
cd->net. When the network namespace exits, cache_unregister_net()
followed by cache_destroy_net() free cd->hash_table and cd
synchronously without RCU deferral. Any subsequent operation on
the still-open file dereferences the freed cache_detail.
The fault produced by sosreport on aarch64 and ppc64le shows the
typical signature: cache_check_rcu() faults reading h->flags off
a garbage cache_head pointer that came from __cache_seq_start()
walking a freed cd->hash_table. Commit e7fcf179b82d ("NFSD: Hold
net reference for the lifetime of /proc/fs/nfs/exports fd") closed
this hole only for the /proc/fs/nfs/exports file, which has its own
open path; the sunrpc cache files were left exposed.
Take a get_net(cd->net) in content_open(), cache_open(), and
open_flush() once the open has otherwise succeeded, and a matching
put_net() at the tail of each release helper. Holding the net
reference for the open file lifetime prevents the namespace from
exiting while a cache fd is open, which in turn prevents
cache_destroy_net() from running and freeing cd from under the
reader.
put_net() can drop the last namespace reference, in which case
__put_net() queues net_cleanup_work on netns_wq. That work runs
ops_undo_list() on another CPU, which invokes sunrpc_exit_net()
and frees cd via cache_destroy_net(). The release helper must
not dereference cd after put_net(): cache_release(),
content_release(), and release_flush() therefore capture
cd->owner and cd->net into local variables before calling
put_net(net) and module_put(owner).
Reported-by: Misbah Anjum N <misanjum@linux.ibm.com>
Closes: https://lore.kernel.org/linux-nfs/8cf80f450085ac17164e8fa1391e9635@linux.ibm.com/
Fixes: 1b10f0b603c0 ("SUNRPC: no need get cache ref when protected by rcu")
Assisted-by: Claude:claude-opus-4-7[1m]
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
net/sunrpc/cache.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index 733bcd3daa46..be7a0c8c416e 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -1037,6 +1037,7 @@ static int cache_open(struct inode *inode, struct file *filp,
if (filp->f_mode & FMODE_WRITE)
atomic_inc(&cd->writers);
filp->private_data = rp;
+ get_net(cd->net);
return 0;
}
@@ -1044,6 +1045,8 @@ static int cache_release(struct inode *inode, struct file *filp,
struct cache_detail *cd)
{
struct cache_reader *rp = filp->private_data;
+ struct module *owner;
+ struct net *net;
if (rp) {
struct cache_request *rq = NULL;
@@ -1080,7 +1083,10 @@ static int cache_release(struct inode *inode, struct file *filp,
atomic_dec(&cd->writers);
cd->last_close = seconds_since_boot();
}
- module_put(cd->owner);
+ owner = cd->owner;
+ net = cd->net;
+ put_net(net);
+ module_put(owner);
return 0;
}
@@ -1466,14 +1472,19 @@ static int content_open(struct inode *inode, struct file *file,
seq = file->private_data;
seq->private = cd;
+ get_net(cd->net);
return 0;
}
static int content_release(struct inode *inode, struct file *file,
struct cache_detail *cd)
{
+ struct module *owner = cd->owner;
+ struct net *net = cd->net;
int ret = seq_release(inode, file);
- module_put(cd->owner);
+
+ put_net(net);
+ module_put(owner);
return ret;
}
@@ -1482,13 +1493,18 @@ static int open_flush(struct inode *inode, struct file *file,
{
if (!cd || !try_module_get(cd->owner))
return -EACCES;
+ get_net(cd->net);
return nonseekable_open(inode, file);
}
static int release_flush(struct inode *inode, struct file *file,
struct cache_detail *cd)
{
- module_put(cd->owner);
+ struct module *owner = cd->owner;
+ struct net *net = cd->net;
+
+ put_net(net);
+ module_put(owner);
return 0;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 6/6] NFSD: Convert nfsd_export_shutdown() to sunrpc_cache_destroy_net()
2026-05-01 14:51 [PATCH 0/6] SUNRPC: Address remaining cache_check_rcu() UAF in cache content files Chuck Lever
` (4 preceding siblings ...)
2026-05-01 14:51 ` [PATCH 5/6] SUNRPC: Hold cd->net for the lifetime of cache files Chuck Lever
@ 2026-05-01 14:51 ` Chuck Lever
2026-05-05 5:32 ` [PATCH 0/6] SUNRPC: Address remaining cache_check_rcu() UAF in cache content files Jeff Layton
2026-05-05 10:49 ` Calum Mackay
7 siblings, 0 replies; 10+ messages in thread
From: Chuck Lever @ 2026-05-01 14:51 UTC (permalink / raw)
To: Misbah Anjum N, Jeff Layton, NeilBrown, Olga Kornievskaia,
Dai Ngo, Tom Talpey, Trond Myklebust, Anna Schumaker,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Yang Erkun
Cc: linux-nfs, linux-kernel, netdev, Chuck Lever
From: Chuck Lever <chuck.lever@oracle.com>
The earlier conversion to the shared sunrpc cache workqueue left
nfsd_export_shutdown() open-coding the unregister + drain + destroy
sequence to amortize a single rcu_barrier()+flush across both
caches. That micro-optimization runs only on namespace teardown
and module unload, neither of which is performance-sensitive.
Switch both caches to sunrpc_cache_destroy_net() so that the
canonical teardown idiom is applied uniformly. A future change to
the per-cache release callback that requires the cache_detail to
remain valid through the drain remains correct without per-call-site
auditing.
With the last external caller of sunrpc_cache_drain() gone, drop
the symbol export and the public declaration, and mark the
function static so the compiler can inline it into
sunrpc_cache_destroy_net().
Assisted-by: Claude:claude-opus-4-7[1m]
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfsd/export.c | 8 ++------
include/linux/sunrpc/cache.h | 1 -
net/sunrpc/cache.c | 7 ++-----
3 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index 3c4340e743fa..c19f8e8c4f9e 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -2250,12 +2250,8 @@ nfsd_export_shutdown(struct net *net)
dprintk("nfsd: shutting down export module (net: %x).\n", net->ns.inum);
- cache_unregister_net(nn->svc_expkey_cache, net);
- cache_unregister_net(nn->svc_export_cache, net);
- /* One drain covers both caches' deferred release work. */
- sunrpc_cache_drain();
- cache_destroy_net(nn->svc_expkey_cache, net);
- cache_destroy_net(nn->svc_export_cache, net);
+ sunrpc_cache_destroy_net(nn->svc_expkey_cache, net);
+ sunrpc_cache_destroy_net(nn->svc_export_cache, net);
svcauth_unix_purge(net);
dprintk("nfsd: export shutdown complete (net: %x).\n", net->ns.inum);
diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
index 84802438a5fc..22c18eeb5a97 100644
--- a/include/linux/sunrpc/cache.h
+++ b/include/linux/sunrpc/cache.h
@@ -238,7 +238,6 @@ extern void cache_flush(void);
extern void cache_purge(struct cache_detail *detail);
#define NEVER (0x7FFFFFFF)
extern void sunrpc_cache_queue_release(struct rcu_work *rwork);
-extern void sunrpc_cache_drain(void);
extern int cache_register_net(struct cache_detail *cd, struct net *net);
extern void cache_unregister_net(struct cache_detail *cd, struct net *net);
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index be7a0c8c416e..62ce334104d9 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -1737,18 +1737,15 @@ void sunrpc_cache_queue_release(struct rcu_work *rwork)
}
EXPORT_SYMBOL_GPL(sunrpc_cache_queue_release);
-/**
- * sunrpc_cache_drain - drain pending cache release work
- *
+/*
* Wait for outstanding RCU callbacks to enqueue their release
* work, then flush that work to completion.
*/
-void sunrpc_cache_drain(void)
+static void sunrpc_cache_drain(void)
{
rcu_barrier();
flush_workqueue(sunrpc_cache_wq);
}
-EXPORT_SYMBOL_GPL(sunrpc_cache_drain);
/**
* sunrpc_cache_destroy_net - quiesce and tear down a per-net cache
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 0/6] SUNRPC: Address remaining cache_check_rcu() UAF in cache content files
2026-05-01 14:51 [PATCH 0/6] SUNRPC: Address remaining cache_check_rcu() UAF in cache content files Chuck Lever
` (5 preceding siblings ...)
2026-05-01 14:51 ` [PATCH 6/6] NFSD: Convert nfsd_export_shutdown() to sunrpc_cache_destroy_net() Chuck Lever
@ 2026-05-05 5:32 ` Jeff Layton
2026-05-05 10:49 ` Calum Mackay
7 siblings, 0 replies; 10+ messages in thread
From: Jeff Layton @ 2026-05-05 5:32 UTC (permalink / raw)
To: Chuck Lever, Misbah Anjum N, NeilBrown, Olga Kornievskaia,
Dai Ngo, Tom Talpey, Trond Myklebust, Anna Schumaker,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Yang Erkun
Cc: linux-nfs, linux-kernel, netdev, Chuck Lever
On Fri, 2026-05-01 at 10:51 -0400, Chuck Lever wrote:
> Misbah Anjum reported a use-after-free in cache_check_rcu()
> reached through e_show() while sosreport was reading
> /proc/fs/nfsd/exports on ppc64le. Two fixes for that report
> landed in v7.0:
>
> 48db892356d6 ("NFSD: Defer sub-object cleanup in export put callbacks")
> e7fcf179b82d ("NFSD: Hold net reference for the lifetime of /proc/fs/nfs/exports fd")
>
> The original e_show() repro is now fixed. However, the same
> sosreport workload still reproduces a closely related fault on
> post-v7.0 mainline (Misbah, ppc64le) and on master.20260424
> (internal report, aarch64). In both cases the fault is in
> cache_check_rcu() reached through c_show() rather than e_show(),
> and the cache_head pointer is plain garbage:
>
> pc : cache_check_rcu+0x40 [sunrpc]
> lr : c_show+0x60 [sunrpc]
> ...faulting on h->flags off h = 0x0000000200000000
>
> c_show() is the generic show callback used by
> /proc/net/rpc/<cd>/content for every per-net cache_detail
> (auth.unix.ip, auth.unix.gid, nfsd.fh, nfsd.export). Two
> bugs combine in that path:
>
> 1. cache_unregister_net() / cache_destroy_net() free cd and
> cd->hash_table synchronously when the namespace exits. The
> /proc/net/rpc/.../content open path takes only a module
> reference, so a fd kept open across a netns exit walks a
> freed hash_table and returns garbage cache_head pointers.
> This is the same hazard that e7fcf179b82d closed for the
> /proc/fs/nfs/exports file alone.
>
> 2. ip_map_put() drops auth_domain_put() before kfree_rcu(), so
> sub-objects can be freed before the RCU grace period -- the
> same hazard that 48db892356d6 fixed for svc_export_put() and
> expkey_put(). unix_gid_put() does not have this bug
> structurally (its put_group_info() runs inside the call_rcu()
> callback) but it uses a separate idiom from the other three
> caches.
>
> This series replaces the v1 narrow fixes with shared
> infrastructure that covers all four cache_detail .put paths
> and all three per-cache file types:
>
> Patch 1 hoists nfsd_export_wq up to the sunrpc layer as
> sunrpc_cache_wq, exposed through sunrpc_cache_queue_release()
> and sunrpc_cache_drain() so all four put callbacks share one
> workqueue and one drain primitive.
>
> Patch 2 converts ip_map_put() to the queue_rcu_work() pattern,
> moving auth_domain_put() into a deferred ip_map_release() that
> runs after the RCU grace period.
>
> Patch 3 unifies unix_gid_put() onto the same pattern for
> consistency (not a bug fix on its own).
>
> Patch 4 takes a get_net(cd->net) in content_open(), cache_open(),
> and open_flush() and drops it in the matching release helpers,
> so cache_destroy_net() cannot run while a sunrpc cache fd is
> open.
>
> Series has been compile-tested only.
>
> ---
> Chuck Lever (6):
> SUNRPC: Move cache_initialize() declaration to sunrpc-private header
> SUNRPC: Provide a shared workqueue for cache release callbacks
> SUNRPC: Defer ip_map sub-object cleanup past RCU grace period
> SUNRPC: Use shared release pattern for the unix_gid cache
> SUNRPC: Hold cd->net for the lifetime of cache files
> NFSD: Convert nfsd_export_shutdown() to sunrpc_cache_destroy_net()
>
> fs/nfsd/export.c | 45 ++--------------------
> fs/nfsd/export.h | 2 -
> fs/nfsd/nfsctl.c | 8 +---
> include/linux/sunrpc/cache.h | 3 +-
> net/sunrpc/cache.c | 90 ++++++++++++++++++++++++++++++++++++++++++--
> net/sunrpc/sunrpc.h | 2 +
> net/sunrpc/sunrpc_syms.c | 23 ++++++-----
> net/sunrpc/svcauth_unix.c | 46 ++++++++++++----------
> 8 files changed, 135 insertions(+), 84 deletions(-)
> ---
> base-commit: f3a313ecd1fdab1f5da119db355363b13af6fcac
> change-id: 20260430-cache-uaf-fix-a13000f67c37
>
> Best regards,
> --
> Chuck Lever
The series looks sane.
Reviewed-by: Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 0/6] SUNRPC: Address remaining cache_check_rcu() UAF in cache content files
2026-05-01 14:51 [PATCH 0/6] SUNRPC: Address remaining cache_check_rcu() UAF in cache content files Chuck Lever
` (6 preceding siblings ...)
2026-05-05 5:32 ` [PATCH 0/6] SUNRPC: Address remaining cache_check_rcu() UAF in cache content files Jeff Layton
@ 2026-05-05 10:49 ` Calum Mackay
2026-05-05 10:53 ` Chuck Lever
7 siblings, 1 reply; 10+ messages in thread
From: Calum Mackay @ 2026-05-05 10:49 UTC (permalink / raw)
To: Chuck Lever, Misbah Anjum N, Jeff Layton, NeilBrown,
Olga Kornievskaia, Dai Ngo, Tom Talpey, Trond Myklebust,
Anna Schumaker, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Yang Erkun
Cc: Calum Mackay, linux-nfs, linux-kernel, netdev, Chuck Lever,
alexandr.alexandrov
On 01/05/2026 3:51 pm, Chuck Lever wrote:
> Misbah Anjum reported a use-after-free in cache_check_rcu()
> reached through e_show() while sosreport was reading
> /proc/fs/nfsd/exports on ppc64le. Two fixes for that report
> landed in v7.0:
>
> 48db892356d6 ("NFSD: Defer sub-object cleanup in export put callbacks")
> e7fcf179b82d ("NFSD: Hold net reference for the lifetime of /proc/fs/nfs/exports fd")
>
> The original e_show() repro is now fixed. However, the same
> sosreport workload still reproduces a closely related fault on
> post-v7.0 mainline (Misbah, ppc64le) and on master.20260424
> (internal report, aarch64). In both cases the fault is in
> cache_check_rcu() reached through c_show() rather than e_show(),
> and the cache_head pointer is plain garbage:
>
> pc : cache_check_rcu+0x40 [sunrpc]
> lr : c_show+0x60 [sunrpc]
> ...faulting on h->flags off h = 0x0000000200000000
>
> c_show() is the generic show callback used by
> /proc/net/rpc/<cd>/content for every per-net cache_detail
> (auth.unix.ip, auth.unix.gid, nfsd.fh, nfsd.export). Two
> bugs combine in that path:
>
> 1. cache_unregister_net() / cache_destroy_net() free cd and
> cd->hash_table synchronously when the namespace exits. The
> /proc/net/rpc/.../content open path takes only a module
> reference, so a fd kept open across a netns exit walks a
> freed hash_table and returns garbage cache_head pointers.
> This is the same hazard that e7fcf179b82d closed for the
> /proc/fs/nfs/exports file alone.
>
> 2. ip_map_put() drops auth_domain_put() before kfree_rcu(), so
> sub-objects can be freed before the RCU grace period -- the
> same hazard that 48db892356d6 fixed for svc_export_put() and
> expkey_put(). unix_gid_put() does not have this bug
> structurally (its put_group_info() runs inside the call_rcu()
> callback) but it uses a separate idiom from the other three
> caches.
>
> This series replaces the v1 narrow fixes with shared
> infrastructure that covers all four cache_detail .put paths
> and all three per-cache file types:
>
> Patch 1 hoists nfsd_export_wq up to the sunrpc layer as
> sunrpc_cache_wq, exposed through sunrpc_cache_queue_release()
> and sunrpc_cache_drain() so all four put callbacks share one
> workqueue and one drain primitive.
>
> Patch 2 converts ip_map_put() to the queue_rcu_work() pattern,
> moving auth_domain_put() into a deferred ip_map_release() that
> runs after the RCU grace period.
>
> Patch 3 unifies unix_gid_put() onto the same pattern for
> consistency (not a bug fix on its own).
>
> Patch 4 takes a get_net(cd->net) in content_open(), cache_open(),
> and open_flush() and drops it in the matching release helpers,
> so cache_destroy_net() cannot run while a sunrpc cache fd is
> open.
>
> Series has been compile-tested only.
>
> ---
> Chuck Lever (6):
> SUNRPC: Move cache_initialize() declaration to sunrpc-private header
> SUNRPC: Provide a shared workqueue for cache release callbacks
> SUNRPC: Defer ip_map sub-object cleanup past RCU grace period
> SUNRPC: Use shared release pattern for the unix_gid cache
> SUNRPC: Hold cd->net for the lifetime of cache files
> NFSD: Convert nfsd_export_shutdown() to sunrpc_cache_destroy_net()
>
> fs/nfsd/export.c | 45 ++--------------------
> fs/nfsd/export.h | 2 -
> fs/nfsd/nfsctl.c | 8 +---
> include/linux/sunrpc/cache.h | 3 +-
> net/sunrpc/cache.c | 90 ++++++++++++++++++++++++++++++++++++++++++--
> net/sunrpc/sunrpc.h | 2 +
> net/sunrpc/sunrpc_syms.c | 23 ++++++-----
> net/sunrpc/svcauth_unix.c | 46 ++++++++++++----------
> 8 files changed, 135 insertions(+), 84 deletions(-)
> ---
> base-commit: f3a313ecd1fdab1f5da119db355363b13af6fcac
> change-id: 20260430-cache-uaf-fix-a13000f67c37
>
> Best regards,
> --
> Chuck Lever
>
>
Looks good Chuck, thanks very much.
With these patches, testing shows no crashes, sosreport no longer hangs,
no seq_file errors.
Tested-by: Alexandr Alexandrov <alexandr.alexandrov@oracle.com>
cheers,
c.
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 0/6] SUNRPC: Address remaining cache_check_rcu() UAF in cache content files
2026-05-05 10:49 ` Calum Mackay
@ 2026-05-05 10:53 ` Chuck Lever
0 siblings, 0 replies; 10+ messages in thread
From: Chuck Lever @ 2026-05-05 10:53 UTC (permalink / raw)
To: Calum Mackay, Misbah Anjum N, Jeff Layton, NeilBrown,
Olga Kornievskaia, Dai Ngo, Tom Talpey, Trond Myklebust,
Anna Schumaker, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Yang Erkun
Cc: linux-nfs, linux-kernel, netdev, Chuck Lever, alexandr.alexandrov
On 5/5/26 12:49 PM, Calum Mackay wrote:
> On 01/05/2026 3:51 pm, Chuck Lever wrote:
>> Misbah Anjum reported a use-after-free in cache_check_rcu()
>> reached through e_show() while sosreport was reading
>> /proc/fs/nfsd/exports on ppc64le. Two fixes for that report
>> landed in v7.0:
>>
>> 48db892356d6 ("NFSD: Defer sub-object cleanup in export put
>> callbacks")
>> e7fcf179b82d ("NFSD: Hold net reference for the lifetime of /proc/
>> fs/nfs/exports fd")
>>
>> The original e_show() repro is now fixed. However, the same
>> sosreport workload still reproduces a closely related fault on
>> post-v7.0 mainline (Misbah, ppc64le) and on master.20260424
>> (internal report, aarch64). In both cases the fault is in
>> cache_check_rcu() reached through c_show() rather than e_show(),
>> and the cache_head pointer is plain garbage:
>>
>> pc : cache_check_rcu+0x40 [sunrpc]
>> lr : c_show+0x60 [sunrpc]
>> ...faulting on h->flags off h = 0x0000000200000000
>>
>> c_show() is the generic show callback used by
>> /proc/net/rpc/<cd>/content for every per-net cache_detail
>> (auth.unix.ip, auth.unix.gid, nfsd.fh, nfsd.export). Two
>> bugs combine in that path:
>>
>> 1. cache_unregister_net() / cache_destroy_net() free cd and
>> cd->hash_table synchronously when the namespace exits. The
>> /proc/net/rpc/.../content open path takes only a module
>> reference, so a fd kept open across a netns exit walks a
>> freed hash_table and returns garbage cache_head pointers.
>> This is the same hazard that e7fcf179b82d closed for the
>> /proc/fs/nfs/exports file alone.
>>
>> 2. ip_map_put() drops auth_domain_put() before kfree_rcu(), so
>> sub-objects can be freed before the RCU grace period -- the
>> same hazard that 48db892356d6 fixed for svc_export_put() and
>> expkey_put(). unix_gid_put() does not have this bug
>> structurally (its put_group_info() runs inside the call_rcu()
>> callback) but it uses a separate idiom from the other three
>> caches.
>>
>> This series replaces the v1 narrow fixes with shared
>> infrastructure that covers all four cache_detail .put paths
>> and all three per-cache file types:
>>
>> Patch 1 hoists nfsd_export_wq up to the sunrpc layer as
>> sunrpc_cache_wq, exposed through sunrpc_cache_queue_release()
>> and sunrpc_cache_drain() so all four put callbacks share one
>> workqueue and one drain primitive.
>>
>> Patch 2 converts ip_map_put() to the queue_rcu_work() pattern,
>> moving auth_domain_put() into a deferred ip_map_release() that
>> runs after the RCU grace period.
>>
>> Patch 3 unifies unix_gid_put() onto the same pattern for
>> consistency (not a bug fix on its own).
>>
>> Patch 4 takes a get_net(cd->net) in content_open(), cache_open(),
>> and open_flush() and drops it in the matching release helpers,
>> so cache_destroy_net() cannot run while a sunrpc cache fd is
>> open.
>>
>> Series has been compile-tested only.
>>
>> ---
>> Chuck Lever (6):
>> SUNRPC: Move cache_initialize() declaration to sunrpc-private
>> header
>> SUNRPC: Provide a shared workqueue for cache release callbacks
>> SUNRPC: Defer ip_map sub-object cleanup past RCU grace period
>> SUNRPC: Use shared release pattern for the unix_gid cache
>> SUNRPC: Hold cd->net for the lifetime of cache files
>> NFSD: Convert nfsd_export_shutdown() to sunrpc_cache_destroy_net()
>>
>> fs/nfsd/export.c | 45 ++--------------------
>> fs/nfsd/export.h | 2 -
>> fs/nfsd/nfsctl.c | 8 +---
>> include/linux/sunrpc/cache.h | 3 +-
>> net/sunrpc/cache.c | 90 ++++++++++++++++++++++++++++++++++
>> ++++++++--
>> net/sunrpc/sunrpc.h | 2 +
>> net/sunrpc/sunrpc_syms.c | 23 ++++++-----
>> net/sunrpc/svcauth_unix.c | 46 ++++++++++++----------
>> 8 files changed, 135 insertions(+), 84 deletions(-)
>> ---
>> base-commit: f3a313ecd1fdab1f5da119db355363b13af6fcac
>> change-id: 20260430-cache-uaf-fix-a13000f67c37
>>
>> Best regards,
>> --
>> Chuck Lever
>>
>>
>
> Looks good Chuck, thanks very much.
>
> With these patches, testing shows no crashes, sosreport no longer hangs,
> no seq_file errors.
>
> Tested-by: Alexandr Alexandrov <alexandr.alexandrov@oracle.com>
>
> cheers,
> c.
>
Excellent; pushed with Jeff's R-b and Alexandr's T-b.
--
Chuck Lever
^ permalink raw reply [flat|nested] 10+ messages in thread