netfilter: nf_tables: missing sanitization in data from userspace
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/2 netfilter: nf_tables: missing sanitization in data from userspace
Do not assume userspace always sends us NFT_DATA_VALUE for bitwise and cmp expressions. Although NFT_DATA_VERDICT does not make any sense, it is still possible to handcraft a netlink message using this incorrect data type.
---
Rebased on top of nf. Remove previous cleanup patches.
net/netfilter/nft_bitwise.c | 19 ++++++++++++++----- net/netfilter/nft_cmp.c | 12 ++++++++++-- 2 files changed, 24 insertions(+), 7 deletions(-)
net/netfilter/nft_bitwise.c +14 -5
@@ -83,17 +83,26 @@ static int nft_bitwise_init(const struct nft_ctx *ctx, tb[NFTA_BITWISE_MASK]);if (err <0 )return err; -if (d1.len != priv->len) -return -EINVAL ; +if (d1.len != priv->len) { + err = -EINVAL ; + goto err1; + } err =nft_data_init (NULL , &priv->xor,sizeof (priv->xor), &d2, tb[NFTA_BITWISE_XOR ]);if (err <0 ) -return err; -if (d2.len != priv->len) -return -EINVAL ; + goto err1; +if (d2.len != priv->len) { + err = -EINVAL ; + goto err2; + }return 0 ; +err2: +nft_data_uninit (&priv->xor, d2.type); +err1: +nft_data_uninit (&priv->mask, d1.type); +return err; }static int nft_bitwise_dump (struct sk_buff *skb,const struct nft_expr *expr)
net/netfilter/nft_cmp.c +10 -2
@@ -201,10 +201,18 @@ nft_cmp_select_ops(const struct nft_ctx *ctx, const struct nlattr * const tb[])if (err <0 )return ERR_PTR (err); +if (desc.type !=NFT_DATA_VALUE ) { + err = -EINVAL ; + goto err1; + } +if (desc.len <=sizeof (u32) && op ==NFT_CMP_EQ )return &nft_cmp_fast_ops; -else -return &nft_cmp_ops; + +return &nft_cmp_ops; +err1: +nft_data_uninit (&data, desc.type); +return ERR_PTR (-EINVAL ); }struct nft_expr_type nft_cmp_type__read_mostly = {
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 2/2 netfilter: nf_tables: revisit chain/object refcounting from elements
Andreas reports that the following incremental update using our commit protocol doesn't work.
# nft -f incremental-update.nft
delete element ip filter client_to_any { 10.180.86.22 : goto CIn_1 }
delete chain ip filter CIn_1
... Error: Could not process rule: Device or resource busyThe existing code is not well-integrated into the commit phase protocol, since element deletions do not result in refcount decrement from the preparation phase. This results in bogus EBUSY errors like the one above.
Two new functions come with this patch:
* nft_set_elem_activate() function is used from the abort path, to restore the set element refcounting on objects that occurred from the preparation phase.
* nft_set_elem_deactivate() that is called from nft_del_setelem() to decrement set element refcounting on objects from the preparation phase in the commit protocol.
The nft_data_uninit() has been renamed to nft_data_release() since this function does not uninitialize any data store in the data register, instead just releases the references to objects. Moreover, a new function nft_data_hold() has been introduced to be used from nft_set_elem_activate().
---
Rebased on top of nf.git, removed cleanup patches.
include/net/netfilter/nf_tables.h | 2 +- net/netfilter/nf_tables_api.c | 82 ++++++++++++++++++++++++++++++++++----- net/netfilter/nft_bitwise.c | 4 +- net/netfilter/nft_cmp.c | 2 +- net/netfilter/nft_immediate.c | 5 ++- net/netfilter/nft_range.c | 4 +- 6 files changed, 81 insertions(+), 18 deletions(-)
include/net/netfilter/nf_tables.h +1 -1
@@ -176,7 +176,7 @@ struct nft_data_desc {int nft_data_init (const struct nft_ctx *ctx,struct nft_data *data,unsigned int size,struct nft_data_desc *desc,const struct nlattr *nla); -void nft_data_uninit (const struct nft_data *data,enum nft_data_types type); +void nft_data_release (const struct nft_data *data,enum nft_data_types type);int nft_data_dump (struct sk_buff *skb,int attr,const struct nft_data *data,enum nft_data_types type,unsigned int len);
net/netfilter/nf_tables_api.c +72 -10
150 lines not on this page · raw message
net/netfilter/nft_bitwise.c +2 -2
@@ -99,9 +99,9 @@ static int nft_bitwise_init(const struct nft_ctx *ctx,return 0 ; err2: -nft_data_uninit (&priv->xor, d2.type); +nft_data_release (&priv->xor, d2.type); err1: -nft_data_uninit (&priv->mask, d1.type); +nft_data_release (&priv->mask, d1.type);return err; }
net/netfilter/nft_cmp.c +1 -1
@@ -211,7 +211,7 @@ nft_cmp_select_ops(const struct nft_ctx *ctx, const struct nlattr * const tb[])return &nft_cmp_ops; err1: -nft_data_uninit (&data, desc.type); +nft_data_release (&data, desc.type);return ERR_PTR (-EINVAL ); }
net/netfilter/nft_immediate.c +3 -2
@@ -65,7 +65,7 @@ static int nft_immediate_init(const struct nft_ctx *ctx,return 0 ; err1: -nft_data_uninit (&priv->data, desc.type); +nft_data_release (&priv->data, desc.type);return err; }
@@ -73,7 +73,8 @@ static void nft_immediate_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr) {const struct nft_immediate_expr *priv =nft_expr_priv (expr); -return nft_data_uninit (&priv->data,nft_dreg_to_type (priv->dreg)); + +return nft_data_release (&priv->data,nft_dreg_to_type (priv->dreg)); }static int nft_immediate_dump (struct sk_buff *skb,const struct nft_expr *expr)
net/netfilter/nft_range.c +2 -2
@@ -102,9 +102,9 @@ static int nft_range_init(const struct nft_ctx *ctx, const struct nft_expr *expr priv->len = desc_from.len;return 0 ; err2: -nft_data_uninit (&priv->data_to, desc_to.type); +nft_data_release (&priv->data_to, desc_to.type); err1: -nft_data_uninit (&priv->data_from, desc_from.type); +nft_data_release (&priv->data_from, desc_from.type);return err; }
Signature · 1 line
2.1.4