Skip to content

Commit c2d9a42

Browse files
Liping Zhangummakynes
authored andcommitted
netfilter: nft_log: fix possible memory leak if log expr init fail
Suppose that we specify the NFTA_LOG_PREFIX, then NFTA_LOG_LEVEL and NFTA_LOG_GROUP are specified together or nf_logger_find_get call returns fail, i.e. expr init fail, memory leak will happen. Signed-off-by: Liping Zhang <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 82de0be commit c2d9a42

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

net/netfilter/nft_log.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ static int nft_log_init(const struct nft_ctx *ctx,
5252
struct nft_log *priv = nft_expr_priv(expr);
5353
struct nf_loginfo *li = &priv->loginfo;
5454
const struct nlattr *nla;
55+
int err;
56+
57+
li->type = NF_LOG_TYPE_LOG;
58+
if (tb[NFTA_LOG_LEVEL] != NULL &&
59+
tb[NFTA_LOG_GROUP] != NULL)
60+
return -EINVAL;
61+
if (tb[NFTA_LOG_GROUP] != NULL)
62+
li->type = NF_LOG_TYPE_ULOG;
5563

5664
nla = tb[NFTA_LOG_PREFIX];
5765
if (nla != NULL) {
@@ -63,13 +71,6 @@ static int nft_log_init(const struct nft_ctx *ctx,
6371
priv->prefix = (char *)nft_log_null_prefix;
6472
}
6573

66-
li->type = NF_LOG_TYPE_LOG;
67-
if (tb[NFTA_LOG_LEVEL] != NULL &&
68-
tb[NFTA_LOG_GROUP] != NULL)
69-
return -EINVAL;
70-
if (tb[NFTA_LOG_GROUP] != NULL)
71-
li->type = NF_LOG_TYPE_ULOG;
72-
7374
switch (li->type) {
7475
case NF_LOG_TYPE_LOG:
7576
if (tb[NFTA_LOG_LEVEL] != NULL) {
@@ -96,7 +97,16 @@ static int nft_log_init(const struct nft_ctx *ctx,
9697
break;
9798
}
9899

99-
return nf_logger_find_get(ctx->afi->family, li->type);
100+
err = nf_logger_find_get(ctx->afi->family, li->type);
101+
if (err < 0)
102+
goto err1;
103+
104+
return 0;
105+
106+
err1:
107+
if (priv->prefix != nft_log_null_prefix)
108+
kfree(priv->prefix);
109+
return err;
100110
}
101111

102112
static void nft_log_destroy(const struct nft_ctx *ctx,

0 commit comments

Comments
 (0)