Netfilter fixes for -stable
Subsystems (2)
Pablo Neira Ayuso
maintainerv2 cover Netfilter fixes for -stable
v2: fix incorrect patch submission.
-o-
Hi Greg, Sasha,
This batch contains a backport fix for 6.6-stable.
The following list shows the backported patches, I am using original commit IDs for reference:
1) 82cfd785c7b3 ("netfilter: nf_tables: bail out if stateful expression provides no .clone")
This is a stable dependency for the next patch.
2) 56fac3c36c8f ("netfilter: nf_tables: allow clone callbacks to sleep")
Without this series, ENOMEM is reported when loading a set with 100k elements with counters.
Please, apply,
Thanks
Florian Westphal (1):
netfilter: nf_tables: allow clone callbacks to sleep
Pablo Neira Ayuso (1):
netfilter: nf_tables: bail out if stateful expression provides no
.clone
include/net/netfilter/nf_tables.h | 4 ++-- net/netfilter/nf_tables_api.c | 21 ++++++++++----------- net/netfilter/nft_connlimit.c | 4 ++-- net/netfilter/nft_counter.c | 4 ++-- net/netfilter/nft_dynset.c | 2 +- net/netfilter/nft_last.c | 4 ++-- net/netfilter/nft_limit.c | 14 ++++++++------ net/netfilter/nft_quota.c | 4 ++-- 8 files changed, 29 insertions(+), 28 deletions(-)
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 1/2 netfilter: nf_tables: bail out if stateful expression provides no .clone
commit 3c13725f43dcf43ad8a9bcd6a9f12add19a8f93e upstream.
All existing NFT_EXPR_STATEFUL provide a .clone interface, remove fallback to copy content of stateful expression since this is never exercised and bail out if .clone interface is not defined.
Stable-dep-of: fa23e0d4b756 ("netfilter: nf_tables: allow clone callbacks to sleep")
--- net/netfilter/nf_tables_api.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
net/netfilter/nf_tables_api.c +7 -8
@@ -3336,14 +3336,13 @@ int nft_expr_clone(struct nft_expr *dst, struct nft_expr *src) {int err; -if (src->ops->clone) { - dst->ops = src->ops; - err = src->ops->clone (dst, src); -if (err <0 ) -return err; - }else { -memcpy (dst, src, src->ops->size); - } +if (WARN_ON_ONCE (!src->ops->clone)) +return -EINVAL ; + + dst->ops = src->ops; + err = src->ops->clone (dst, src); +if (err <0 ) +return err;__module_get (src->ops->type->owner);
Signature · 1 line
2.30.2
Sasha Levin
maintainerRe: [PATCH -stable,6.6 v2 1/2] netfilter: nf_tables: bail out if stateful expression provides no .clone
[ Sasha's backport helper bot ]
Hi,
The upstream commit SHA1 provided is correct: 3c13725f43dcf43ad8a9bcd6a9f12add19a8f93e
Status in newer kernel trees:
6.13.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
Note: The patch differs from the upstream commit:
---
1: 3c13725f43dcf ! 1: 297e4b7613a98 netfilter: nf_tables: bail out if stateful expression provides no .clone
@@ Metadata
## Commit message ##
netfilter: nf_tables: bail out if stateful expression provides no .clone
+ commit 3c13725f43dcf43ad8a9bcd6a9f12add19a8f93e upstream.
+
All existing NFT_EXPR_STATEFUL provide a .clone interface, remove fallback to copy content of stateful expression since this is never exercised and bail out if .clone interface is not defined.
+ Stable-dep-of: fa23e0d4b756 ("netfilter: nf_tables: allow clone callbacks to sleep")
## net/netfilter/nf_tables_api.c ##
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | Current branch | Success | Success |
Pablo Neira Ayuso
maintainerPATCH v2 2/2 netfilter: nf_tables: allow clone callbacks to sleep
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
commit fa23e0d4b756d25829e124d6b670a4c6bbd4bf7e upstream.
Sven Auhagen reports transaction failures with following error:
./main.nft:13:1-26: Error: Could not process rule: Cannot allocate memory
percpu: allocation failed, size=16 align=8 atomic=1, atomic alloc failed, no space left
This points to failing pcpu allocation with GFP_ATOMIC flag. However, transactions happen from user context and are allowed to sleep.
One case where we can call into percpu allocator with GFP_ATOMIC is nft_counter expression.
Normally this happens from control plane, so this could use GFP_KERNEL instead. But one use case, element insertion from packet path, needs to use GFP_ATOMIC allocations (nft_dynset expression).
At this time, .clone callbacks always use GFP_ATOMIC for this reason.
Add gfp_t argument to the .clone function and pass GFP_KERNEL or GFP_ATOMIC flag depending on context, this allows all clone memory allocations to sleep for the normal (transaction) case.
--- include/net/netfilter/nf_tables.h | 4 ++-- net/netfilter/nf_tables_api.c | 8 ++++---- net/netfilter/nft_connlimit.c | 4 ++-- net/netfilter/nft_counter.c | 4 ++-- net/netfilter/nft_dynset.c | 2 +- net/netfilter/nft_last.c | 4 ++-- net/netfilter/nft_limit.c | 14 ++++++++------ net/netfilter/nft_quota.c | 4 ++-- 8 files changed, 23 insertions(+), 21 deletions(-)
include/net/netfilter/nf_tables.h +2 -2
@@ -407,7 +407,7 @@ struct nft_expr_info;int nft_expr_inner_parse (const struct nft_ctx *ctx,const struct nlattr *nla,struct nft_expr_info *info); -int nft_expr_clone (struct nft_expr *dst,struct nft_expr *src); +int nft_expr_clone (struct nft_expr *dst,struct nft_expr *src,gfp_t gfp);void nft_expr_destroy (const struct nft_ctx *ctx,struct nft_expr *expr);int nft_expr_dump (struct sk_buff *skb,unsigned int attr,const struct nft_expr *expr,bool reset);
@@ -930,7 +930,7 @@ struct nft_expr_ops {struct nft_regs *regs, const struct nft_pktinfo *pkt);int (*clone)(struct nft_expr *dst, -const struct nft_expr *src); +const struct nft_expr *src,gfp_t gfp);unsigned int size; int (*init)(const struct nft_ctx *ctx,
net/netfilter/nf_tables_api.c +4 -4
@@ -3332,7 +3332,7 @@ static struct nft_expr *nft_expr_init(const struct nft_ctx *ctx,return ERR_PTR (err); } -int nft_expr_clone (struct nft_expr *dst,struct nft_expr *src) +int nft_expr_clone (struct nft_expr *dst,struct nft_expr *src,gfp_t gfp) {int err;
@@ -3340,7 +3340,7 @@ int nft_expr_clone(struct nft_expr *dst, struct nft_expr *src)return -EINVAL ; dst->ops = src->ops; - err = src->ops->clone (dst, src); + err = src->ops->clone (dst, src, gfp);if (err <0 )return err;
@@ -6457,7 +6457,7 @@ int nft_set_elem_expr_clone(const struct nft_ctx *ctx, struct nft_set *set,if (!expr) goto err_expr; - err =nft_expr_clone (expr, set->exprs[i]); + err =nft_expr_clone (expr, set->exprs[i],GFP_KERNEL_ACCOUNT );if (err <0 ) {kfree (expr); goto err_expr;
@@ -6496,7 +6496,7 @@ static int nft_set_elem_expr_setup(struct nft_ctx *ctx,for (i =0 ; i < num_exprs; i++) { expr =nft_setelem_expr_at (elem_expr, elem_expr->size); - err =nft_expr_clone (expr, expr_array[i]); + err =nft_expr_clone (expr, expr_array[i],GFP_KERNEL_ACCOUNT );if (err <0 ) goto err_elem_expr_setup;
net/netfilter/nft_connlimit.c +2 -2
@@ -210,12 +210,12 @@ static void nft_connlimit_destroy(const struct nft_ctx *ctx,nft_connlimit_do_destroy (ctx, priv); } -static int nft_connlimit_clone (struct nft_expr *dst,const struct nft_expr *src) +static int nft_connlimit_clone (struct nft_expr *dst,const struct nft_expr *src,gfp_t gfp) {struct nft_connlimit *priv_dst =nft_expr_priv (dst);struct nft_connlimit *priv_src =nft_expr_priv (src); - priv_dst->list =kmalloc (sizeof (*priv_dst->list),GFP_ATOMIC ); + priv_dst->list =kmalloc (sizeof (*priv_dst->list), gfp);if (!priv_dst->list)return -ENOMEM ;
net/netfilter/nft_counter.c +2 -2
@@ -231,7 +231,7 @@ static void nft_counter_destroy(const struct nft_ctx *ctx,nft_counter_do_destroy (priv); } -static int nft_counter_clone (struct nft_expr *dst,const struct nft_expr *src) +static int nft_counter_clone (struct nft_expr *dst,const struct nft_expr *src,gfp_t gfp) {struct nft_counter_percpu_priv *priv =nft_expr_priv (src);struct nft_counter_percpu_priv *priv_clone =nft_expr_priv (dst);
@@ -241,7 +241,7 @@ static int nft_counter_clone(struct nft_expr *dst, const struct nft_expr *src)nft_counter_fetch (priv, &total); - cpu_stats = alloc_percpu_gfp(struct nft_counter, GFP_ATOMIC); + cpu_stats = alloc_percpu_gfp(struct nft_counter, gfp);if (cpu_stats ==NULL )return -ENOMEM ;
net/netfilter/nft_dynset.c +1 -1
@@ -35,7 +35,7 @@ static int nft_dynset_expr_setup(const struct nft_dynset *priv,for (i =0 ; i < priv->num_exprs; i++) { expr =nft_setelem_expr_at (elem_expr, elem_expr->size); -if (nft_expr_clone (expr, priv->expr_array[i]) <0 ) +if (nft_expr_clone (expr, priv->expr_array[i],GFP_ATOMIC ) <0 )return -1 ; elem_expr->size += priv->expr_array[i]->ops->size;
net/netfilter/nft_last.c +2 -2
@@ -102,12 +102,12 @@ static void nft_last_destroy(const struct nft_ctx *ctx,kfree (priv->last); } -static int nft_last_clone (struct nft_expr *dst,const struct nft_expr *src) +static int nft_last_clone (struct nft_expr *dst,const struct nft_expr *src,gfp_t gfp) {struct nft_last_priv *priv_dst =nft_expr_priv (dst);struct nft_last_priv *priv_src =nft_expr_priv (src); - priv_dst->last =kzalloc (sizeof (*priv_dst->last),GFP_ATOMIC ); + priv_dst->last =kzalloc (sizeof (*priv_dst->last), gfp);if (!priv_dst->last)return -ENOMEM ;
net/netfilter/nft_limit.c +8 -6
@@ -150,7 +150,7 @@ static void nft_limit_destroy(const struct nft_ctx *ctx, }static int nft_limit_clone (struct nft_limit_priv *priv_dst, -const struct nft_limit_priv *priv_src) +const struct nft_limit_priv *priv_src,gfp_t gfp) { priv_dst->tokens_max = priv_src->tokens_max; priv_dst->rate = priv_src->rate;
@@ -158,7 +158,7 @@ static int nft_limit_clone(struct nft_limit_priv *priv_dst, priv_dst->burst = priv_src->burst; priv_dst->invert = priv_src->invert; - priv_dst->limit =kmalloc (sizeof (*priv_dst->limit),GFP_ATOMIC ); + priv_dst->limit =kmalloc (sizeof (*priv_dst->limit), gfp);if (!priv_dst->limit)return -ENOMEM ;
@@ -223,14 +223,15 @@ static void nft_limit_pkts_destroy(const struct nft_ctx *ctx,nft_limit_destroy (ctx, &priv->limit); } -static int nft_limit_pkts_clone (struct nft_expr *dst,const struct nft_expr *src) +static int nft_limit_pkts_clone (struct nft_expr *dst,const struct nft_expr *src, +gfp_t gfp) {struct nft_limit_priv_pkts *priv_dst =nft_expr_priv (dst);struct nft_limit_priv_pkts *priv_src =nft_expr_priv (src); priv_dst->cost = priv_src->cost; -return nft_limit_clone (&priv_dst->limit, &priv_src->limit); +return nft_limit_clone (&priv_dst->limit, &priv_src->limit, gfp); }static struct nft_expr_type nft_limit_type;
@@ -281,12 +282,13 @@ static void nft_limit_bytes_destroy(const struct nft_ctx *ctx,nft_limit_destroy (ctx, priv); } -static int nft_limit_bytes_clone (struct nft_expr *dst,const struct nft_expr *src) +static int nft_limit_bytes_clone (struct nft_expr *dst,const struct nft_expr *src, +gfp_t gfp) {struct nft_limit_priv *priv_dst =nft_expr_priv (dst);struct nft_limit_priv *priv_src =nft_expr_priv (src); -return nft_limit_clone (priv_dst, priv_src); +return nft_limit_clone (priv_dst, priv_src, gfp); }static const struct nft_expr_ops nft_limit_bytes_ops = {
net/netfilter/nft_quota.c +2 -2
@@ -233,7 +233,7 @@ static void nft_quota_destroy(const struct nft_ctx *ctx,return nft_quota_do_destroy (ctx, priv); } -static int nft_quota_clone (struct nft_expr *dst,const struct nft_expr *src) +static int nft_quota_clone (struct nft_expr *dst,const struct nft_expr *src,gfp_t gfp) {struct nft_quota *priv_dst =nft_expr_priv (dst);struct nft_quota *priv_src =nft_expr_priv (src);
@@ -241,7 +241,7 @@ static int nft_quota_clone(struct nft_expr *dst, const struct nft_expr *src) priv_dst->quota = priv_src->quota; priv_dst->flags = priv_src->flags; - priv_dst->consumed =kmalloc (sizeof (*priv_dst->consumed),GFP_ATOMIC ); + priv_dst->consumed =kmalloc (sizeof (*priv_dst->consumed), gfp);if (!priv_dst->consumed)return -ENOMEM ;
Signature · 1 line
2.30.2
Sasha Levin
maintainerRe: [PATCH -stable,6.6 v2 2/2] netfilter: nf_tables: allow clone callbacks to sleep
[ Sasha's backport helper bot ]
Hi,
The upstream commit SHA1 provided is correct: fa23e0d4b756d25829e124d6b670a4c6bbd4bf7e
WARNING: Author mismatch between patch and upstream commit:
Backport author: Pablo Neira Ayuso<[email protected]> Commit author: Florian Westphal<[email protected]>
Status in newer kernel trees:
6.13.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
Note: The patch differs from the upstream commit:
---
1: fa23e0d4b756d ! 1: aba47a0bb9bcb netfilter: nf_tables: allow clone callbacks to sleep
@@ Metadata
## Commit message ##
netfilter: nf_tables: allow clone callbacks to sleep
+ commit fa23e0d4b756d25829e124d6b670a4c6bbd4bf7e upstream.
+
Sven Auhagen reports transaction failures with following error:
./main.nft:13:1-26: Error: Could not process rule: Cannot allocate memory
percpu: allocation failed, size=16 align=8 atomic=1, atomic alloc failed, no space left
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | Current branch | Success | Success |