The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] usb: ljca: fix NULL pointer dereference on events for callback-less clients
@ 2026-11-20 15:01 YuanZhe Liu
  2026-11-20 16:06 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: YuanZhe Liu @ 2026-11-20 15:01 UTC (permalink / raw)
  To: Lixu Zhang, Sakari Ailus, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, stable, Bin Yu, Cheng Wen

ljca_handle_event() dispatches an incoming event message to the first
client whose type matches the message type and calls that client's event
callback without checking that a callback is registered.  Only the GPIO
client calls ljca_register_event_cb(); the I2C and SPI clients never do,
so their event_cb stays NULL for as long as the adapter is bound, while
they are present in adap->client_list.

A device that sends a message without LJCA_ACK_FLAG and with the type of
such a client therefore makes the driver call a NULL function pointer
from the URB completion handler:

  BUG: kernel NULL pointer dereference, address: 0000000000000000
  #PF: supervisor instruction fetch in kernel mode
  RIP: 0010:0x0
  Call Trace:
   ljca_handle_event drivers/usb/misc/usb-ljca.c:217 [inline]
   ljca_recv+0x651/0x850 drivers/usb/misc/usb-ljca.c:295
   __usb_hcd_giveback_urb+0x238/0x550 drivers/usb/core/hcd.c:1657

Check event_cb under client->event_cb_lock and skip the call when no
callback is registered.  The same lock is taken by
ljca_register_event_cb() and ljca_unregister_event_cb(), so the check
cannot be invalidated before the call.

Fixes: acd6199f195d ("usb: Add support for Intel LJCA device")
Cc: stable@vger.kernel.org
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
 drivers/usb/misc/usb-ljca.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/misc/usb-ljca.c b/drivers/usb/misc/usb-ljca.c
index fcb627b49eac..36e01783252b 100644
--- a/drivers/usb/misc/usb-ljca.c
+++ b/drivers/usb/misc/usb-ljca.c
@@ -214,8 +214,9 @@ static void ljca_handle_event(struct ljca_adapter *adap,
 			unsigned long flags;
 
 			spin_lock_irqsave(&client->event_cb_lock, flags);
-			client->event_cb(client->context, header->cmd,
-					 header->data, header->len);
+			if (client->event_cb)
+				client->event_cb(client->context, header->cmd,
+						 header->data, header->len);
 			spin_unlock_irqrestore(&client->event_cb_lock, flags);
 
 			break;
-- 
2.34.1


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

end of thread, other threads:[~2026-11-20 16:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 15:01 [PATCH] usb: ljca: fix NULL pointer dereference on events for callback-less clients YuanZhe Liu
2026-11-20 16:06 ` Greg Kroah-Hartman
2026-11-20 16:35   ` YuanZhe Liu

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