Skip to content

Commit 5a893b9

Browse files
Phil Sutterummakynes
authored andcommitted
netfilter: nf_tables: nft_obj_filter fits into cb->ctx
No need to allocate it if one may just use struct netlink_callback's scratch area for it. Signed-off-by: Phil Sutter <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 2eda95c commit 5a893b9

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7690,7 +7690,7 @@ struct nft_obj_dump_ctx {
76907690
static int nf_tables_dump_obj(struct sk_buff *skb, struct netlink_callback *cb)
76917691
{
76927692
const struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh);
7693-
struct nft_obj_dump_ctx *ctx = cb->data;
7693+
struct nft_obj_dump_ctx *ctx = (void *)cb->ctx;
76947694
struct net *net = sock_net(skb->sk);
76957695
int family = nfmsg->nfgen_family;
76967696
struct nftables_pernet *nft_net;
@@ -7752,34 +7752,28 @@ static int nf_tables_dump_obj(struct sk_buff *skb, struct netlink_callback *cb)
77527752

77537753
static int nf_tables_dump_obj_start(struct netlink_callback *cb)
77547754
{
7755+
struct nft_obj_dump_ctx *ctx = (void *)cb->ctx;
77557756
const struct nlattr * const *nla = cb->data;
7756-
struct nft_obj_dump_ctx *ctx = NULL;
77577757

7758-
ctx = kzalloc(sizeof(*ctx), GFP_ATOMIC);
7759-
if (!ctx)
7760-
return -ENOMEM;
7758+
BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx));
77617759

77627760
if (nla[NFTA_OBJ_TABLE]) {
77637761
ctx->table = nla_strdup(nla[NFTA_OBJ_TABLE], GFP_ATOMIC);
7764-
if (!ctx->table) {
7765-
kfree(ctx);
7762+
if (!ctx->table)
77667763
return -ENOMEM;
7767-
}
77687764
}
77697765

77707766
if (nla[NFTA_OBJ_TYPE])
77717767
ctx->type = ntohl(nla_get_be32(nla[NFTA_OBJ_TYPE]));
77727768

7773-
cb->data = ctx;
77747769
return 0;
77757770
}
77767771

77777772
static int nf_tables_dump_obj_done(struct netlink_callback *cb)
77787773
{
7779-
struct nft_obj_dump_ctx *ctx = cb->data;
7774+
struct nft_obj_dump_ctx *ctx = (void *)cb->ctx;
77807775

77817776
kfree(ctx->table);
7782-
kfree(ctx);
77837777

77847778
return 0;
77857779
}

0 commit comments

Comments
 (0)