[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20200611070805.2982-1-zhengbin13@huawei.com>
Date: Thu, 11 Jun 2020 15:08:05 +0800
From: Zheng Bin <zhengbin13@...wei.com>
To: <pablo@...filter.org>, <kadlec@...filter.org>, <fw@...len.de>,
<davem@...emloft.net>, <kuba@...nel.org>,
<netfilter-devel@...r.kernel.org>, <coreteam@...filter.org>,
<netdev@...r.kernel.org>
CC: <zhengbin13@...wei.com>
Subject: [PATCH -next] netfilter: ctnetlink: Fix memleak in ctnetlink_alloc_filter
ctnetlink_alloc_filter
filter = kzalloc
In the following process(such as ctnetlink_parse_zone,
ctnetlink_parse_filter), if return fail, need to kfree filter.
Fixes: cb8aa9a3affb ("netfilter: ctnetlink: add kernel side filtering for dump")
Signed-off-by: Zheng Bin <zhengbin13@...wei.com>
---
net/netfilter/nf_conntrack_netlink.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index d7bd8b1f27d5..f7fdd91ece6d 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -939,7 +939,8 @@ ctnetlink_alloc_filter(const struct nlattr * const cda[], u8 family)
filter->mark.mask = 0xffffffff;
}
} else if (cda[CTA_MARK_MASK]) {
- return ERR_PTR(-EINVAL);
+ err = -EINVAL;
+ goto error;
}
#endif
if (!cda[CTA_FILTER])
@@ -947,15 +948,17 @@ ctnetlink_alloc_filter(const struct nlattr * const cda[], u8 family)
err = ctnetlink_parse_zone(cda[CTA_ZONE], &filter->zone);
if (err < 0)
- return ERR_PTR(err);
+ goto error;
err = ctnetlink_parse_filter(cda[CTA_FILTER], filter);
if (err < 0)
- return ERR_PTR(err);
+ goto error;
if (filter->orig_flags) {
- if (!cda[CTA_TUPLE_ORIG])
- return ERR_PTR(-EINVAL);
+ if (!cda[CTA_TUPLE_ORIG]) {
+ err = -EINVAL;
+ goto error;
+ }
err = ctnetlink_parse_tuple_filter(cda, &filter->orig,
CTA_TUPLE_ORIG,
@@ -963,12 +966,14 @@ ctnetlink_alloc_filter(const struct nlattr * const cda[], u8 family)
&filter->zone,
filter->orig_flags);
if (err < 0)
- return ERR_PTR(err);
+ goto error;
}
if (filter->reply_flags) {
- if (!cda[CTA_TUPLE_REPLY])
- return ERR_PTR(-EINVAL);
+ if (!cda[CTA_TUPLE_REPLY]) {
+ err = -EINVAL;
+ goto error;
+ }
err = ctnetlink_parse_tuple_filter(cda, &filter->reply,
CTA_TUPLE_REPLY,
@@ -976,10 +981,14 @@ ctnetlink_alloc_filter(const struct nlattr * const cda[], u8 family)
&filter->zone,
filter->orig_flags);
if (err < 0)
- return ERR_PTR(err);
+ goto error;
}
return filter;
+
+error:
+ kfree(filter);
+ return ERR_PTR(err);
}
static bool ctnetlink_needs_filter(u8 family, const struct nlattr * const *cda)
--
2.26.0.106.g9fadedd
Powered by blists - more mailing lists