mirror-linux/drivers
Qasim Ijaz 1bb3363da8 HID: apple: validate feature-report field count to prevent NULL pointer dereference
A malicious HID device with quirk APPLE_MAGIC_BACKLIGHT can trigger a NULL
pointer dereference whilst the power feature-report is toggled and sent to
the device in apple_magic_backlight_report_set(). The power feature-report
is expected to have two data fields, but if the descriptor declares one
field then accessing field[1] and dereferencing it in
apple_magic_backlight_report_set() becomes invalid
since field[1] will be NULL.

An example of a minimal descriptor which can cause the crash is something
like the following where the report with ID 3 (power report) only
references a single 1-byte field. When hid core parses the descriptor it
will encounter the final feature tag, allocate a hid_report (all members
of field[] will be zeroed out), create field structure and populate it,
increasing the maxfield to 1. The subsequent field[1] access and
dereference causes the crash.

  Usage Page (Vendor Defined 0xFF00)
  Usage (0x0F)
  Collection (Application)
    Report ID (1)
    Usage (0x01)
    Logical Minimum (0)
    Logical Maximum (255)
    Report Size (8)
    Report Count (1)
    Feature (Data,Var,Abs)

    Usage (0x02)
    Logical Maximum (32767)
    Report Size (16)
    Report Count (1)
    Feature (Data,Var,Abs)

    Report ID (3)
    Usage (0x03)
    Logical Minimum (0)
    Logical Maximum (1)
    Report Size (8)
    Report Count (1)
    Feature (Data,Var,Abs)
  End Collection

