Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3295258rwa; Tue, 23 Aug 2022 02:10:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR6iXX3fcJoXLrsFuoJY9JW+gfW0ac4Kqt9b0w3kT4V4lIk54Mg4PWL6x3TetQYVFkYSNn9t X-Received: by 2002:a17:907:2c48:b0:73d:14e6:15f2 with SMTP id hf8-20020a1709072c4800b0073d14e615f2mr12055525ejc.313.1661245851362; Tue, 23 Aug 2022 02:10:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661245851; cv=none; d=google.com; s=arc-20160816; b=r+v6t6W+bKuJRKp2XntBop9xxAt/ghDZEBY0dab+AUAI3YQBJLVjW60vh4lhpBC2Gb 3u9rkNf3F+zWVVDOSXCjIvuDakUMjUr9GWbvJT8TayowyBecDUSpH2Gaik2CNFnr2yeP sKop8yEfCmDUMgA2DfRWmbp48D/IWbcXDAVQKzSzaugGA6HMjd9SliNa51zEklSd1wVm ba0mUluFqpUo4naID7qZYa1lbh3WJPWYPtnp6dh9Vje113hSFFvB/mcMYw6E2pRFsoLe Ej/9HHUsvxNvRcUVDm8l8l/hgDXKZrATX1nQy4x2KVn4ksVNto0vdyD8UlnB2uxQoNly d+fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cVq9BCKu/c1IrJg8zPXAyKw0CqFJomvxB4crv8Qjx8w=; b=DZs8Pz5XVPdKir4HycYmOB3UWgQ5sBGJOdpUU2GkxD5c6TNchTsVsJQSJskhQ5CPtS RmNnCuzTJayKVfe4zaxk0u24ZV574BwsW73O82f8BPBGKnkwbQvTxCqIjjVc6y6+TuI2 J36qPmoK8MmJTUFPw1ibVYhikukpTsLwf/cBs06H9g4i7S1F9z9pDzsX/z6TC1f33V/g baWQNTlAuzyEi3EKiNV8IVj+BlbinCu1JmYeqcknQE7mgETuvwbx1NOWs5NGJV8AQeBQ GTWlXBfzJ7ovznOJzPK69qVSRFNcNsUrrzq04mvA4NwdSelBV++FxCvIBEPsjK5g/ma4 sqNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OnipR9Gd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n20-20020a170906701400b0072af6e1fff0si10676986ejj.330.2022.08.23.02.10.23; Tue, 23 Aug 2022 02:10:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OnipR9Gd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347916AbiHWJG4 (ORCPT + 99 others); Tue, 23 Aug 2022 05:06:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348118AbiHWJFs (ORCPT ); Tue, 23 Aug 2022 05:05:48 -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 BD05E85F9E; Tue, 23 Aug 2022 01:29:46 -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 1932161257; Tue, 23 Aug 2022 08:28:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F624C433D7; Tue, 23 Aug 2022 08:28:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243307; bh=/0xUtoBD7lVWZLLkImr4H5x1++n8+L53UF+qUa8F/D0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OnipR9Gdr1LQKXmpZpu90OVVNu0W75NDjtCAw4pHyy1FDVRjaKKIJH5w9ZOB5F1l7 JIy4Gbx8R7DEQLda8pB4hF7gijDTKDn8TN8YSmgmfIrUGfG86AlFHXbxKpyWlo0DmF XByY9sUvBzVSR0CMBcOjJGRkzPw2LdQ14mVwZqr8= 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.19 205/365] net/sunrpc: fix potential memory leaks in rpc_sysfs_xprt_state_change() Date: Tue, 23 Aug 2022 10:01:46 +0200 Message-Id: <20220823080126.779775500@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 @@ -291,8 +291,10 @@ static ssize_t rpc_sysfs_xprt_state_chan int offline = 0, online = 0, remove = 0; struct rpc_xprt_switch *xps = rpc_sysfs_xprt_kobj_get_xprt_switch(kobj); - if (!xprt) - return 0; + if (!xprt || !xps) { + count = 0; + goto out_put; + } if (!strncmp(buf, "offline", 7)) offline = 1;