Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: rc@rexion.ai
Cc: pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de,
	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
Subject: Re: [PATCH nf-next v4 3/4] netfilter: nf_conntrack_amanda: use nf_ct_helper_parse_port()
Date: Sun, 27 Sep 2026 17:37:03 +0000	[thread overview]
Message-ID: <179053062399.2160803.9591526412956900613@kernel.org> (raw)
In-Reply-To: <20260923151501.3093863-1-rc@rexion.ai>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] amanda_help() in net/netfilter/nf_conntrack_amanda.c still
  silently cuts a port field of six or more digits down to a different,…

--

netfilter: nf_conntrack_amanda: use nf_ct_helper_parse_port()

This patch replaces the simple_strtoul() + htons() port parsing in
amanda_help() with nf_ct_helper_parse_port(). The goal is to reject port 0
and values above 65535 instead of silently truncating them to a u16. The
NAT mangle length is still taken from the parser's end pointer.

> diff --git a/net/netfilter/nf_conntrack_amanda.c b/net/netfilter/nf_conntrack_amanda.c
> index 14ae660491f36..f157c96b7d223 100644
> --- a/net/netfilter/nf_conntrack_amanda.c
> +++ b/net/netfilter/nf_conntrack_amanda.c
> @@ -89,7 +89,7 @@ static int amanda_help(struct sk_buff *skb,
>  	struct nf_conntrack_tuple *tuple;
>  	unsigned int dataoff, start, stop, off, i;
>  	char pbuf[sizeof("65535")], *tmp;
> -	u16 len;
> +	u16 len, parsed_port;
>  	__be16 port;
>  	int ret = NF_ACCEPT;
>  	nf_nat_amanda_hook_fn *nf_nat_amanda;
> @@ -132,10 +132,10 @@ static int amanda_help(struct sk_buff *skb,
>  			break;
>  		pbuf[len] = '\0';
>  
> -		port = htons(simple_strtoul(pbuf, &tmp, 10));
> -		len = tmp - pbuf;
> -		if (port == 0 || len > 5)
> +		if (nf_ct_helper_parse_port(pbuf, len, &parsed_port, &tmp))
>  			break;
> +		port = htons(parsed_port);
> +		len = tmp - pbuf;

[Severity: High]
Can a port field with six or more digits still be truncated into a
different valid port here?

pbuf is only 6 bytes, and just before this hunk amanda_help() caps the
copy at 5 bytes:

	len = min_t(unsigned int, sizeof(pbuf) - 1, stop - off);
	if (skb_copy_bits(skb, off, pbuf, len))
		break;
	pbuf[len] = '\0';

So nf_ct_helper_parse_port(pbuf, 5, ...) only ever sees the first five
digits. The range check there only covers the len bytes it is given:

net/netfilter/nf_conntrack_helper.c:nf_ct_helper_parse_port() {
	val = nf_ct_helper_parse_uint(cp, len, &e);
	if (e == cp || val == 0 || val > 65535)
		return -1;
}

Nothing checks whether skb byte off + len is another digit. So a reply
such as "CONNECT ... DATA 123456\n" would be accepted as port 12345. In
the same way, 100000 would become 10000 and 655350 would become 65535.
nf_ct_expect_init() would then install a TCP expectation for a port that
never appeared on the wire.

On the NAT path, len = tmp - pbuf is 5 and is passed as matchlen.
help() in net/netfilter/nf_nat_amanda.c then does:

	if (!nf_nat_mangle_udp_packet(skb, ct, ctinfo,
				      protoff, matchoff, matchlen,
				      buffer, strlen(buffer))) {

Only the first 5 bytes get replaced, so the extra digit stays in the
payload. For example, a NAT-chosen port of 40000 would come out as
"400006", which no longer matches the expectation.

The commit message says:

    The digit string is copied into a 6-byte buffer,
    so at most five digits are parsed, but values 65536-99999 still truncated

and:

    Use nf_ct_helper_parse_port(), which rejects port 0 and values above
    65535 in one call.

With the 5-byte window, is that accurate? Values above 99999 are also
above 65535, and they still truncate through the window instead of being
rejected. The later commit "netfilter: nf_conntrack_sip: use shared
helper parsers" in this series does not touch amanda, so this code is
unchanged at the end of the series.

Would it work to copy one extra byte into pbuf, or to check that skb
byte off + len is not a digit, and reject the field when the digit run
is longer than five characters?

>  
>  		exp = nf_ct_expect_alloc(ct);
>  		if (exp == NULL) {

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260923091608.2617604-1-rc%40rexion.ai

  reply	other threads:[~2026-09-27 17:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23  9:16 [PATCH nf-next v4 0/4] netfilter: conntrack: shared port parser for helpers Rahul Chandelkar
2026-09-23 12:07 ` [PATCH nf-next v4 1/4] netfilter: conntrack: add shared uint and port parsers " Rahul Chandelkar
2026-09-27 17:37   ` netdev-bot+sashiko
2026-09-28 14:18     ` Rahul Chandelkar
2026-09-23 13:15 ` [PATCH nf-next v4 2/4] netfilter: nf_conntrack_irc: use nf_ct_helper_parse_port() Rahul Chandelkar
2026-09-27 17:37   ` netdev-bot+sashiko
2026-09-28 15:23     ` Rahul Chandelkar
2026-09-23 15:15 ` [PATCH nf-next v4 3/4] netfilter: nf_conntrack_amanda: " Rahul Chandelkar
2026-09-27 17:37   ` netdev-bot+sashiko [this message]
2026-09-28 11:58     ` Rahul Chandelkar
2026-09-23 17:15 ` [PATCH nf-next v4 4/4] netfilter: nf_conntrack_sip: use shared helper parsers Rahul Chandelkar
2026-09-27 17:37   ` netdev-bot+sashiko
2026-09-28 13:13     ` 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=179053062399.2160803.9591526412956900613@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --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 \
    --cc=rc@rexion.ai \
    /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