* [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* Re: [PATCH] usb: ljca: fix NULL pointer dereference on events for callback-less clients
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
0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-20 16:06 UTC (permalink / raw)
To: YuanZhe Liu
Cc: Lixu Zhang, Sakari Ailus, linux-usb, linux-kernel, stable, Bin Yu,
Cheng Wen
On Fri, Nov 20, 2026 at 11:01:43PM +0800, YuanZhe Liu wrote:
> 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:
What device does that? How?
>
> 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.
How was this tested, shouldn't the driver be fixed up not to do that
instead of this workaround?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: ljca: fix NULL pointer dereference on events for callback-less clients
2026-11-20 16:06 ` Greg Kroah-Hartman
@ 2026-11-20 16:35 ` YuanZhe Liu
0 siblings, 0 replies; 3+ messages in thread
From: YuanZhe Liu @ 2026-11-20 16:35 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Lixu Zhang, Sakari Ailus, linux-usb, linux-kernel, stable, Bin Yu,
Cheng Wen
On Fri, Nov 20, 2026 at 05:06:20PM +0100, Greg Kroah-Hartman wrote:
> > 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:
>
> What device does that? How?
The link carries one message per bulk-IN transfer, laid out as {type, cmd,
flags, len, data}. ljca_recv() decides whether a message is an
acknowledgement or an event from bit 0 of flags alone, and ljca_handle_event()
then dispatches events by type only. The I2C (type 4) and SPI (type 5)
clients are created during enumeration and never call ljca_register_event_cb(),
so their event_cb stays NULL for as long as the adapter is bound.
A device answering an ordinary I2C command (cmd 3..6, START/STOP/READ/WRITE)
answers with flags = LJCA_CMPL_FLAG | LJCA_ACK_FLAG = 0x05. Clearing bit 0 of
that byte, one bit, turns the very same reply into an event: {type = 0x04,
cmd = 0x03, flags = 0x00, len = 0x03}. That matches the report exactly: cmd
3/4/5/6, len 3 for the short replies and 3+N for READ. So any device that
emits such a message, be it buggy firmware or a device that does not implement
the protocol exactly, oopses the kernel from the URB completion handler.
> How was this tested, shouldn't the driver be fixed up not to do that
> instead of this workaround?
The callback is optional by design: ljca_register_event_cb() is how a client
opts in, and the comment in ljca_handle_event() notes that only GPIO registers
one. What is missing is that the dispatcher does not honour that contract, it
matches on type alone and calls whatever is there. The patch makes the
dispatch deliver events only to clients that registered for them, which is the
driver being fixed up to do what its own API promises.
The alternatives look worse: a no-op callback in the I2C and SPI clients (fake
handlers), keeping those clients out of the list (they are needed for
transfers), or validating event types in ljca_recv() (the type space belongs to
the firmware, the driver has no table of valid event types).
Testing: compiled with CONFIG_USB_LJCA=y, CONFIG_GPIO_LJCA=y and
CONFIG_I2C_LJCA=y; the oops above is from 7.3.1 with a device sending that
message.
thanks,
^ permalink raw reply [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