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 9DC34244694 for ; Wed, 9 Sep 2026 00:25:31 +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=1788913532; cv=none; b=LaOndCY7QINuhr+u6zQ4ecbdO3TQ7x3IOP/ow6kUIYaNlt+jy1QYMF6z9PVxX8NYP79Qhc396L3noHeh7yAsSFTLq7C0Zcm1gGQQVRsdvKKJVvLDhw9iYrL/wP3i32hMIzVFZItQ6+9eEmG4qNt8du4sV1vD2y7+qazRIGXHaGQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788913532; c=relaxed/simple; bh=4S+BUrR5jFykbMWW7pVnXCMnwdoZqDuBwUvV8eF/T0c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t+ihmOtIHxvpjEc3ORbsxVq8ISZI4PXpq/FSHCxTJ/5XTxs+q8hj+UDLZxH3jevtYKL9gNSiye1yNfiR6/S0Wqz73pJcTYDBZ2DubHG6Le0d8xpoTNJg2RRxCn+Fpxypz3V4tesGni76Pf/OAIx+lWwuV4VBBTN+7gex0L1gPMg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KYvklc9l; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KYvklc9l" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9807B1F00A3A; Wed, 9 Sep 2026 00:25:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788913531; bh=gyMTHh5KYTT6h4vILDQPkBZyC+RbaWlxVJ6iCieXXxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KYvklc9lEvPAUwtgJ8+su6M9kHGLA8V9rtKIFcdYim9V4+p9OWxQT8RoEGuZJar3K vtgEeBzYU/QN8fPpaOqAk7FH5aTu2v3C++qRx+o2U80TRl2hmLfb27GVX/AsdNYEvr 67ctDwvSMbWiJI1Vyvcbf+h12PsakHpgeb96o2J/k996gJI5sKfUXuFk/cYsz00bCi 9UBTgSorjd9/NOMvFjlwKqmW+UidjRm3B7SK39SkoXAuVaBQYq56v9qGznTH5Y4tfb jUdM+5PktRrxV5W6Xx0DNtoBub2/6a5O0QjrS1gY0+NEi+47ei+oCnL2ShYecPGeQ9 GpOOGMGyW7o6A== From: Sasha Levin To: stable@vger.kernel.org Cc: Luxiao Xu , Yuan Tan , Xin Liu , Ren Wei , Trond Myklebust , Sasha Levin Subject: [PATCH 6.6.y 4/4] sunrpc: fix use-after-free in __rpc_clnt_handle_event and __rpc_clnt_remove_pipedir Date: Tue, 8 Sep 2026 20:25:27 -0400 Message-ID: <20260909002527.728386-4-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260909002527.728386-1-sashal@kernel.org> References: <2026090317-fame-salami-c28b@gregkh> <20260909002527.728386-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Luxiao Xu [ Upstream commit 932a8cf6abb2b2f8677b79153a823108d8861fe2 ] Normal client creation goes through rpc_setup_pipedir(), which records clnt->pipefs_sb, but the mount-event path in __rpc_clnt_handle_event() calls rpc_setup_pipedir_sb() directly and never refreshes that field. The umount path also removes the directory without clearing clnt->pipefs_sb. After a late pipefs mount or any remount, rpc_clnt_remove_pipedir() compares the current superblock against a stale pipefs_sb pointer and skips cleanup, leaving pipefs dentries whose inode private data still points at a freed rpc_clnt, leading to a potential use-after-free during subsequent rpc_info_open() or rpc_show_info() calls. Fix this by properly updating clnt->pipefs_sb upon mount events and clearing it during unmount or failure paths. Fixes: bfca5fb4e97c ("SUNRPC: Fix RPC client cleaned up the freed pipefs dentries") Cc: stable@vger.kernel.org Reported-by: Yuan Tan Reported-by: Xin Liu Reviewed-by: Ren Wei Assisted-by: Codex:gpt-5.4 Signed-off-by: Luxiao Xu Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- net/sunrpc/clnt.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 5ccf04cdfd483..0afb3b300be52 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -101,7 +101,10 @@ static void rpc_unregister_client(struct rpc_clnt *clnt) static void __rpc_clnt_remove_pipedir(struct rpc_clnt *clnt) { - rpc_remove_client_dir(clnt); + if (clnt->pipefs_sb) { + rpc_remove_client_dir(clnt); + clnt->pipefs_sb = NULL; + } } static void rpc_clnt_remove_pipedir(struct rpc_clnt *clnt) @@ -182,19 +185,28 @@ static int rpc_clnt_skip_event(struct rpc_clnt *clnt, unsigned long event) } static int __rpc_clnt_handle_event(struct rpc_clnt *clnt, unsigned long event, - struct super_block *sb) + struct super_block *sb) { + int err = 0; + switch (event) { case RPC_PIPEFS_MOUNT: - return rpc_setup_pipedir_sb(sb, clnt); + clnt->pipefs_sb = sb; + err = rpc_setup_pipedir_sb(sb, clnt); + if (err) + clnt->pipefs_sb = NULL; + break; case RPC_PIPEFS_UMOUNT: - __rpc_clnt_remove_pipedir(clnt); + if (clnt->pipefs_sb == sb) { + __rpc_clnt_remove_pipedir(clnt); + clnt->pipefs_sb = NULL; + } break; default: printk(KERN_ERR "%s: unknown event: %ld\n", __func__, event); return -ENOTSUPP; } - return 0; + return err; } static int __rpc_pipefs_event(struct rpc_clnt *clnt, unsigned long event, -- 2.53.0