From nobody Thu Dec 18 04:13:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C126C07E9D for ; Mon, 26 Sep 2022 11:15:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237525AbiIZLPJ (ORCPT ); Mon, 26 Sep 2022 07:15:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237678AbiIZLNy (ORCPT ); Mon, 26 Sep 2022 07:13:54 -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 7F5D26113F; Mon, 26 Sep 2022 03:36:22 -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 33735B8091E; Mon, 26 Sep 2022 10:29:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80CB3C433D6; Mon, 26 Sep 2022 10:29:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188186; bh=Sx/ZtVz5BhS6emHclKu+X9velFI4oMJK6XW2r9uSD8k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gVWO9uISYTOd3bki2Am5HyN4itMxyGrWwtiSOkxgZBxMGKIGe7UaYsaOnr7mhSd1A OfjYFDZIT1eqSMDJeG9faEaQqrwF22fpgJYVZq9TyoASgZcmre0YMb+16c+QAnzwhg k/sgG6K3yif2nTesmj5xOoWSztWNwraEW4LUZnso= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Leadbeater , Florian Westphal , Sasha Levin Subject: [PATCH 5.10 069/141] netfilter: nf_conntrack_irc: Tighten matching on DCC message Date: Mon, 26 Sep 2022 12:11:35 +0200 Message-Id: <20220926100756.934344642@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100754.639112000@linuxfoundation.org> References: <20220926100754.639112000@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: David Leadbeater [ Upstream commit e8d5dfd1d8747b56077d02664a8838c71ced948e ] CTCP messages should only be at the start of an IRC message, not anywhere within it. While the helper only decodes packes in the ORIGINAL direction, its possible to make a client send a CTCP message back by empedding one into a PING request. As-is, thats enough to make the helper believe that it saw a CTCP message. Fixes: 869f37d8e48f ("[NETFILTER]: nf_conntrack/nf_nat: add IRC helper port= ") Signed-off-by: David Leadbeater Signed-off-by: Florian Westphal Signed-off-by: Sasha Levin --- net/netfilter/nf_conntrack_irc.c | 34 ++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/net/netfilter/nf_conntrack_irc.c b/net/netfilter/nf_conntrack_= irc.c index 26245419ef4a..65b5b05fe38d 100644 --- a/net/netfilter/nf_conntrack_irc.c +++ b/net/netfilter/nf_conntrack_irc.c @@ -148,15 +148,37 @@ static int help(struct sk_buff *skb, unsigned int pro= toff, data =3D ib_ptr; data_limit =3D ib_ptr + skb->len - dataoff; =20 - /* strlen("\1DCC SENT t AAAAAAAA P\1\n")=3D24 - * 5+MINMATCHLEN+strlen("t AAAAAAAA P\1\n")=3D14 */ - while (data < data_limit - (19 + MINMATCHLEN)) { - if (memcmp(data, "\1DCC ", 5)) { + /* Skip any whitespace */ + while (data < data_limit - 10) { + if (*data =3D=3D ' ' || *data =3D=3D '\r' || *data =3D=3D '\n') + data++; + else + break; + } + + /* strlen("PRIVMSG x ")=3D10 */ + if (data < data_limit - 10) { + if (strncasecmp("PRIVMSG ", data, 8)) + goto out; + data +=3D 8; + } + + /* strlen(" :\1DCC SENT t AAAAAAAA P\1\n")=3D26 + * 7+MINMATCHLEN+strlen("t AAAAAAAA P\1\n")=3D26 + */ + while (data < data_limit - (21 + MINMATCHLEN)) { + /* Find first " :", the start of message */ + if (memcmp(data, " :", 2)) { data++; continue; } + data +=3D 2; + + /* then check that place only for the DCC command */ + if (memcmp(data, "\1DCC ", 5)) + goto out; data +=3D 5; - /* we have at least (19+MINMATCHLEN)-5 bytes valid data left */ + /* we have at least (21+MINMATCHLEN)-(2+5) bytes valid data left */ =20 iph =3D ip_hdr(skb); pr_debug("DCC found in master %pI4:%u %pI4:%u\n", @@ -172,7 +194,7 @@ static int help(struct sk_buff *skb, unsigned int proto= ff, pr_debug("DCC %s detected\n", dccprotos[i]); =20 /* we have at least - * (19+MINMATCHLEN)-5-dccprotos[i].matchlen bytes valid + * (21+MINMATCHLEN)-7-dccprotos[i].matchlen bytes valid * data left (=3D=3D 14/13 bytes) */ if (parse_dcc(data, data_limit, &dcc_ip, &dcc_port, &addr_beg_p, &addr_end_p)) { --=20 2.35.1