Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6019153pxb; Mon, 14 Feb 2022 13:16:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJydISL2Zyz5G4pYbjM34dFB/lQgwmMuZacaUOgf5k92DdERE1ZGuHrgxNqMO+OKt/VxAlMx X-Received: by 2002:aa7:8545:: with SMTP id y5mr837913pfn.26.1644873384837; Mon, 14 Feb 2022 13:16:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644873384; cv=none; d=google.com; s=arc-20160816; b=WczW/hQQdbvBQYfGQR7tKIuN7e46p+sz0rVBmqLuK/55YhphHOt0HqgYrgxF7sGekc p8z1q9bjp50PjFPYVMq2teXkJ0UFK1iftul4CZrIdi5YULNgcHJNQmh6L1keNB8nQ5nk qYFN+x6fQar0Sszb6Weue9oj5I2vSmtNpnn4uneThwQ3qbqQC6VB29tQbbqcpobi587l B4U1JVL1dQZrZ4fR7s3WUnYJllM5dp0pEJn4eGU/hURUm8lUz7LyhmuBH7m9IADcmNVd UTF3jgwy3Iktyp/sO6vQoTQStcIMFFkbuzg10n6D+mgA4uvu6/hWzUaD/60DABgXV4L2 614A== 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=oOIE5y/ZKZtBFuhLHairseFUbA9TviZhkItwm1ixTSg=; b=bF9y4d6dX+1iNlQQtsA5lgIHdbZWevRBFh5YL/FdsAK6AwpuA7EIYMGMtv5CGpQ2Gg lCez+g4o9LmuEPpGrKOFtp7+sjgzBXgWb4R6XtDcJWDt2XtnJcw5Q9dUmam+L+Bsem36 lF5CFz59Hat50swQ7hJINTOFAkrTq93a2P5cAru2w1Rek9Qbn8Hvk6Yg7zbUPOpvLJnL oEP7b60JfjWGLiOjPnUGKOY8SWNPOyrRQZ/8uEpbfMBBluNAC25YxCiqvD90I6dK7F35 YEynTp3DRZLnkgsOxcg6d4I1MeHpRrESzaYUsLvvJlmtK/v4MWkiqWw58ODVNzHm9EMN c4VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tIDt0FKh; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m13si12965941pls.622.2022.02.14.13.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 13:16:24 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tIDt0FKh; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 527731A277F; Mon, 14 Feb 2022 12:35:19 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345137AbiBNKF4 (ORCPT + 99 others); Mon, 14 Feb 2022 05:05:56 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345210AbiBNKB2 (ORCPT ); Mon, 14 Feb 2022 05:01:28 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75ACC13E33; Mon, 14 Feb 2022 01:47:34 -0800 (PST) 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 12E0361252; Mon, 14 Feb 2022 09:47:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD902C340EF; Mon, 14 Feb 2022 09:47:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644832053; bh=+NBcL0Eq3UCVybOvYfablR+3wu7sDTLFohP96udNTEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tIDt0FKh0O02NDla50BKPZEFj+3lGKZWuiL1LvRiiWDTBQnVW1B2uKjHjKmkcX+K+ D2iqJi+VAI4/it2Z7C9W7N15ACv4l+wbEqFiqDTJs+lHRe3JDSE56kSjPTzi5aWRoX H2pH8uMcEnschqByGXt+J6afllAAvxGsY0qlbiJ8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiyu Yang , Xin Xiong , Xin Tan , Anna Schumaker , Sasha Levin Subject: [PATCH 5.15 033/172] net/sunrpc: fix reference count leaks in rpc_sysfs_xprt_state_change Date: Mon, 14 Feb 2022 10:24:51 +0100 Message-Id: <20220214092507.542826837@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092506.354292783@linuxfoundation.org> References: <20220214092506.354292783@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Xiyu Yang [ Upstream commit 776d794f28c95051bc70405a7b1fa40115658a18 ] The refcount leak issues take place in an error handling path. When the 3rd argument buf doesn't match with "offline", "online" or "remove", the function simply returns -EINVAL and forgets to decrease the reference count of a rpc_xprt object and a rpc_xprt_switch object increased by rpc_sysfs_xprt_kobj_get_xprt() and rpc_sysfs_xprt_kobj_get_xprt_switch(), causing reference count leaks of both unused objects. Fix this issue by jumping to the error handling path labelled with out_put when buf matches none of "offline", "online" or "remove". Signed-off-by: Xiyu Yang Signed-off-by: Xin Xiong Signed-off-by: Xin Tan Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- net/sunrpc/sysfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c index 9a6f17e18f73b..379cf0e4d965b 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -291,8 +291,10 @@ static ssize_t rpc_sysfs_xprt_state_change(struct kobject *kobj, online = 1; else if (!strncmp(buf, "remove", 6)) remove = 1; - else - return -EINVAL; + else { + count = -EINVAL; + goto out_put; + } if (wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_KILLABLE)) { count = -EINTR; -- 2.34.1