Linux CAN drivers development
 help / color / mirror / Atom feed
* [PATCH net] can: peak_usb: fix slab-out-of-bounds read in pcan_usb_handle_bus_evt()
@ 2026-09-06 22:21 Xiang Mei
  2026-09-06 22:36 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Xiang Mei @ 2026-09-06 22:21 UTC (permalink / raw)
  To: mkl, mailhol, linux-can; +Cc: s.grosjean, co+5e2bcf11e7027510, Xiang Mei

pcan_usb_handle_bus_evt() reads mc->ptr[1] and mc->ptr[2] without checking
them against mc->end. On entry mc->ptr may already equal mc->end, and the
rx buffer is an exact kmalloc(64), so a device sending a full 64-byte
transfer reads past the slab object.

The two bytes end up in pdev->bec, which user space can read back via
IFLA_CAN_BERR_COUNTER.

Bail out unless both bytes are within the buffer.

  BUG: KASAN: slab-out-of-bounds in pcan_usb_decode_buf (drivers/net/can/usb/peak_usb/pcan_usb.c:563)
  Read of size 1 at addr ffff8880100921c1 by task swapper/1/0
  Call Trace:
   <IRQ>
   kasan_report (mm/kasan/report.c:595)
   pcan_usb_decode_buf (drivers/net/can/usb/peak_usb/pcan_usb.c:563)
   peak_usb_read_bulk_callback (drivers/net/can/usb/peak_usb/pcan_usb_core.c:267)
   __usb_hcd_giveback_urb (drivers/usb/core/hcd.c:1657)
   dummy_timer (drivers/usb/gadget/udc/dummy_hcd.c:2019)
   __hrtimer_run_queues (kernel/time/hrtimer.c:2067)
   handle_softirqs (kernel/softirq.c:645)
   </IRQ>

  The buggy address is located 1 bytes to the right of
   allocated 64-byte region [ffff888010092180, ffff8880100921c0)

Fixes: ea8b33bde76c ("can: pcan_usb: add support of rxerr/txerr counters")
Reported-by: co+5e2bcf11e7027510@bugs.sh
Closes: https://lore.kernel.org/linux-can/upsCxxaJjg2FJWhfCx6KjFXLlh8o4IhaHKJi@bugs.sh/
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Xiang Mei <xmei5@asu.edu>
---
 drivers/net/can/usb/peak_usb/pcan_usb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
index 8fd058c32856..e87ed7657cc1 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
@@ -558,6 +558,8 @@ static int pcan_usb_handle_bus_evt(struct pcan_usb_msg_context *mc, u8 ir)
 	switch (ir) {
 	case PCAN_USB_ERR_CNT_DEC:
 	case PCAN_USB_ERR_CNT_INC:
+		if ((mc->ptr + 3) > mc->end)
+			return -EINVAL;
 
 		/* save rx/tx error counters from in the device context */
 		pdev->bec.rxerr = mc->ptr[1];
-- 
2.43.0


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

end of thread, other threads:[~2026-09-06 22:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-06 22:21 [PATCH net] can: peak_usb: fix slab-out-of-bounds read in pcan_usb_handle_bus_evt() Xiang Mei
2026-09-06 22:36 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox