Skip to content

Commit 69e687c

Browse files
committed
netfilter: nf_tables: missing objects with no memcg accounting
Several ruleset objects are still not using GFP_KERNEL_ACCOUNT for memory accounting, update them. This includes: - catchall elements - compat match large info area - log prefix - meta secctx - numgen counters - pipapo set backend datastructure - tunnel private objects Fixes: 33758c8 ("memcg: enable accounting for nft objects") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 4ffcf5c commit 69e687c

File tree

7 files changed

+17
-15
lines changed

7 files changed

+17
-15
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6684,7 +6684,7 @@ static int nft_setelem_catchall_insert(const struct net *net,
66846684
}
66856685
}
66866686

6687-
catchall = kmalloc(sizeof(*catchall), GFP_KERNEL);
6687+
catchall = kmalloc(sizeof(*catchall), GFP_KERNEL_ACCOUNT);
66886688
if (!catchall)
66896689
return -ENOMEM;
66906690

net/netfilter/nft_compat.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ nft_match_large_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
535535
struct xt_match *m = expr->ops->data;
536536
int ret;
537537

538-
priv->info = kmalloc(XT_ALIGN(m->matchsize), GFP_KERNEL);
538+
priv->info = kmalloc(XT_ALIGN(m->matchsize), GFP_KERNEL_ACCOUNT);
539539
if (!priv->info)
540540
return -ENOMEM;
541541

@@ -808,7 +808,7 @@ nft_match_select_ops(const struct nft_ctx *ctx,
808808
goto err;
809809
}
810810

