[PATCH] usb: ljca: fix NULL pointer dereference on events for callback-less clients

From: YuanZhe Liu

Date: Fri Nov 20 2026 - 10:07:37 EST


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@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
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