Thread View: linux.kernel.netdev
4 messages
4 total messages
Started by hyunjungg
Thu, 29 Oct 2026 16:35
[PATCH net] net/sched: em_ipt: reject hook values >= NF_INET_NUMHOOKS
Author: hyunjungg
Date: Thu, 29 Oct 2026 16:35
Date: Thu, 29 Oct 2026 16:35
58 lines
12819 bytes
12819 bytes
From: Hyunjung Ko <hj351016@gmail.com>
em_ipt_change() reads the TCA_EM_IPT_HOOK netlink attribute into im->hook
as an unbounded u32, and check_match() later uses it as a shift amount:
im->hook = nla_get_u32(tb[TCA_EM_IPT_HOOK]);
...
mtpar.hook_mask = 1 << im->hook;
TCA_EM_IPT_HOOK has no nla_policy range (it is a bare NLA_U32), and the
only range check on the hook lives in policy_validate_match_data(), which
rejects hook != NF_INET_PRE_ROUTING. That validator runs only for the
"policy" match; the "addrtype" match added by commit 0c4231c784b4 ("net:
sched: em_ipt: add support for addrtype matching") has its own validator
which does not look at the hook at all. A filter using match_name
"addrtype" can therefore carry an arbitrary hook value.
For hook >= 32 the "1 << im->hook" in check_match() is a shift that is
out of range for the 32-bit int, i.e. undefined behaviour; im->hook is
also passed unchecked to nf_hook_state_init() on the match path. Valid
hooks are only NF_INET_PRE_ROUTING..NF_INET_POST_ROUTING, so reject
anything >= NF_INET_NUMHOOKS when the attribute is parsed.
Reproduced on v7.3-rc3 (CONFIG_UBSAN=y) by adding a "basic" classifier
carrying an em_ipt "addrtype" ematch (match revision 1, nfproto AF_INET)
with TCA_EM_IPT_HOOK = 32:
UBSAN: shift-out-of-bounds in net/sched/em_ipt.c:52:17
shift exponent 32 is too large for 32-bit type 'int'
It requires CAP_NET_ADMIN (a tc filter add in a netns the caller controls).
Fixes: 0c4231c784b4 ("net: sched: em_ipt: add support for addrtype matching")
Cc: stable@vger.kernel.org # v5.3+
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
net/sched/em_ipt.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/sched/em_ipt.c b/net/sched/em_ipt.c
index 3650117da47f..c16469fb3e92 100644
--- a/net/sched/em_ipt.c
+++ b/net/sched/em_ipt.c
@@ -165,6 +165,11 @@ static int em_ipt_change(struct net *net, void *data, int data_len,
im->match = match;
im->hook = nla_get_u32(tb[TCA_EM_IPT_HOOK]);
+ if (im->hook >= NF_INET_NUMHOOKS) {
+ ret = -EINVAL;
+ goto err;
+ }
+
im->nfproto = nfproto;
nla_memcpy(im->match_data, tb[TCA_EM_IPT_MATCH_DATA], mdata_len);
--
2.43.0
Re: [PATCH net] net/sched: em_ipt: reject hook values >= NF_INET_NUMHOOKS
Author: netdev-bot+sinfo
Date: Thu, 29 Oct 2026 16:38
Date: Thu, 29 Oct 2026 16:38
18 lines
8405 bytes
8405 bytes
Hi! This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information: - How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan. Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then. The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Re: [PATCH net] net/sched: em_ipt: reject hook values >= NF_INET_NUMHOOKS
Author: khj
Date: Thu, 29 Oct 2026 16:47
Date: Thu, 29 Oct 2026 16:47
36 lines
13461 bytes
13461 bytes
Hi, Thanks. The issue was found by static analysis: a small checker that flags values read from netlink attributes (nla_get_u8/u16/u32) that are then used as a shift count without a range check. em_ipt's TCA_EM_IPT_HOOK was flagged because it has no nla_policy bound and only the "policy" match validates the hook, while the "addrtype" match does not. I then confirmed it at runtime with UBSAN using the reproducer described in the commit message (a basic classifier with an em_ipt "addrtype" ematch and TCA_EM_IPT_HOOK = 32). Thanks, Hyunjung Ko 2026λ 10μ 30μΌ (κΈ) μ€μ 1:38, <netdev-bot+sinfo@kernel.org>λμ΄ μμ±: > > Hi! > > This is an automated message. This series looks like a fix, but its > commit messages seem to be missing some information: > > - How the issue was discovered, e.g. hit in production, hit during > development, syzbot report, manual code inspection, LLM or static > analysis tool scan. > > Please do not repost the series just to address the above. Instead, > reply to this email with the missing information, so that reviewers > can take it into account. If the series needs another revision for > other reasons, please include the information in the commit messages > then. > > The evaluation is done by an LLM so it may be wrong, if you think > that is the case please reply and explain.
Re: [PATCH net] net/sched: em_ipt: reject hook values >= NF_INET_NUMHOOKS
Author: netdev-bot+sashiko
Date: Mon, 02 Nov 2026 17:46
Date: Mon, 02 Nov 2026 17:46
90 lines
10873 bytes
10873 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 Β· High: 0 Β· Medium: 1 Β· Low: 0
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 patch is redundant.
--
net/sched: em_ipt: reject hook values >= NF_INET_NUMHOOKS
This patch adds a range check on TCA_EM_IPT_HOOK in em_ipt_change(), so
hook values >= NF_INET_NUMHOOKS are rejected before check_match() uses
im->hook as a shift amount. According to the commit message, an "addrtype"
match can otherwise carry any hook value and trigger a UBSAN
shift-out-of-bounds.
> diff --git a/net/sched/em_ipt.c b/net/sched/em_ipt.c
> index 26f1c4269a487..53358886a88c5 100644
> --- a/net/sched/em_ipt.c
> +++ b/net/sched/em_ipt.c
> @@ -168,6 +168,11 @@ static int em_ipt_change(struct net *net, void *data, int data_len,
>
> im->match = match;
> im->hook = nla_get_u32(tb[TCA_EM_IPT_HOOK]);
> + if (im->hook >= NF_INET_NUMHOOKS) {
> + ret = -EINVAL;
> + goto err;
> + }
> +
[Severity: Medium]
Can this condition ever be true? The tree already contains commit
94cea342e891 ("net: sched: em_ipt: validate hook value from netlink").
That commit added the same check to em_ipt_change(), right after the
required-attribute check:
net/sched/em_ipt.c:em_ipt_change() {
...
if (!tb[TCA_EM_IPT_HOOK] || !tb[TCA_EM_IPT_MATCH_NAME] ||
!tb[TCA_EM_IPT_MATCH_DATA] || !tb[TCA_EM_IPT_NFPROTO])
return -EINVAL;
if (nla_get_u32(tb[TCA_EM_IPT_HOOK]) >= NF_INET_NUMHOOKS)
return -EINVAL;
...
}
That check runs before get_xt_match() and kzalloc(), for every match name,
"addrtype" included. A hook value of 32 is rejected with -EINVAL long
before check_match() gets to:
mtpar.hook_mask = 1 << im->hook;
So the new branch looks like dead code.
For the same reason, some statements in the commit message don't seem to
match the current tree:
"em_ipt_change() reads the TCA_EM_IPT_HOOK netlink attribute into
im->hook as an unbounded u32"
"the only range check on the hook lives in
policy_validate_match_data()"
"A filter using match_name "addrtype" can therefore carry an arbitrary
hook value."
Was the v7.3-rc3 reproduction done on a tree without 94cea342e891?
94cea342e891 has no Fixes: or Cc: stable tag. Would it be better to drop
this patch and ask for 94cea342e891 to be backported to stable instead?
If the range should also be enforced in the netlink policy, em_ipt_policy
still has a bare NLA_U32 entry:
[TCA_EM_IPT_HOOK] = { .type = NLA_U32 },
Could this become NLA_POLICY_MAX(NLA_U32, NF_INET_NUMHOOKS - 1) and replace
the open-coded check, instead of adding a second copy of it?
--
Sashiko AI review Β· https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261029163516.2476127-1-hj351016%40gmail.com
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