linux/drivers/acpi
Weiming Shi f6484cadbc ACPI: EC: clean up handlers on probe failure in acpi_ec_setup()
When ec_install_handlers() returns -EPROBE_DEFER on reduced-hardware
platforms, it has already started the EC and installed the address
space handler with the struct acpi_ec pointer as handler context.
However, acpi_ec_setup() propagates the error without any cleanup.

The caller acpi_ec_add() then frees the struct acpi_ec for non-boot
instances, leaving a dangling handler context in ACPICA.

Any subsequent AML evaluation that accesses an EC OpRegion field
dispatches into acpi_ec_space_handler() with the freed pointer,
causing a use-after-free:

 BUG: KASAN: slab-use-after-free in mutex_lock (kernel/locking/mutex.c:289)
 Write of size 8 at addr ffff88800721de38 by task init/1
 Call Trace:
  <TASK>
  mutex_lock (kernel/locking/mutex.c:289)
  acpi_ec_space_handler (drivers/acpi/ec.c:1362)
  acpi_ev_address_space_dispatch (drivers/acpi/acpica/evregion.c:293)
  acpi_ex_access_region (drivers/acpi/acpica/exfldio.c:246)
  acpi_ex_field_datum_io (drivers/acpi/acpica/exfldio.c:509)
  acpi_ex_extract_from_field (drivers/acpi/acpica/exfldio.c:700)
  acpi_ex_read_data_from_field (drivers/acpi/acpica/exfield.c:327)
  acpi_ex_resolve_node_to_value (drivers/acpi/acpica/exresolv.c:392)
  </TASK>

 Allocated by task 1:
  acpi_ec_alloc (drivers/acpi/ec.c:1424)
  acpi_ec_add (drivers/acpi/ec.c:1692)

 Freed by task 1:
  kfree (mm/slub.c:6876)
  acpi_ec_add (drivers/acpi/ec.c:1751)

The bug triggers on reduced-hardware EC platforms (ec->gpe < 0)
when the GPIO IRQ provider defers probing. Once the stale handler
exists, any unprivileged sysfs read that causes AML to touch an
EC OpRegion (battery, thermal, backlight) exercises the dangling
pointer.

Fix this by calling ec_remove_handlers() in the error path of
acpi_ec_setup() before clearing first_ec. ec_remove_handlers()
checks each EC_FLAGS_* bit before acting, so it is safe to call
regardless of how far ec_install_handlers() progressed:

  -ENODEV  (handler not installed): only calls acpi_ec_stop()
  -EPROBE_DEFER (handler installed): removes handler, stops EC

