* [PATCH net-next] ethtool: fix a memory leak in ethnl_default_start()
@ 2020-01-08 5:39 Dan Carpenter
2020-01-08 9:06 ` Michal Kubecek
2020-01-09 0:03 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2020-01-08 5:39 UTC (permalink / raw)
To: David S. Miller, Michal Kubecek
Cc: Florian Fainelli, Andrew Lunn, netdev, kernel-janitors
If ethnl_default_parse() fails then we need to free a couple
memory allocations before returning.
Fixes: 728480f12442 ("ethtool: default handlers for GET requests")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
net/ethtool/netlink.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c
index 4ca96c7b86b3..5d16436498ac 100644
--- a/net/ethtool/netlink.c
+++ b/net/ethtool/netlink.c
@@ -472,8 +472,8 @@ static int ethnl_default_start(struct netlink_callback *cb)
return -ENOMEM;
reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
if (!reply_data) {
- kfree(req_info);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto free_req_info;
}
ret = ethnl_default_parse(req_info, cb->nlh, sock_net(cb->skb->sk), ops,
@@ -487,7 +487,7 @@ static int ethnl_default_start(struct netlink_callback *cb)
req_info->dev = NULL;
}
if (ret < 0)
- return ret;
+ goto free_reply_data;
ctx->ops = ops;
ctx->req_info = req_info;
@@ -496,6 +496,13 @@ static int ethnl_default_start(struct netlink_callback *cb)
ctx->pos_idx = 0;
return 0;
+
+free_reply_data:
+ kfree(reply_data);
+free_req_info:
+ kfree(req_info);
+
+ return ret;
}
/* default ->done() handler for GET requests */
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] ethtool: fix a memory leak in ethnl_default_start()
2020-01-08 5:39 [PATCH net-next] ethtool: fix a memory leak in ethnl_default_start() Dan Carpenter
@ 2020-01-08 9:06 ` Michal Kubecek
2020-01-09 0:03 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Michal Kubecek @ 2020-01-08 9:06 UTC (permalink / raw)
To: netdev
Cc: Dan Carpenter, David S. Miller, Florian Fainelli, Andrew Lunn,
kernel-janitors
On Wed, Jan 08, 2020 at 08:39:48AM +0300, Dan Carpenter wrote:
> If ethnl_default_parse() fails then we need to free a couple
> memory allocations before returning.
>
> Fixes: 728480f12442 ("ethtool: default handlers for GET requests")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> net/ethtool/netlink.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c
> index 4ca96c7b86b3..5d16436498ac 100644
> --- a/net/ethtool/netlink.c
> +++ b/net/ethtool/netlink.c
> @@ -472,8 +472,8 @@ static int ethnl_default_start(struct netlink_callback *cb)
> return -ENOMEM;
> reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
> if (!reply_data) {
> - kfree(req_info);
> - return -ENOMEM;
> + ret = -ENOMEM;
> + goto free_req_info;
> }
We could avoid the block statement by setting ret unconditionally but
this is OK.
>
> ret = ethnl_default_parse(req_info, cb->nlh, sock_net(cb->skb->sk), ops,
> @@ -487,7 +487,7 @@ static int ethnl_default_start(struct netlink_callback *cb)
> req_info->dev = NULL;
> }
> if (ret < 0)
> - return ret;
> + goto free_reply_data;
>
> ctx->ops = ops;
> ctx->req_info = req_info;
> @@ -496,6 +496,13 @@ static int ethnl_default_start(struct netlink_callback *cb)
> ctx->pos_idx = 0;
>
> return 0;
> +
> +free_reply_data:
> + kfree(reply_data);
> +free_req_info:
> + kfree(req_info);
> +
> + return ret;
> }
>
> /* default ->done() handler for GET requests */
Reviewed-by: Michal Kubecek <mkubecek@suse.cz>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] ethtool: fix a memory leak in ethnl_default_start()
2020-01-08 5:39 [PATCH net-next] ethtool: fix a memory leak in ethnl_default_start() Dan Carpenter
2020-01-08 9:06 ` Michal Kubecek
@ 2020-01-09 0:03 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2020-01-09 0:03 UTC (permalink / raw)
To: dan.carpenter; +Cc: mkubecek, f.fainelli, andrew, netdev, kernel-janitors
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Wed, 8 Jan 2020 08:39:48 +0300
> If ethnl_default_parse() fails then we need to free a couple
> memory allocations before returning.
>
> Fixes: 728480f12442 ("ethtool: default handlers for GET requests")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-01-09 0:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-08 5:39 [PATCH net-next] ethtool: fix a memory leak in ethnl_default_start() Dan Carpenter
2020-01-08 9:06 ` Michal Kubecek
2020-01-09 0:03 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).