811-
ops = kzalloc(sizeof(struct nft_expr_ops), GFP_KERNEL);
811+
ops = kzalloc(sizeof(struct nft_expr_ops), GFP_KERNEL_ACCOUNT);
812812
if (!ops) {
813813
err = -ENOMEM;
814814
goto err;
@@ -898,7 +898,7 @@ nft_target_select_ops(const struct nft_ctx *ctx,
898898
goto err;
899899
}
900900

901-
ops = kzalloc(sizeof(struct nft_expr_ops), GFP_KERNEL);
901+
ops = kzalloc(sizeof(struct nft_expr_ops), GFP_KERNEL_ACCOUNT);
902902
if (!ops) {
903903
err = -ENOMEM;
904904
goto err;

net/netfilter/nft_log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static int nft_log_init(const struct nft_ctx *ctx,
163163

164164
nla = tb[NFTA_LOG_PREFIX];
165165
if (nla != NULL) {
166-
priv->prefix = kmalloc(nla_len(nla) + 1, GFP_KERNEL);
166+
priv->prefix = kmalloc(nla_len(nla) + 1, GFP_KERNEL_ACCOUNT);
167167
if (priv->prefix == NULL)
168168
return -ENOMEM;
169169
nla_strscpy(priv->prefix, nla, nla_len(nla) + 1);

net/netfilter/nft_meta.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ static int nft_secmark_obj_init(const struct nft_ctx *ctx,
952952
if (tb[NFTA_SECMARK_CTX] == NULL)
953953
return -EINVAL;
954954

955-
priv->ctx = nla_strdup(tb[NFTA_SECMARK_CTX], GFP_KERNEL);
955+
priv->ctx = nla_strdup(tb[NFTA_SECMARK_CTX], GFP_KERNEL_ACCOUNT);
956956
if (!priv->ctx)
957957
return -ENOMEM;
958958

net/netfilter/nft_numgen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static int nft_ng_inc_init(const struct nft_ctx *ctx,
6666
if (priv->offset + priv->modulus - 1 < priv->offset)
6767
return -EOVERFLOW;
6868

69-
priv->counter = kmalloc(sizeof(*priv->counter), GFP_KERNEL);
69+
priv->counter = kmalloc(sizeof(*priv->counter), GFP_KERNEL_ACCOUNT);
7070
if (!priv->counter)
7171
return -ENOMEM;
7272

net/netfilter/nft_set_pipapo.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ static int pipapo_realloc_mt(struct nft_pipapo_field *f,
663663
check_add_overflow(rules, extra, &rules_alloc))
664664
return -EOVERFLOW;
665665

666-
new_mt = kvmalloc_array(rules_alloc, sizeof(*new_mt), GFP_KERNEL);
666+
new_mt = kvmalloc_array(rules_alloc, sizeof(*new_mt), GFP_KERNEL_ACCOUNT);
667667
if (!new_mt)
668668
return -ENOMEM;
669669

@@ -936,7 +936,7 @@ static void pipapo_lt_bits_adjust(struct nft_pipapo_field *f)
936936
return;
937937
}
938938

939-
new_lt = kvzalloc(lt_size + NFT_PIPAPO_ALIGN_HEADROOM, GFP_KERNEL);
939+
new_lt = kvzalloc(lt_size + NFT_PIPAPO_ALIGN_HEADROOM, GFP_KERNEL_ACCOUNT);
940940
if (!new_lt)
941941
return;
942942

@@ -1212,7 +1212,7 @@ static int pipapo_realloc_scratch(struct nft_pipapo_match *clone,
12121212
scratch = kzalloc_node(struct_size(scratch, map,
12131213
bsize_max * 2) +
12141214
NFT_PIPAPO_ALIGN_HEADROOM,
1215-
GFP_KERNEL, cpu_to_node(i));
1215+
GFP_KERNEL_ACCOUNT, cpu_to_node(i));
12161216
if (!scratch) {
12171217
/* On failure, there's no need to undo previous
12181218
* allocations: this means that some scratch maps have
@@ -1427,7 +1427,7 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old)
14271427
struct nft_pipapo_match *new;
14281428
int i;
14291429

1430-
new = kmalloc(struct_size(new, f, old->field_count), GFP_KERNEL);
1430+
new = kmalloc(struct_size(new, f, old->field_count), GFP_KERNEL_ACCOUNT);
14311431
if (!new)
14321432
return NULL;
14331433

@@ -1457,7 +1457,7 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old)
14571457
new_lt = kvzalloc(src->groups * NFT_PIPAPO_BUCKETS(src->bb) *
14581458
src->bsize * sizeof(*dst->lt) +
14591459
NFT_PIPAPO_ALIGN_HEADROOM,
1460-
GFP_KERNEL);
1460+
GFP_KERNEL_ACCOUNT);
14611461
if (!new_lt)
14621462
goto out_lt;
14631463

@@ -1470,7 +1470,8 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old)
14701470

14711471
if (src->rules > 0) {
14721472
dst->mt = kvmalloc_array(src->rules_alloc,
1473-
sizeof(*src->mt), GFP_KERNEL);
1473+
sizeof(*src->mt),
1474+
GFP_KERNEL_ACCOUNT);
14741475
if (!dst->mt)
14751476
goto out_mt;
14761477

net/netfilter/nft_tunnel.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,13 +509,14 @@ static int nft_tunnel_obj_init(const struct nft_ctx *ctx,
509509
return err;
510510
}
511511

512-
md = metadata_dst_alloc(priv->opts.len, METADATA_IP_TUNNEL, GFP_KERNEL);
512+
md = metadata_dst_alloc(priv->opts.len, METADATA_IP_TUNNEL,
513+
GFP_KERNEL_ACCOUNT);
513514
if (!md)
514515
return -ENOMEM;
515516

516517
memcpy(&md->u.tun_info, &info, sizeof(info));
517518
#ifdef CONFIG_DST_CACHE
518-
err = dst_cache_init(&md->u.tun_info.dst_cache, GFP_KERNEL);
519+
err = dst_cache_init(&md->u.tun_info.dst_cache, GFP_KERNEL_ACCOUNT);
519520
if (err < 0) {
520521
metadata_dst_free(md);
521522
return err;

0 commit comments

Comments
 (0)