From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 014B83EC699; Mon, 17 Aug 2026 14:39:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786977552; cv=none; b=hflWO23NT/ziCeqqat05o3tzWirvM9FnwIftW5vNHk9tTJ7UEeS2TwOZjGNnk+w+akxBr19mhYuRorpd/1Uvr6JEzn+EoCyp3aQQmr8t8rR3i/pjaUJpROG87k8yn0v2SZuyIucgKUWZCJtSgcok8hnh5nbu+lW0jn5Rg894ITw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786977552; c=relaxed/simple; bh=wl5faM3/16or6fCOiqbdY0U11bSjzPP+ai8vicPyMD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VbmM5SPacrcrANfHtHSUSPO/DjvMrkDeRueyd0iYQeIrPEdCJMBQSsPkp5CwGg3ncxH6J8viwDQ7n/oYjm3ZaxxCG2CzSLWtH2CRiI49B+OCO1F2KfJLvFzdSrUEiVTKtqCXxxSHbIzI666rEgXhHrgGx3XfCXZ2FDq9/ZNwnT4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=gPTmdQRe; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="gPTmdQRe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AA4E1F000E9; Mon, 17 Aug 2026 14:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786977550; bh=QFKiRZKvRREpa6FBa5vVaNBlgYT0hp0MTKPsChjr5ng=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gPTmdQReQi8Gzpse7qijpbavDDS/SVu0FVNvD71XDakNypVB5iJjEfQ/1j5YZ3N4v NwbKAHlFC7iRSvoTpSlzP26PRXBeUQUyYVGgAgvybaSaIfuH9pov3fIC7ZGt5fhETo FQXHuPjnhLJCJLf1YbBQJM8APx0CowH/2dJsRrec= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dan Aloni , Anna Schumaker , Sasha Levin Subject: [PATCH 5.15 369/456] NFS: Pin the struct nfs_server during a FREE_STATEID call Date: Mon, 17 Aug 2026 15:32:39 +0200 Message-ID: <20260817132553.911960632@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817132539.792407575@linuxfoundation.org> References: <20260817132539.792407575@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Anna Schumaker [ Upstream commit cf616096a0f3a2b60f7d68b6b39674a6867ded9c ] Dan Aloni reports that he was able to hit a use-after-free bug if a FREE_STATEID operation gets delayed for whatever reason. Fix this by bumping the refcount of the 'struct nfs_server' object for the duration of the FREE_STATEID so it doesn't get cleaned up from underneath us while operations are still in flight. Reported-by: Dan Aloni Fixes: 7c1d5fae4a87 ("NFSv4: Convert nfs41_free_stateid to use an asynchronous RPC call") Tested-by: Dan Aloni Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- fs/nfs/nfs4proc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 41bbc9407680f..25aaae1d6345e 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -10297,6 +10297,7 @@ static void nfs41_free_stateid_release(void *calldata) struct nfs_free_stateid_data *data = calldata; struct nfs_client *clp = data->server->nfs_client; + nfs_sb_deactive(data->server->super); nfs_put_client(clp); kfree(calldata); } @@ -10338,6 +10339,10 @@ static int nfs41_free_stateid(struct nfs_server *server, if (!refcount_inc_not_zero(&clp->cl_count)) return -EIO; + if (!nfs_sb_active(server->super)) { + nfs_put_client(clp); + return -EIO; + } nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID, &task_setup.rpc_client, &msg); -- 2.53.0