Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6815614rwn; Tue, 13 Sep 2022 09:20:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR753N8wWzkgNo0bBnDG8nNvcpCTegLRaQoHtZ0+0vrwdDHhOjw4WdR/wWSmgdtZAaI5BrJa X-Received: by 2002:a63:824a:0:b0:438:8ba3:fb6a with SMTP id w71-20020a63824a000000b004388ba3fb6amr18197847pgd.49.1663086027166; Tue, 13 Sep 2022 09:20:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663086027; cv=none; d=google.com; s=arc-20160816; b=yLGxYO3TURY5ud7WpltsXTSsRbfvHRd6MQbW8K2zQxXuk5KcAb83rJ2W1uFNSow9jg UQ3cvedoBMwG7oOb7s0xCNwDgTtOSQmiR9O6SPUsTln3vLn/tRzNuEyEcPiuR3pIYdp5 ep6hpS/xcpuuSV8jtUe48ngfv+8ekQ5D94OHuERXkWtM75hpd4JITIElTXhTYaBuemL1 HJIyYR29ReyDdyZ1Qc461uvHHcT+Ct7c+mMyw6M/wOwx8s2R5ppa+UG40y4WnuRLriFy VCk1yncicRZOA+ovZhdn0R8ZoLL0qQbMCoJh2icaSyyRD27C8UvZBsrtr1gWI/pkXoy/ Jhlg== 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=3MB7V1+p+QJYxhUFx43TABulgrxKKvtg6rBLvNkV0Ds=; b=mqbEDI4x1oonI99YNoD4f9w7ZXqph8xyPpA56HRrwfgKF3tPRk957IyrP8E8pbwTVs lCpk4uzj/EYZIMwQ8JPUAGzKNypfT23A3SnEN5FuKi7G6oCd5CcfC8XIQvcT30v48kzU qSya8Emtb0sifTxtQEyhIFXfXn1CfPKetokNIa6AGq/+tO8p3qWHteBY9lZ9lwlSlkYw tjfHsEMqWkSMRM3yyLmRivyaFxmuQ1XmbtpCd8n1eq34rkRnun6HFq19F6Rgynm5fjcN lmheSHzZjW2J6KM5hF9NESmwnX1l/ehRD/NWG09qIqh+ebSsM1OiX2uFpdzwCaCAsoTQ HjmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sSNZlt09; 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 w136-20020a627b8e000000b0052e7d706a6fsi2264655pfc.149.2022.09.13.09.20.15; Tue, 13 Sep 2022 09:20: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=sSNZlt09; 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 S236194AbiIMP1E (ORCPT + 99 others); Tue, 13 Sep 2022 11:27:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236376AbiIMPYV (ORCPT ); Tue, 13 Sep 2022 11:24:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2968E7CB71; Tue, 13 Sep 2022 07:38:10 -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 2C417B81002; Tue, 13 Sep 2022 14:35:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1771C433D6; Tue, 13 Sep 2022 14:35:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079745; bh=TLxpiS+QLk3u35ml0El4E7ff5Vr8imnfzWibFYBBCQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sSNZlt09hcba+a/nHTNZB3Q9k2wILMtjbJAy1+AqFX90j1LLn/IKilpul3eSICEcc qhqPY62QhdVahjPBWd8fksyvG+V25PfKse6jP4UwSE5h8tB4Neb67gG12axALvM6Wl 5WcvHrLGM9FhLHAHgD2sy8bRofzN23n0CyhgWa90= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Leadbeater , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.14 51/61] netfilter: nf_conntrack_irc: Fix forged IP logic Date: Tue, 13 Sep 2022 16:07:53 +0200 Message-Id: <20220913140349.014875416@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140346.422813036@linuxfoundation.org> References: <20220913140346.422813036@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: David Leadbeater [ Upstream commit 0efe125cfb99e6773a7434f3463f7c2fa28f3a43 ] Ensure the match happens in the right direction, previously the destination used was the server, not the NAT host, as the comment shows the code intended. Additionally nf_nat_irc uses port 0 as a signal and there's no valid way it can appear in a DCC message, so consider port 0 also forged. Fixes: 869f37d8e48f ("[NETFILTER]: nf_conntrack/nf_nat: add IRC helper port") Signed-off-by: David Leadbeater Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_conntrack_irc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nf_conntrack_irc.c b/net/netfilter/nf_conntrack_irc.c index 5523acce9d699..814220f7be676 100644 --- a/net/netfilter/nf_conntrack_irc.c +++ b/net/netfilter/nf_conntrack_irc.c @@ -187,8 +187,9 @@ static int help(struct sk_buff *skb, unsigned int protoff, /* dcc_ip can be the internal OR external (NAT'ed) IP */ tuple = &ct->tuplehash[dir].tuple; - if (tuple->src.u3.ip != dcc_ip && - tuple->dst.u3.ip != dcc_ip) { + if ((tuple->src.u3.ip != dcc_ip && + ct->tuplehash[!dir].tuple.dst.u3.ip != dcc_ip) || + dcc_port == 0) { net_warn_ratelimited("Forged DCC command from %pI4: %pI4:%u\n", &tuple->src.u3.ip, &dcc_ip, dcc_port); -- 2.35.1