can: mcba_usb: fix memory leak in mcba_usb
Subsystems (4)
Hi Pavel,
Apologize for the late reply.
Since 6bd3d80d1f019cef, my Microchip CAN Analyzer stopped working, more precisely I can't capture any data with it and repeated messages from the driver flod the syslog. I usually use the Debian kernel image and linux 5.10.46-2 migrated to unstable on July 20th. I noticed my device stopped working a few days later but didn't have time to bisect.
Does your device work with the patch?
Does the patch work on the main line?
I've posted some report with my hardware configuration at debian mailing list:
https://bugs.debian.org/990850
Please let me know if you need any more information.
Best,
--
yashi
Quoted 2 lines · On Sun, 25 Jul 2021 16:42:49 +0900 Yasushi SHOJI <[email protected]>…
Hi Pavel,
Hi, Yasushi!
Quoted 9 lines
Apologize for the late reply.
Since
6bd3d80d1f019cef, my Microchip CAN Analyzer stopped working, more precisely I can't capture any data with it and repeated messages from the driver flod the syslog. I usually use the Debian kernel image and linux 5.10.46-2 migrated to unstable on July 20th. I noticed my device stopped working a few days later but didn't have time to bisect.
Quoted 3 lines
Does your device work with the patch?
Does the patch work on the main line?
I don't have this device, I just fixed this syzbot bug report:
https://syzkaller.appspot.com/bug?id=c94c1c23e829d5ac97995d51219f0c5a0cd1fa54.
I think, I found the root case. In this patch I saved dma_buff to local variable and then to array, but forgot to assign it to urb->transfer_buf. This log
[ 33.862175] DMAR: [DMA Write] Request device [00:14.0] PASID ffffffff fault addr 0 [fault reason 05] PTE Write access is not set
points exactly to this problem.
Can You try the following patch?
drivers/net/can/usb/mcba_usb.c +2 -0
@@ -653,6 +653,8 @@ static int mcba_usb_start(struct mcba_priv *priv)break ; } + urb->transfer_dma = buf_dma; + usb_fill_bulk_urb(urb, priv->udev, usb_rcvbulkpipe(priv->udev, MCBA_USB_EP_IN), buf, MCBA_USB_RX_BUFF_SIZE,
I've added Marc to this discussion, I believe, he can help us, since he is CAN maintainer.
I am sorry for breaking your device :(
Quoted 8 lines
I've posted some report with my hardware configuration at debian mailing list: https://bugs.debian.org/990850
Please let me know if you need any more information.
Best,
--
yashi
With regards,
Pavel Skripkin
Marc Kleine-Budde
maintainerQuoted 1 line · Pavel Skripkin
Can You try the following patch?
Can you create a proper patch with you S-o-b?
Quoted 16 lines
drivers/net/can/usb/mcba_usb.c +2
-0@@ -653,6 +653,8 @@ static int mcba_usb_start(struct mcba_priv *priv)break ; } + urb->transfer_dma = buf_dma; + usb_fill_bulk_urb(urb, priv->udev, usb_rcvbulkpipe(priv->udev, MCBA_USB_EP_IN), buf, MCBA_USB_RX_BUFF_SIZE,
Quoted 2 lines
I've added Marc to this discussion, I believe, he can help us, since he is CAN maintainer.
Yasushi, please test and post your Tested-by here. After Pavel posts a proper patch and you tested it, I'll forward it to net/master, then it will be applied to the stable kernels. Debian can even pick up the patch earlier.
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 5 lines · On Sun, 25 Jul 2021 11:42:46 +0200 Marc Kleine-Budde <[email protected]> wrote:
Quoted 1 line · Pavel Skripkin
Can You try the following patch?
Can you create a proper patch with you S-o-b?
Hi, Marc.
Sure! I thought about a bit diffrent fix path like:
diff -> Yasushi's test -> patch with Tested-by tag. I guess, your approach is more standard, so, I will send pacth as reply to your email.
Thanks!
Quoted 24 lines
Quoted 16 lines
(quoted diff) +0
-0
b/drivers/net/can/usb/mcba_usb.cindexa45865bd7254..a1a154c08b7f100644 ---a/drivers/net/can/usb/mcba_usb.c
+++b/drivers/net/can/usb/mcba_usb.cdrivers/net/can/usb/mcba_usb.c +2
-0@@ -653,6 +653,8 @@ static int mcba_usb_start(struct mcba_priv *priv) break; } + urb->transfer_dma = buf_dma; + usb_fill_bulk_urb(urb, priv->udev, usb_rcvbulkpipe(priv->udev, MCBA_USB_EP_IN), buf, MCBA_USB_RX_BUFF_SIZE,Quoted 2 lines
I've added Marc to this discussion, I believe, he can help us, since he is CAN maintainer.
Yasushi, please test and post your Tested-by here. After Pavel posts a proper patch and you tested it, I'll forward it to net/master, then it will be applied to the stable kernels. Debian can even pick up the patch earlier.
Quoted 3 lines
regards,
Marc
With regards,
Pavel Skripkin
PATCH 1/1 net: can: add missing urb->transfer_dma initialization
In reply to Marc Kleine-BuddeYasushi reported, that his Microchip CAN Analyzer stopped working since commit 91c02557174b ("can: mcba_usb: fix memory leak in mcba_usb"). The problem was in missing urb->transfer_dma initialization.
In my previous patch to this driver I refactored mcba_usb_start() code to avoid leaking usb coherent buffers. To achive it, I passed local stack variable to usb_alloc_coherent() and then saved it to private array to correctly free all coherent buffers on ->close() call. But I forgot to inialize urb->transfer_dma with variable passed to usb_alloc_coherent().
All of this was causing device to not work, since dma addr 0 is not valid and following log can be found on bug report page, which points exactly to problem described above.
[ 33.862175] DMAR: [DMA Write] Request device [00:14.0] PASID ffffffff fault addr 0 [fault reason 05] PTE Write access is not set
Bug report: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=990850
--- drivers/net/can/usb/mcba_usb.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/can/usb/mcba_usb.c +2 -0
@@ -653,6 +653,8 @@ static int mcba_usb_start(struct mcba_priv *priv)break ; } + urb->transfer_dma = buf_dma; + usb_fill_bulk_urb(urb, priv->udev, usb_rcvbulkpipe(priv->udev, MCBA_USB_EP_IN), buf, MCBA_USB_RX_BUFF_SIZE,
Signature · 1 line
2.32.0
Re: [PATCH] net: can: add missing urb->transfer_dma initialization
Hi Pavel,
I've tested this patch on top of v5.14-rc2. All good.
Some nitpicks.
Quoted 7 lines · Pavel Skripkin
Yasushi reported, that his Microchip CAN Analyzer stopped working since commit
91c02557174b("can:mcba_usb: fix memory leak inmcba_usb"). The problem was in missingurb->transfer_dmainitialization.In my previous patch to this driver I refactored
mcba_usb_start()code to avoid leaking usb coherent buffers. To achive it, I passed local stack
achieve
Quoted 3 lines
variable to
usb_alloc_coherent()and then saved it to private array to correctly free all coherent buffers on ->close() call. But I forgot to inializeurb->transfer_dmawith variable passed tousb_alloc_coherent().
initialize
Quoted 29 lines
All of this was causing device to not work, since dma addr 0 is not valid and following log can be found on bug report page, which points exactly to problem described above.
[ 33.862175] DMAR: [DMA Write] Request device [00:14.0] PASID ffffffff fault addr 0 [fault reason 05] PTE Write access is not setBug report: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=990850
Reported-by Yasushi SHOJI <[email protected]>Fixes 91c02557174b ("can: mcba_usb: fix memory leak in mcba_usb")Signed-off-by Pavel Skripkin <[email protected]>--- drivers/net/can/usb/mcba_usb.c | 2 ++ 1 file changed, 2 insertions(+)drivers/net/can/usb/mcba_usb.c +2
-1@@ -653,6 +653,8 @@ static int mcba_usb_start(struct mcba_priv *priv)break ; } + urb->transfer_dma = buf_dma; + usb_fill_bulk_urb(urb, priv->udev, usb_rcvbulkpipe(priv->udev, MCBA_USB_EP_IN), buf, MCBA_USB_RX_BUFF_SIZE, --
Quoted 1 line
2.32.0
Pavel, thanks again for your quick fix. :-)
Best,
--
yashi
Marc Kleine-Budde
maintainerRe: [PATCH] net: can: add missing urb->transfer_dma initialization
Quoted 17 lines · Yasushi SHOJI
Hi Pavel,
I've tested this patch on top of v5.14-rc2. All good.
Tested-by Yasushi SHOJI <[email protected]>Some nitpicks.
Quoted 7 lines · Pavel Skripkin
Yasushi reported, that his Microchip CAN Analyzer stopped working since commit
91c02557174b("can:mcba_usb: fix memory leak inmcba_usb"). The problem was in missingurb->transfer_dmainitialization.In my previous patch to this driver I refactored
mcba_usb_start()code to avoid leaking usb coherent buffers. To achive it, I passed local stack
Quoted 7 lines
achieve
Quoted 3 lines
variable to
usb_alloc_coherent()and then saved it to private array to correctly free all coherent buffers on ->close() call. But I forgot to inializeurb->transfer_dmawith variable passed tousb_alloc_coherent().initialize
Fixed while applying.
Thanks,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Yasushi SHOJI
Tested-byHi Pavel,
Quoted 7 lines · Pavel Skripkin
Can You try the following patch?
drivers/net/can/usb/mcba_usb.c +0
-0
drivers/net/can/usb/mcba_usb.c static int mcba_usb_start(struct mcba_priv *priv) · line 660
Quoted 8 lines
drivers/net/can/usb/mcba_usb.c +2
-0@@ -653,6 +653,8 @@ static int mcba_usb_start(struct mcba_priv *priv)break ; } + urb->transfer_dma = buf_dma; + usb_fill_bulk_urb(urb, priv->udev, usb_rcvbulkpipe(priv->udev, MCBA_USB_EP_IN), buf, MCBA_USB_RX_BUFF_SIZE,
Yup, this patch fixed it. I've tested on top of v5.10.52.
Quoted 1 line
I am sorry for breaking your device :(
No problem. It'd be nice if we'd test with real hardware before merging into the stable tree, though.
Anyway, thank you for your quick fix!
Best regards,
--
yashi
Marc Kleine-Budde
maintainerQuoted 21 lines · Yasushi SHOJI
Hi Pavel,
Quoted 7 lines · Pavel Skripkin
Can You try the following patch?
drivers/net/can/usb/mcba_usb.c +0
-0drivers/net/can/usb/mcba_usb.c static int mcba_usb_start(struct mcba_priv *priv) · line 660
Quoted 8 lines
drivers/net/can/usb/mcba_usb.c +2
-0@@ -653,6 +653,8 @@ static int mcba_usb_start(struct mcba_priv *priv)break ; } + urb->transfer_dma = buf_dma; + usb_fill_bulk_urb(urb, priv->udev, usb_rcvbulkpipe(priv->udev, MCBA_USB_EP_IN), buf, MCBA_USB_RX_BUFF_SIZE,Yup, this patch fixed it. I've tested on top of v5.10.52.
Quoted 6 lines
Tested-by Yasushi SHOJI <[email protected]>Quoted 1 line
I am sorry for breaking your device :(
No problem. It'd be nice if we'd test with real hardware before merging into the stable tree, though.
Yes absolutely - but I don't have access to that hardware. Since you're interested in that hardware, what about adding you as a reviewer to the kernel. Then for every change on this driver, you'll be added on Cc and can test it. What do you think?
Quoted 1 line
Anyway, thank you for your quick fix!
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hi,
Quoted 4 lines · Marc Kleine-Budde
Yes absolutely - but I don't have access to that hardware. Since you're interested in that hardware, what about adding you as a reviewer to the kernel. Then for every change on this driver, you'll be added on Cc and can test it. What do you think?
Sure, I'm happy to help.
Signature · 1 line
yashi
Marc Kleine-Budde
maintainerQuoted 7 lines · Yasushi SHOJI
Quoted 4 lines · Marc Kleine-Budde
Yes absolutely - but I don't have access to that hardware. Since you're interested in that hardware, what about adding you as a reviewer to the kernel. Then for every change on this driver, you'll be added on Cc and can test it. What do you think?
Sure, I'm happy to help.
Great! I've send an update to the MAINTAINERs file, Can you reply with your "Acked-by:"?
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Marc Kleine-Budde
maintainerQuoted 11 lines · Marc Kleine-Budde
Quoted 7 lines · Yasushi SHOJI
Quoted 4 lines · Marc Kleine-Budde
Yes absolutely - but I don't have access to that hardware. Since you're interested in that hardware, what about adding you as a reviewer to the kernel. Then for every change on this driver, you'll be added on Cc and can test it. What do you think?
Sure, I'm happy to help.
Great! I've send an update to the MAINTAINERs file, Can you reply with your "Acked-by:"?
BTW: is this the device we're talking about?
https://www.microchip.com/Developmenttools/ProductDetails/APGDT002
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Yasushi SHOJI
reviewerHi Marc,
Quoted 3 lines · Marc Kleine-Budde
BTW: is this the device we're talking about?
https://www.microchip.com/Developmenttools/ProductDetails/APGDT002
Yes, that's what I have. It's about $200 USD.
Signature · 1 line
yashi
Hi Marc,
Quoted 2 lines · Marc Kleine-Budde
Great! I've send an update to the MAINTAINERs file, Can you reply with your "Acked-by:"?
Signature · 1 line
yashi
Marc Kleine-Budde
maintainerQuoted 7 lines · Yasushi SHOJI
Hi Marc,
Quoted 2 lines · Marc Kleine-Budde
Great! I've send an update to the MAINTAINERs file, Can you reply with your "Acked-by:"?
Acked-by Yasushi SHOJI <[email protected]>
Sorry for not being clear - I mean reply to the patch I've send.
However, I've updated your email address, add your Acked-by and sent a v2.
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Yasushi SHOJI
reviewerQuoted 4 lines · Marc Kleine-Budde
Sorry for not being clear - I mean reply to the patch I've send.
However, I've updated your email address, add your Acked-by and sent a v2.
Thanks!
Signature · 1 line
yashi