* [PATCH 1/2] HID: intel-thc-hid: intel-quicki2c: Fix ACPI dsd ICRS/ISUB length
@ 2025-08-03 6:57 Aaron Ma
2025-08-03 6:57 ` [PATCH 2/2] HID: intel-thc-hid: intel-thc: Fix incorrect pointer arithmetic in I2C regs save Aaron Ma
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Aaron Ma @ 2025-08-03 6:57 UTC (permalink / raw)
To: even.xu, xinpeng.sun, jikos, bentiss, linux-input, linux-kernel,
aaron.ma
The QuickI2C ACPI _DSD methods return ICRS and ISUB data with a
trailing byte, making the actual length is one more byte than the
structs defined.
It caused stack-out-of-bounds and kernel crash:
kernel: BUG: KASAN: stack-out-of-bounds in quicki2c_acpi_get_dsd_property.constprop.0+0x111/0x1b0 [intel_quicki2c]
kernel: Write of size 12 at addr ffff888106d1f900 by task kworker/u33:2/75
kernel:
kernel: CPU: 3 UID: 0 PID: 75 Comm: kworker/u33:2 Not tainted 6.16.0+ #3 PREEMPT(voluntary)
kernel: Workqueue: async async_run_entry_fn
kernel: Call Trace:
kernel: <TASK>
kernel: dump_stack_lvl+0x76/0xa0
kernel: print_report+0xd1/0x660
kernel: ? __pfx__raw_spin_lock_irqsave+0x10/0x10
kernel: ? __kasan_slab_free+0x5d/0x80
kernel: ? kasan_addr_to_slab+0xd/0xb0
kernel: kasan_report+0xe1/0x120
kernel: ? quicki2c_acpi_get_dsd_property.constprop.0+0x111/0x1b0 [intel_quicki2c]
kernel: ? quicki2c_acpi_get_dsd_property.constprop.0+0x111/0x1b0 [intel_quicki2c]
kernel: kasan_check_range+0x11c/0x200
kernel: __asan_memcpy+0x3b/0x80
kernel: quicki2c_acpi_get_dsd_property.constprop.0+0x111/0x1b0 [intel_quicki2c]
kernel: ? __pfx_quicki2c_acpi_get_dsd_property.constprop.0+0x10/0x10 [intel_quicki2c]
kernel: quicki2c_get_acpi_resources+0x237/0x730 [intel_quicki2c]
[...]
kernel: </TASK>
kernel:
kernel: The buggy address belongs to stack of task kworker/u33:2/75
kernel: and is located at offset 48 in frame:
kernel: quicki2c_get_acpi_resources+0x0/0x730 [intel_quicki2c]
kernel:
kernel: This frame has 3 objects:
kernel: [32, 36) 'hid_desc_addr'
kernel: [48, 59) 'i2c_param'
kernel: [80, 224) 'i2c_config'
ACPI DSD methods return:
\_SB.PC00.THC0.ICRS Buffer 000000003fdc947b 001 Len 0C = 0A 00 80 1A 06 00 00 00 00 00 00 00
\_SB.PC00.THC0.ISUB Buffer 00000000f2fcbdc4 001 Len 91 = 00 00 00 00 00 00 00 00 00 00 00 00
Adding reserved padding to quicki2c_subip_acpi_parameter/config.
Fixes: 5282e45ccbfa9 ("HID: intel-thc-hid: intel-quicki2c: Add THC QuickI2C ACPI interfaces")
Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
---
drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
index 6ddb584bd6110..97085a6a7452d 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
@@ -71,6 +71,7 @@ struct quicki2c_subip_acpi_parameter {
u16 device_address;
u64 connection_speed;
u8 addressing_mode;
+ u8 reserved;
} __packed;
/**
@@ -120,6 +121,7 @@ struct quicki2c_subip_acpi_config {
u64 HMTD;
u64 HMRD;
u64 HMSL;
+ u8 reserved;
};
struct device;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/2] HID: intel-thc-hid: intel-thc: Fix incorrect pointer arithmetic in I2C regs save 2025-08-03 6:57 [PATCH 1/2] HID: intel-thc-hid: intel-quicki2c: Fix ACPI dsd ICRS/ISUB length Aaron Ma @ 2025-08-03 6:57 ` Aaron Ma 2025-08-05 2:15 ` Xu, Even 2025-08-05 2:14 ` [PATCH 1/2] HID: intel-thc-hid: intel-quicki2c: Fix ACPI dsd ICRS/ISUB length Xu, Even 2025-08-11 11:39 ` Jiri Kosina 2 siblings, 1 reply; 6+ messages in thread From: Aaron Ma @ 2025-08-03 6:57 UTC (permalink / raw) To: even.xu, xinpeng.sun, jikos, bentiss, linux-input, linux-kernel, aaron.ma Improper use of secondary pointer (&dev->i2c_subip_regs) caused kernel crash and out-of-bounds error: BUG: KASAN: slab-out-of-bounds in _regmap_bulk_read+0x449/0x510 Write of size 4 at addr ffff888136005dc0 by task kworker/u33:5/5107 CPU: 3 UID: 0 PID: 5107 Comm: kworker/u33:5 Not tainted 6.16.0+ #3 PREEMPT(voluntary) Workqueue: async async_run_entry_fn Call Trace: <TASK> dump_stack_lvl+0x76/0xa0 print_report+0xd1/0x660 ? __pfx__raw_spin_lock_irqsave+0x10/0x10 ? kasan_complete_mode_report_info+0x26/0x200 kasan_report+0xe1/0x120 ? _regmap_bulk_read+0x449/0x510 ? _regmap_bulk_read+0x449/0x510 __asan_report_store4_noabort+0x17/0x30 _regmap_bulk_read+0x449/0x510 ? __pfx__regmap_bulk_read+0x10/0x10 regmap_bulk_read+0x270/0x3d0 pio_complete+0x1ee/0x2c0 [intel_thc] ? __pfx_pio_complete+0x10/0x10 [intel_thc] ? __pfx_pio_wait+0x10/0x10 [intel_thc] ? regmap_update_bits_base+0x13b/0x1f0 thc_i2c_subip_pio_read+0x117/0x270 [intel_thc] thc_i2c_subip_regs_save+0xc2/0x140 [intel_thc] ? __pfx_thc_i2c_subip_regs_save+0x10/0x10 [intel_thc] [...] The buggy address belongs to the object at ffff888136005d00 which belongs to the cache kmalloc-rnd-12-192 of size 192 The buggy address is located 0 bytes to the right of allocated 192-byte region [ffff888136005d00, ffff888136005dc0) Replaced with direct array indexing (&dev->i2c_subip_regs[i]) to ensure safe memory access. Fixes: 4228966def884 ("HID: intel-thc-hid: intel-thc: Add THC I2C config interfaces") Signed-off-by: Aaron Ma <aaron.ma@canonical.com> --- drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c index c105df7f6c873..4698722e0d0a6 100644 --- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c +++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c @@ -1539,7 +1539,7 @@ int thc_i2c_subip_regs_save(struct thc_device *dev) for (int i = 0; i < ARRAY_SIZE(i2c_subip_regs); i++) { ret = thc_i2c_subip_pio_read(dev, i2c_subip_regs[i], - &read_size, (u32 *)&dev->i2c_subip_regs + i); + &read_size, &dev->i2c_subip_regs[i]); if (ret < 0) return ret; } @@ -1562,7 +1562,7 @@ int thc_i2c_subip_regs_restore(struct thc_device *dev) for (int i = 0; i < ARRAY_SIZE(i2c_subip_regs); i++) { ret = thc_i2c_subip_pio_write(dev, i2c_subip_regs[i], - write_size, (u32 *)&dev->i2c_subip_regs + i); + write_size, &dev->i2c_subip_regs[i]); if (ret < 0) return ret; } -- 2.43.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* RE: [PATCH 2/2] HID: intel-thc-hid: intel-thc: Fix incorrect pointer arithmetic in I2C regs save 2025-08-03 6:57 ` [PATCH 2/2] HID: intel-thc-hid: intel-thc: Fix incorrect pointer arithmetic in I2C regs save Aaron Ma @ 2025-08-05 2:15 ` Xu, Even 0 siblings, 0 replies; 6+ messages in thread From: Xu, Even @ 2025-08-05 2:15 UTC (permalink / raw) To: Aaron, Ma, Sun, Xinpeng, jikos@kernel.org, bentiss@kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Aaron, Ma > -----Original Message----- > From: Aaron Ma <aaron.ma@canonical.com> > Sent: Sunday, August 3, 2025 2:57 PM > To: Xu, Even <even.xu@intel.com>; Sun, Xinpeng <xinpeng.sun@intel.com>; > jikos@kernel.org; bentiss@kernel.org; linux-input@vger.kernel.org; linux- > kernel@vger.kernel.org; Aaron, Ma <aaron.ma@canonical.com> > Subject: [PATCH 2/2] HID: intel-thc-hid: intel-thc: Fix incorrect pointer arithmetic > in I2C regs save > > Improper use of secondary pointer (&dev->i2c_subip_regs) caused kernel crash > and out-of-bounds error: > > BUG: KASAN: slab-out-of-bounds in _regmap_bulk_read+0x449/0x510 Write of > size 4 at addr ffff888136005dc0 by task kworker/u33:5/5107 > > CPU: 3 UID: 0 PID: 5107 Comm: kworker/u33:5 Not tainted 6.16.0+ #3 > PREEMPT(voluntary) > Workqueue: async async_run_entry_fn > Call Trace: > <TASK> > dump_stack_lvl+0x76/0xa0 > print_report+0xd1/0x660 > ? __pfx__raw_spin_lock_irqsave+0x10/0x10 > ? kasan_complete_mode_report_info+0x26/0x200 > kasan_report+0xe1/0x120 > ? _regmap_bulk_read+0x449/0x510 > ? _regmap_bulk_read+0x449/0x510 > __asan_report_store4_noabort+0x17/0x30 > _regmap_bulk_read+0x449/0x510 > ? __pfx__regmap_bulk_read+0x10/0x10 > regmap_bulk_read+0x270/0x3d0 > pio_complete+0x1ee/0x2c0 [intel_thc] > ? __pfx_pio_complete+0x10/0x10 [intel_thc] > ? __pfx_pio_wait+0x10/0x10 [intel_thc] > ? regmap_update_bits_base+0x13b/0x1f0 > thc_i2c_subip_pio_read+0x117/0x270 [intel_thc] > thc_i2c_subip_regs_save+0xc2/0x140 [intel_thc] > ? __pfx_thc_i2c_subip_regs_save+0x10/0x10 [intel_thc] [...] The buggy address > belongs to the object at ffff888136005d00 > which belongs to the cache kmalloc-rnd-12-192 of size 192 The buggy address is > located 0 bytes to the right of > allocated 192-byte region [ffff888136005d00, ffff888136005dc0) > > Replaced with direct array indexing (&dev->i2c_subip_regs[i]) to ensure safe > memory access. > > Fixes: 4228966def884 ("HID: intel-thc-hid: intel-thc: Add THC I2C config > interfaces") > Signed-off-by: Aaron Ma <aaron.ma@canonical.com> > --- > drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c b/drivers/hid/intel- > thc-hid/intel-thc/intel-thc-dev.c > index c105df7f6c873..4698722e0d0a6 100644 > --- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c > +++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c > @@ -1539,7 +1539,7 @@ int thc_i2c_subip_regs_save(struct thc_device *dev) > > for (int i = 0; i < ARRAY_SIZE(i2c_subip_regs); i++) { > ret = thc_i2c_subip_pio_read(dev, i2c_subip_regs[i], > - &read_size, (u32 *)&dev- > >i2c_subip_regs + i); > + &read_size, &dev- > >i2c_subip_regs[i]); > if (ret < 0) > return ret; > } > @@ -1562,7 +1562,7 @@ int thc_i2c_subip_regs_restore(struct thc_device > *dev) > > for (int i = 0; i < ARRAY_SIZE(i2c_subip_regs); i++) { > ret = thc_i2c_subip_pio_write(dev, i2c_subip_regs[i], > - write_size, (u32 *)&dev- > >i2c_subip_regs + i); > + write_size, &dev- > >i2c_subip_regs[i]); > if (ret < 0) > return ret; > } Thanks for the fix! Reviewed-by: Even Xu <even.xu@intel.com> Tested-by: Even Xu <even.xu@intel.com> > -- > 2.43.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH 1/2] HID: intel-thc-hid: intel-quicki2c: Fix ACPI dsd ICRS/ISUB length 2025-08-03 6:57 [PATCH 1/2] HID: intel-thc-hid: intel-quicki2c: Fix ACPI dsd ICRS/ISUB length Aaron Ma 2025-08-03 6:57 ` [PATCH 2/2] HID: intel-thc-hid: intel-thc: Fix incorrect pointer arithmetic in I2C regs save Aaron Ma @ 2025-08-05 2:14 ` Xu, Even 2025-08-11 11:39 ` Jiri Kosina 2 siblings, 0 replies; 6+ messages in thread From: Xu, Even @ 2025-08-05 2:14 UTC (permalink / raw) To: Aaron, Ma, Sun, Xinpeng, jikos@kernel.org, bentiss@kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Aaron, Ma > -----Original Message----- > From: Aaron Ma <aaron.ma@canonical.com> > Sent: Sunday, August 3, 2025 2:57 PM > To: Xu, Even <even.xu@intel.com>; Sun, Xinpeng <xinpeng.sun@intel.com>; > jikos@kernel.org; bentiss@kernel.org; linux-input@vger.kernel.org; linux- > kernel@vger.kernel.org; Aaron, Ma <aaron.ma@canonical.com> > Subject: [PATCH 1/2] HID: intel-thc-hid: intel-quicki2c: Fix ACPI dsd ICRS/ISUB > length > > The QuickI2C ACPI _DSD methods return ICRS and ISUB data with a trailing byte, > making the actual length is one more byte than the structs defined. > > It caused stack-out-of-bounds and kernel crash: > > kernel: BUG: KASAN: stack-out-of-bounds in > quicki2c_acpi_get_dsd_property.constprop.0+0x111/0x1b0 [intel_quicki2c] > kernel: Write of size 12 at addr ffff888106d1f900 by task kworker/u33:2/75 > kernel: > kernel: CPU: 3 UID: 0 PID: 75 Comm: kworker/u33:2 Not tainted 6.16.0+ #3 > PREEMPT(voluntary) > kernel: Workqueue: async async_run_entry_fn > kernel: Call Trace: > kernel: <TASK> > kernel: dump_stack_lvl+0x76/0xa0 > kernel: print_report+0xd1/0x660 > kernel: ? __pfx__raw_spin_lock_irqsave+0x10/0x10 > kernel: ? __kasan_slab_free+0x5d/0x80 > kernel: ? kasan_addr_to_slab+0xd/0xb0 > kernel: kasan_report+0xe1/0x120 > kernel: ? quicki2c_acpi_get_dsd_property.constprop.0+0x111/0x1b0 > [intel_quicki2c] > kernel: ? quicki2c_acpi_get_dsd_property.constprop.0+0x111/0x1b0 > [intel_quicki2c] > kernel: kasan_check_range+0x11c/0x200 > kernel: __asan_memcpy+0x3b/0x80 > kernel: quicki2c_acpi_get_dsd_property.constprop.0+0x111/0x1b0 > [intel_quicki2c] > kernel: ? __pfx_quicki2c_acpi_get_dsd_property.constprop.0+0x10/0x10 > [intel_quicki2c] > kernel: quicki2c_get_acpi_resources+0x237/0x730 [intel_quicki2c] [...] > kernel: </TASK> > kernel: > kernel: The buggy address belongs to stack of task kworker/u33:2/75 > kernel: and is located at offset 48 in frame: > kernel: quicki2c_get_acpi_resources+0x0/0x730 [intel_quicki2c] > kernel: > kernel: This frame has 3 objects: > kernel: [32, 36) 'hid_desc_addr' > kernel: [48, 59) 'i2c_param' > kernel: [80, 224) 'i2c_config' > > ACPI DSD methods return: > > \_SB.PC00.THC0.ICRS Buffer 000000003fdc947b 001 Len 0C = 0A 00 80 1A 06 > 00 00 00 00 00 00 00 > \_SB.PC00.THC0.ISUB Buffer 00000000f2fcbdc4 001 Len 91 = 00 00 00 00 00 > 00 00 00 00 00 00 00 > > Adding reserved padding to quicki2c_subip_acpi_parameter/config. Good finding, thanks for the fix! > > Fixes: 5282e45ccbfa9 ("HID: intel-thc-hid: intel-quicki2c: Add THC QuickI2C ACPI > interfaces") > Signed-off-by: Aaron Ma <aaron.ma@canonical.com> > --- > drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h > b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h > index 6ddb584bd6110..97085a6a7452d 100644 > --- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h > +++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h > @@ -71,6 +71,7 @@ struct quicki2c_subip_acpi_parameter { > u16 device_address; > u64 connection_speed; > u8 addressing_mode; > + u8 reserved; > } __packed; > > /** > @@ -120,6 +121,7 @@ struct quicki2c_subip_acpi_config { > u64 HMTD; > u64 HMRD; > u64 HMSL; > + u8 reserved; > }; Reviewed-by: Even Xu <even.xu@intel.com> Tested-by: Even Xu <even.xu@intel.com> > > struct device; > -- > 2.43.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] HID: intel-thc-hid: intel-quicki2c: Fix ACPI dsd ICRS/ISUB length 2025-08-03 6:57 [PATCH 1/2] HID: intel-thc-hid: intel-quicki2c: Fix ACPI dsd ICRS/ISUB length Aaron Ma 2025-08-03 6:57 ` [PATCH 2/2] HID: intel-thc-hid: intel-thc: Fix incorrect pointer arithmetic in I2C regs save Aaron Ma 2025-08-05 2:14 ` [PATCH 1/2] HID: intel-thc-hid: intel-quicki2c: Fix ACPI dsd ICRS/ISUB length Xu, Even @ 2025-08-11 11:39 ` Jiri Kosina 2025-08-12 0:55 ` Xu, Even 2 siblings, 1 reply; 6+ messages in thread From: Jiri Kosina @ 2025-08-11 11:39 UTC (permalink / raw) To: Aaron Ma; +Cc: even.xu, xinpeng.sun, bentiss, linux-input, linux-kernel Both patches now applied to hid.git#for-6.17/upstream-fixes, thanks. -- Jiri Kosina SUSE Labs ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH 1/2] HID: intel-thc-hid: intel-quicki2c: Fix ACPI dsd ICRS/ISUB length 2025-08-11 11:39 ` Jiri Kosina @ 2025-08-12 0:55 ` Xu, Even 0 siblings, 0 replies; 6+ messages in thread From: Xu, Even @ 2025-08-12 0:55 UTC (permalink / raw) To: Jiri Kosina, Aaron, Ma Cc: Sun, Xinpeng, bentiss@kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Thanks! Best Regards, Even Xu > -----Original Message----- > From: Jiri Kosina <jikos@kernel.org> > Sent: Monday, August 11, 2025 7:39 PM > To: Aaron, Ma <aaron.ma@canonical.com> > Cc: Xu, Even <even.xu@intel.com>; Sun, Xinpeng <xinpeng.sun@intel.com>; > bentiss@kernel.org; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org > Subject: Re: [PATCH 1/2] HID: intel-thc-hid: intel-quicki2c: Fix ACPI dsd ICRS/ISUB > length > > Both patches now applied to hid.git#for-6.17/upstream-fixes, thanks. > > -- > Jiri Kosina > SUSE Labs ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-08-12 0:55 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-08-03 6:57 [PATCH 1/2] HID: intel-thc-hid: intel-quicki2c: Fix ACPI dsd ICRS/ISUB length Aaron Ma 2025-08-03 6:57 ` [PATCH 2/2] HID: intel-thc-hid: intel-thc: Fix incorrect pointer arithmetic in I2C regs save Aaron Ma 2025-08-05 2:15 ` Xu, Even 2025-08-05 2:14 ` [PATCH 1/2] HID: intel-thc-hid: intel-quicki2c: Fix ACPI dsd ICRS/ISUB length Xu, Even 2025-08-11 11:39 ` Jiri Kosina 2025-08-12 0:55 ` Xu, Even
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox