Re: [PATCH] HID: lg4ff: validate report length before fixed offsets

Jiri Kosina <[email protected]>
Newsgroups org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Fri, 24 Jul 2026, Jiancheng Huang wrote:

> lg4ff_raw_event() rewrites fixed report offsets when combined pedals are
> enabled. It currently assumes that each product report contains every
> source and destination byte used by the rewrite.
> 
> Return without rewriting a short report before each product-specific
> access. Apply the same bound to the computed offset path.
> 
> Fixes: c832f86effbc ("HID: hid-logitech: Add combined pedal support Logitech wheels")
> Signed-off-by: Jiancheng Huang <[email protected]>
> Assisted-by: Codex:gpt-5.6-luna

Thanks for the patch. Next time please CC at least some relevant 
mailinglists as well.

CCing now LKML and applying.

> ---
> Evidence (v7.2-rc4 KUnit/KASAN oracle under bounded QEMU):
> Source: confirmed/hid_lg4ff_short_report_oob_raw_excerpt.log
> 
> [    2.638792] KTAP version 1
> [    2.638888] 1..1
> [    2.641100]     KTAP version 1
> [    2.641235]     # Subtest: hid-lg4ff-exploration
> [    2.641784]     # module: hid_logitech
> [    2.641962]     1..1
> [    2.644581] ==================================================================
> [    2.645008] BUG: KASAN: slab-out-of-bounds in lg4ff_raw_event+0x2fd/0x410
> [    2.645369] Read of size 1 at addr ffff88800229fc63 by task kunit_try_catch/67
> [    2.645369] 
> [    2.645369] CPU: 1 UID: 0 PID: 67 Comm: kunit_try_catch Tainted: G                 N  7.2.0-rc4-dirty #3 PREEMPT(full) 
> [    2.645369] Tainted: [N]=TEST
> [    2.645369] Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
> [    2.645369] Call Trace:
> [    2.645369]  <TASK>
> [    2.645369]  dump_stack_lvl+0x53/0x70
> [    2.645369]  print_report+0xd0/0x630
> [    2.645369]  ? __pfx__raw_spin_lock_irqsave+0x10/0x10
> [    2.645369]  ? lg4ff_raw_event+0x2fd/0x410
> [    2.645369]  kasan_report+0xe5/0x120
> [    2.645369]  ? lg4ff_raw_event+0x2fd/0x410
> [    2.645369]  lg4ff_raw_event+0x2fd/0x410
> [    2.645369]  lg4ff_short_report_oob_test+0x14e/0x250
> 
>  drivers/hid/hid-lg4ff.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
> index e901fdb7d..62f99a932 100644
> --- a/drivers/hid/hid-lg4ff.c
> +++ b/drivers/hid/hid-lg4ff.c
> @@ -336,6 +336,8 @@ int lg4ff_raw_event(struct hid_device *hdev, struct hid_report *report,
>  	if (entry->wdata.combine) {
>  		switch (entry->wdata.product_id) {
>  		case USB_DEVICE_ID_LOGITECH_WHEEL:
> +			if (size < 7)
> +				return 0;
>  			rd[5] = rd[3];
>  			rd[6] = 0x7F;
>  			return 1;
> @@ -343,10 +345,14 @@ int lg4ff_raw_event(struct hid_device *hdev, struct hid_report *report,
>  		case USB_DEVICE_ID_LOGITECH_WINGMAN_FFG:
>  		case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL:
>  		case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2:
> +			if (size < 6)
> +				return 0;
>  			rd[4] = rd[3];
>  			rd[5] = 0x7F;
>  			return 1;
>  		case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
> +			if (size < 7)
> +				return 0;
>  			rd[5] = rd[4];
>  			rd[6] = 0x7F;
>  			return 1;
> @@ -366,6 +372,8 @@ int lg4ff_raw_event(struct hid_device *hdev, struct hid_report *report,
>  		}
>  
>  		/* Compute a combined axis when wheel does not supply it */
> +		if (size <= offset + 1)
> +			return 0;
>  		rd[offset] = (0xFF + rd[offset] - rd[offset+1]) >> 1;
>  		rd[offset+1] = 0x7F;
>  		return 1;
> -- 
> 2.43.0
> 

-- 
Jiri Kosina
SUSE Labs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.