Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3573107pxb; Mon, 24 Jan 2022 12:32:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzMiWenFI1ME62CkZFXs2rHxUdkFgW5oIowoVHgNUbhh0UDnavhkCv10eiUGbfdseIYIVUz X-Received: by 2002:a17:902:8695:b0:14a:f006:db03 with SMTP id g21-20020a170902869500b0014af006db03mr15445599plo.173.1643056278948; Mon, 24 Jan 2022 12:31:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643056278; cv=none; d=google.com; s=arc-20160816; b=IeDNdBZqyWHhOHFwQ1qOkIvwdFmG0UO2XtevKyyr8tCl0yMGtLdbjK0Iky59gaIYMh H3WZMp5+DRdy1zKBJUNNJY4EqDrmFOvwYR6RHhAdXIzUWzBCI60rAMoIgTCrCjbuPpst 4z70L6Ja+hUH73isiGl8bOrhVJtaqgzBPgxTPjizoRulXSyRzMaIaYKD8gNMoZd2qirL an9gQNyP4FyYXDiATo2ZmxscV93XVMB161kCG0K60eZXlSovX+F4Kl7UuyARHkAoeY8I F6v6xOYX4NeS6EB2W2NxL2PC9y6wYpsHeFOP+DaTpFp4/IHrWAWnWN/O8/RPu35cq5LS ovFw== 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=pIqtDFZBVEkCRf899KdJV5ftiBqQ8IDa7piMcrmQjFI=; b=PUIyEEgonrFPVVAkxACYRHFdHhph0eCimuhmio7+se9Sq7XPTPa4xS2rjqZ//8TGip 7CEZ43+vcHvWtWuNKZpC6QL3selKmlp1shvHQ5ZHy5E/0wedi/aMqL+8ubxjv8iPajyo ThscZCO/MIqEPTaLO6LO/WDLKsA0CjLFC9mx2RbTgWrvBSoV2ls9J6ItHvdbrfMTzPBG 8UQDtg5bp/0AGEAaiVrQE1F1p8GU3DR45gOTYTcq2W5mbdGA3d/rECgwi/mDGVzDSlKb kN3PueL9yLdHIbQYG6QaNDAsFgkNOr91BivH3/r0cCu1B8BNlMGFS8YeMxYHMIKd1hmQ JcIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Lfyu98jf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mh17si383316pjb.31.2022.01.24.12.31.05; Mon, 24 Jan 2022 12:31:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Lfyu98jf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1354353AbiAXTgd (ORCPT + 99 others); Mon, 24 Jan 2022 14:36:33 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:54102 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352812AbiAXTbG (ORCPT ); Mon, 24 Jan 2022 14:31:06 -0500 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 AE9E6B8121B; Mon, 24 Jan 2022 19:31:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD8CEC340E5; Mon, 24 Jan 2022 19:31:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052664; bh=ojLv2A8YiZqQBiDKnhqmW0NP9PBK7G+zSluVkxtI0IA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lfyu98jfTxtiuJfCC18FGhkwArO/yLNz7l1027LZgoFume2GuYJSRiDsuR61dUT7z gl14gsUjCXLZuII55rR/+lVe3wn4wm+zRTJkLQ6L3zZtYcBm9yxLHB9CkPY7cadiiA qixTcQ4lZt6AwaboNPTnndYLIBc1Q/lXITS51uVo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Xiong , Xiyu Yang , Xin Tan , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.4 101/320] netfilter: ipt_CLUSTERIP: fix refcount leak in clusterip_tg_check() Date: Mon, 24 Jan 2022 19:41:25 +0100 Message-Id: <20220124183957.161789148@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Xiong [ Upstream commit d94a69cb2cfa77294921aae9afcfb866e723a2da ] The issue takes place in one error path of clusterip_tg_check(). When memcmp() returns nonzero, the function simply returns the error code, forgetting to decrease the reference count of a clusterip_config object, which is bumped earlier by clusterip_config_find_get(). This may incur reference count leak. Fix this issue by decrementing the refcount of the object in specific error path. Fixes: 06aa151ad1fc74 ("netfilter: ipt_CLUSTERIP: check MAC address when duplicate config is set") Signed-off-by: Xin Xiong Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/ipv4/netfilter/ipt_CLUSTERIP.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c index 6bdb1ab8af617..63ebb87d85331 100644 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c @@ -505,8 +505,11 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par) if (IS_ERR(config)) return PTR_ERR(config); } - } else if (memcmp(&config->clustermac, &cipinfo->clustermac, ETH_ALEN)) + } else if (memcmp(&config->clustermac, &cipinfo->clustermac, ETH_ALEN)) { + clusterip_config_entry_put(config); + clusterip_config_put(config); return -EINVAL; + } ret = nf_ct_netns_get(par->net, par->family); if (ret < 0) { -- 2.34.1