Skip to content

Commit 728f479

Browse files
Wyatt Fenggregkh
authored andcommitted
netfilter: xt_u32: reject invalid shift counts
[ Upstream commit 64cdf7d ] u32_match_it() executes rule-supplied shift operands on a 32-bit value. A malformed u32 rule can provide a shift count of 32 or more, triggering an undefined shift out-of-bounds during packet evaluation. Validate XT_U32_LEFTSH and XT_U32_RIGHTSH operands in u32_mt_checkentry() and reject malformed rules before they reach the packet path. Fixes: 1b50b8a ("[NETFILTER]: Add u32 match") Reported-by: Yuan Tan <yuantan098@gmail.com> Reported-by: Yifan Wu <yifanwucs@gmail.com> Reported-by: Juefei Pu <tomapufckgml@gmail.com> Reported-by: Zhengchuan Liang <zcliangcn@gmail.com> Reported-by: Xin Liu <bird@lzu.edu.cn> Assisted-by: Codex:GPT-5.4 Signed-off-by: Wyatt Feng <bronzed_45_vested@icloud.com> Signed-off-by: Ren Wei <n05ec@lzu.edu.cn> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 2c4de99 commit 728f479

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

net/netfilter/xt_u32.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static int u32_mt_checkentry(const struct xt_mtchk_param *par)
100100
{
101101
const struct xt_u32 *data = par->matchinfo;
102102
const struct xt_u32_test *ct;
103-
unsigned int i;
103+
unsigned int i, j;
104104

105105
if (data->ntests > ARRAY_SIZE(data->tests))
106106
return -EINVAL;
@@ -111,6 +111,16 @@ static int u32_mt_checkentry(const struct xt_mtchk_param *par)
111111
if (ct->nnums > ARRAY_SIZE(ct->location) ||
112112
ct->nvalues > ARRAY_SIZE(ct->value))
113113
return -EINVAL;
114+
115+
for (j = 1; j < ct->nnums; ++j) {
116+
switch (ct->location[j].nextop) {
117+
case XT_U32_LEFTSH:
118+
case XT_U32_RIGHTSH:
119+
if (ct->location[j].number >= 32)
120+
return -EINVAL;
121+
break;
122+
}
123+
}
114124
}
115125

116126
return 0;

0 commit comments

Comments
 (0)