Fixes: 03e9a0e057 ("ACPI: EC: Consolidate event handler installation code")
Reported-by: Xiang Mei <xmei5@asu.edu>
Signed-off-by: Weiming Shi <bestswngs@gmail.com>
Link: https://patch.msgid.link/20260324165458.1337233-2-bestswngs@gmail.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2026-03-24 18:47:10 +01:00
..
acpica ACPICA: Update the format of Arg3 of _DSM 2026-03-17 20:51:13 +01:00
apei Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
arm64 Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
dptf Thermal control updates for 6.19-rc1 2025-12-02 17:49:12 -08:00
nfit Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
numa Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
pmic ACPI: PMIC: Remove unneeded check in tps68470_pmic_opregion_probe() 2024-08-02 17:05:08 +02:00
riscv Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
x86 Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
Kconfig ACPI: video: Switch over to auxiliary bus type 2026-03-10 15:08:21 +01:00
Makefile ACPI: MRRM: Minimal parse of ACPI MRRM table 2025-05-12 15:43:16 +02:00
ac.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
acpi_adxl.c
acpi_apd.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
acpi_configfs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
acpi_dbg.c ACPI: debug: fix signedness issues in read/write helpers 2025-09-23 15:45:28 +02:00
acpi_extlog.c ACPI: extlog: Trace CPER CXL Protocol Error Section 2026-01-14 17:09:34 +01:00
acpi_ffh.c ACPI: FFH: Drop the inclusion of linux/arm-smccc.h 2023-06-12 19:28:20 +02:00
acpi_fpdt.c ACPI: FPDT: properly handle invalid FPDT subtables 2023-10-03 21:12:22 +02:00
acpi_ipmi.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
acpi_lpat.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
acpi_lpit.c x86/msr: Rename 'rdmsrl_safe()' to 'rdmsrq_safe()' 2025-04-10 11:58:38 +02:00
acpi_memhotplug.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
acpi_mrrm.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
acpi_pad.c ACPI: PAD: Update arguments of mwait_idle_with_hints() 2025-06-10 20:47:56 +02:00
acpi_pcc.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
acpi_platform.c ACPI: video: Switch over to auxiliary bus type 2026-03-10 15:08:21 +01:00
acpi_pnp.c ACPI: PNP: Drop acpi_nonpnp_device_ids[] 2025-12-16 21:51:04 +01:00
acpi_processor.c ACPI: processor: Fix previous acpi_processor_errata_piix4() fix 2026-03-18 11:53:07 +01:00
acpi_tad.c ACPI: TAD: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR() 2025-11-14 21:25:15 +01:00
acpi_video.c ACPI: video: Switch over to auxiliary bus type 2026-03-10 15:08:21 +01:00
acpi_watchdog.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
battery.c ACPI: battery: Drop redundant checks from acpi_battery_remove() 2026-02-13 14:22:19 +01:00
bgrt.c sysfs: treewide: switch back to attribute_group::bin_attrs 2025-06-17 10:44:15 +02:00
bus.c ACPI: bus: Fix MFD child automatic modprobe issue 2026-03-18 11:57:22 +01:00
button.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
container.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
cppc_acpi.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
debugfs.c
device_pm.c Revert "ACPI: PM: Let acpi_dev_pm_attach() skip devices without ACPI PM" 2026-03-03 15:32:53 +01:00
device_sysfs.c ACPI: sysfs: Replace sprintf() with sysfs_emit() 2026-01-27 21:58:58 +01:00
dock.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ec.c ACPI: EC: clean up handlers on probe failure in acpi_ec_setup() 2026-03-24 18:47:10 +01:00
ec_sys.c
event.c ACPI: event: Use strscpy() instead of strcpy() 2024-11-05 21:35:35 +01:00
evged.c ACPI: Switch back to struct platform_driver::remove() 2024-11-12 21:30:30 +01:00
fan.h Thermal control updates for 6.19-rc1 2025-12-02 17:49:12 -08:00
fan_attr.c ACPI: fan: Use ACPI handle when retrieving _FST 2025-10-24 10:29:08 +02:00
fan_core.c ACPI: fan: Add support for Microsoft fan extensions 2025-10-27 20:56:01 +01:00
fan_hwmon.c ACPI: fan: Add hwmon notification support 2025-10-27 20:56:01 +01:00
glue.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
hed.c ACPI: HED: Convert the driver to a platform one 2025-12-29 21:04:10 +01:00
internal.h ACPI: DPTF: Remove int340x thermal scan handler 2025-11-07 20:45:37 +01:00
ioapic.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
irq.c ACPI: irq: Add interrupt affinity reporting interface 2025-10-27 17:16:32 +01:00
mipi-disco-img.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
nhlt.c ACPI: NHLT: Streamline struct naming 2024-03-27 16:36:45 +01:00
nvs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
osi.c ACPI: OSI: Add DMI quirk for Acer Aspire One D255 2026-02-24 15:43:51 +01:00
osl.c ACPI: OSL: fix __iomem type on return from acpi_os_map_generic_address() 2026-03-11 12:30:45 +01:00
pci_irq.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
pci_link.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
pci_mcfg.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
pci_root.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
pci_slot.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
pfr_telemetry.c Merge branch 'acpi-misc' 2024-11-15 20:52:02 +01:00
pfr_update.c ACPI: pfr_update: Fix the driver update version check 2025-08-20 15:30:36 +02:00
platform_profile.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
power.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
pptt.c ACPI / PPTT: Add a helper to fill a cpumask from a cache_id 2025-11-19 18:34:14 +00:00
prmt.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
proc.c ACPI: proc: Prefer to use octal permission 2025-06-26 21:08:13 +02:00
processor_core.c ACPI: processor_core: fix map_x2apic_id for amd-pstate on am4 2025-11-26 18:06:25 +01:00
processor_driver.c ACPI: processor: Do not expose global variable acpi_idle_driver 2026-01-09 22:38:22 +01:00
processor_idle.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
processor_pdc.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
processor_perflib.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
processor_thermal.c ACPI: processor: thermal: Release policy references using __free() 2025-09-08 19:53:32 +02:00
processor_throttling.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
property.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
reboot.c
resource.c ACPI: resource: Add JWIPC JVC9100 to irq1_level_low_skip_override[] 2026-01-14 17:25:19 +01:00
sbs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
sbshc.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
sbshc.h
scan.c ACPI: video: Switch over to auxiliary bus type 2026-03-10 15:08:21 +01:00
sleep.c ACPI: PM: Save NVS memory on Lenovo G70-35 2026-02-19 11:54:52 +01:00
sleep.h ACPI: PM: s2idle: Staticise LPS0 callback functions 2025-10-20 20:39:33 +02:00
spcr.c ACPI: SPCR: Check for table version when using precise baudrate 2025-10-27 20:43:41 +01:00
sysfs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
tables.c ACPI / MPAM: Parse the MPAM table 2025-11-19 18:34:20 +00:00
thermal.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
thermal_lib.c module: Convert symbol namespace to string literal 2024-12-02 11:34:44 -08:00
tiny-power-button.c ACPI: tiny-power-button: Convert the driver to a platform one 2025-12-26 15:08:57 +01:00
utils.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
video_detect.c ACPI: video: force native for Lenovo 82K8 2025-08-25 20:00:17 +02:00
viot.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
wakeup.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00