Netdev List
 help / color / mirror / Atom feed
From: Rahul Chandelkar <rc@rexion.ai>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Jozsef Kadlecsik <kadlec@netfilter.org>,
	Florian Westphal <fw@strlen.de>, Phil Sutter <phil@nwl.cc>,
	netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org,
	Rahul Chandelkar <rc@rexion.ai>
Subject: [PATCH nf-next v5 2/4] netfilter: nf_conntrack_irc: use nf_ct_helper_parse_port()
Date: Mon, 28 Sep 2026 18:39:01 +0000	[thread overview]
Message-ID: <7ddfde1970b5daaba5c72a1a0f13455caa5e41f3.1790596690.git.rc@rexion.ai> (raw)
In-Reply-To: <cover.1790596690.git.rc@rexion.ai>

parse_dcc() stores the result of simple_strtoul() directly into the u16
*port, so a DCC port above 65535 is silently truncated (e.g. 65537
becomes 1) and a conntrack expectation is created for a port that never
appeared in the DCC command.

Use nf_ct_helper_parse_port(), which parses the length-delimited buffer
without relying on NUL termination and rejects port 0, values above
65535 and digit runs longer than five characters.

Since parse_dcc() now fails for port 0, the dcc_port == 0 test in help()
can no longer be true; remove it.  A DCC command with port 0 is now
dropped through the "unable to parse dcc command" debug path instead of
the ratelimited "Forged DCC command" warning; no expectation is created
in either case.

Build-tested with allmodconfig and allyesconfig (W=1) and sparse, and
cross-built for i386 and big-endian powerpc.  It has not
been run-time tested with IRC traffic.

Fixes: 869f37d8e48f ("[NETFILTER]: nf_conntrack/nf_nat: add IRC helper port")
Assisted-by: Claude-Code:claude-opus-5-5 sparse
Signed-off-by: Rahul Chandelkar <rc@rexion.ai>
---
 net/netfilter/nf_conntrack_irc.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/net/netfilter/nf_conntrack_irc.c b/net/netfilter/nf_conntrack_irc.c
index 92360963757a..88c4530c4841 100644
--- a/net/netfilter/nf_conntrack_irc.c
+++ b/net/netfilter/nf_conntrack_irc.c
@@ -88,7 +88,9 @@ static int parse_dcc(char *data, const char *data_end, __be32 *ip,
 		data++;
 	}
 
-	*port = simple_strtoul(data, &data, 10);
+	if (nf_ct_helper_parse_port(data, data_end - data, port, &data))
+		return -1;
+
 	*ad_end_p = data;
 
 	return 0;
@@ -206,9 +208,8 @@ 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 &&
-			     ct->tuplehash[!dir].tuple.dst.u3.ip != dcc_ip) ||
-			    dcc_port == 0) {
+			if (tuple->src.u3.ip != dcc_ip &&
+			    ct->tuplehash[!dir].tuple.dst.u3.ip != dcc_ip) {
 				net_warn_ratelimited("Forged DCC command from %pI4: %pI4:%u\n",
 						     &tuple->src.u3.ip,
 						     &dcc_ip, dcc_port);
-- 
2.43.0


  parent reply	other threads:[~2026-09-28 18:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 16:28 [PATCH nf-next v5 0/4] netfilter: conntrack: shared port parser for helpers Rahul Chandelkar
2026-09-28 17:33 ` [PATCH nf-next v5 1/4] netfilter: conntrack: add shared uint and port parsers " Rahul Chandelkar
2026-09-28 18:39 ` Rahul Chandelkar [this message]
2026-09-28 19:44 ` [PATCH nf-next v5 3/4] netfilter: nf_conntrack_amanda: use nf_ct_helper_parse_port() Rahul Chandelkar
2026-09-28 20:49 ` [PATCH nf-next v5 4/4] netfilter: nf_conntrack_sip: use shared helper parsers Rahul Chandelkar
2026-09-28 20:56 ` [PATCH nf-next v5 0/4] netfilter: conntrack: shared port parser for helpers netdev-bot+sinfo
2026-09-30  9:57   ` Rahul Chandelkar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7ddfde1970b5daaba5c72a1a0f13455caa5e41f3.1790596690.git.rc@rexion.ai \
    --to=rc@rexion.ai \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=kadlec@netfilter.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=phil@nwl.cc \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox