Commit 2bf4fade authored by Liping Zhang's avatar Liping Zhang Committed by Pablo Neira Ayuso

netfilter: nft_compat: put back match/target module if init fail

If the user specify the invalid NFTA_MATCH_INFO/NFTA_TARGET_INFO attr
or memory alloc fail, we should call module_put to the related match
or target. Otherwise, we cannot remove the module even nobody use it.
Signed-off-by: default avatarLiping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 96d1327a
...@@ -634,6 +634,7 @@ nft_match_select_ops(const struct nft_ctx *ctx, ...@@ -634,6 +634,7 @@ nft_match_select_ops(const struct nft_ctx *ctx,
struct xt_match *match; struct xt_match *match;
char *mt_name; char *mt_name;
u32 rev, family; u32 rev, family;
int err;
if (tb[NFTA_MATCH_NAME] == NULL || if (tb[NFTA_MATCH_NAME] == NULL ||
tb[NFTA_MATCH_REV] == NULL || tb[NFTA_MATCH_REV] == NULL ||
...@@ -660,13 +661,17 @@ nft_match_select_ops(const struct nft_ctx *ctx, ...@@ -660,13 +661,17 @@ nft_match_select_ops(const struct nft_ctx *ctx,
if (IS_ERR(match)) if (IS_ERR(match))
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
if (match->matchsize > nla_len(tb[NFTA_MATCH_INFO])) if (match->matchsize > nla_len(tb[NFTA_MATCH_INFO])) {
return ERR_PTR(-EINVAL); err = -EINVAL;
goto err;
}
/* This is the first time we use this match, allocate operations */ /* This is the first time we use this match, allocate operations */
nft_match = kzalloc(sizeof(struct nft_xt), GFP_KERNEL); nft_match = kzalloc(sizeof(struct nft_xt), GFP_KERNEL);
if (nft_match == NULL) if (nft_match == NULL) {
return ERR_PTR(-ENOMEM); err = -ENOMEM;
goto err;
}
nft_match->ops.type = &nft_match_type; nft_match->ops.type = &nft_match_type;
nft_match->ops.size = NFT_EXPR_SIZE(XT_ALIGN(match->matchsize)); nft_match->ops.size = NFT_EXPR_SIZE(XT_ALIGN(match->matchsize));
...@@ -680,6 +685,9 @@ nft_match_select_ops(const struct nft_ctx *ctx, ...@@ -680,6 +685,9 @@ nft_match_select_ops(const struct nft_ctx *ctx,
list_add(&nft_match->head, &nft_match_list); list_add(&nft_match->head, &nft_match_list);
return &nft_match->ops; return &nft_match->ops;
err:
module_put(match->me);
return ERR_PTR(err);
} }
static void nft_match_release(void) static void nft_match_release(void)
...@@ -717,6 +725,7 @@ nft_target_select_ops(const struct nft_ctx *ctx, ...@@ -717,6 +725,7 @@ nft_target_select_ops(const struct nft_ctx *ctx,
struct xt_target *target; struct xt_target *target;
char *tg_name; char *tg_name;
u32 rev, family; u32 rev, family;
int err;
if (tb[NFTA_TARGET_NAME] == NULL || if (tb[NFTA_TARGET_NAME] == NULL ||
tb[NFTA_TARGET_REV] == NULL || tb[NFTA_TARGET_REV] == NULL ||
...@@ -743,13 +752,17 @@ nft_target_select_ops(const struct nft_ctx *ctx, ...@@ -743,13 +752,17 @@ nft_target_select_ops(const struct nft_ctx *ctx,
if (IS_ERR(target)) if (IS_ERR(target))
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
if (target->targetsize > nla_len(tb[NFTA_TARGET_INFO])) if (target->targetsize > nla_len(tb[NFTA_TARGET_INFO])) {
return ERR_PTR(-EINVAL); err = -EINVAL;
goto err;
}
/* This is the first time we use this target, allocate operations */ /* This is the first time we use this target, allocate operations */
nft_target = kzalloc(sizeof(struct nft_xt), GFP_KERNEL); nft_target = kzalloc(sizeof(struct nft_xt), GFP_KERNEL);
if (nft_target == NULL) if (nft_target == NULL) {
return ERR_PTR(-ENOMEM); err = -ENOMEM;
goto err;
}
nft_target->ops.type = &nft_target_type; nft_target->ops.type = &nft_target_type;
nft_target->ops.size = NFT_EXPR_SIZE(XT_ALIGN(target->targetsize)); nft_target->ops.size = NFT_EXPR_SIZE(XT_ALIGN(target->targetsize));
...@@ -767,6 +780,9 @@ nft_target_select_ops(const struct nft_ctx *ctx, ...@@ -767,6 +780,9 @@ nft_target_select_ops(const struct nft_ctx *ctx,
list_add(&nft_target->head, &nft_target_list); list_add(&nft_target->head, &nft_target_list);
return &nft_target->ops; return &nft_target->ops;
err:
module_put(target->me);
return ERR_PTR(err);
} }
static void nft_target_release(void) static void nft_target_release(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment