Hi Paolo,
On Wed, Oct 21, 2026 at 9:42 AM Paolo Abeni [off-list ref] wrote:
On 10/16/26 17:01, Victor Nogueira wrote:
quoted
This is a follow-up to commit 9c572a83037a ("net/sched: fix potential
stack infoleak in em_text_dump()"), which zero-initialised the dump-side
struct. Sashiko separately pointed at the unaligned pattern tail on the
same dump path.
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.
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. 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 (namespace-local via 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 ematch 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
Reviewed-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Victor Nogueira <redacted>
---
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 4132f8c3c5fc..fbf78d61f109 100644
--- a/net/sched/em_text.c
+++ b/net/sched/em_text.c
@@ -125,8 +125,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;
Sashiko suspects this can introduce another issue:
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/QDISC-7SHE.v1.r0.20261016101330-1@mojatatu.com
(the 2nd concern)
I think it should be addressed in the same patch.
We looked closely at this, sashiko premise that pattern_len 65477
will cause the issue is false.
at most pattern_len = 65476, which yields TCA_OPTIONS = 65532 is
accepted. 65477 is already rejected with -EINVAL by the existing u16
wrap of the request attribute, before even tcf_em_tree_validate() runs
So that code is simply unreachable.
For that reason it doesnt make sense to send a v2.
cheers,
jamal
pattern_len = 65476, which yields TCA_OPTIONS = 65532; 65477 is
already rejected with -EINVAL
/P