Skip to content

Commit d77df03

Browse files
walacvvarma
authored andcommitted
netfilter: xt_u32: validate user space input
commit 69c5d28 upstream. The xt_u32 module doesn't validate the fields in the xt_u32 structure. An attacker may take advantage of this to trigger an OOB read by setting the size fields with a value beyond the arrays boundaries. Add a checkentry function to validate the structure. This was originally reported by the ZDI project (ZDI-CAN-18408). Fixes: 1b50b8a ("[NETFILTER]: Add u32 match") Cc: [email protected] Signed-off-by: Wander Lairson Costa <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e271902 commit d77df03

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

net/netfilter/xt_u32.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,32 @@ static bool u32_mt(const struct sk_buff *skb, struct xt_action_param *par)
9696
return ret ^ data->invert;
9797
}
9898

99+
static int u32_mt_checkentry(const struct xt_mtchk_param *par)
100+
{
101+
const struct xt_u32 *data = par->matchinfo;
102+
const struct xt_u32_test *ct;
103+
unsigned int i;
104+
105+
if (data->ntests > ARRAY_SIZE(data->tests))
106+
return -EINVAL;
107+
108+
for (i = 0; i < data->ntests; ++i) {
109+
ct = &data->tests[i];
110+
111+
if (ct->nnums > ARRAY_SIZE(ct->location) ||
112+
ct->nvalues > ARRAY_SIZE(ct->value))
113+
return -EINVAL;
114+
}
115+
116+
return 0;
117+
}
118+
99119
static struct xt_match xt_u32_mt_reg __read_mostly = {
100120
.name = "u32",
101121
.revision = 0,
102122
.family = NFPROTO_UNSPEC,
103123
.match = u32_mt,
124+
.checkentry = u32_mt_checkentry,
104125
.matchsize = sizeof(struct xt_u32),
105126
.me = THIS_MODULE,
106127
};

0 commit comments

Comments
 (0)