From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795914387; b=D5NqLbdc+MTOJUQ0YR3FzMkD7xoEFWZyKyFdL/3LOculv/oiJYajTPBJnJfGKA3sCdC0 7zzc9+Xk4COb9KnUU+gbWNfZItiGakSDde2cCKMNY8nifb3uzrqS4wPgaSzpaGm26y5Sg CfOzQr6Ul0uPlnaJdzcvfBRPl/uNtib6hPyWBkjldBbugObuYXICmarDcCSmzKVc6jUUl ppY8oMP8hFNrKppWf/9xh4v1hEVmBMLHbzaJDtLWg8dKU0g77uWbey6eOvYdF2zxUkHja Onh/923YB8fcIbS7OEDOpcgxdQRETM15NYMTRHpC2Iy4JpUyBzAj+ACJC8xxP+M1FPw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795914387; h=Received:DKIM-Signature:Message-ID:Subject:From:To:Cc:Date: In-Reply-To:References:Content-Type:Content-Transfer-Encoding: User-Agent:MIME-Version; bh=x/SeFsgpbC9/Be88RHIOUINQ7Y9ndsxgr8UepO8s4VA=; b=uQqBHbRR2/68TVs38RvWzgV9fPutKwaQF6KWF6S5ZZkkWqK2fFZAULJql+7V2+Hsa9+S H7FNsF6K0dj2udP6gKWwXmt1eBuOiKlfYTMf2c9q57kcmCVM9FLfngiIiqq/AGPpROgM2 Vwo7Qt6SGU3jFIESIcaf/OLyp8lGo1Yos8gk/XaN4cOqu3aRYz/5y3SGamOI3DhQEDyyY mQKXnoNu4Be9IUCKu1RDQd7IPcMCkeOiTTTD2DhQmm4x5wlAg8WuzdAPZDwYwmk6B6l6S KsMAQekmt0d8H3+Q7qICTq5xbvB/iHc1RoyqdjfcT4uRaYMd7rPxFL5keaHtbkw6vvw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ooPGmxBn; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8BA0606A31C; Sun, 29 Nov 2026 01:06:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ooPGmxBn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 893B51F000C1; Sun, 29 Nov 2026 01:06:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795914387; bh=x/SeFsgpbC9/Be88RHIOUINQ7Y9ndsxgr8UepO8s4VA=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=ooPGmxBnCplRhcnDLXZs5Co6nwmB9aC+b0U+w/J9TUInSuE34rbudeoiZkgp+hl0k lPs9bMJODiQDcoi7gjjofgAA6dZlUKpm8Hp+U+RIbOjbqUXh0kmsVYZin5xSdbswhJ 72dViA7jRrddmhevdfvPa97x+Vswfq+xuBqdbIRsxbDn3xmY4CWDvn/f+t9fKbX0XS GMvK/0liZyu4OnFjmP2fEJE+cmeh6oTDcL7WS1JEYHSDDNjsdQBEimLbQToF+Ar6lJ eWe1BSNoTl9tGj4zFCHcNzR5anhZUILCLrPQoJtBo3B4xp8KaTNkLrKJEnnPqesf+m D50jwcioQ7AJA== Message-ID: <7efff03de5428b1f203e1d5d44aafcba547cfed9.camel@kernel.org> Subject: Re: [PATCH v2] NFS: defer access-cache entry and group_info free past RCU From: Trond Myklebust To: Cheng Yongkang , Anna Schumaker Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Date: Sat, 28 Nov 2026 20:06:25 -0500 In-Reply-To: <20261026105230.1150218-1-teel4res@gmail.com> References: <20261026105230.1150218-1-teel4res@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.62.1 (3.62.1-1.fc45) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Mon, 2026-10-26 at 03:52 -0700, Cheng Yongkang wrote: > nfs_access_free_entry() drops the group_info reference synchronously > while the nfs_access_entry itself is only freed after an RCU grace > period.=C2=A0 The lockless lookup path (nfs_access_get_cached_rcu() -> > access_cmp()) can still be walking group_info->ngroups/gid[] after > the > entry was replaced and unlinked, so put_group_info() can reach > groups_free() -> kvfree() under a reader and free the array it is > reading: a slab-use-after-free read. >=20 > put_group_info() may end in kvfree(), so it cannot run from a plain > RCU > callback.=C2=A0 Defer both the group_info reference drop and the entry > free > to process context after a grace period with queue_rcu_work() on > nfsiod_workqueue.=C2=A0 The entry accounting (nfs_access_nr_entries) and > all > call-site locking are unchanged; the work only drops the reference > and > frees the entry. >=20 > On a 7.3 KASAN kernel, the following workload triggers the report: a > userspace NFSv3 server plus eight readers doing faccessat() with 2048 > supplementary gids, and serialized credential replacements that > detach > the previous killer's group_info reference. >=20 > =C2=A0BUG: KASAN: use-after-free in nfs_access_get_cached+0xb8f/0xf80 > =C2=A0Read of size 4 at addr ... by task poc/9552 > =C2=A0Call Trace: > =C2=A0 nfs_access_get_cached > =C2=A0 nfs_do_access > =C2=A0 nfs_permission > =C2=A0 inode_permission > =C2=A0 do_faccessat > =C2=A0Page last allocated by task ...: > =C2=A0 __kvmalloc_node_noprof > =C2=A0 __se_sys_setgroups > =C2=A0Page last freed by task ...: > =C2=A0 nfs_access_free_entry > =C2=A0 nfs_access_add_cache > =C2=A0 nfs_do_access >=20 > The trigger needs CAP_SETGID in the guest for the setgroups-based > credential churn; the faulty read path is the ordinary access(2) / > faccessat(2) path used by any NFS user. >=20 > Link: > https://lore.kernel.org/all/20261025180329.349613-1-teel4res@gmail.com/ > Fixes: 6238aec83f3f ("NFS: don't store 'struct cred *' in struct > nfs_access_entry") > Cc: stable@vger.kernel.org > Assisted-by: LLM > Signed-off-by: Cheng Yongkang > --- > v2: add Link, Fixes and stable tags, and remove local validation > details from the > commit message. >=20 > =C2=A0fs/nfs/dir.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 | 21 +++++++++++++++++---- > =C2=A0include/linux/nfs_fs.h |=C2=A0 3 ++- > =C2=A02 files changed, 19 insertions(+), 5 deletions(-) >=20 > diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c > --- a/fs/nfs/dir.c > +++ b/fs/nfs/dir.c > @@ -2898,10 +2898,25 @@ > =C2=A0module_param(nfs_access_max_cachesize, ulong, 0644); > =C2=A0MODULE_PARM_DESC(nfs_access_max_cachesize, "NFS access maximum tota= l > cache length"); >=20 > -static void nfs_access_free_entry(struct nfs_access_entry *entry) > +static void nfs_access_free_entry_work(struct work_struct *work) > =C2=A0{ > +=09struct nfs_access_entry *entry =3D > +=09=09container_of(to_rcu_work(work), struct > nfs_access_entry, rcu_work); > + > =C2=A0=09put_group_info(entry->group_info); > -=09kfree_rcu(entry, rcu_head); > +=09kfree(entry); > +} > + > +static void nfs_access_free_entry(struct nfs_access_entry *entry) > +{ > +=09/* > +=09 * The entry can still be reached by RCU readers that > dereference > +=09 * its group_info in access_cmp().=C2=A0 Drop the group_info > reference > +=09 * only after a grace period, in process context because > +=09 * put_group_info() may end in kvfree(). > +=09 */ > +=09INIT_RCU_WORK(&entry->rcu_work, nfs_access_free_entry_work); > +=09queue_rcu_work(nfsiod_workqueue, &entry->rcu_work); Why is this a workqueue job and not just an RCU callback? --=20 Trond Myklebust Linux NFS client maintainer, Hammerspace trondmy@kernel.org, trond.myklebust@hammerspace.com