🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #18093

Re: [PATCH net-next v2] net/sched: em_text: pad the text pattern in the ematch dump

#18093
From: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 19:59
169 lines
14505 bytes
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
Technical Details
Message-ID: <179494556684.3136.3254895311432959761@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365591-linux-kernel-netdev=dewy.ru
References: <QDISC-7SHE.v2.r0.20261109072128-1@mojatatu.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365591-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v2] net/sched: em_text: pad the text pattern in
 the ematch dump
Date: Tue, 17 Nov 2026 19:59:26 +0000
Organization: Usenet Network
Message-ID: <179494556684.3136.3254895311432959761@kernel.org>
References: <QDISC-7SHE.v2.r0.20261109072128-1@mojatatu.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2415774"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:PA7vuTcTkebpNp4JlifxfRM5nNk= sha256:5CAvepoEC5JXtipnNGB+bRAZ1s3JMcCZwMLCIEjxxkk=
	sha1:6/1mGcerky9GaWddOHI6gema8M4= sha256:snxzvXKIUk9PK0vgIx8fCFYQqfb/bNL+h7uJ5Der780=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 1B08311507F; Tue, 17 Nov 2026 22:59:46 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id YWquwQUUt2Rg;
	Tue, 17 Nov 2026 22:59:42 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-365591-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 0151C115073; Tue, 17 Nov 2026 22:59:31 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 5DB0343ADA; Tue, 17 Nov 2026 19:59:30 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794945568;
	b=FXSHhe48ZjhmgvDliK27gWrIFz+KC8d56Ghx5S4GUpugsDEWopW1g0nyYYpAn/Mpy7bz
	 Yk3lOQ4OwT6Z4yXMse2nwTdz1sryarQqGnGaCVLOVpnFren9rByGdl9tHPGseD6+uKMQ4
	 nFnqUEix6AjoIsJGh497Q8p5JZkpNDC0UPQ74hObxfYALzZm8AonuB9qBAbMBr1DcoiUE
	 IXpA2QgJ455FTAoknSxzN2kC4ibFja1F/7af46ksq5iKWazj9FZRrYtFZjKa+2kI8HRe2
	 MF+R4vbX4NyosHAA8jENDc1XhjqnrHG4BEopaEeoSuOZN1DSalc8HtR0HyIjDSilzHw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794945568;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=IQR3igTBNU7ZDEZUBg66UUtdh/DXmx8v8trPPrK13qs=;
	b=ru6rf9vzmjkTBJMaV6lnm56smPQP92Qjam3o3ODGdFZuge4aSLvMQvs3QjZy584Wni/R
	 65yi9blNRVJ1DMmyltwrFM0Mmnr8xlz5RdSR/fJQxmlfP9LFidkSQuyJepJnC6qfQAao7
	 +bRSD7VSOFeeseRShswagmaobL0w2kiB7he8OY5gcu3bcUYLarhoUY03FlXQSWoLKzMOh
	 ZVcYtwh4T44c/bog3dwaNsO+VEqGp2K5It4qvABctzg6yt4jGbteCXDqjEAGCKL95bN53
	 eRbMxT8CChVdp1TmRCJGyeNFToeowyk4aLGZzXx1K6WRFuJWVhSljhrd491NH5gRWPQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lLfQ75Qm;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id C099A606A333;
	Tue, 17 Nov 2026 19:59:28 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lLfQ75Qm
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794945567;
	b=5mFzfNNHtSWFJLP+NU7IV+jdWsPwZP2DtE4QuW3M0sbtD5EMm8GS1uqaQeM4DAWeUorR
	 7tOvHiVl2/cK2dIt5iU4FnZvpuXf1lOwWQejGqrw34tdOumnN2/2m7rLkYVAVFVodu10A
	 N5GFUOT5YCy0AK4kBtITvGNoBFpw5sezz2cV9kwJFzsBMpmKdvKatSzfDuyqaGJpFrmsM
	 yynHzwTG5HPbAIDEHntyilk6WeMKSn0WQ4IRJnETHQQW0c1W3okltBPfCW1qVfA7IdGT2
	 h3xIcethtH027vitddC3GG6+FZgL1CeS0DJuly77+7QxXEdZeiku+DPsAeSTKgKJ8zg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794945567;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=IQR3igTBNU7ZDEZUBg66UUtdh/DXmx8v8trPPrK13qs=;
	b=LZm6DsP7HdM3E7o5luSblP+6P6X0/t/iPs+eSaZ9DeZxeQjy5dzKzHfwxp8P7zqYgR8V
	 kqoOsai1WLJ5ZxLviHRyMH5bn5z+l58PRZlD8z72LJ4kB+NLRoGlwVek2l8DHOh2gWlT9
	 QKvECMOYxFpfFwRH1zcmaKXS85VcF2UY5yjwOFK5DY1hTQAX2kdQ36I+mHRvwithMxG1U
	 lb4f32fuJBXOtKSfl0vSnu5OXwX77yk8mx3QJW4r6bf1vvS+lgjqwowEatKR6z0ycujy2
	 8RixUdr26z76pgLufRyBV2cjYWTNo4k05sJ3AWxsWQX9pt3N6xJ2FmogkWoApwFJuTg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lLfQ75Qm;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF6AE606A31C
	for <netdev@vger.kernel.org>; Tue, 17 Nov 2026 19:59:27 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44F291F000C5;
	Tue, 17 Nov 2026 19:59:27 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794945567;
	bh=IQR3igTBNU7ZDEZUBg66UUtdh/DXmx8v8trPPrK13qs=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=lLfQ75QmVFWytUrhPBcecjg/6vm7k4rjunCVgK/Xzzo5Fbt8MRFu1cogsGN5I7X20
	 dGw5EUkzkt/Dr77mNzDxgOuB0q7Edws1cmBQZGp9BYRq1A2EFnjWcRybUS6PCuYWJH
	 gdgonkOvBqXO0BrjQfLKsWov0CrQ4U3hwbZAhCPbgLsVo2XbvY1whxXNzUfSG6fsAW
	 Tca0dpL9slbhaP97SvSzG9dHsCSPEGaPDv6sSaQHTH7oSkFC6Sv2K4P2eDoulLHrtt
	 +Yb/3ua67qnaFJz7c70ibv/ynRqFSzy+aRPd9y89B09bDQ3K/tN+uaaEUhZCkMMsrV
	 prKPNeR5+fZDA==
X-Cc: netdev@vger.kernel.org, jiri@resnulli.us, jhs@mojatatu.com,
 davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 horms@kernel.org, sashiko-bot@kernel.org
X-In-Reply-To: <QDISC-7SHE.v2.r0.20261109072128-1@mojatatu.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list