Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3052715rwe; Mon, 29 Aug 2022 05:11:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR5xlEdhdImz4fyCUcuB64g5YXeDbzOXVKmIfEfa/4SplcXuXE9TtULD/Uc2QdQp7s3EvWtU X-Received: by 2002:a17:902:cf0d:b0:172:715f:69b6 with SMTP id i13-20020a170902cf0d00b00172715f69b6mr16209235plg.110.1661775087907; Mon, 29 Aug 2022 05:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661775087; cv=none; d=google.com; s=arc-20160816; b=pPDw3uX28VvENexkTLPBw0fEDiQq9coeYCSp76nvx8I0r+PIyRsg41Ws77s4Ifdr9K +o8MSlRhpnl6mR7LavzDduGg3PDbO6qfcroesNPUc/FtdTzEeE6gYkuYBPOO0eWrkMnE IrtXc6GYNr+9rk8IsHOzpsNVDn1UuH+nHRs2XAhuJB2HbRAgl2m4KbASYhf9c/ESd1e4 vSDeiPG/lRjJnw9yjoF+lteQdXo9xmAa/huOcJWbbV6XBmCJOzZ/6WEHtjNAjlpklMRQ l65smb1Y+Biu1oOXD7zvcBZD6K/zuJJob1oDVJG2ARZE6D2sPuRb5T2llA8KZVlsOlfj 0E3w== 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=00iWMzaVelLKQbiNlmRVvr8y3HN7W37LmROtycMV41o=; b=vXAtgRWKhjnvGGJ4/dff4yceHF8fzzPQXsupZugdlQ6a6eWrs3jEprS+oRdONWW0ni axO6RD7CCBNyJ0dhODA6YIJywBmuiZjFsCX/ZfsPX7UVA9/UCasEEtQt9TWA5xuHfST0 Wd0G/U5DGTNOtU2hs78CnLE2qCPLya6+Vgokk0ucM/yvbzmHYel/WjZF3gjVMluBmmzf 1gmzWINwn0FEPeHMsdS41Hj1zgCqcnzcvDO6hivSQ3KKBqaAKD8Xs1kCDqxThqSx2B8z Il4RdbWAmQFU0RieG2VC6LdaZKD1f5mLWIpSvVW4LRz0H2iY5QXVxO6RI03r/291LVvh 5r9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GL0liS7E; 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 n16-20020a170903111000b001712e1efa90si9516004plh.22.2022.08.29.05.10.58; Mon, 29 Aug 2022 05:11:27 -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=GL0liS7E; 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 S230093AbiH2LGZ (ORCPT + 99 others); Mon, 29 Aug 2022 07:06:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230255AbiH2LFs (ORCPT ); Mon, 29 Aug 2022 07:05:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78FAD61D57; Mon, 29 Aug 2022 04:04:05 -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 ams.source.kernel.org (Postfix) with ESMTPS id EAFD9B80EF3; Mon, 29 Aug 2022 11:04:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A534C433C1; Mon, 29 Aug 2022 11:04:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771043; bh=Hg0iic/LV1UHfhKvfDy001aBE/HyLI2pbHSboJUYZH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GL0liS7EzVDUOmdEVm6Rg4cTdhJQDjnaTRbJPfJq4duLeWnceAgz7zruiNelTFo20 iwGu6EmwowB0PMH8MZRezg78Ob9Ngg4mU2oThHDjLMMsPb+gi8fqYEhMJPs6hD0iZa p/xk/lwMpH5+tUCKm32FsDfpb7pBm5e5FRmlJY6A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Xiong , Xin Tan , Steffen Klassert , Sasha Levin Subject: [PATCH 5.10 12/86] xfrm: fix refcount leak in __xfrm_policy_check() Date: Mon, 29 Aug 2022 12:58:38 +0200 Message-Id: <20220829105757.031310925@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105756.500128871@linuxfoundation.org> References: <20220829105756.500128871@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 [ Upstream commit 9c9cb23e00ddf45679b21b4dacc11d1ae7961ebe ] The issue happens on an error path in __xfrm_policy_check(). When the fetching process of the object `pols[1]` fails, the function simply returns 0, forgetting to decrement the reference count of `pols[0]`, which is incremented earlier by either xfrm_sk_policy_lookup() or xfrm_policy_lookup(). This may result in memory leaks. Fix it by decreasing the reference count of `pols[0]` in that path. Fixes: 134b0fc544ba ("IPsec: propagate security module errors up from flow_cache_lookup") Signed-off-by: Xin Xiong Signed-off-by: Xin Tan Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/xfrm/xfrm_policy.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index 603b05ed7eb4c..2cd66f3e52386 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -3641,6 +3641,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, if (pols[1]) { if (IS_ERR(pols[1])) { XFRM_INC_STATS(net, LINUX_MIB_XFRMINPOLERROR); + xfrm_pol_put(pols[0]); return 0; } pols[1]->curlft.use_time = ktime_get_real_seconds(); -- 2.35.1