History

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.

Liping Zhang committed 10 years ago

Commit 2bf4fad1 parent 96d13271 file · +24 −8Browse files

Unified · Split

net/netfilter/nft_compat.c+24−8
@@ -634,6 +634,7 @@ nft_match_select_ops(const struct nft_ctx *ctx, · 633 unmodified lines
634634 struct xt_match *match;
635635 char *mt_name;
636636 u32 rev, family;
637+ int err;
637638
638639 if (tb[NFTA_MATCH_NAME] == NULL ||
639640 tb[NFTA_MATCH_REV] == NULL ||
@@ -660,13 +661,17 @@ nft_match_select_ops(const struct nft_ctx *ctx, · 20 unmodified lines
660661 if (IS_ERR(match))
661662 return ERR_PTR(-ENOENT);
662663
663− if (match->matchsize > nla_len(tb[NFTA_MATCH_INFO]))
664− return ERR_PTR(-EINVAL);
664+ if (match->matchsize > nla_len(tb[NFTA_MATCH_INFO])) {
665+ err = -EINVAL;
666+ goto err;
667+ }
665668
666669 /* This is the first time we use this match, allocate operations */
667670 nft_match = kzalloc(sizeof(struct nft_xt), GFP_KERNEL);
668− if (nft_match == NULL)
669− return ERR_PTR(-ENOMEM);
671+ if (nft_match == NULL) {
672+ err = -ENOMEM;
673+ goto err;
674+ }
670675
671676 nft_match->ops.type = &nft_match_type;
672677 nft_match->ops.size = NFT_EXPR_SIZE(XT_ALIGN(match->matchsize));
@@ -680,6 +685,9 @@ nft_match_select_ops(const struct nft_ctx *ctx, · 7 unmodified lines
680685 list_add(&nft_match->head, &nft_match_list);
681686
682687 return &nft_match->ops;
688+err:
689+ module_put(match->me);
690+ return ERR_PTR(err);
683691 }
684692
685693 static void nft_match_release(void)
@@ -717,6 +725,7 @@ nft_target_select_ops(const struct nft_ctx *ctx, · 31 unmodified lines
717725 struct xt_target *target;
718726 char *tg_name;
719727 u32 rev, family;
728+ int err;
720729
721730 if (tb[NFTA_TARGET_NAME] == NULL ||
722731 tb[NFTA_TARGET_REV] == NULL ||
@@ -743,13 +752,17 @@ nft_target_select_ops(const struct nft_ctx *ctx, · 20 unmodified lines
743752 if (IS_ERR(target))
744753 return ERR_PTR(-ENOENT);
745754
746− if (target->targetsize > nla_len(tb[NFTA_TARGET_INFO]))
747− return ERR_PTR(-EINVAL);
755+ if (target->targetsize > nla_len(tb[NFTA_TARGET_INFO])) {
756+ err = -EINVAL;
757+ goto err;
758+ }
748759
749760 /* This is the first time we use this target, allocate operations */
750761 nft_target = kzalloc(sizeof(struct nft_xt), GFP_KERNEL);
751− if (nft_target == NULL)
752− return ERR_PTR(-ENOMEM);
762+ if (nft_target == NULL) {
763+ err = -ENOMEM;
764+ goto err;
765+ }
753766
754767 nft_target->ops.type = &nft_target_type;
755768 nft_target->ops.size = NFT_EXPR_SIZE(XT_ALIGN(target->targetsize));
@@ -767,6 +780,9 @@ nft_target_select_ops(const struct nft_ctx *ctx, · 11 unmodified lines
767780 list_add(&nft_target->head, &nft_target_list);
768781
769782 return &nft_target->ops;
783+err:
784+ module_put(target->me);
785+ return ERR_PTR(err);
770786 }
771787
772788 static void nft_target_release(void)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t