@@ -1641,7 +1641,8 @@ static int compat_match_to_user(struct ebt_entry_match *m, void __user **dstptr,
1641
1641
int off = ebt_compat_match_offset (match , m -> match_size );
1642
1642
compat_uint_t msize = m -> match_size - off ;
1643
1643
1644
- BUG_ON (off >= m -> match_size );
1644
+ if (WARN_ON (off >= m -> match_size ))
1645
+ return - EINVAL ;
1645
1646
1646
1647
if (copy_to_user (cm -> u .name , match -> name ,
1647
1648
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,
1671
1672
int off = xt_compat_target_offset (target );
1672
1673
compat_uint_t tsize = t -> target_size - off ;
1673
1674
1674
- BUG_ON (off >= t -> target_size );
1675
+ if (WARN_ON (off >= t -> target_size ))
1676
+ return - EINVAL ;
1675
1677
1676
1678
if (copy_to_user (cm -> u .name , target -> name ,
1677
1679
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,
1902
1904
if (state -> buf_kern_start == NULL )
1903
1905
goto count_only ;
1904
1906
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 ;
1906
1909
1907
1910
memcpy (state -> buf_kern_start + state -> buf_kern_offset , data , sz );
1908
1911
@@ -1915,7 +1918,8 @@ static int ebt_buf_add_pad(struct ebt_entries_buf_state *state, unsigned int sz)
1915
1918
{
1916
1919
char * b = state -> buf_kern_start ;
1917
1920
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 ;
1919
1923
1920
1924
if (b != NULL && sz > 0 )
1921
1925
memset (b + state -> buf_kern_offset , 0 , sz );
@@ -1992,8 +1996,10 @@ static int compat_mtw_from_user(struct compat_ebt_entry_mwt *mwt,
1992
1996
pad = XT_ALIGN (size_kern ) - size_kern ;
1993
1997
1994
1998
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 ;
1997
2003
memset (dst + size_kern , 0 , pad );
1998
2004
}
1999
2005
return off + match_size ;
@@ -2043,7 +2049,8 @@ static int ebt_size_mwt(struct compat_ebt_entry_mwt *match32,
2043
2049
if (ret < 0 )
2044
2050
return ret ;
2045
2051
2046
- BUG_ON (ret < match32 -> match_size );
2052
+ if (WARN_ON (ret < match32 -> match_size ))
2053
+ return - EINVAL ;
2047
2054
growth += ret - match32 -> match_size ;
2048
2055
growth += ebt_compat_entry_padsize ();
2049
2056
@@ -2140,7 +2147,8 @@ static int size_entry_mwt(struct ebt_entry *entry, const unsigned char *base,
2140
2147
2141
2148
startoff = state -> buf_user_offset - startoff ;
2142
2149
2143
- BUG_ON (* total < startoff );
2150
+ if (WARN_ON (* total < startoff ))
2151
+ return - EINVAL ;
2144
2152
* total -= startoff ;
2145
2153
return 0 ;
2146
2154
}
@@ -2267,7 +2275,8 @@ static int compat_do_replace(struct net *net, void __user *user,
2267
2275
state .buf_kern_len = size64 ;
2268
2276
2269
2277
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 ;
2271
2280
2272
2281
vfree (entries_tmp );
2273
2282
tmp .entries_size = size64 ;
0 commit comments