Skip to content

Commit

Permalink
netfilter: compat: reject huge allocation requests
Browse files Browse the repository at this point in the history
no need to bother even trying to allocating huge compat offset arrays,
such ruleset is rejected later on anyway becaus we refuse to allocate
overly large rule blobs.

However, compat translation happens before blob allocation, so we should
add a check there too.

This is supposed to help with fuzzing by avoiding oom-killer.

Signed-off-by: Florian Westphal <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
  • Loading branch information
Florian Westphal authored and ummakynes committed Mar 5, 2018
1 parent 9782a11 commit 7d7d7e0
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions net/netfilter/x_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,14 +582,8 @@ int xt_compat_add_offset(u_int8_t af, unsigned int offset, int delta)
{
struct xt_af *xp = &xt[af];

if (!xp->compat_tab) {
if (!xp->number)
return -EINVAL;
xp->compat_tab = vmalloc(sizeof(struct compat_delta) * xp->number);
if (!xp->compat_tab)
return -ENOMEM;
xp->cur = 0;
}
if (WARN_ON(!xp->compat_tab))
return -ENOMEM;

if (xp->cur >= xp->number)
return -EINVAL;
Expand Down Expand Up @@ -634,6 +628,22 @@ EXPORT_SYMBOL_GPL(xt_compat_calc_jump);

int xt_compat_init_offsets(u8 af, unsigned int number)
{
size_t mem;

if (!number || number > (INT_MAX / sizeof(struct compat_delta)))
return -EINVAL;

if (WARN_ON(xt[af].compat_tab))
return -EINVAL;

mem = sizeof(struct compat_delta) * number;
if (mem > XT_MAX_TABLE_SIZE)
return -ENOMEM;

xt[af].compat_tab = vmalloc(mem);
if (!xt[af].compat_tab)
return -ENOMEM;

xt[af].number = number;
xt[af].cur = 0;

Expand Down

0 comments on commit 7d7d7e0

Please sign in to comment.