public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <cel@kernel.org>
To: Misbah Anjum N <misanjum@linux.ibm.com>,
	 Jeff Layton <jlayton@kernel.org>, NeilBrown <neil@brown.name>,
	 Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <Dai.Ngo@oracle.com>,  Tom Talpey <tom@talpey.com>,
	Trond Myklebust <trondmy@kernel.org>,
	 Anna Schumaker <anna@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	 Yang Erkun <yangerkun@huawei.com>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	 netdev@vger.kernel.org, Chuck Lever <chuck.lever@oracle.com>
Subject: [PATCH 0/6] SUNRPC: Address remaining cache_check_rcu() UAF in cache content files
Date: Fri, 01 May 2026 10:51:06 -0400	[thread overview]
Message-ID: <20260501-cache-uaf-fix-v1-0-a49928bf4817@oracle.com> (raw)

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


             reply	other threads:[~2026-05-01 14:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-01 14:51 Chuck Lever [this message]
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 ` [PATCH 3/6] SUNRPC: Defer ip_map sub-object cleanup past RCU grace period Chuck Lever
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 ` [PATCH 5/6] SUNRPC: Hold cd->net for the lifetime of cache files Chuck Lever
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 ` [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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260501-cache-uaf-fix-v1-0-a49928bf4817@oracle.com \
    --to=cel@kernel.org \
    --cc=Dai.Ngo@oracle.com \
    --cc=anna@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=misanjum@linux.ibm.com \
    --cc=neil@brown.name \
    --cc=netdev@vger.kernel.org \
    --cc=okorniev@redhat.com \
    --cc=pabeni@redhat.com \
    --cc=tom@talpey.com \
    --cc=trondmy@kernel.org \
    --cc=yangerkun@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox