netfilter: nf_tables: replace BUG_ON by element length check
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v3 1/1 netfilter: nf_tables: replace BUG_ON by element length check
BUG_ON can be triggered from userspace with an element with a large userdata area. Replace it by length check and return EINVAL instead. Over time extensions have been growing in size.
Pick a sufficiently old Fixes: tag to propagate this fix.
Fixes 7d7402642eaf ("netfilter: nf_tables: variable sized set element keys / data")
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
v3: rebase without previous patch dependency.
include/net/netfilter/nf_tables.h | 14 ++++--- net/netfilter/nf_tables_api.c | 66 ++++++++++++++++++++++--------- 2 files changed, 56 insertions(+), 24 deletions(-)
include/net/netfilter/nf_tables.h +9 -5
@@ -657,18 +657,22 @@ static inline void nft_set_ext_prepare(struct nft_set_ext_tmpl *tmpl) tmpl->len =sizeof (struct nft_set_ext ); } -static inline void nft_set_ext_add_length (struct nft_set_ext_tmpl *tmpl,u8 id, -unsigned int len) +static inline int nft_set_ext_add_length (struct nft_set_ext_tmpl *tmpl,u8 id, +unsigned int len) { tmpl->len =ALIGN (tmpl->len, nft_set_ext_types[id].align); -BUG_ON (tmpl->len >U8_MAX ); +if (tmpl->len >U8_MAX ) +return -EINVAL ; + tmpl->offset[id] = tmpl->len; tmpl->len += nft_set_ext_types[id].len + len; + +return 0 ; } -static inline void nft_set_ext_add (struct nft_set_ext_tmpl *tmpl,u8 id) +static inline int nft_set_ext_add (struct nft_set_ext_tmpl *tmpl,u8 id) { -nft_set_ext_add_length (tmpl, id,0 ); +return nft_set_ext_add_length (tmpl, id,0 ); } static inline void nft_set_ext_init(struct nft_set_ext *ext,
net/netfilter/nf_tables_api.c +47 -19
129 lines not on this page · raw message
Signature · 1 line
2.30.2