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 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. Cc: Sven Auhagen <sven.auhagen@voleatech.de> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
7d64835c13
commit
b2a587e7a5
5 changed files with 10 additions and 10 deletions
|
@ -786,7 +786,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,
|
||||
|
@ -837,7 +837,7 @@ static inline void *nft_expr_priv(const struct nft_expr *expr)
|
|||
return (void *)expr->data;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -2968,13 +2968,13 @@ err_expr_parse:
|
|||
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;
|
||||
|
||||
if (src->ops->clone) {
|
||||
dst->ops = src->ops;
|
||||
err = src->ops->clone(dst, src);
|
||||
err = src->ops->clone(dst, src, gfp);
|
||||
if (err < 0)
|
||||
return err;
|
||||
} else {
|
||||
|
@ -5524,7 +5524,7 @@ static int nft_set_elem_expr_setup(struct nft_ctx *ctx,
|
|||
if (expr == NULL)
|
||||
return 0;
|
||||
|
||||
err = nft_expr_clone(elem_expr, expr);
|
||||
err = nft_expr_clone(elem_expr, expr, GFP_KERNEL);
|
||||
if (err < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -5632,7 +5632,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
|
|||
if (!expr)
|
||||
return -ENOMEM;
|
||||
|
||||
err = nft_expr_clone(expr, set->expr);
|
||||
err = nft_expr_clone(expr, set->expr, GFP_KERNEL);
|
||||
if (err < 0)
|
||||
goto err_set_elem_expr;
|
||||
}
|
||||
|
|
|
@ -195,7 +195,7 @@ 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);
|
||||
|
|
|
@ -224,7 +224,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);
|
||||
|
@ -234,7 +234,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;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ static void *nft_dynset_new(struct nft_set *set, const struct nft_expr *expr,
|
|||
|
||||
ext = nft_set_elem_ext(set, elem);
|
||||
if (priv->expr != NULL &&
|
||||
nft_expr_clone(nft_set_ext_expr(ext), priv->expr) < 0)
|
||||
nft_expr_clone(nft_set_ext_expr(ext), priv->expr, GFP_ATOMIC) < 0)
|
||||
goto err2;
|
||||
|
||||
return elem;
|
||||
|
|
Loading…
Reference in a new issue