* [PATCH net-next v2] net/sched: em_text: pad the text pattern in the ematch dump
@ 2026-11-13 19:10 Victor Nogueira
2026-11-17 19:59 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Victor Nogueira @ 2026-11-13 19:10 UTC (permalink / raw)
To: netdev
Cc: Jiri Pirko, Jamal Hadi Salim, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Sashiko
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
Reported-by: Sashiko (gemini) <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260918133953.12494-1-bernard.ladenthin%40gmail.com
Link: https://lore.kernel.org/netdev/e0f4776a-0457-4069-9f79-3c97de2a54d0@redhat.com/
Reviewed-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
---
v1 -> v2:
- No change to the code since v1. Sashiko (nipa) reported that the added
padding could push the cls_cgroup TCA_OPTIONS nest past the u16 nla_len
limit, and Paolo Abeni relayed the concern and asked that it be
addressed here. On review the premise does not hold: a padded text
ematch dumps to the same size as the request that installed it, so it
cannot push TCA_OPTIONS above 65535. The changelog now explains where
the resulting pattern_len limit (65476) comes from. A guard for this
would have been dead code, so the patch is unchanged.
- A filter at the maximal accepted size still cannot be dumped, but that
is the pre-existing netlink dump skb limit near 32 KiB, not the u16
length, and it is unchanged by this patch.
---
net/sched/em_text.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/sched/em_text.c b/net/sched/em_text.c
index bc45edb8c03b..1e7b41e579e2 100644
--- a/net/sched/em_text.c
+++ b/net/sched/em_text.c
@@ -128,8 +128,8 @@ static int em_text_dump(struct sk_buff *skb, struct tcf_ematch *m)
if (nla_put_nohdr(skb, sizeof(conf), &conf) < 0)
goto nla_put_failure;
- if (nla_append(skb, conf.pattern_len,
- textsearch_get_pattern(tm->config)) < 0)
+ if (nla_put_nohdr(skb, conf.pattern_len,
+ textsearch_get_pattern(tm->config)) < 0)
goto nla_put_failure;
return 0;
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net-next v2] net/sched: em_text: pad the text pattern in the ematch dump
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
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-17 19:59 UTC (permalink / raw)
To: victor; +Cc: netdev, jiri, jhs, davem, edumazet, kuba, pabeni, horms,
sashiko-bot
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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).
- [Medium] The commit message says "A padded text ematch is the same size
as the request that installed it ... Since the dump is no larger than…
- [Low] The patch fixes a long-standing, user-visible netlink dump bug
but carries no Fixes: tag.
- [Low] The commit message describes the impact as "the ematch list is
therefore misparsed", and its reproducer needs two text ematches.
--
net/sched: em_text: pad the text pattern in the ematch dump
This patch changes em_text_dump() to append the text pattern with
nla_put_nohdr() instead of nla_append(). The pattern is now padded to a
4-byte boundary, so the next ematch in the dump stays aligned. The commit
message also argues that a padded dump can never be larger than the
request that installed the filter.
Link: https://lore.kernel.org/netdev/e0f4776a-0457-4069-9f79-3c97de2a54d0@redhat.com/
> This is a followup of commit 9c572a83037a ("net/sched: fix potential
> stack infoleak in em_text_dump()") as reported by Sashiko.
[Severity: Low]
Should this patch have a Fixes: tag? Commit 9c572a83037a fixed a different
issue: it zero-initialized conf to plug a stack infoleak. It did not
introduce the misalignment.
The unpadded append goes back to the original em_text implementation in
d675c989ed2d ("[PKT_SCHED]: Packet classification based on textsearch
(ematch)"):
RTA_PUT_NOHDR(skb, sizeof(conf), &conf);
RTA_APPEND(skb, conf.pattern_len, textsearch_get_pattern(tm->config));
add93b610a4e ("[NET_SCHED]: Convert classifiers from rtnetlink to new
netlink API") converted this directly to nla_put_nohdr() plus nla_append(),
so the bug stayed in.
Without something like:
Fixes: d675c989ed2d ("[PKT_SCHED]: Packet classification based on textsearch (ematch)")
the stable tooling may not pick this up.
> 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.
[Severity: Low]
Is the impact wider than the ematch list? em_text_dump() leaves the skb
tail unaligned. tcf_em_tree_dump() then uses that raw tail for
match_start->nla_len and for both nla_nest_end() calls.
cls_basic_dump() and cls_cgroup_dump() close TCA_OPTIONS at the same
unaligned tail and then write the action stats after it:
net/sched/cls_basic.c:basic_dump() {
...
if (nla_nest_end_safe(skb, nest) < 0)
goto nla_put_failure;
if (tcf_exts_dump_stats(skb, &f->exts) < 0)
...
}
tcf_fill_node() then sets nlh->nlmsg_len = skb_tail_pointer(skb) - b,
which is also unaligned. In a filter dump, the next filter's nlmsghdr from
nlmsg_put() and the NLMSG_DONE from netlink_dump() go into the same skb at
that unaligned offset.
Userspace NLMSG_NEXT() steps by NLMSG_ALIGN(nlmsg_len), so every later
message in that recv buffer is read from the wrong offset. This means a
single text ematch with pattern_len % 4 != 0 can corrupt a whole tc filter
show batch. The reproducer in the commit message, by contrast, uses two
text ematches.
Could the commit message describe this, so stable maintainers can judge
backport priority?
> diff --git a/net/sched/em_text.c b/net/sched/em_text.c
> index bc45edb8c03bf..1e7b41e579e24 100644
> --- a/net/sched/em_text.c
> +++ b/net/sched/em_text.c
> @@ -128,8 +128,8 @@ static int em_text_dump(struct sk_buff *skb, struct tcf_ematch *m)
>
> if (nla_put_nohdr(skb, sizeof(conf), &conf) < 0)
> goto nla_put_failure;
> - if (nla_append(skb, conf.pattern_len,
> - textsearch_get_pattern(tm->config)) < 0)
> + if (nla_put_nohdr(skb, conf.pattern_len,
> + textsearch_get_pattern(tm->config)) < 0)
[Severity: Medium]
Does the size argument in the commit message hold when the request uses
unaligned trailing lengths? The commit message says:
Since the dump is no larger than the request, the padding cannot push the
dumped TCA_OPTIONS past U16_MAX.
The kernel does not seem to require the request lengths to be 4-byte
aligned. nla_ok() only checks that nla_len fits in the remaining length.
So the last attribute at each nesting level can have an unaligned nla_len,
including in tcf_em_tree_validate():
for (idx = 0; nla_ok(rt_match, list_len); idx++) {
and em_text_change() only checks:
if (len < sizeof(*conf) || len < (sizeof(*conf) + conf->pattern_len))
return -EINVAL;
rtm_tca_policy does not validate TCA_OPTIONS at all, and cgroup_policy
and em_policy only mark the nests as NLA_NESTED.
A hand-built RTM_NEWTFILTER for cls_cgroup with exact, unpadded lengths
appears to be accepted:
TCA_OPTIONS nla_len 65533
TCA_CGROUP_EMATCHES nla_len 65529
TCA_EMATCH_TREE_HDR nla_len 8
TCA_EMATCH_TREE_LIST nla_len 65517
ematch nla_len 65513 (data_len 65501 = 24 + 65477)
Before this patch, that filter dumps back to an identical 65533-byte
TCA_OPTIONS. With nla_put_nohdr(), the pattern now takes
NLA_ALIGN(65477) = 65480 bytes, so the dumped sizes become:
ematch 65516, list 65520, TCA_CGROUP_EMATCHES 65532,
TCA_OPTIONS 65536
The dump then fails:
cls_cgroup_dump()
nla_nest_end_safe() -> -EMSGSIZE
tcf_fill_node() -> -EMSGSIZE
tfilter_notify_prep()
if (size > U16_MAX + NLMSG_GOODSIZE)
return ERR_PTR(-EMSGSIZE);
After that, RTM_GETTFILTER for this filter always fails. The RTM_NEWTFILTER
notification is never sent, and tfilter_del_notify() deletes the filter
without a notification. Any pattern_len from 65477 to 65479 triggers this,
and cls_basic has the same 56-byte overhead.
Should em_text_change() reject a pattern_len whose padded size cannot be
dumped? If not, the claim in the commit message should be corrected.
> goto nla_put_failure;
> return 0;
>
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/QDISC-7SHE.v2.r0.20261109072128-1%40mojatatu.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-17 19:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox