From nobody Tue Dec 16 04:06:50 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 8D5DCC07E9D for ; Mon, 26 Sep 2022 11:46:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238588AbiIZLqR (ORCPT ); Mon, 26 Sep 2022 07:46:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238401AbiIZLnW (ORCPT ); Mon, 26 Sep 2022 07:43:22 -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 CF7D872873; Mon, 26 Sep 2022 03:46:17 -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 683D0B802C5; Mon, 26 Sep 2022 10:45:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE0D0C433C1; Mon, 26 Sep 2022 10:45:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664189147; bh=dPxiUNwktI/6LHpnNjBpRpD+Vb/t8nqMClxe9ag4g2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wiaZNj9yUx8QgNEBCsLBCwITzEGS0Wivu3ma6V1nv3ItEsPX1LVwB/o3+7GUpELzy HphIs9K+ltIo5/b5lvskOA3ZC/Gq3qNaWrbfxOwmMEpnl9hNIG6yg8iINVYHIMfLPM zWMn1cEbF0Ghx6/sCc09ooNObRnjSNoWO95A3uvU= 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.19 088/207] netfilter: nf_conntrack_irc: Tighten matching on DCC message Date: Mon, 26 Sep 2022 12:11:17 +0200 Message-Id: <20220926100810.523597344@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100806.522017616@linuxfoundation.org> References: <20220926100806.522017616@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 992decbcaa5c..5703846bea3b 100644 --- a/net/netfilter/nf_conntrack_irc.c +++ b/net/netfilter/nf_conntrack_irc.c @@ -157,15 +157,37 @@ static int help(struct sk_buff *skb, unsigned int pro= toff, data =3D ib_ptr; data_limit =3D ib_ptr + datalen; =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", @@ -181,7 +203,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