Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6816839rwn; Tue, 13 Sep 2022 09:21:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7d8J/iHftuqn+rnPLTEsJwl07Zd1dkv9KQ8FokhKFRuvRzUy7hTaMSXQEO5xyaRhteDE/T X-Received: by 2002:a17:90a:4607:b0:202:d8b7:2c1b with SMTP id w7-20020a17090a460700b00202d8b72c1bmr108384pjg.64.1663086082539; Tue, 13 Sep 2022 09:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663086082; cv=none; d=google.com; s=arc-20160816; b=a9Um/6HqUdzeBW7tqQ7vBodWDRYixYfbde7qMBK4RB6my5PuCmmq9lpGy+WsuP4SF+ /yztUFSci64kNfmE2pcY6hIHEP9RskWxcO/h+5VUzzdIxETtbHTZSelsfxjdhj0BwKbL 33OXXP3hZ45Aui2oE2khIykcOnwKiBDhFNyn5zarRzeEbxXj3VO453MMxnDK1BvZKp9N 9v8AoauZeLgxoYaWyLp5NYGfQnOftC0gmlklCC4tUBU5wHWjXDrfiiSgi/exRWzPzvUw jELi5YCb24j/ng6A2AR79Y/WPoLaTJZ387VH8bktKPID8zmkXrlqoCRQaOYGri23GCkh Agxg== 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=VCSGystSTQwLPsi5STwjf4get1OZTr069DZL4ZmFwYY=; b=TfY5YqsEDvSxnVcO2OewDROsBqcfR2sDa0dEhjdFtBuPjLGzMea4uzgu7o68w0irEG MSfWZAC/JZ2wCMPohR5ppn9TbWvpYMrjzkw/MIlWxVA+mcH3Wk7wg6W3NhLsfnTmEgtH QZAkWuyx+avAJnKtioeLhfRPIbY0NLHGCL+zN3Tf9FFMeBNU1SOAVEY0QbxV2jYUvruJ eO0XSa2ZK34JV2zvwqNaYQ++x6VLmZ8SDEFJ4rzS45f8LzD9cwP5C1yh8v1DTAsGkeMw N2nTjFb9EGl97bF5gddkNTTm7plx00Q+1kayjfg6vgtSKvPB3bJs1BNfSIowCF6NeX/i zJcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zHuEwBfY; 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 h21-20020a056a001a5500b0054289be8a17si9184132pfv.328.2022.09.13.09.21.09; Tue, 13 Sep 2022 09:21:22 -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=zHuEwBfY; 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 S236319AbiIMP3s (ORCPT + 99 others); Tue, 13 Sep 2022 11:29:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233537AbiIMP2D (ORCPT ); Tue, 13 Sep 2022 11:28:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDB577E00F; Tue, 13 Sep 2022 07:39:14 -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 72883614CA; Tue, 13 Sep 2022 14:37:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83218C433D6; Tue, 13 Sep 2022 14:37:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079842; bh=BLBfV+1nH+k/x9oc66dvDyZereog3bqBuCBlo+jNS6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zHuEwBfYS7R8klPiny/7bXpjvZ7hLCGxOTTstBILhw5RNag47tYohN9Yn8xubIKm/ 5pEhzqo55VnX1fbaJDinQR8h9dsQQS6+x7CfXc6t7c/S6U/s+wTi50RSIENES0QYQa J95DRxG6Y7RF5YWw7dL5K6kXt2uYjfjUhrTESiaU= 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.9 35/42] netfilter: nf_conntrack_irc: Fix forged IP logic Date: Tue, 13 Sep 2022 16:08:06 +0200 Message-Id: <20220913140344.151883075@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140342.228397194@linuxfoundation.org> References: <20220913140342.228397194@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 1972a149f9583..c6a8bdc3a226d 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