Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3602442pxb; Mon, 24 Jan 2022 13:16:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNiZ/P1B6gSk4+SiBpMy2syhjG5zJtKbRJ0UuY0mcup+Px8JSWUl8nXPNQ84WixB0L0sMR X-Received: by 2002:a17:902:a404:b0:148:c0e0:423f with SMTP id p4-20020a170902a40400b00148c0e0423fmr15884102plq.90.1643058978045; Mon, 24 Jan 2022 13:16:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643058978; cv=none; d=google.com; s=arc-20160816; b=Dmt3fOfh2QIGpC5HpwVV9M6zRpg+UXdNX+aizIXwepZIBjEcyESH3fyPbyy0V3faWM ZgcahoWFNqsgwDdGoSdad2JqMvxK73RM082gT2bhO4tzW4AEa3QK5abWP9K7R0lGOPg6 Ib8gF4ErBJhIwjF+SD+qzOT4glqsqFiRCILT16LH7nv3mB3WFfxVscHQnXwDSNdlWkv0 RIBlV2DkZYMXa14J/7NKYrAUCZfh4BY0LGS7oMav/93CakIFEhmrnLH0v8yFTryxp3Y9 jTED9dhc3ReSd2tnWCfeaYhiPIC+TDfzhZ0PyU8BgqlTjVhCO1aaqKA3ydi2wSb1+dWB Dyew== 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=gzjfkohmx+zbcv37ivE6y8D91WN4yIWLuSP3GHAs4Ts=; b=V5N9Zn+qK9Poe5NRIUx6EF3iVhku3AGibPxQ0dtHQC8J1PB3Sw2Znc8XtKSUdZBqK1 LZ8Pir/e97Eihx70AuIJnd77LAE3lbxZe8w32JaN61xXgRHnOiFZlXTVQCpLJKFYpPmX wcEQy+E43wIOHBNVrRlrJRMREt7Hg6fO8m1D8a7pPCpMEmmiV0VvfB8yP3vVq3GOKwcq WJuBCBZM/0aSjh8A7cML1e8n3qN7RhYFUijRqmTR1YxJoo2R718uv+zAPlGvTsl5TfEf YTB4AM7qAzljp6sIcEq5MeqAFaJbC1CMuNN8VLp1yTrNk6AtErPxVtYUWc6zdsi1IdD/ xXdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="b/OroVOP"; 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 6si12734949pgi.55.2022.01.24.13.16.06; Mon, 24 Jan 2022 13:16: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="b/OroVOP"; 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 S1358233AbiAXUtN (ORCPT + 99 others); Mon, 24 Jan 2022 15:49:13 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:33514 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382135AbiAXUZP (ORCPT ); Mon, 24 Jan 2022 15:25:15 -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 F354CB811FB; Mon, 24 Jan 2022 20:25:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28472C340E5; Mon, 24 Jan 2022 20:25:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055912; bh=v3CmNcQuVcLWxRTsj4bwVZeaXhS0Z8OOc7cj1SIMdtw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b/OroVOPtNvXPY/5tTh0E+jigHIWLisjzgUdyalt3PUSyU5N8lWnJqrM+DaLdmEP4 QHE7VBwxEj3fM65nxKjA11j9XtcqecfR1xLEADzeiXJMYR2sB00f6Qv1uLMzHNihoJ wwpr/UuNQx6g8YQjoWXAktJz3bFimtz0VvWHEmbM= 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.15 308/846] netfilter: ipt_CLUSTERIP: fix refcount leak in clusterip_tg_check() Date: Mon, 24 Jan 2022 19:37:05 +0100 Message-Id: <20220124184111.534886909@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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 8fd1aba8af31c..b518f20c9a244 100644 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c @@ -520,8 +520,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