From: Pablo Neira Ayuso <pablo@netfilter.org>
To: HACKE-RC <rc@rexion.ai>
Cc: Florian Westphal <fw@strlen.de>, Phil Sutter <phil@nwl.cc>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 2/2] netfilter: nf_conntrack_amanda: reject port values above 65535
Date: Thu, 30 Apr 2026 18:21:24 +0200 [thread overview]
Message-ID: <afOBhH9Ef7z-QqxL@chamomile> (raw)
In-Reply-To: <20260430161515.3449513-3-rc@rexion.ai>
Hi,
On Thu, Apr 30, 2026 at 09:45:15PM +0530, HACKE-RC wrote:
> amanda_help() converts the result of simple_strtoul() to __be16 via
> htons() without checking the parsed value fits in 16 bits. The
> existing len > 5 guard limits strings to five digits, capping the
> parseable range at 99999, but values 65536-99999 still silently
> truncate on the htons() conversion.
>
> Use an intermediate unsigned long and reject out-of-range values
> before converting to network byte order.
>
> Fixes: 16958900578b ("[NETFILTER]: nf_conntrack/nf_nat: add amanda helper port")
> Signed-off-by: HACKE-RC <rc@rexion.ai>
> ---
> net/netfilter/nf_conntrack_amanda.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/net/netfilter/nf_conntrack_amanda.c b/net/netfilter/nf_conntrack_amanda.c
> index d2c09e8dd..58d6c9f29 100644
> --- a/net/netfilter/nf_conntrack_amanda.c
> +++ b/net/netfilter/nf_conntrack_amanda.c
> @@ -88,11 +88,12 @@ static int amanda_help(struct sk_buff *skb,
> struct nf_conntrack_expect *exp;
> struct nf_conntrack_tuple *tuple;
> unsigned int dataoff, start, stop, off, i;
> + nf_nat_amanda_hook_fn *nf_nat_amanda;
> char pbuf[sizeof("65535")], *tmp;
> + unsigned long parsed_port;
> + int ret = NF_ACCEPT;
> u_int16_t len;
> __be16 port;
> - int ret = NF_ACCEPT;
> - nf_nat_amanda_hook_fn *nf_nat_amanda;
>
> /* Only look at packets from the Amanda server */
> if (CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL)
> @@ -132,10 +133,11 @@ static int amanda_help(struct sk_buff *skb,
> break;
> pbuf[len] = '\0';
>
> - port = htons(simple_strtoul(pbuf, &tmp, 10));
> + parsed_port = simple_strtoul(pbuf, &tmp, 10);
While being here, I would replace this simple_strtoul by a parser
which does not rely on nul-terminated strings.
A similar patch went in for the sip helper recently, maybe you can
just take such function to parse ports, move it to the
nf_conntrack_helper core so it can be shared by helpers.
> len = tmp - pbuf;
> - if (port == 0 || len > 5)
> + if (parsed_port == 0 || parsed_port > 65535 || len > 5)
> break;
> + port = htons(parsed_port);
>
> exp = nf_ct_expect_alloc(ct);
> if (exp == NULL) {
> --
> 2.54.0
>
prev parent reply other threads:[~2026-04-30 16:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 16:15 [PATCH net-next 2/2] netfilter: nf_conntrack_amanda: reject port values above 65535 HACKE-RC
2026-04-30 16:21 ` Pablo Neira Ayuso [this message]
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=afOBhH9Ef7z-QqxL@chamomile \
--to=pablo@netfilter.org \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--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