Skip to content

Commit fc6a5d0

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: ebtables: convert BUG_ONs to WARN_ONs
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: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent c4585a2 commit fc6a5d0

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

net/bridge/netfilter/ebtables.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,8 @@ static int compat_match_to_user(struct ebt_entry_match *m, void __user **dstptr,
16411641
int off = ebt_compat_match_offset(match, m->match_size);
16421642
compat_uint_t msize = m->match_size - off;
16431643

1644-
BUG_ON(off >= m->match_size);
1644+
if (WARN_ON(off >= m->match_size))
1645+
return -EINVAL;
16451646

16461647
if (copy_to_user(cm->u.name, match->name,
16471648
strlen(match->name) + 1) || put_user(msize, &cm->match_size))
@@ -1671,7 +1672,8 @@ static int compat_target_to_user(struct ebt_entry_target *t,
16711672
int off = xt_compat_target_offset(target);
16721673
compat_uint_t tsize = t->target_size - off;
16731674

1674-
BUG_ON(off >= t->target_size);
1675+
if (WARN_ON(off >= t->target_size))
1676+
return -EINVAL;
16751677

16761678
if (copy_to_user(cm->u.name, target->name,
16771679
strlen(target->name) + 1) || put_user(tsize, &cm->match_size))
@@ -1902,7 +1904,8 @@ static int ebt_buf_add(struct ebt_entries_buf_state *state,
19021904
if (state->buf_kern_start == NULL)
19031905
goto count_only;
19041906

1905-
BUG_ON(state->buf_kern_offset + sz > state->buf_kern_len);
1907+
if (WARN_ON(state->buf_kern_offset + sz > state->buf_kern_len))
1908+
return -EINVAL;
19061909

19071910
memcpy(state->buf_kern_start + state->buf_kern_offset, data, sz);
19081911

@@ -1915,7 +1918,8 @@ static int ebt_buf_add_pad(struct ebt_entries_buf_state *state, unsigned int sz)
19151918
{
19161919
char *b = state->buf_kern_start;
19171920

1918-
BUG_ON(b && state->buf_kern_offset > state->buf_kern_len);
1921+
if (WARN_ON(b && state->buf_kern_offset > state->buf_kern_len))
1922+
return -EINVAL;
19191923

19201924
if (b != NULL && sz > 0)
19211925
memset(b + state->buf_kern_offset, 0, sz);
@@ -1992,8 +1996,10 @@ static int compat_mtw_from_user(struct compat_ebt_entry_mwt *mwt,
19921996
pad = XT_ALIGN(size_kern) - size_kern;
19931997

19941998
if (pad > 0 && dst) {
1995-
BUG_ON(state->buf_kern_len <= pad);
1996-
BUG_ON(state->buf_kern_offset - (match_size + off) + size_kern > state->buf_kern_len - pad);
1999+
if (WARN_ON(state->buf_kern_len <= pad))
2000+
return -EINVAL;
2001+
if (WARN_ON(state->buf_kern_offset - (match_size + off) + size_kern > state->buf_kern_len - pad))
2002+
return -EINVAL;
19972003
memset(dst + size_kern, 0, pad);
19982004
}
19992005
return off + match_size;
@@ -2043,7 +2049,8 @@ static int ebt_size_mwt(struct compat_ebt_entry_mwt *match32,
20432049
if (ret < 0)
20442050
return ret;
20452051

2046-
BUG_ON(ret < match32->match_size);
2052+
if (WARN_ON(ret < match32->match_size))
2053+
return -EINVAL;
20472054
growth += ret - match32->match_size;
20482055
growth += ebt_compat_entry_padsize();
20492056

@@ -2140,7 +2147,8 @@ static int size_entry_mwt(struct ebt_entry *entry, const unsigned char *base,
21402147

21412148
startoff = state->buf_user_offset - startoff;
21422149

2143-
BUG_ON(*total < startoff);
2150+
if (WARN_ON(*total < startoff))
2151+
return -EINVAL;
21442152
*total -= startoff;
21452153
return 0;
21462154
}
@@ -2267,7 +2275,8 @@ static int compat_do_replace(struct net *net, void __user *user,
22672275
state.buf_kern_len = size64;
22682276

22692277
ret = compat_copy_entries(entries_tmp, tmp.entries_size, &state);
2270-
BUG_ON(ret < 0); /* parses same data again */
2278+
if (WARN_ON(ret < 0))
2279+
goto out_unlock;
22712280

22722281
vfree(entries_tmp);
22732282
tmp.entries_size = size64;

0 commit comments

Comments
 (0)