Commit 173fb593 authored by Florian Westphal's avatar Florian Westphal Committed by Greg Kroah-Hartman

netfilter: ebtables: convert BUG_ONs to WARN_ONs

[ Upstream commit fc6a5d06 ]

All of these conditions are not fatal and should have
been WARN_ONs from the get-go.

Convert them to WARN_ONs and bail out.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5075324c
...@@ -1614,7 +1614,8 @@ static int compat_match_to_user(struct ebt_entry_match *m, void __user **dstptr, ...@@ -1614,7 +1614,8 @@ static int compat_match_to_user(struct ebt_entry_match *m, void __user **dstptr,
int off = ebt_compat_match_offset(match, m->match_size); int off = ebt_compat_match_offset(match, m->match_size);
compat_uint_t msize = m->match_size - off; compat_uint_t msize = m->match_size - off;
BUG_ON(off >= m->match_size); if (WARN_ON(off >= m->match_size))
return -EINVAL;
if (copy_to_user(cm->u.name, match->name, if (copy_to_user(cm->u.name, match->name,
strlen(match->name) + 1) || put_user(msize, &cm->match_size)) strlen(match->name) + 1) || put_user(msize, &cm->match_size))
...@@ -1641,7 +1642,8 @@ static int compat_target_to_user(struct ebt_entry_target *t, ...@@ -1641,7 +1642,8 @@ static int compat_target_to_user(struct ebt_entry_target *t,
int off = xt_compat_target_offset(target); int off = xt_compat_target_offset(target);
compat_uint_t tsize = t->target_size - off; compat_uint_t tsize = t->target_size - off;
BUG_ON(off >= t->target_size); if (WARN_ON(off >= t->target_size))
return -EINVAL;
if (copy_to_user(cm->u.name, target->name, if (copy_to_user(cm->u.name, target->name,
strlen(target->name) + 1) || put_user(tsize, &cm->match_size)) strlen(target->name) + 1) || put_user(tsize, &cm->match_size))
...@@ -1869,7 +1871,8 @@ static int ebt_buf_add(struct ebt_entries_buf_state *state, ...@@ -1869,7 +1871,8 @@ static int ebt_buf_add(struct ebt_entries_buf_state *state,
if (state->buf_kern_start == NULL) if (state->buf_kern_start == NULL)
goto count_only; goto count_only;
BUG_ON(state->buf_kern_offset + sz > state->buf_kern_len); if (WARN_ON(state->buf_kern_offset + sz > state->buf_kern_len))
return -EINVAL;
memcpy(state->buf_kern_start + state->buf_kern_offset, data, sz); memcpy(state->buf_kern_start + state->buf_kern_offset, data, sz);
...@@ -1882,7 +1885,8 @@ static int ebt_buf_add_pad(struct ebt_entries_buf_state *state, unsigned int sz) ...@@ -1882,7 +1885,8 @@ static int ebt_buf_add_pad(struct ebt_entries_buf_state *state, unsigned int sz)
{ {
char *b = state->buf_kern_start; char *b = state->buf_kern_start;
BUG_ON(b && state->buf_kern_offset > state->buf_kern_len); if (WARN_ON(b && state->buf_kern_offset > state->buf_kern_len))
return -EINVAL;
if (b != NULL && sz > 0) if (b != NULL && sz > 0)
memset(b + state->buf_kern_offset, 0, sz); memset(b + state->buf_kern_offset, 0, sz);
...@@ -1959,8 +1963,10 @@ static int compat_mtw_from_user(struct compat_ebt_entry_mwt *mwt, ...@@ -1959,8 +1963,10 @@ static int compat_mtw_from_user(struct compat_ebt_entry_mwt *mwt,
pad = XT_ALIGN(size_kern) - size_kern; pad = XT_ALIGN(size_kern) - size_kern;
if (pad > 0 && dst) { if (pad > 0 && dst) {
BUG_ON(state->buf_kern_len <= pad); if (WARN_ON(state->buf_kern_len <= pad))
BUG_ON(state->buf_kern_offset - (match_size + off) + size_kern > state->buf_kern_len - pad); return -EINVAL;
if (WARN_ON(state->buf_kern_offset - (match_size + off) + size_kern > state->buf_kern_len - pad))
return -EINVAL;
memset(dst + size_kern, 0, pad); memset(dst + size_kern, 0, pad);
} }
return off + match_size; return off + match_size;
...@@ -2011,7 +2017,8 @@ static int ebt_size_mwt(struct compat_ebt_entry_mwt *match32, ...@@ -2011,7 +2017,8 @@ static int ebt_size_mwt(struct compat_ebt_entry_mwt *match32,
if (ret < 0) if (ret < 0)
return ret; return ret;
BUG_ON(ret < match32->match_size); if (WARN_ON(ret < match32->match_size))
return -EINVAL;
growth += ret - match32->match_size; growth += ret - match32->match_size;
growth += ebt_compat_entry_padsize(); growth += ebt_compat_entry_padsize();
...@@ -2121,7 +2128,8 @@ static int size_entry_mwt(struct ebt_entry *entry, const unsigned char *base, ...@@ -2121,7 +2128,8 @@ static int size_entry_mwt(struct ebt_entry *entry, const unsigned char *base,
startoff = state->buf_user_offset - startoff; startoff = state->buf_user_offset - startoff;
BUG_ON(*total < startoff); if (WARN_ON(*total < startoff))
return -EINVAL;
*total -= startoff; *total -= startoff;
return 0; return 0;
} }
...@@ -2249,7 +2257,8 @@ static int compat_do_replace(struct net *net, void __user *user, ...@@ -2249,7 +2257,8 @@ static int compat_do_replace(struct net *net, void __user *user,
state.buf_kern_len = size64; state.buf_kern_len = size64;
ret = compat_copy_entries(entries_tmp, tmp.entries_size, &state); ret = compat_copy_entries(entries_tmp, tmp.entries_size, &state);
BUG_ON(ret < 0); /* parses same data again */ if (WARN_ON(ret < 0))
goto out_unlock;
vfree(entries_tmp); vfree(entries_tmp);
tmp.entries_size = size64; tmp.entries_size = size64;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment