Skip to content

Commit b718121

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: ebtables: CONFIG_COMPAT: don't trust userland offsets
We need to make sure the offsets are not out of range of the total size. Also check that they are in ascending order. The WARN_ON triggered by syzkaller (it sets panic_on_warn) is changed to also bail out, no point in continuing parsing. Briefly tested with simple ruleset of -A INPUT --limit 1/s' --log plus jump to custom chains using 32bit ebtables binary. Reported-by: <[email protected]> Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent fc6a5d0 commit b718121

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

net/bridge/netfilter/ebtables.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,9 @@ static int ebt_size_mwt(struct compat_ebt_entry_mwt *match32,
20602060
if (match_kern)
20612061
match_kern->match_size = ret;
20622062

2063-
WARN_ON(type == EBT_COMPAT_TARGET && size_left);
2063+
if (WARN_ON(type == EBT_COMPAT_TARGET && size_left))
2064+
return -EINVAL;
2065+
20642066
match32 = (struct compat_ebt_entry_mwt *) buf;
20652067
}
20662068

@@ -2116,6 +2118,15 @@ static int size_entry_mwt(struct ebt_entry *entry, const unsigned char *base,
21162118
*
21172119
* offsets are relative to beginning of struct ebt_entry (i.e., 0).
21182120
*/
2121+
for (i = 0; i < 4 ; ++i) {
2122+
if (offsets[i] >= *total)
2123+
return -EINVAL;
2124+
if (i == 0)
2125+
continue;
2126+
if (offsets[i-1] > offsets[i])
2127+
return -EINVAL;
2128+
}
2129+
21192130
for (i = 0, j = 1 ; j < 4 ; j++, i++) {
21202131
struct compat_ebt_entry_mwt *match32;
21212132
unsigned int size;

0 commit comments

Comments
 (0)