linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] can: can327: fix potential skb leak when netdev is down
@ 2022-11-10  6:14 Ziyang Xuan
  2022-11-10 16:04 ` Max Staudt
  0 siblings, 1 reply; 4+ messages in thread
From: Ziyang Xuan @ 2022-11-10  6:14 UTC (permalink / raw)
  To: max, wg, mkl, davem, edumazet, kuba, pabeni, linux-can, netdev
  Cc: linux-kernel

In can327_feed_frame_to_netdev(), it did not free the skb when netdev
is down, and all callers of can327_feed_frame_to_netdev() did not free
allocated skb too. That would trigger skb leak.

Fix it by adding kfree_skb() in can327_feed_frame_to_netdev() when netdev
is down. Not tested, just compiled.

Fixes: 43da2f07622f ("can: can327: CAN/ldisc driver for ELM327 based OBD-II adapters")
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
 drivers/net/can/can327.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/can327.c b/drivers/net/can/can327.c
index 0aa1af31d0fe..17bca63f3dd3 100644
--- a/drivers/net/can/can327.c
+++ b/drivers/net/can/can327.c
@@ -263,8 +263,10 @@ static void can327_feed_frame_to_netdev(struct can327 *elm, struct sk_buff *skb)
 {
 	lockdep_assert_held(&elm->lock);
 
-	if (!netif_running(elm->dev))
+	if (!netif_running(elm->dev)) {
+		kfree_skb(skb);
 		return;
+	}
 
 	/* Queue for NAPI pickup.
 	 * rx-offload will update stats and LEDs for us.
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] can: can327: fix potential skb leak when netdev is down
  2022-11-10  6:14 [PATCH] can: can327: fix potential skb leak when netdev is down Ziyang Xuan
@ 2022-11-10 16:04 ` Max Staudt
  2022-11-22  2:10   ` Ziyang Xuan (William)
  0 siblings, 1 reply; 4+ messages in thread
From: Max Staudt @ 2022-11-10 16:04 UTC (permalink / raw)
  To: Ziyang Xuan
  Cc: wg, mkl, davem, edumazet, kuba, pabeni, linux-can, netdev,
	linux-kernel, Vincent Mailhol

(CC Vincent, he may be interested)


On Thu, 10 Nov 2022 14:14:37 +0800
Ziyang Xuan <william.xuanziyang@huawei.com> wrote:

> Fix it by adding kfree_skb() in can327_feed_frame_to_netdev() when netdev
> is down. Not tested, just compiled.

Looks correct to me, so:

Reviewed-by: Max Staudt <max@enpas.org>


Thank you very much for finding and fixing this!

Max

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] can: can327: fix potential skb leak when netdev is down
  2022-11-10 16:04 ` Max Staudt
@ 2022-11-22  2:10   ` Ziyang Xuan (William)
  2022-11-22 10:09     ` Max Staudt
  0 siblings, 1 reply; 4+ messages in thread
From: Ziyang Xuan (William) @ 2022-11-22  2:10 UTC (permalink / raw)
  To: Max Staudt
  Cc: wg, mkl, davem, edumazet, kuba, pabeni, linux-can, netdev,
	linux-kernel, Vincent Mailhol

Hello,

Gently ask.

Is there any other problem? And can it be applied?

Thanks.

> (CC Vincent, he may be interested)
> 
> 
> On Thu, 10 Nov 2022 14:14:37 +0800
> Ziyang Xuan <william.xuanziyang@huawei.com> wrote:
> 
>> Fix it by adding kfree_skb() in can327_feed_frame_to_netdev() when netdev
>> is down. Not tested, just compiled.
> 
> Looks correct to me, so:
> 
> Reviewed-by: Max Staudt <max@enpas.org>
> 
> 
> Thank you very much for finding and fixing this!
> 
> Max
> 
> .
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] can: can327: fix potential skb leak when netdev is down
  2022-11-22  2:10   ` Ziyang Xuan (William)
@ 2022-11-22 10:09     ` Max Staudt
  0 siblings, 0 replies; 4+ messages in thread
From: Max Staudt @ 2022-11-22 10:09 UTC (permalink / raw)
  To: wg, mkl
  Cc: Ziyang Xuan (William),
	davem, edumazet, kuba, pabeni, linux-can, netdev, linux-kernel,
	Vincent Mailhol

Marc, Wolfgang,

Could you please include William's patch to can327, provided that you
see no issue with it?


Thanks :)

Max




On Tue, 22 Nov 2022 10:10:50 +0800
"Ziyang Xuan (William)" <william.xuanziyang@huawei.com> wrote:

> Hello,
> 
> Gently ask.
> 
> Is there any other problem? And can it be applied?
> 
> Thanks.
> 
> > (CC Vincent, he may be interested)
> > 
> > 
> > On Thu, 10 Nov 2022 14:14:37 +0800
> > Ziyang Xuan <william.xuanziyang@huawei.com> wrote:
> >   
> >> Fix it by adding kfree_skb() in can327_feed_frame_to_netdev() when netdev
> >> is down. Not tested, just compiled.  
> > 
> > Looks correct to me, so:
> > 
> > Reviewed-by: Max Staudt <max@enpas.org>
> > 
> > 
> > Thank you very much for finding and fixing this!
> > 
> > Max
> > 
> > .
> >   


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-22 10:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10  6:14 [PATCH] can: can327: fix potential skb leak when netdev is down Ziyang Xuan
2022-11-10 16:04 ` Max Staudt
2022-11-22  2:10   ` Ziyang Xuan (William)
2022-11-22 10:09     ` Max Staudt

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).