Here we see the KASAN splat when the kernel dereferences the
NULL pointer and crashes:

  [   15.164723] Oops: general protection fault, probably for non-canonical address 0xdffffc0000000006: 0000 [#1] SMP KASAN NOPTI
  [   15.165691] KASAN: null-ptr-deref in range [0x0000000000000030-0x0000000000000037]
  [   15.165691] CPU: 0 UID: 0 PID: 10 Comm: kworker/0:1 Not tainted 6.15.0 #31 PREEMPT(voluntary)
  [   15.165691] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
  [   15.165691] RIP: 0010:apple_magic_backlight_report_set+0xbf/0x210
  [   15.165691] Call Trace:
  [   15.165691]  <TASK>
  [   15.165691]  apple_probe+0x571/0xa20
  [   15.165691]  hid_device_probe+0x2e2/0x6f0
  [   15.165691]  really_probe+0x1ca/0x5c0
  [   15.165691]  __driver_probe_device+0x24f/0x310
  [   15.165691]  driver_probe_device+0x4a/0xd0
  [   15.165691]  __device_attach_driver+0x169/0x220
  [   15.165691]  bus_for_each_drv+0x118/0x1b0
  [   15.165691]  __device_attach+0x1d5/0x380
  [   15.165691]  device_initial_probe+0x12/0x20
  [   15.165691]  bus_probe_device+0x13d/0x180
  [   15.165691]  device_add+0xd87/0x1510
  [...]

To fix this issue we should validate the number of fields that the
backlight and power reports have and if they do not have the required
number of fields then bail.

Fixes: 394ba612f9 ("HID: apple: Add support for magic keyboard backlight on T2 Macs")
Cc: stable@vger.kernel.org
Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
Reviewed-by: Orlando Chamberlain <orlandoch.dev@gmail.com>
Tested-by: Aditya Garg <gargaditya08@live.com>
Link: https://patch.msgid.link/20250713233008.15131-1-qasdev00@gmail.com
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
2025-07-18 18:10:57 +02:00
..
accel IOMMU Updates for Linux v6.16: 2025-05-30 10:44:20 -07:00
accessibility
acpi hyperv-next for v6.16 2025-06-03 08:39:20 -07:00
amba
android vfs-6.16-rc1.async.dir 2025-05-26 08:02:43 -07:00
ata ata changes for 6.16-rc1 2025-06-03 09:42:38 -07:00
atm
auxdisplay
base - The 11 patch series "Add folio_mk_pte()" from Matthew Wilcox 2025-05-31 15:44:16 -07:00
bcma
block - The 2 patch series "zram: support algorithm-specific parameters" from 2025-06-02 16:00:26 -07:00
bluetooth Bluetooth: btintel: Check dsbr size from EFI variable 2025-05-22 13:06:28 -04:00
bus ARM: soc updates for 6.16 2025-05-31 08:03:09 -07:00
cache
cdrom cdrom: Remove unnecessary NULL check before unregister_sysctl_table() 2025-05-15 16:25:20 -06:00
cdx
char Restructure the IPMI driver for 6.16 2025-05-29 21:37:11 -07:00
clk I've recently moved computers (among other things) so I'm sending this from a 2025-05-30 09:15:40 -07:00
clocksource Updates for clocksource/clockevent drivers: 2025-05-27 09:01:26 -07:00
comedi
connector
counter
cpufreq - The 3 patch series "hung_task: extend blocking task stacktrace dump to 2025-05-31 19:12:53 -07:00
cpuidle Merge branch 'pm-cpuidle' 2025-05-30 20:21:36 +02:00
crypto Core x86 updates for v6.16: 2025-05-26 16:04:17 -07:00
cxl
dax DAX: warn when kmem regions are truncated for memory block alignment 2025-05-12 23:50:49 -07:00
dca
devfreq
dio
dma IOMMU Updates for Linux v6.16: 2025-05-30 10:44:20 -07:00
dma-buf bpf-next-6.16 2025-05-28 15:52:42 -07:00
dpll
edac EDAC/altera: Use correct write width with the INTTEST register 2025-05-29 17:38:55 +02:00
eisa
extcon
firewire treewide, timers: Rename destroy_timer_on_stack() as timer_destroy_on_stack() 2025-05-08 19:49:33 +02:00
firmware hyperv-next for v6.16 2025-06-03 08:39:20 -07:00
fpga
fsi
fwctl
gnss
gpio gpio updates for v6.16-rc1 2025-05-27 15:22:01 -07:00
gpu bitmap-for-6.16 2025-06-03 07:39:23 -07:00
greybus
hid HID: apple: validate feature-report field count to prevent NULL pointer dereference 2025-07-18 18:10:57 +02:00
hsi
hte
hv hyperv-next for v6.16 2025-06-03 08:39:20 -07:00
hwmon hwmon updates for v6.16 2025-06-03 09:11:26 -07:00
hwspinlock
hwtracing
i2c i2c-for-6.16-rc1 2025-05-30 10:07:53 -07:00
i3c i3c: controllers do not need to depend on I3C 2025-05-24 22:49:07 +02:00
idle Power management updates for 6.16-rc1 2025-05-27 16:48:47 -07:00
iio - The 3 patch series "hung_task: extend blocking task stacktrace dump to 2025-05-31 19:12:53 -07:00
infiniband RDMA v6.16 merge window pull request 2025-05-30 10:18:56 -07:00
input Merge branch 'next' into for-linus 2025-06-01 21:41:07 -07:00
interconnect
iommu Revert "iommu: make inclusion of arm/arm-smmu-v3 directory conditional" 2025-05-31 07:43:16 -07:00
ipack
irqchip Another set of timer API cleanups: 2025-05-27 08:31:21 -07:00
isdn
leds
macintosh
mailbox sophgo: add driver for CV18XX series 2025-06-02 10:58:00 -07:00
mcb
md - The 3 patch series "hung_task: extend blocking task stacktrace dump to 2025-05-31 19:12:53 -07:00
media i2c-for-6.16-rc1 2025-05-30 10:07:53 -07:00
memory soc: drivers for 6.16 2025-05-31 07:53:30 -07:00
memstick
message
mfd gpio updates for v6.16-rc1 2025-05-27 15:22:01 -07:00
misc IOMMU Updates for Linux v6.16: 2025-05-30 10:44:20 -07:00
mmc SCSI misc on 20250529 2025-05-29 22:17:52 -07:00
most
mtd A big core MTD change is the introduction of a new class to always 2025-06-02 11:08:17 -07:00
mux
net hardening fixes for v6.16-rc1 (take 2) 2025-06-01 11:37:01 -07:00
nfc nfc: Correct Samsung "Electronics" spelling in copyright headers 2025-05-21 20:31:18 -07:00
ntb
nubus
nvdimm
nvme - The 3 patch series "hung_task: extend blocking task stacktrace dump to 2025-05-31 19:12:53 -07:00
nvmem gpio updates for v6.16-rc1 2025-05-27 15:22:01 -07:00
of - The 11 patch series "Add folio_mk_pte()" from Matthew Wilcox 2025-05-31 15:44:16 -07:00
opp OPP: switch to use kmemdup_array() 2025-05-19 15:37:53 +05:30
parisc
parport
pci hyperv-next for v6.16 2025-06-03 08:39:20 -07:00
pcmcia
peci
perf arm64 updates for 6.16 2025-05-28 14:55:35 -07:00
phy phy: Fix error handling in tegra_xusb_port_init 2025-05-14 12:28:43 +01:00
pinctrl Pin control bulk changes for v6.16: 2025-05-30 09:46:28 -07:00
platform soc: drivers for 6.16 2025-05-31 07:53:30 -07:00
pmdomain pmdomain: ti: Fix STANDBY handling of PER power domain 2025-05-19 16:11:05 +02:00
pnp
power - The 3 patch series "hung_task: extend blocking task stacktrace dump to 2025-05-31 19:12:53 -07:00
powercap
pps
ps3
ptp Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2025-05-22 09:42:41 -07:00
pwm pwm: adp5585: make sure to include mod_devicetable.h 2025-05-19 18:07:39 +02:00
rapidio rapidio: remove unused functions 2025-05-11 17:54:09 -07:00
ras Linux 6.15-rc5 2025-05-06 10:00:58 +02:00
regulator regulator: Updates for v6.16 2025-05-27 15:49:58 -07:00
remoteproc remoteproc updates for v6.16 2025-06-02 11:04:29 -07:00
reset
rpmsg rpmsg: qcom_smd: Fix uninitialized return variable in __qcom_smd_send() 2025-05-20 21:46:10 -05:00
rtc
s390 - The 3 patch series "hung_task: extend blocking task stacktrace dump to 2025-05-31 19:12:53 -07:00
sbus
scsi SCSI misc on 20250529 2025-05-29 22:17:52 -07:00
sh sh: Switch to irq_domain_create_*() 2025-05-16 21:06:11 +02:00
siox
slimbus
soc soc: drivers for 6.16 2025-05-31 07:53:30 -07:00
soundwire soundwire fix for 6.15 2025-05-17 12:04:19 -07:00
spi A big core MTD change is the introduction of a new class to always 2025-06-02 11:08:17 -07:00
spmi
ssb
staging [GIT PULL for v6.16] media updates 2025-05-28 09:17:20 -07:00
target SCSI misc on 20250529 2025-05-29 22:17:52 -07:00
tc
tee Small TEE updates for v6.16 2025-05-10 11:09:49 +02:00
thermal Thermal control updates for 6.16-rc1 2025-05-27 16:28:02 -07:00
thunderbolt
tty
ufs SCSI misc on 20250529 2025-05-29 22:17:52 -07:00
uio uio_hv_generic: Align ring size to system page 2025-05-23 16:30:56 +00:00
usb hid-for-linus-2025060301 2025-06-03 10:34:36 -07:00
vdpa vdpa/octeon_ep: Control PCI dev enabling manually 2025-05-27 10:27:53 -04:00
vfio vfio/type1: Fix error unwind in migration dirty bitmap allocation 2025-05-22 10:41:24 -06:00
vhost virtio, vhost: features, fixes 2025-05-29 08:15:35 -07:00
video fbdev: Fix fb_set_var to prevent null-ptr-deref in fb_videomode_to_var 2025-05-31 10:24:02 +02:00
virt Merge branch 'for-6.16/tsm-mr' into tsm-next 2025-05-13 11:28:25 -07:00
virtio virtio_rtc: Add RTC class driver 2025-05-27 10:27:54 -04:00
w1 w1: ds2406: use crc16() instead of crc16_byte() loop 2025-05-13 20:37:16 -07:00
watchdog linux-watchdog 6.16-rc1 tag 2025-06-01 09:01:58 -07:00
xen xen/x86: fix initial memory balloon target 2025-05-23 07:09:00 +02:00
zorro
Kconfig
Makefile