Skip to content

Commit 73506b8

Browse files
pyma1edoardocanepa
authored andcommitted
HID: intel-thc-hid: intel-thc: Fix incorrect pointer arithmetic in I2C regs save
BugLink: https://bugs.launchpad.net/bugs/2119738 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: 4228966 ("HID: intel-thc-hid: intel-thc: Add THC I2C config interfaces") Signed-off-by: Aaron Ma <[email protected]> Reviewed-by: Even Xu <[email protected]> Tested-by: Even Xu <[email protected]> Signed-off-by: Jiri Kosina <[email protected]> (cherry picked from commit a7fc15ed629be89e51e09b743277c53e0a0168f5) Signed-off-by: Aaron Ma <[email protected]> Acked-by: Manuel Diewald <[email protected]> Acked-by: Alessio Faina <[email protected]> Signed-off-by: Edoardo Canepa <[email protected]>
1 parent 5d5c4b1 commit 73506b8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,7 @@ int thc_i2c_subip_regs_save(struct thc_device *dev)
15391539

15401540
for (int i = 0; i < ARRAY_SIZE(i2c_subip_regs); i++) {
15411541
ret = thc_i2c_subip_pio_read(dev, i2c_subip_regs[i],
1542-
&read_size, (u32 *)&dev->i2c_subip_regs + i);
1542+
&read_size, &dev->i2c_subip_regs[i]);
15431543
if (ret < 0)
15441544
return ret;
15451545
}
@@ -1562,7 +1562,7 @@ int thc_i2c_subip_regs_restore(struct thc_device *dev)
15621562

15631563
for (int i = 0; i < ARRAY_SIZE(i2c_subip_regs); i++) {
15641564
ret = thc_i2c_subip_pio_write(dev, i2c_subip_regs[i],
1565-
write_size, (u32 *)&dev->i2c_subip_regs + i);
1565+
write_size, &dev->i2c_subip_regs[i]);
15661566
if (ret < 0)
15671567
return ret;
15681568
}

0 commit comments

Comments
 (0)