netfilter: nf_tables: validate variable length element extension
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v4 1/1 netfilter: nf_tables: validate variable length element extension
Update template to validate variable length extensions. This patch adds a new .ext_len[id] field to the template to store the expected extension length. This is used to sanity check the initialization of the variable length extension.
Use PTR_ERR() in nft_set_elem_init() to report errors since, after this update, there are two reason why this might fail, either because of ENOMEM or insufficient room in the extension field (EINVAL).
Kernels up until 7e6bc1f6cabc ("netfilter: nf_tables: stricter validation of element data") allowed to copy more data to the extension than was allocated. This ext_len field allows to validate if the destination has the correct size as additional check.
---
v4: add err_elem_userdata goto tag, otherwise obj->use underflows on error
path (it is only bumped after element userdata handling).
include/net/netfilter/nf_tables.h | 4 +- net/netfilter/nf_tables_api.c | 84 +++++++++++++++++++++++++------ net/netfilter/nft_dynset.c | 2 +- 3 files changed, 73 insertions(+), 17 deletions(-)
include/net/netfilter/nf_tables.h +3 -1
@@ -651,6 +651,7 @@ extern const struct nft_set_ext_type nft_set_ext_types[];struct nft_set_ext_tmpl {u16 len;u8 offset[NFT_SET_EXT_NUM ]; +u8 ext_len[NFT_SET_EXT_NUM ]; };/**
@@ -680,7 +681,8 @@ static inline int nft_set_ext_add_length(struct nft_set_ext_tmpl *tmpl, u8 id,return -EINVAL ; tmpl->offset[id] = tmpl->len; - tmpl->len += nft_set_ext_types[id].len + len; + tmpl->ext_len[id] = nft_set_ext_types[id].len + len; + tmpl->len += tmpl->ext_len[id];return 0 ; }
net/netfilter/nf_tables_api.c +69 -15
161 lines not on this page · raw message
net/netfilter/nft_dynset.c +1 -1
@@ -60,7 +60,7 @@ static void *nft_dynset_new(struct nft_set *set, const struct nft_expr *expr, ®s->data[priv->sreg_key],NULL , ®s->data[priv->sreg_data], timeout, 0, GFP_ATOMIC); -if (elem ==NULL ) +if (IS_ERR (elem)) goto err1; ext =nft_set_elem_ext (set, elem);
Signature · 1 line
2.30.2
Quoted 5 lines · Pablo Neira Ayuso
Update template to validate variable length extensions. This patch adds a new .ext_len[id] field to the template to store the expected extension length. This is used to sanity check the initialization of the variable length extension.
Quoted 8 lines
Use
PTR_ERR()innft_set_elem_init()to report errors since, after this update, there are two reason why this might fail, either because of ENOMEM or insufficient room in the extension field (EINVAL).Kernels up until
7e6bc1f6cabc("netfilter:nf_tables: stricter validation of element data") allowed to copy more data to the extension than was allocated. Thisext_lenfield allows to validate if the destination has the correct size as additional check.
I have applied this to nf.git