* [PATCH net] net: qualcomm: rmnet: Fix a double free
@ 2017-09-08 10:23 Dan Carpenter
2017-09-08 19:44 ` Subash Abhinov Kasiviswanathan
0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2017-09-08 10:23 UTC (permalink / raw)
To: Subash Abhinov Kasiviswanathan; +Cc: David S. Miller, netdev, kernel-janitors
This is called from rmnet_map_ingress_handler(). When the
rmnet_map_deaggregate() returns NULL then the caller calls
consume_skb(skb) which frees the skb. The kfree_skb() on this error
path leads to a double free.
Fixes: ceed73a2cf4a ("drivers: net: ethernet: qualcomm: rmnet: Initial implementation")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
This is from static analysis and not tested.
diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
index 557c9bf1a469..0335fce54201 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
@@ -95,10 +95,8 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb)
skb_pull(skb, packet_len);
/* Some hardware can send us empty frames. Catch them */
- if (ntohs(maph->pkt_len) == 0) {
- kfree_skb(skb);
+ if (ntohs(maph->pkt_len) == 0)
return NULL;
- }
return skbn;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: qualcomm: rmnet: Fix a double free
2017-09-08 10:23 [PATCH net] net: qualcomm: rmnet: Fix a double free Dan Carpenter
@ 2017-09-08 19:44 ` Subash Abhinov Kasiviswanathan
2017-09-09 8:58 ` [PATCH v2 " Dan Carpenter
0 siblings, 1 reply; 5+ messages in thread
From: Subash Abhinov Kasiviswanathan @ 2017-09-08 19:44 UTC (permalink / raw)
To: Dan Carpenter; +Cc: David S. Miller, netdev, kernel-janitors
> diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
> b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
> index 557c9bf1a469..0335fce54201 100644
> --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
> +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
> @@ -95,10 +95,8 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff
> *skb)
> skb_pull(skb, packet_len);
>
> /* Some hardware can send us empty frames. Catch them */
> - if (ntohs(maph->pkt_len) == 0) {
> - kfree_skb(skb);
> + if (ntohs(maph->pkt_len) == 0)
> return NULL;
> - }
>
> return skbn;
> }
Thanks for the patch. This is fixing the double free, but is leaking the
new skb skbn
created. Perhaps we should add the check earlier -
diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
index 557c9bf..86b8c75 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
@@ -84,6 +84,10 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff
*skb)
if (((int)skb->len - (int)packet_len) < 0)
return NULL;
+ /* Some hardware can send us empty frames. Catch them */
+ if (ntohs(maph->pkt_len) == 0)
+ return NULL;
+
skbn = alloc_skb(packet_len + RMNET_MAP_DEAGGR_SPACING,
GFP_ATOMIC);
if (!skbn)
return NULL;
@@ -94,11 +98,5 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff
*skb)
memcpy(skbn->data, skb->data, packet_len);
skb_pull(skb, packet_len);
- /* Some hardware can send us empty frames. Catch them */
- if (ntohs(maph->pkt_len) == 0) {
- kfree_skb(skb);
- return NULL;
- }
-
return skbn;
}
--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a
Linux Foundation Collaborative Project
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 net] net: qualcomm: rmnet: Fix a double free
2017-09-08 19:44 ` Subash Abhinov Kasiviswanathan
@ 2017-09-09 8:58 ` Dan Carpenter
2017-09-09 18:59 ` Subash Abhinov Kasiviswanathan
2017-09-09 21:34 ` David Miller
0 siblings, 2 replies; 5+ messages in thread
From: Dan Carpenter @ 2017-09-09 8:58 UTC (permalink / raw)
To: David S. Miller, Subash Abhinov Kasiviswanathan; +Cc: netdev, kernel-janitors
There is a typo here so we accidentally free "skb" instead of "skbn".
It leads to a double free and a leak. After discussing with Subash,
it's better to just move the check before the allocation and avoid the
need to free.
Fixes: ceed73a2cf4a ("drivers: net: ethernet: qualcomm: rmnet: Initial implementation")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: Fix the leak as well. Thanks Subash!
diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
index 557c9bf1a469..86b8c758f94e 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
@@ -84,6 +84,10 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb)
if (((int)skb->len - (int)packet_len) < 0)
return NULL;
+ /* Some hardware can send us empty frames. Catch them */
+ if (ntohs(maph->pkt_len) == 0)
+ return NULL;
+
skbn = alloc_skb(packet_len + RMNET_MAP_DEAGGR_SPACING, GFP_ATOMIC);
if (!skbn)
return NULL;
@@ -94,11 +98,5 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb)
memcpy(skbn->data, skb->data, packet_len);
skb_pull(skb, packet_len);
- /* Some hardware can send us empty frames. Catch them */
- if (ntohs(maph->pkt_len) == 0) {
- kfree_skb(skb);
- return NULL;
- }
-
return skbn;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 net] net: qualcomm: rmnet: Fix a double free
2017-09-09 8:58 ` [PATCH v2 " Dan Carpenter
@ 2017-09-09 18:59 ` Subash Abhinov Kasiviswanathan
2017-09-09 21:34 ` David Miller
1 sibling, 0 replies; 5+ messages in thread
From: Subash Abhinov Kasiviswanathan @ 2017-09-09 18:59 UTC (permalink / raw)
To: Dan Carpenter; +Cc: David S. Miller, netdev, kernel-janitors
On 2017-09-09 02:58, Dan Carpenter wrote:
> There is a typo here so we accidentally free "skb" instead of "skbn".
> It leads to a double free and a leak. After discussing with Subash,
> it's better to just move the check before the allocation and avoid the
> need to free.
>
> Fixes: ceed73a2cf4a ("drivers: net: ethernet: qualcomm: rmnet: Initial
> implementation")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: Fix the leak as well. Thanks Subash!
>
> diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
> b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
> index 557c9bf1a469..86b8c758f94e 100644
> --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
> +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
> @@ -84,6 +84,10 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff
> *skb)
> if (((int)skb->len - (int)packet_len) < 0)
> return NULL;
>
> + /* Some hardware can send us empty frames. Catch them */
> + if (ntohs(maph->pkt_len) == 0)
> + return NULL;
> +
> skbn = alloc_skb(packet_len + RMNET_MAP_DEAGGR_SPACING, GFP_ATOMIC);
> if (!skbn)
> return NULL;
> @@ -94,11 +98,5 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff
> *skb)
> memcpy(skbn->data, skb->data, packet_len);
> skb_pull(skb, packet_len);
>
> - /* Some hardware can send us empty frames. Catch them */
> - if (ntohs(maph->pkt_len) == 0) {
> - kfree_skb(skb);
> - return NULL;
> - }
> -
> return skbn;
> }
Acked-by: Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>
--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a
Linux Foundation Collaborative Project
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 net] net: qualcomm: rmnet: Fix a double free
2017-09-09 8:58 ` [PATCH v2 " Dan Carpenter
2017-09-09 18:59 ` Subash Abhinov Kasiviswanathan
@ 2017-09-09 21:34 ` David Miller
1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2017-09-09 21:34 UTC (permalink / raw)
To: dan.carpenter; +Cc: subashab, netdev, kernel-janitors
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Sat, 9 Sep 2017 11:58:03 +0300
> There is a typo here so we accidentally free "skb" instead of "skbn".
> It leads to a double free and a leak. After discussing with Subash,
> it's better to just move the check before the allocation and avoid the
> need to free.
>
> Fixes: ceed73a2cf4a ("drivers: net: ethernet: qualcomm: rmnet: Initial implementation")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: Fix the leak as well. Thanks Subash!
Applied, thanks Dan.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-09-09 21:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-08 10:23 [PATCH net] net: qualcomm: rmnet: Fix a double free Dan Carpenter
2017-09-08 19:44 ` Subash Abhinov Kasiviswanathan
2017-09-09 8:58 ` [PATCH v2 " Dan Carpenter
2017-09-09 18:59 ` Subash Abhinov Kasiviswanathan
2017-09-09 21:34 ` 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).