netfilter: nf_tables: elements with timeout below CONFIG_HZ never expire
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v3 1/9 netfilter: nf_tables: elements with timeout below CONFIG_HZ never expire
Element timeout that is below CONFIG_HZ never expires because the timeout extension is not allocated given that nf_msecs_to_jiffies64() returns 0. Set timeout to the minimum value to honor timeout.
---
v3: no changes
net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -4587,7 +4587,7 @@ int nf_msecs_to_jiffies64(const struct nlattr *nla, u64 *result)return -ERANGE ; ms *=NSEC_PER_MSEC ; - *result =nsecs_to_jiffies64 (ms); + *result =nsecs_to_jiffies64 (ms) ? : !!ms;return 0 ; }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v3 2/9 netfilter: nf_tables: reject element expiration with no timeout
If element timeout is unset and set provides no default timeout, the element expiration is silently ignored, reject this instead to let user know this is unsupported.
Also prepare for supporting timeout that never expire, where zero timeout and expiration must be also rejected.
---
v3: no changes
net/netfilter/nf_tables_api.c | 3 +++ 1 file changed, 3 insertions(+)
net/netfilter/nf_tables_api.c +3 -0
@@ -6917,6 +6917,9 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,if (nla[NFTA_SET_ELEM_EXPIRATION ] !=NULL ) {if (!(set->flags &NFT_SET_TIMEOUT ))return -EINVAL ; +if (timeout ==0 ) +return -EOPNOTSUPP ; + err =nf_msecs_to_jiffies64 (nla[NFTA_SET_ELEM_EXPIRATION ], &expiration);if (err)
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v3 3/9 netfilter: nf_tables: reject expiration higher than timeout
In reply to Pablo Neira AyusoReport ERANGE to userspace if user specifies an expiration larger than the timeout.
---
v3: no changes
net/netfilter/nf_tables_api.c | 3 +++ 1 file changed, 3 insertions(+)
net/netfilter/nf_tables_api.c +3 -0
@@ -6924,6 +6924,9 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, &expiration);if (err)return err; + +if (expiration > timeout) +return -ERANGE ; }if (nla[NFTA_SET_ELEM_EXPR ]) {
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v3 4/9 netfilter: nf_tables: remove annotation to access set timeout while holding lock
In reply to Pablo Neira AyusoMutex is held when adding an element, no need for READ_ONCE, remove it.
---
v3: no changes
net/netfilter/nf_tables_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +2 -2
@@ -6910,7 +6910,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,return err; }else if (set->flags &NFT_SET_TIMEOUT && !(flags &NFT_SET_ELEM_INTERVAL_END )) { - timeout =READ_ONCE (set->timeout); + timeout = set->timeout; } expiration =0 ;
@@ -7017,7 +7017,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,if (err <0 ) goto err_parse_key_end; -if (timeout !=READ_ONCE (set->timeout)) { +if (timeout != set->timeout) { err =nft_set_ext_add (&tmpl,NFT_SET_EXT_TIMEOUT );if (err <0 ) goto err_parse_key_end;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v3 5/9 netfilter: nft_dynset: annotate data-races around set timeout
In reply to Pablo Neira Ayusoset timeout can be read locklessly while being updated from control plane, add annotation.
---
v3: no changes
net/netfilter/nft_dynset.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nft_dynset.c +3 -3
@@ -56,7 +56,7 @@ static struct nft_elem_priv *nft_dynset_new(struct nft_set *set,if (!atomic_add_unless (&set->nelems,1 , set->size))return NULL ; - timeout = priv->timeout ? : set->timeout; + timeout = priv->timeout ? :READ_ONCE (set->timeout); elem_priv = nft_set_elem_init(set, &priv->tmpl, ®s->data[priv->sreg_key], NULL, ®s->data[priv->sreg_data],
@@ -95,7 +95,7 @@ void nft_dynset_eval(const struct nft_expr *expr, expr, regs, &ext)) {if (priv->op ==NFT_DYNSET_OP_UPDATE &&nft_set_ext_exists (ext,NFT_SET_EXT_EXPIRATION )) { - timeout = priv->timeout ? : set->timeout; + timeout = priv->timeout ? :READ_ONCE (set->timeout); *nft_set_ext_expiration (ext) =get_jiffies_64 () + timeout; }
@@ -313,7 +313,7 @@ static int nft_dynset_init(const struct nft_ctx *ctx,nft_dynset_ext_add_expr (priv);if (set->flags &NFT_SET_TIMEOUT ) { -if (timeout || set->timeout) { +if (timeout ||READ_ONCE (set->timeout)) {nft_set_ext_add (&priv->tmpl,NFT_SET_EXT_TIMEOUT );nft_set_ext_add (&priv->tmpl,NFT_SET_EXT_EXPIRATION ); }
Signature · 1 line
2.30.2