Re: [PATCH] usb: ljca: fix NULL pointer dereference on events for callback-less clients
From: YuanZhe Liu
Date: Fri Nov 20 2026 - 11:35:51 EST
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,