net/sched: em_ipt: reject hook values >= NF_INET_NUMHOOKS
Subsystems (4)
PATCH 1/1 net/sched: em_ipt: reject hook values >= NF_INET_NUMHOOKS
From: Hyunjung Ko <[email protected]>
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).
--- net/sched/em_ipt.c | 5 +++++ 1 file changed, 5 insertions(+)
net/sched/em_ipt.c +5 -0
@@ -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);
Signature · 1 line
2.43.0
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
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.
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, <[email protected]>님이 작성:
Quoted 18 lines
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.
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
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.
net/sched/em_ipt.c static int em_ipt_change(struct net *net, void *data, int data_len, · line 175
Quoted 13 lines
net/sched/em_ipt.c +5
-0@@ -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?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261029163516.2476127-1-hj351016%40gmail.com