🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Victor Nogueira Fri, 16 Oct 2026 15:01
[PATCH net-next] net/sched: em_text: pad the text pattern in the ematch dump
#4013
Author: Victor Nogueira
Date: Fri, 16 Oct 2026 15:01
60 lines
10201 bytes
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 <victor@mojatatu.com>
---
 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;
 
-- 
2.43.0
Re: [PATCH net-next] net/sched: em_text: pad the text pattern in the ematch dump
#6180
Author: Victor Nogueira
Date: Wed, 21 Oct 2026 20:44
90 lines
15356 bytes
On Wed, Oct 21, 2026 at 10:42 AM Paolo Abeni <pabeni@redhat.com> wrote:
>
> On 10/16/26 17:01, Victor Nogueira wrote:
> > 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 <victor@mojatatu.com>
> > ---
> >   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.

Ok, also think it merits a respin.
Will do once net-next reopens.

cheers,
Victor
Re: [PATCH net-next] net/sched: em_text: pad the text pattern in the ematch dump
#14263
Author: Jamal Hadi Salim
Date: Tue, 10 Nov 2026 22:32
102 lines
15890 bytes
Hi Paolo,

On Wed, Oct 21, 2026 at 9:42 AM Paolo Abeni <pabeni@redhat.com> wrote:
>
> On 10/16/26 17:01, Victor Nogueira wrote:
> > 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 <victor@mojatatu.com>
> > ---
> >   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
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads