* [PATCH bluetooth-next] ieee802154: 6lowpan: fix memory leak
@ 2015-10-22 10:11 Alexander Aring
2015-10-22 10:14 ` Alexander Aring
2015-10-22 10:25 ` Marcel Holtmann
0 siblings, 2 replies; 3+ messages in thread
From: Alexander Aring @ 2015-10-22 10:11 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, jukka.rissanen, Alexander Aring
Looking at current situation of memory management in 6lowpan receive
function I detected some invalid handling. After calling
lowpan_invoke_rx_handlers we will do a kfree_skb and then NET_RX_DROP on
error handling. We don't do this before, also on
skb_share_check/skb_unshare which might manipulate the reference
counters.
After running some 'grep -r "dev_add_pack" net/' to look how others
packet-layer receive callbacks works I detected that every subsystem do
a kfree_skb, then NET_RX_DROP without calling skb functions which
might manipulate the skb reference counters. This is the reason why we
should do the same here like all others subsystems. I didn't find any
documentation how the packet-layer receive callbacks handle NET_RX_DROP
return values either.
This patch will add a kfree_skb, then NET_RX_DROP handling for the
"trivial checks", in case of skb_share_check/skb_unshare the kfree_skb
call will be done inside these functions.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
References how other filesystem handle the callback:
[0] http://lxr.free-electrons.com/source/net/ipx/af_ipx.c#L1638
[1] http://lxr.free-electrons.com/source/net/can/af_can.c#L709
[2] http://lxr.free-electrons.com/source/net/phonet/af_phonet.c#L371
net/ieee802154/6lowpan/rx.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/net/ieee802154/6lowpan/rx.c b/net/ieee802154/6lowpan/rx.c
index 403f171..ef185dd 100644
--- a/net/ieee802154/6lowpan/rx.c
+++ b/net/ieee802154/6lowpan/rx.c
@@ -284,16 +284,16 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
if (wdev->type != ARPHRD_IEEE802154 ||
skb->pkt_type == PACKET_OTHERHOST ||
!lowpan_rx_h_check(skb))
- return NET_RX_DROP;
+ goto drop;
ldev = wdev->ieee802154_ptr->lowpan_dev;
if (!ldev || !netif_running(ldev))
- return NET_RX_DROP;
+ goto drop;
/* Replacing skb->dev and followed rx handlers will manipulate skb. */
skb = skb_share_check(skb, GFP_ATOMIC);
if (!skb)
- return NET_RX_DROP;
+ goto out;
skb->dev = ldev;
/* When receive frag1 it's likely that we manipulate the buffer.
@@ -304,10 +304,15 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
lowpan_is_iphc(*skb_network_header(skb))) {
skb = skb_unshare(skb, GFP_ATOMIC);
if (!skb)
- return NET_RX_DROP;
+ goto out;
}
return lowpan_invoke_rx_handlers(skb);
+
+drop:
+ kfree_skb(skb);
+out:
+ return NET_RX_DROP;
}
static struct packet_type lowpan_packet_type = {
--
2.6.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bluetooth-next] ieee802154: 6lowpan: fix memory leak
2015-10-22 10:11 [PATCH bluetooth-next] ieee802154: 6lowpan: fix memory leak Alexander Aring
@ 2015-10-22 10:14 ` Alexander Aring
2015-10-22 10:25 ` Marcel Holtmann
1 sibling, 0 replies; 3+ messages in thread
From: Alexander Aring @ 2015-10-22 10:14 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, jukka.rissanen
On Thu, Oct 22, 2015 at 12:11:27PM +0200, Alexander Aring wrote:
> Looking at current situation of memory management in 6lowpan receive
> function I detected some invalid handling. After calling
> lowpan_invoke_rx_handlers we will do a kfree_skb and then NET_RX_DROP on
> error handling. We don't do this before, also on
> skb_share_check/skb_unshare which might manipulate the reference
> counters.
>
> After running some 'grep -r "dev_add_pack" net/' to look how others
> packet-layer receive callbacks works I detected that every subsystem do
> a kfree_skb, then NET_RX_DROP without calling skb functions which
> might manipulate the skb reference counters. This is the reason why we
> should do the same here like all others subsystems. I didn't find any
> documentation how the packet-layer receive callbacks handle NET_RX_DROP
> return values either.
>
> This patch will add a kfree_skb, then NET_RX_DROP handling for the
> "trivial checks", in case of skb_share_check/skb_unshare the kfree_skb
> call will be done inside these functions.
>
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> ---
> References how other filesystem handle the callback:
s/filesystem/subsystems/
- Alex
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bluetooth-next] ieee802154: 6lowpan: fix memory leak
2015-10-22 10:11 [PATCH bluetooth-next] ieee802154: 6lowpan: fix memory leak Alexander Aring
2015-10-22 10:14 ` Alexander Aring
@ 2015-10-22 10:25 ` Marcel Holtmann
1 sibling, 0 replies; 3+ messages in thread
From: Marcel Holtmann @ 2015-10-22 10:25 UTC (permalink / raw)
To: Alexander Aring; +Cc: linux-wpan, kernel, jukka.rissanen
Hi Alex,
> Looking at current situation of memory management in 6lowpan receive
> function I detected some invalid handling. After calling
> lowpan_invoke_rx_handlers we will do a kfree_skb and then NET_RX_DROP on
> error handling. We don't do this before, also on
> skb_share_check/skb_unshare which might manipulate the reference
> counters.
>
> After running some 'grep -r "dev_add_pack" net/' to look how others
> packet-layer receive callbacks works I detected that every subsystem do
> a kfree_skb, then NET_RX_DROP without calling skb functions which
> might manipulate the skb reference counters. This is the reason why we
> should do the same here like all others subsystems. I didn't find any
> documentation how the packet-layer receive callbacks handle NET_RX_DROP
> return values either.
>
> This patch will add a kfree_skb, then NET_RX_DROP handling for the
> "trivial checks", in case of skb_share_check/skb_unshare the kfree_skb
> call will be done inside these functions.
>
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> ---
> References how other filesystem handle the callback:
>
> [0] http://lxr.free-electrons.com/source/net/ipx/af_ipx.c#L1638
> [1] http://lxr.free-electrons.com/source/net/can/af_can.c#L709
> [2] http://lxr.free-electrons.com/source/net/phonet/af_phonet.c#L371
>
> net/ieee802154/6lowpan/rx.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-10-22 10:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-22 10:11 [PATCH bluetooth-next] ieee802154: 6lowpan: fix memory leak Alexander Aring
2015-10-22 10:14 ` Alexander Aring
2015-10-22 10:25 ` Marcel Holtmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.