From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796014238; b=YQT+CgpQA4+91NThEW00Gdd8KFyKamYGBBI3yz1/du+MJAa+SSlqxCcpPtBWIn9CYC0x PyQ7QJ+uPok1Y4QZwWhdQm9WseQQx3+iW0cbK2NtL1XiZtLBn5DDQpuVcg8xdyCQxD6Q6 JPBfReWvuCZUYcEPlakzDqnpDI/tboa/YZgny4B/tYM4NrlFfaZtjFTPyIzHJX8uOUOsK 46/PmInsHRX0iGPDVGEg/kfMoqKEvRcx/3IOWeSAjWOkUHpksc4PQy37e1nR0dA7Q9rz2 SJ4HCoT2pvWraskzrHYT5llx5mwJw7GLBQ3GTGHcGjMyc658/x3u9bzxrcE2as1biQw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796014238; 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:MIME-Version: Content-Transfer-Encoding; bh=FEUZWC+NqkGZoSB5N2/f8I+XHi3CvjZCBptuiyLnF5g=; b=zLZQhNduV5EvQlqX9BsSo2hy2zkZq//hPhqKY0skLI1ZcLem5DM6AkSGsB0mY5degPJY zcH1rusloSD3bcr1WVZZojmiamBFnGSH6HcYLCWRge8y3mJaLZhQyDcTRyZqqBu6IG3Gg Ypu4l10VVswVKe1q+HsLe5CnMFY+3TXNZ417yZ21E/5RIOyPzvJKdpY68SNSJdDUPq2Mr XUl5rSi7M/RiFGgAPZ1YiUXbOsh1Sz6LQzlYPpKyevBNws2lgBbWywDrk48GEZPShtzyw 6msGF5QKQh5HIyp8wIyRiDSk/fTrUern7ZRKK0Td2KM4Wm5I6kb37CA+2F9tW4Nb/DA== 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=K+ZZYEAA; arc=none smtp.remote-ip=74.125.82.182 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (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 E4218606A325 for ; Mon, 30 Nov 2026 04:50:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E4218606A325 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=K+ZZYEAA Received: by mail-dy1-f182.google.com with SMTP id 5a478bee46e88-385d8a00598so17189618eec.1 for ; Sun, 29 Nov 2026 20:50:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796014237; x=1796619037; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=FEUZWC+NqkGZoSB5N2/f8I+XHi3CvjZCBptuiyLnF5g=; b=K+ZZYEAAkMa1f5IoqgY0gqsLhp6iJjjD4KjMG1D8o2371lY8ZO4OxyiOPgBT54tRH0 xhqZtsMHAEFgAdzliwQTLbEwlwDrontu44BTlOtIcvD6J0n6rCa/8bEN2x4uckNLywkD zwIvbQZRBI06gcB9fzBxFvHG31cD5QdDwBylbBfPe/tjkpSywFAhjYL2qT++4ecbRACL ci1Zwv/wnvORNm0UvaFJ5x5WpZOP/ROVinHX1JWqVPA5r0EshYnLtNmxEDrtlFr/eBH9 afHwX7lhEIYt+uKjZ50PU353Qo5QUf1qRik02zzG8VoFTAbxvxoaOVmd7f3te3/ccAF8 4CzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796014237; x=1796619037; h=content-transfer-encoding:mime-version: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=FEUZWC+NqkGZoSB5N2/f8I+XHi3CvjZCBptuiyLnF5g=; b=UmoGkI2WDzQRbFentWHQsCeo8mrp+whf39ONVrM8ouO9ivGidNKLcICRBK7PZeEYCJ TtUjDIsx0EQLvi3/tYfPQhYEcwcPmqkpD9BTBRa3In772c3kaTqIfLQo4yzaWe2SA3XV Hyhb94SyEKC4AvFIGf38dSJ/cjdoR3SaMXn+L3pFd5VhSNNJLzotC5C6K/cs1PWrhLvR S4KWqxM2B5cbi/YTfoki8qAb16xmx5qxK25ZdY1m1EvIdfMrEfYmS8+qJbMnr/Pt1hkh dPoCjQSRbqxHZDThB0Q+x/2R6T+RzPfGtW4Kxk3lT4a6RskyEEj/hn9AzAE9cmIchge8 0Yvg== X-Forwarded-Encrypted: i=1; AL+hErF8OxINvAEtpSiKXANsGOI4W3ngo+CnUQiEjkCA5bBb0kAHNX3LgtHyndZzOWn69b+CSbP8elpZ86R99Tk=@vger.kernel.org X-Gm-Message-State: APuU4Z99/VWKqf2cmMGXQN+hILTQJyiD8t/ebCWHF3iXIh14n13qbEVK A8lVVaD6J7qdEY1p1oPqbZZnz8BZ2NTtw+TOK2OKtYj/iYR2Ubj6L79m X-Gm-Gg: AZFdTZcqQ0OLGC+duzTqX++MT8xdFYFh52yEIdDpHJEU2gUDfb2VUfxNT/gPD/ErZ08 gA7+3FrGx/OKfF9f8UMS9LfPZfIQsolgMzCFEQG+l4EQe7dgLlJXV9lWwMIAATUHHQK/vEBEKWg dspzQqrBaSP8Q9qUD8X5Nf/+xziVA3EhRpj7975MhQYXCmS8/5lxVogwjXt4eYiD4Jt5sVd1Rf5 QFt7fpJpAMCZ8dEdh/pdyeXtA8aDaz9APIgEu2TbbAt1dVfwE8IXwCt4U08r2K5SgwWZfuBEQ7B telIburfwkjaAGeRSs5xkQ26iH+yfVexZZYtkkDD/KoygThemyPruMYs7loeekaSaoglimAqWHW hc0e7qLuoTdr2n6vYFwqCqdvzvb55Ekz1lkF6s9eokkkMz6mGd9zcJD5kgKgfKFeSCR0mTTDXDV E+pisWdjG2/e6zL7eWoHurwLH/zLO6IYk45KNDJnh3CwHL+w5cyzqZ03SAGmucdAivA/HVK4Zpz rnPge9qbBDwYEjHRgeZ8UhsiYmcqJAaIGt+Vy1UTW1CoJaP0WucAxLqmHxxLHrhyVrGLTrgeaEO faasTtwcghE7+EhIH6XvSBDTyDrK+h3/DW5gXeDBQFkiAoofRYEtOM6p+kqVBteDIN7p X-Received: by 2002:a05:7301:6405:b0:36e:aa5c:7851 with SMTP id 5a478bee46e88-38570355b25mr34281400eec.27.1796014236980; Sun, 29 Nov 2026 20:50:36 -0800 (PST) Received: from youngkk-vm.localdomain (67.216.200.102.16clouds.com. [67.216.200.102]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38567abb870sm80004596eec.25.2026.11.29.20.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 20:50:36 -0800 (PST) From: Cheng Yongkang To: Trond Myklebust , Anna Schumaker Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v3] NFS: defer access-cache entry and group_info free past RCU Date: Sun, 29 Nov 2026 20:50:29 -0800 Message-Id: <20261130045029.3414698-1-teel4res@gmail.com> X-Mailer: git-send-email 2.34.1 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 Content-Transfer-Encoding: 8bit nfs_access_free_entry() drops the group_info reference synchronously, while the nfs_access_entry itself is only freed after an RCU grace period. nfs_access_get_cached_rcu() calls access_cmp() on the most recently used entry under rcu_read_lock(), and access_cmp() reads the entry's group_info->ngroups and gid[] whenever the caller's group_info is a different object. An entry that is replaced in nfs_access_add_rbtree(), or removed by the shrinker or nfs_access_zap_cache(), can still be in use by such a reader. If the entry holds the last reference, put_group_info() frees the array while the reader is comparing it: BUG: KASAN: use-after-free in nfs_access_get_cached+0xb8f/0xf80 Read of size 4 at addr ... by task poc/9503 Call Trace: nfs_access_get_cached nfs_do_access nfs_permission inode_permission do_faccessat freed by: nfs_access_free_entry nfs_access_add_cache nfs_do_access Before commit 6238aec83f3f ("NFS: don't store 'struct cred *' in struct nfs_access_entry"), the entry held a cred, and put_cred() freed the cred, and with it the group_info, only after a grace period. Drop the group_info reference in an RCU callback that then frees the entry. put_group_info() can run there: groups_free() uses kvfree(), which may be called in interrupt context, and put_cred_rcu() already drops a group_info reference from an RCU callback. Fixes: 6238aec83f3f ("NFS: don't store 'struct cred *' in struct nfs_access_entry") Cc: stable@vger.kernel.org Signed-off-by: Cheng Yongkang --- Changes in v3: - Use call_rcu() instead of queue_rcu_work(); put_group_info() can run in an RCU callback (Trond). - Leave struct nfs_access_entry unchanged. - Describe the KASAN report as a use-after-free, not a slab use-after-free. v2: https://lore.kernel.org/all/20261026105230.1150218-1-teel4res@gmail.com/ v1: https://lore.kernel.org/all/20261025180329.349613-1-teel4res@gmail.com/ fs/nfs/dir.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 49437037f948..deed0dc49fc2 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -2895,10 +2895,19 @@ static unsigned long nfs_access_max_cachesize = 4*1024*1024; module_param(nfs_access_max_cachesize, ulong, 0644); MODULE_PARM_DESC(nfs_access_max_cachesize, "NFS access maximum total cache length"); -static void nfs_access_free_entry(struct nfs_access_entry *entry) +static void nfs_access_free_entry_rcu(struct rcu_head *head) { + struct nfs_access_entry *entry = + container_of(head, struct nfs_access_entry, rcu_head); + put_group_info(entry->group_info); - kfree_rcu(entry, rcu_head); + kfree(entry); +} + +static void nfs_access_free_entry(struct nfs_access_entry *entry) +{ + /* RCU readers may still be comparing entry->group_info in access_cmp() */ + call_rcu(&entry->rcu_head, nfs_access_free_entry_rcu); smp_mb__before_atomic(); atomic_long_dec(&nfs_access_nr_entries); smp_mb__after_atomic(); base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f -- 2.34.1