Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3412140rwa; Tue, 23 Aug 2022 04:28:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR7gGwe1xU6eLwgEdKQRuqzEIzbITuOcSPclxq1roLgfDl1XFkmtf3HNh2wbmz3w2Orz9sBc X-Received: by 2002:a17:903:1cd:b0:171:3543:6b13 with SMTP id e13-20020a17090301cd00b0017135436b13mr24583068plh.96.1661254098983; Tue, 23 Aug 2022 04:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254098; cv=none; d=google.com; s=arc-20160816; b=qXLcCdJLSA7zxdOJK5HxQtZsfxKLKun/YndsWClNTJxDsi875k5NLP3YPWuhWkn3+2 m2+7SBvUCbDS5JolAShqOv5Q9TAr7ml5HKZX91ZJP9bofiZGQ1/XYX36PHSt0kilftEH 2dLl+QofX+it8thA0XizzwZWS+y4VGf9hqdeyjx+XRYc8Vciip/rhGzhK49XnOmDR5BP IvxTf/XkP7mPAlhT6EryeM1oE/1p4sTNtcJUJ9LloJn2ypCrge4MtCXy1cQlkJg6pr4O 8O2qhCmDfDcHSshrsJpIv9Szm2kn4gwcUiBF8n5QZ7qJ/OE/Jp4mADBr2DLwg2imv+Vl iYrQ== 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=Ec1Afgu/le8VOGa40R3g/ujLW29cmvVhfgThQwyhTYc=; b=LR1iV4WSADSMdLzmzHyrcL3RaVZIYa3osWC3sfo4SxxqOWRXkWDK9C/23s7+S4jIbm s5QsmMRsaAq0Hxiy+dX0TRZjPdzdNzePKw4QZY/qY2zPElXlD/NmavlxWyUTIODInDzn O/Uo4L0fvRzSFBf9Oup2ArJyRD36AiOVymuQ9pe0xXr4GLg8XEs9aZ67FDOh0yz83flJ hgHA+glfSkO6AIdPXpagg8nYvmIUBtlxZ7KmkkY1UsTPmuHHjidSZOsgGd7lEwdvP8Cf vzv8zfnd9DE1FmPxmvJ5Omlhv8NQqPfxYvonWy5wPlJELv7Ac847XIjx4vEiegG4JKgo YZlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B3mcezs3; 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 x10-20020a170902a38a00b0016dc3b5367asi14109579pla.608.2022.08.23.04.28.06; Tue, 23 Aug 2022 04:28:18 -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=B3mcezs3; 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 S1353555AbiHWKLi (ORCPT + 99 others); Tue, 23 Aug 2022 06:11:38 -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-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 @@ -282,8 +282,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;