From nobody Sat Sep 27 20:22:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9216AC48BEA for ; Tue, 23 Aug 2022 10:12:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353567AbiHWKLj (ORCPT ); Tue, 23 Aug 2022 06:11:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352164AbiHWKEh (ORCPT ); Tue, 23 Aug 2022 06:04:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D2007CAAD; Tue, 23 Aug 2022 01:51:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8EE1C611DD; Tue, 23 Aug 2022 08:51:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F03DC433C1; Tue, 23 Aug 2022 08:51:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244688; bh=BUABD0JN2H9C+CJyiBeVXutjaNxEATd60hiao3q3jFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B3mcezs3w3cqhOc/r/ECqabk8/qAuQUWkV8m3Duiqu3tSiLj8oARd2FHYY4M1H5LY GsdMfWOZSiwCGZJur+8pKbTFWTeigT4L3XuZMmuTFQX3/NNZKaNwmyaLwUh277axWZ sL7tIKGQQ8ZnecXpQ9tkKUHu8N09UThSXWtGK7As= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Xiong , Xin Tan , "David S. Miller" Subject: [PATCH 5.15 134/244] net/sunrpc: fix potential memory leaks in rpc_sysfs_xprt_state_change() Date: Tue, 23 Aug 2022 10:24:53 +0200 Message-Id: <20220823080103.611981010@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Xin Xiong commit bfc48f1b0505ffcb03a6d749139b7577d6b81ae0 upstream. The issue happens on some error handling paths. When the function fails to grab the object `xprt`, it simply returns 0, forgetting to decrease the reference count of another object `xps`, which is increased by rpc_sysfs_xprt_kobj_get_xprt_switch(), causing refcount leaks. Also, the function forgets to check whether `xps` is valid before using it, which may result in NULL-dereferencing issues. Fix it by adding proper error handling code when either `xprt` or `xps` is NULL. Fixes: 5b7eb78486cd ("SUNRPC: take a xprt offline using sysfs") Signed-off-by: Xin Xiong Signed-off-by: Xin Tan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sunrpc/sysfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -282,8 +282,10 @@ static ssize_t rpc_sysfs_xprt_state_chan int offline =3D 0, online =3D 0, remove =3D 0; struct rpc_xprt_switch *xps =3D rpc_sysfs_xprt_kobj_get_xprt_switch(kobj); =20 - if (!xprt) - return 0; + if (!xprt || !xps) { + count =3D 0; + goto out_put; + } =20 if (!strncmp(buf, "offline", 7)) offline =3D 1;