Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796217700; b=EOKEyYFh2E81Jmn9rMl67fomWmFLBeblo3MDDTbcEPk8Co8m06LXWsJoOU06RqcomB8C ajxHJKZvXp7AlYdGQ+cdsBS5UL+ZGlJhjlUuMWDX/3/tWXg+FBUxBSW6c+yuBa+5sflZ2 hP/Or92+/mmVD3QNdRX9vmpIF6pccOx5Sic6jx33Nu3uHUD4MzNkQzWXU6lieygY7p0Po OfZUnxWXMSlTgYpHbClPO0vAGOtz7ETk/CejxDBWyH278mo+uEwHtYfqsgrnFoRxPg6Xv pOoNhrH4wCbSqFg/WL9PtTflMKAkiXCH11/B10Q1B99Iu7BL0stkUYgWlaSr5aNLIrw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796217700; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=lU2AdKZbFq/rW52XtZdKBs2jn0Djo2lHA8Il6MQ0NXw=; b=mnri95islZ/qQ/7+auOK+M/bM8u88gRdf15stU2QwGHiz3JX4tbFVioYg7TRVt0zLSGX bdMxlCF7taaBDp79oW6RrVCAoupGUFiFxp6y0+EocaEJbCJkfGs74FMMqLO9gY9prWZoh wVN73qy0wn3aSU66n9u/n5QXRkKb9aeuJ5Fuuz2efcZh6Yq9E3M5RFY0NHWxqCqx1CCXj 97Sv2tGsh1cIlq72gRv8Z5EdGbPAnerZVWvQ6k5LApMx4TkQQoeRI60AU/aZcBR45uRs5 LeJ10s+xn/CE3YlwLO5FLWP4UJJJK1Vi22aCN6zcJBXFIxNxBHtgajxXpUEn9YG8boQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=gcupF1Fp; arc=none smtp.remote-ip=74.125.82.54 Received: from mail-dl1-f54.google.com (mail-dl1-f54.google.com [74.125.82.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B74D606A322 for ; Wed, 2 Dec 2026 13:21:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8B74D606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=gcupF1Fp Received: by mail-dl1-f54.google.com with SMTP id a92af1059eb24-1aefd1bf74aso8319613c88.1 for ; Wed, 02 Dec 2026 05:21:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796217700; x=1796822500; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lU2AdKZbFq/rW52XtZdKBs2jn0Djo2lHA8Il6MQ0NXw=; b=gcupF1FpmJ2Wv186AqrEJpt0i0FzxRU4kDK3XBTMYKYU5C6i2irTj9fMAI0wEPcdKz AQ+sd5UqLOE2mEhWu1xMh4GPomzHurMcB/Kx4piL0XVtvd7q/MbyxNuJXWIKw0KKWlwh Tf5dIQvvnyXLD6n4mYsyvxKqYuzq8KEl3BNqc+r42rdTRO3YWryHE7uh4AQRynQkkeY1 6h+n5rshLDCq81pNR1bB2Go1SZB6j0n97cHNuJaE+7oZssjIID8/i1Mp2SmFd2/Mgxnq PVTVv/AHuTCIMp+wS81uAku3gXPGEPTuJcjss6SbnqdxApUsumZK/1iOj6rIdwayLzNw /EwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796217700; x=1796822500; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=lU2AdKZbFq/rW52XtZdKBs2jn0Djo2lHA8Il6MQ0NXw=; b=bGTPmmDVHNRYrg1rhdDA9h0YVbFX4OropjviLYbfU1YbYV9UnvObVeuHKPleOf6wwY Sk3zvj/KYF0H4IaAdukCW+xKLhVnxoUGLmtUfAIJgRlt/UrT0e00kbyjWK9n9iZqItrR liLMWToxpi7Bbb8OHA3x7cckl6TMGYaXli4szw2TT1lX16cm2fAc+VvraknsnHMX6yTZ 1yYjE2iwsMgqn+CHynpuzHeqTZuxvEH8jnx+RphgokTobw0Z+cK1HY7BQDUGmT91d/F6 lhL9V35byhq0rl/nMDCchOrjRVOyTt94nPzT9VfNe3+HU4XrX1C/Ae8BKgkzOKUNj71d bvKg== X-Forwarded-Encrypted: i=1; AL+hErEN4KoUgvcFXj7GniwEGdc0eq/YVuaZuF+GlbZTo0GCqsv8pGch8IDuNPUohWRvcmJ8FGCNVExggiU=@vger.kernel.org X-Gm-Message-State: APuU4Z+BpikjU6qbwFCt/P8zVv82JagSFVdgxO2Xb2QiuxyBJRbHq7NW ln1yUFnqHiw5MgWpmcfbxCXr7VTXPiJNmuOHz7utjPUUyiyPnnvMeIPr X-Gm-Gg: AZFdTZfwtZebNbrFvPbPAJkfdFd5XPWibzMzNcsK+OalFd0IP/Mji/sFqQ6fmfzSK6x L4Lnu19V5G98Z+FukJzWu9dMvKCiABshDgpD6Pf7VKlX0r8eWw8r/dSqZaS5FKdgpE27CADBB4P pIMHG2a/A6ITWhI53VpdmQvG97PeJER5D5mV30W0xbYxI45I7A48mVNflHui9xl6+SEUgz282VY gDlo++VL0lwaIYbEO+3GvG8bIHx2Fxc6ETox1XnjpbJ/+tPP7kaiMUH/0eromXRLfMQRWzuN8m7 qF4r7WCdYfC//otr4+tRmcS2FwTrZcf8V6k5FKvQR0LQeiTtjVLb96dX33qFXEgD/8LR4+Oa2/t MXp+cm+SvstQm7rg4jTTvV4m0qC0CHZEHrKC9EPpxO62CVmt89Jb0jlugJdeEaFB+iSGi3oLbdq RfP9IkaI4LOyzn9gdOAZe95qR7FtbAS+eXkJpvOCH0W144h7MXECLz5dlbajTbp6fOCE9VRUI8H l5Xuh2T9x3S0EwaJ4hECdZzSw9Q5psVui3zqn/teeiGTSPTtGrRKmGdrdRqCe7Zqwo6ak4GntDD bFM/LAPKoKbxW6tj3Py7XbXJ5tbx X-Received: by 2002:a05:7022:7f19:b0:19f:cc98:f603 with SMTP id a92af1059eb24-1b5520d7d86mr36761297c88.1.1796217699423; Wed, 02 Dec 2026 05:21:39 -0800 (PST) Received: from Mac ([123.215.20.10]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5569bffd2sm87145227c88.0.2026.12.02.05.21.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 02 Dec 2026 05:21:38 -0800 (PST) From: Jiwoong Wi To: Chuck Lever , Jeff Layton , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org, bobtobabz@gmail.com Subject: [PATCH 2/2] SUNRPC: avoid GSS init cache entries without a writer Date: Wed, 2 Dec 2026 22:21:14 +0900 Message-ID: <20261202132114.31702-2-dwdnlzj@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261202132114.31702-1-dwdnlzj@gmail.com> References: <20261202132114.31702-1-dwdnlzj@gmail.com> X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The legacy RPCSEC_GSS init cache retains each new context-handle and input-token key before checking whether userspace can process its upcall. An unauthenticated client can send distinct keys and exhaust memory when no GSS helper is running. New keys can also accumulate during the 30-second daemon-restart grace period. Require an open channel writer before inserting a new GSS init cache entry. Look up existing keys first, and serialize writer open and close with the admission check under hash_lock. Apply the admission rule only to the GSS init cache. When a new key is refused during the restart grace period, drop the RPC request without closing its connection so the client can retransmit after the helper returns. Preserve the existing close behavior if the channel was never opened, the grace period expired, or allocation failed. Report the no-writer rejection from the admission path to distinguish it from allocation failure. Validated the full series on nfsd-testing with a 4 KiB arm64 kernel built by GCC 13.3 with CONFIG_WERROR=y, Generic KASAN, and lockdep. The changed objects passed W=1. In QEMU, an NFSv4.2 sec=krb5 mount remained pending for 25 seconds with zero rsi_alloc() calls while rpc.svcgssd was closed. After the helper reopened, the same mount and read/write I/O succeeded. A fresh request after the restart grace period closed without allocating a cache entry. A cache API module passed 41 checks. No KASAN, lockdep, Oops, or panic report occurred. The vulnerability research and validation were conducted by members of the Tobabz team as part of the Best of the Best 15th program. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Jiwoong Wi --- include/linux/sunrpc/cache.h | 5 ++ net/sunrpc/auth_gss/svcauth_gss.c | 17 ++++--- net/sunrpc/cache.c | 77 ++++++++++++++++++++++++------- 3 files changed, 77 insertions(+), 22 deletions(-) diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h index 2735c332ddb7..32b58613f24c 100644 --- a/include/linux/sunrpc/cache.h +++ b/include/linux/sunrpc/cache.h @@ -71,6 +71,7 @@ enum { struct cache_detail { struct module * owner; int hash_size; + bool require_writer; /* for new cache entries */ struct hlist_head * hash_table; spinlock_t hash_lock; @@ -187,6 +188,10 @@ extern const struct file_operations cache_flush_operations_pipefs; extern struct cache_head * sunrpc_cache_lookup_rcu(struct cache_detail *detail, struct cache_head *key, int hash); +struct cache_head * +sunrpc_cache_lookup_rcu_with_grace(struct cache_detail *detail, + struct cache_head *key, int hash, + bool *restart_grace); extern struct cache_head * sunrpc_cache_update(struct cache_detail *detail, struct cache_head *new, struct cache_head *old, int hash); diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c index ce84a58bb22b..4ec48ce0f060 100644 --- a/net/sunrpc/auth_gss/svcauth_gss.c +++ b/net/sunrpc/auth_gss/svcauth_gss.c @@ -107,7 +107,8 @@ struct rsi { }; static struct rsi *rsi_update(struct cache_detail *cd, struct rsi *new, struct rsi *old); -static struct rsi *rsi_lookup(struct cache_detail *cd, struct rsi *item); +static struct rsi *rsi_lookup(struct cache_detail *cd, struct rsi *item, + bool *restart_grace); static bool rsi_key_too_large(unsigned int handle_len, unsigned int token_len) @@ -262,7 +263,7 @@ static int rsi_parse(struct cache_detail *cd, if (dup_to_netobj(&rsii.in_token, buf, len)) goto out; - rsip = rsi_lookup(cd, &rsii); + rsip = rsi_lookup(cd, &rsii, NULL); if (!rsip) goto out; @@ -318,6 +319,7 @@ static int rsi_parse(struct cache_detail *cd, static const struct cache_detail rsi_cache_template = { .owner = THIS_MODULE, .hash_size = RSI_HASHMAX, + .require_writer = true, .name = "auth.rpcsec.init", .cache_put = rsi_put, .cache_upcall = rsi_upcall, @@ -329,12 +331,14 @@ static const struct cache_detail rsi_cache_template = { .alloc = rsi_alloc, }; -static struct rsi *rsi_lookup(struct cache_detail *cd, struct rsi *item) +static struct rsi *rsi_lookup(struct cache_detail *cd, struct rsi *item, + bool *restart_grace) { struct cache_head *ch; int hash = rsi_hash(item); - ch = sunrpc_cache_lookup_rcu(cd, &item->h, hash); + ch = sunrpc_cache_lookup_rcu_with_grace(cd, &item->h, hash, + restart_grace); if (ch) return container_of(ch, struct rsi, h); else @@ -1170,6 +1174,7 @@ svcauth_gss_legacy_init(struct svc_rqst *rqstp, __be32 *p; u32 len; int ret; + bool restart_grace; struct sunrpc_net *sn = net_generic(SVC_NET(rqstp), sunrpc_net_id); memset(&rsikey, 0, sizeof(rsikey)); @@ -1205,10 +1210,10 @@ svcauth_gss_legacy_init(struct svc_rqst *rqstp, rsikey.in_token.len = len; /* Perform upcall, or find upcall result: */ - rsip = rsi_lookup(sn->rsi_cache, &rsikey); + rsip = rsi_lookup(sn->rsi_cache, &rsikey, &restart_grace); rsi_free(&rsikey); if (!rsip) - return SVC_CLOSE; + return restart_grace ? SVC_DROP : SVC_CLOSE; if (cache_check(sn->rsi_cache, &rsip->h, &rqstp->rq_chandle) < 0) /* No upcall result: */ return SVC_CLOSE; diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index 871ba9562684..5b6476d571f0 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -99,9 +99,17 @@ static void sunrpc_end_cache_remove_entry(struct cache_head *ch, cache_put(ch, cd); } +static bool cache_restart_grace(struct cache_detail *detail) +{ + time64_t last_close = READ_ONCE(detail->last_close); + + /* Allow 30 seconds for a userspace daemon to reopen its channel. */ + return last_close && last_close >= seconds_since_boot() - 30; +} + static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail, struct cache_head *key, - int hash) + int hash, bool *restart_grace) { struct cache_head *new, *tmp, *freeme = NULL; struct hlist_head *head = &detail->hash_table[hash]; @@ -135,6 +143,16 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail, cache_put(new, detail); return tmp; } + /* Channel writer changes are serialized with this admission check. */ + if (detail->require_writer && !atomic_read(&detail->writers)) { + if (restart_grace) + *restart_grace = cache_restart_grace(detail); + spin_unlock(&detail->hash_lock); + if (freeme) + sunrpc_end_cache_remove_entry(freeme, detail); + cache_put(new, detail); + return NULL; + } cache_get(new); hlist_add_head_rcu(&new->cache_list, head); @@ -148,16 +166,48 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail, return new; } -struct cache_head *sunrpc_cache_lookup_rcu(struct cache_detail *detail, - struct cache_head *key, int hash) +/** + * sunrpc_cache_lookup_rcu_with_grace - find or insert a cache entry + * @detail: cache to search + * @key: entry key to look up + * @hash: hash bucket index for @key + * @restart_grace: if non-NULL, set when insertion is refused during the + * daemon restart grace period because no writer is open + * + * Return: A referenced cache entry, or %NULL if lookup or insertion fails. + */ +struct cache_head * +sunrpc_cache_lookup_rcu_with_grace(struct cache_detail *detail, + struct cache_head *key, int hash, + bool *restart_grace) { struct cache_head *ret; + if (restart_grace) + *restart_grace = false; ret = sunrpc_cache_find_rcu(detail, key, hash); if (ret) return ret; + if (detail->require_writer && !atomic_read(&detail->writers)) { + if (!restart_grace) + return NULL; + spin_lock(&detail->hash_lock); + if (!atomic_read(&detail->writers)) { + *restart_grace = cache_restart_grace(detail); + spin_unlock(&detail->hash_lock); + return NULL; + } + spin_unlock(&detail->hash_lock); + } /* Didn't find anything, insert an empty entry */ - return sunrpc_cache_add_entry(detail, key, hash); + return sunrpc_cache_add_entry(detail, key, hash, restart_grace); +} +EXPORT_SYMBOL_GPL(sunrpc_cache_lookup_rcu_with_grace); + +struct cache_head *sunrpc_cache_lookup_rcu(struct cache_detail *detail, + struct cache_head *key, int hash) +{ + return sunrpc_cache_lookup_rcu_with_grace(detail, key, hash, NULL); } EXPORT_SYMBOL_GPL(sunrpc_cache_lookup_rcu); @@ -1032,8 +1082,11 @@ static int cache_open(struct inode *inode, struct file *filp, list_add(&rp->list, &cd->readers); spin_unlock(&cd->queue_lock); } - if (filp->f_mode & FMODE_WRITE) + if (filp->f_mode & FMODE_WRITE) { + spin_lock(&cd->hash_lock); atomic_inc(&cd->writers); + spin_unlock(&cd->hash_lock); + } filp->private_data = rp; return 0; } @@ -1075,8 +1128,10 @@ static int cache_release(struct inode *inode, struct file *filp, kfree(rp); } if (filp->f_mode & FMODE_WRITE) { + spin_lock(&cd->hash_lock); atomic_dec(&cd->writers); cd->last_close = seconds_since_boot(); + spin_unlock(&cd->hash_lock); } module_put(cd->owner); return 0; @@ -1182,17 +1237,7 @@ static bool cache_listeners_exist(struct cache_detail *detail) { if (atomic_read(&detail->writers)) return true; - if (detail->last_close == 0) - /* This cache was never opened */ - return false; - if (detail->last_close < seconds_since_boot() - 30) - /* - * We allow for the possibility that someone might - * restart a userspace daemon without restarting the - * server; but after 30 seconds, we give up. - */ - return false; - return true; + return cache_restart_grace(detail); } /* -- 2.50.1 (Apple Git-155)