All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: Zhiling Zou <zhilinz@nebusec.ai>,
	netfilter-devel@vger.kernel.org, netdev@vger.kernel.org,
	phil@nwl.cc, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	kaber@trash.net, zhaojignmin@hotmail.com, vega@nebusec.ai
Subject: Re: [PATCH nf v2 1/1] netfilter: validate L4 headers after userspace packet writes
Date: Thu, 30 Jul 2026 13:34:51 +0200	[thread overview]
Message-ID: <ams22yfvR5oNSxIN@chamomile> (raw)
In-Reply-To: <amswI7g2oCttFAvH@strlen.de>

On Thu, Jul 30, 2026 at 01:06:27PM +0200, Florian Westphal wrote:
> Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > > +	const struct nf_conn *ct;
> > > +
> > > +	ct = nf_ct_get(e->skb, &ctinfo);
> > > +	if (ct && !nf_ct_is_template(ct) && nf_ct_protonum(ct) != proto)
> > 
> > I think it should be easier to disallow protocol number mangling in
> > the IP header (layer 3 restrictions), if not done already.
> 
> How?  nfqueue is whole-replace, not a delta.
> Or do you mean checking ip_hdr(skb) vs. the protocol field in userspace
> provided buffer?
> 
> I would prefer this solution (i.e. check ct protocol), it still allows theoretical nfqueue based
> tunneling header insertion, if done in prerouting before conntrack.

OK

> > > +	switch (proto) {
> > > +	case IPPROTO_TCP: {
> > > +		const struct tcphdr *th = (const struct tcphdr *)data;
> > 
> > This needs to use skb_header_pointer() here, you cannot assume the tcp
> > header is in a linear area.
> 
> data is a linear buffer coming from userspace
> (nla_data(nfqa[NFQA_PAYLOAD]).

Indeed.

> > > +	case IPPROTO_SCTP:
> > > +		return data_len >= sizeof(struct sctphdr);
> > > +	case IPPROTO_GRE:
> > > +		return data_len >= sizeof(struct gre_base_hdr);
> > > +	case IPPROTO_NONE:
> > 
> > Remove this and make it part of default and return true if protocol is
> > unknown.
> 
> Hmm.  Its likely safe to accept unknown headers, here.
> 
> Perhaps next iteration should indeed do what you suggest but also check
> check ESP and AH.
> 
> > Default is false for an unknown protocol, should be true.
> 
> I suggested it this way, i.e. don't permit unknown l4 protocols, but
> maybe its too restrictive.
> 
> > > +	if (pkt->tprot != IPPROTO_TCP)
> > > +		return true;
> > > +
> > > +	return priv->offset > doff || priv->offset + priv->len <= doff;
> >                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > 
> > maybe simply check priv->offset >= doff here?
> 
> Could you elaborate?  The above LGTM.  priv->offset > doff is already
> tested?  I mean, write is ok either if offset exceeds doff (lhs)
> or if offset + length doesn't touch doff area (rhs).
> 
> Did you mean "just reject everything exceeding doff"?
> 
> Patch LGTM, except perhaps switching to "allow unknowns" in nfqueue.

OK, thanks for explaining.

      reply	other threads:[~2026-07-30 11:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30  7:30 [PATCH nf v2 1/1] netfilter: validate L4 headers after userspace packet writes Zhiling Zou
2026-07-30 10:34 ` Pablo Neira Ayuso
2026-07-30 11:06   ` Florian Westphal
2026-07-30 11:34     ` 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=ams22yfvR5oNSxIN@chamomile \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=kaber@trash.net \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=phil@nwl.cc \
    --cc=vega@nebusec.ai \
    --cc=zhaojignmin@hotmail.com \
    --cc=zhilinz@nebusec.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.