Netdev List
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Victor Nogueira <victor@mojatatu.com>
Cc: netdev@vger.kernel.org, Jiri Pirko <jiri@resnulli.us>,
	Jamal Hadi Salim <jhs@mojatatu.com>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>, Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH net-next v2] net/sched: em_text: pad the text pattern in the ematch dump
Date: Tue, 17 Nov 2026 14:16:53 -0800	[thread overview]
Message-ID: <20261117141653.60ce5d92@phoenix.local> (raw)
In-Reply-To: <QDISC-7SHE.v2.r0.20261109072128-1@mojatatu.com>

On Fri, 13 Nov 2026 16:10:03 -0300
Victor Nogueira <victor@mojatatu.com> wrote:

> This is a followup of commit 9c572a83037a ("net/sched: fix potential
> stack infoleak in em_text_dump()") as reported by Sashiko.
> 
> The issue: em_text_dump() appends the text pattern with nla_append(),
> which is a bare skb_put_data() and does not pad the attribute to a 4-byte
> boundary.  When pattern_len is not a multiple of four the skb tail is left
> unaligned.
> 
> tcf_em_tree_dump() records the raw span as the ematch entry's nla_len and
> then writes the next ematch's nlattr header at that unaligned tail.
> Userspace walks the list with RTA_NEXT()/NLA_NEXT(), which rounds each
> attribute length up to four bytes, so it looks for the next entry at an
> aligned offset the kernel did not write.  The ematch list is therefore
> misparsed as soon as a text ematch has a pattern length that is not a
> multiple of four.
> 
> The Fix: append the pattern with nla_put_nohdr(), which reserves
> NLA_ALIGN(attrlen) bytes and zero-fills the padding, so the following
> ematch stays aligned.  The emitted ematch entry then carries the padding
> in its nla_len, which is what NLA_NEXT() already assumes.  em_text_change()
> only checks that len covers the struct and the pattern, so a dump replayed
> as a request is still accepted.
> 
> A padded text ematch is the same size as the request that installed it:
> both sides carry the 8-byte match header and the 24-byte configuration
> followed by the pattern rounded up to four bytes, so a tree that installs
> can still be dumped.
> 
> The kernel has no explicit bound on pattern_len; it comes from the
> request. TCA_OPTIONS carries a u16 nla_len, and for cls_cgroup it holds
> 56 bytes of nested headers, the ematch header and struct tcf_em_text
> ahead of the 4-byte-aligned pattern. So the largest pattern that can be
> installed is 65476 bytes (65532-byte options). At 65477 the aligned
> options length wraps to 0, the attribute is dropped by
> nlmsg_parse_deprecated() and cls_cgroup_change() returns -EINVAL. Since
> the dump is no larger than the request, the padding cannot push the
> dumped TCA_OPTIONS past U16_MAX.
> 
> This also removes the last variable-length nla_append() caller (sch_gred's
> is a fixed-size, already aligned struct).
> 
> Conditions to recreate the bug:
> - CAP_NET_ADMIN on the target netns (unshare -Urn is enough)
> - add a basic filter with two text ematches whose pattern_len is not a
>   multiple of 4 (e.g. 1 and 2), then dump it with RTM_GETTFILTER; the first
>   entry comes back with an unaligned nla_len and the next entry's nlattr
>   header is written at that raw offset, while RTA_NEXT() reads an aligned
>   offset three bytes later

Teach your AI to write shorter commit messages please

      parent reply	other threads:[~2026-11-17 22:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 19:10 [PATCH net-next v2] net/sched: em_text: pad the text pattern in the ematch dump Victor Nogueira
2026-11-17 19:59 ` netdev-bot+sashiko
2026-11-17 22:16 ` Stephen Hemminger [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=20261117141653.60ce5d92@phoenix.local \
    --to=stephen@networkplumber.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sashiko-bot@kernel.org \
    --cc=victor@mojatatu.com \
    /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