Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp476970imn; Wed, 27 Jul 2022 11:17:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vpZQNbdfnK72ISJ81vG/7xMvLsBhyAuisQvveuRhSuemALT3XQX/tfcVzC2LO9OwtDRhjZ X-Received: by 2002:a05:6402:34c5:b0:43a:8f90:e643 with SMTP id w5-20020a05640234c500b0043a8f90e643mr24084990edc.88.1658945819805; Wed, 27 Jul 2022 11:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658945819; cv=none; d=google.com; s=arc-20160816; b=OyxAwR5HmU/bPV4ZWqieE6gqgptVUm9ZwPdQ1pobIZYyDmqvDrO7KHQsXlIIiSfc7Q DeYNVyyy6nGHOgOC4bQx70voNTar+j4FJYxf+9hjz9GzydiunA+2ekQYaIjXSSy7pMQ4 Fecv0s4W2rA19lSa9SG1T8i+1VeRKI+6Citp08+znjTX4IVLtBQWtPHKbBxPiYZEq3Aa mGtSYrt4gaB3F01BCJ0OrnVkws2rxv2YUAJF6gP9ysrObeGhfmtStdvwxhoJXb4cPQvb 6/nvaAuSjHmqzgiHNWXu2FTiIUB4YPwwhIbF71h85LW8glCWeAIOzG8deSAIOVkR2Y8X cyVg== 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=Txn+AHcu6fS4YDTTLWuog7zczxpXQzbCuMVtDEzO4ec=; b=JVsBVHtuwfeCSXGlIBIC4ESZl8bvmD2VpndJHg827yxrT8ECy1VmyTiPwrPPKz6l9H SwJpqZpYmPcPUYJY9XhboppPjZSWKxjvQn2vRoKzOptbB0Fu7y3NIq7C8SZUIUf04LWH oWDgcIII4DhZHfELM6zTy51Fu2MvBT+Lfhxp6KtJT6FdxX7GufhcjiltcprDLrC2vOJ+ XfQJE0toWALC/hLx0nTMjZOJlp8FlPAgaOVeJrHyRcZK5LatQ81tH+i/M9v2199TZvWw mdeAKqK3Ook7tqtAM5qKVWA6YqC7hiacrP1HsK+S6xx6ycfrUrR6MvGTRxnqe/l5TwAq ux5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vOftltn1; 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 i8-20020a1709064fc800b0072b4f1c6680si23821523ejw.75.2022.07.27.11.16.34; Wed, 27 Jul 2022 11:16:59 -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=vOftltn1; 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 S240888AbiG0Qwz (ORCPT + 99 others); Wed, 27 Jul 2022 12:52:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240813AbiG0QwO (ORCPT ); Wed, 27 Jul 2022 12:52:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF96D4C61A; Wed, 27 Jul 2022 09:34:04 -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 5C36661A7E; Wed, 27 Jul 2022 16:34:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69BCBC433C1; Wed, 27 Jul 2022 16:34:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939643; bh=b1zYqBD/WqElTEuUwmtzh0IfW8TiO4wTB0nofd3g2Yk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vOftltn1uzG4v19tOKOeCzM9KkBt/bP4ZKRiZFN4sCeOIYYmokrQ8xVzhU85c7PvX e5QQaeWOJOsj48MUx61dQtC2FflTa8X9hX8Yrrf7h2ByaAiQn2rvLrauMZfLbOTpJn rRrz5QPsMI9g47T/wqvoz7iTcmOCNdKbcpAUErUQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hangyu Hua , Steffen Klassert , Sasha Levin Subject: [PATCH 5.10 022/105] xfrm: xfrm_policy: fix a possible double xfrm_pols_put() in xfrm_bundle_lookup() Date: Wed, 27 Jul 2022 18:10:08 +0200 Message-Id: <20220727161012.982229722@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161012.056867467@linuxfoundation.org> References: <20220727161012.056867467@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=-7.7 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 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: Hangyu Hua [ Upstream commit f85daf0e725358be78dfd208dea5fd665d8cb901 ] xfrm_policy_lookup() will call xfrm_pol_hold_rcu() to get a refcount of pols[0]. This refcount can be dropped in xfrm_expand_policies() when xfrm_expand_policies() return error. pols[0]'s refcount is balanced in here. But xfrm_bundle_lookup() will also call xfrm_pols_put() with num_pols == 1 to drop this refcount when xfrm_expand_policies() return error. This patch also fix an illegal address access. pols[0] will save a error point when xfrm_policy_lookup fails. This lead to xfrm_pols_put to resolve an illegal address in xfrm_bundle_lookup's error path. Fix these by setting num_pols = 0 in xfrm_expand_policies()'s error path. Fixes: 80c802f3073e ("xfrm: cache bundles instead of policies for outgoing flows") Signed-off-by: Hangyu Hua Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/xfrm/xfrm_policy.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index 93cbcc8f9b39..603b05ed7eb4 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -2680,8 +2680,10 @@ static int xfrm_expand_policies(const struct flowi *fl, u16 family, *num_xfrms = 0; return 0; } - if (IS_ERR(pols[0])) + if (IS_ERR(pols[0])) { + *num_pols = 0; return PTR_ERR(pols[0]); + } *num_xfrms = pols[0]->xfrm_nr; @@ -2696,6 +2698,7 @@ static int xfrm_expand_policies(const struct flowi *fl, u16 family, if (pols[1]) { if (IS_ERR(pols[1])) { xfrm_pols_put(pols, *num_pols); + *num_pols = 0; return PTR_ERR(pols[1]); } (*num_pols)++; -- 2.35.1