kernel_optimize_test/drivers/acpi
Nathan Chancellor cc0b1776fd ACPI: bgrt: Fix CFI violation
[ Upstream commit f37ccf8fce155d08ae2a4fb3db677911ced0c21a ]

clang's Control Flow Integrity requires that every indirect call has a
valid target, which is based on the type of the function pointer. The
*_show() functions in this file are written as if they will be called
from dev_attr_show(); however, they will be called from
sysfs_kf_seq_show() because the files were created by
sysfs_create_group() and the sysfs ops are based on kobj_sysfs_ops
because of kobject_add_and_create(). Because the *_show() functions do
not match the type of the show() member in struct kobj_attribute, there
is a CFI violation.

$ cat /sys/firmware/acpi/bgrt/{status,type,version,{x,y}offset}}
1
0
1
522
307

$ dmesg | grep "CFI failure"
[  267.761825] CFI failure (target: type_show.d5e1ad21498a5fd14edbc5c320906598.cfi_jt+0x0/0x8):
[  267.762246] CFI failure (target: xoffset_show.d5e1ad21498a5fd14edbc5c320906598.cfi_jt+0x0/0x8):
[  267.762584] CFI failure (target: status_show.d5e1ad21498a5fd14edbc5c320906598.cfi_jt+0x0/0x8):
[  267.762973] CFI failure (target: yoffset_show.d5e1ad21498a5fd14edbc5c320906598.cfi_jt+0x0/0x8):
[  267.763330] CFI failure (target: version_show.d5e1ad21498a5fd14edbc5c320906598.cfi_jt+0x0/0x8):

Convert these functions to the type of the show() member in struct
kobj_attribute so that there is no more CFI violation. Because these
functions are all so similar, combine them into a macro.

Fixes: d1ff4b1cdb ("ACPI: Add support for exposing BGRT data")
Link: https://github.com/ClangBuiltLinux/linux/issues/1406
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-07-14 16:56:12 +02:00
..
acpica ACPICA: Fix memory leak caused by _CID repair function 2021-07-14 16:55:59 +02:00
apei ACPI: APEI: fix synchronous external aborts in user-mode 2021-07-14 16:56:12 +02:00
arm64 ACPI: GTDT: Don't corrupt interrupt mappings on watchdow probe failure 2021-05-11 14:47:34 +02:00
dptf
nfit
numa
pmic
x86
ac.c
acpi_adxl.c
acpi_amba.c
acpi_apd.c serial: 8250_dw: Add device HID for new AMD UART controller 2021-06-03 09:00:33 +02:00
acpi_cmos_rtc.c
acpi_configfs.c
acpi_dbg.c
acpi_extlog.c
acpi_ipmi.c
acpi_lpat.c
acpi_lpit.c
acpi_lpss.c
acpi_memhotplug.c
acpi_pad.c ACPI: Use DEVICE_ATTR_<RW|RO|WO> macros 2021-07-14 16:56:12 +02:00
acpi_platform.c
acpi_pnp.c
acpi_processor.c
acpi_tad.c ACPI: Use DEVICE_ATTR_<RW|RO|WO> macros 2021-07-14 16:56:12 +02:00
acpi_video.c
acpi_watchdog.c
battery.c
bgrt.c ACPI: bgrt: Fix CFI violation 2021-07-14 16:56:12 +02:00
blacklist.c
bus.c ACPI: bus: Call kobject_put() in acpi_init() error path 2021-07-14 16:55:59 +02:00
button.c
container.c
cppc_acpi.c ACPI: CPPC: Replace cppc_attr with kobj_attribute 2021-05-14 09:50:16 +02:00
custom_method.c ACPI: custom_method: fix a possible memory leak 2021-05-11 14:47:12 +02:00
debugfs.c
device_pm.c ACPI: PM / fan: Put fan device IDs into separate header file 2021-07-14 16:56:11 +02:00
device_sysfs.c ACPI: Use DEVICE_ATTR_<RW|RO|WO> macros 2021-07-14 16:56:12 +02:00
dock.c ACPI: Use DEVICE_ATTR_<RW|RO|WO> macros 2021-07-14 16:56:12 +02:00
ec_sys.c
ec.c ACPI: EC: trust DSDT GPE for certain HP laptop 2021-07-14 16:56:01 +02:00
event.c
evged.c
fan.c ACPI: PM / fan: Put fan device IDs into separate header file 2021-07-14 16:56:11 +02:00
fan.h ACPI: PM / fan: Put fan device IDs into separate header file 2021-07-14 16:56:11 +02:00
glue.c
hed.c
internal.h ACPI: scan: Use unique number for instance_no 2021-03-30 14:32:06 +02:00
ioapic.c
irq.c
Kconfig
Makefile ACPI: tables: Add custom DSDT file as makefile prerequisite 2021-07-14 16:56:01 +02:00
nvs.c
osi.c
osl.c
pci_irq.c
pci_link.c
pci_mcfg.c
pci_root.c
pci_slot.c
power.c ACPI: Use DEVICE_ATTR_<RW|RO|WO> macros 2021-07-14 16:56:12 +02:00
pptt.c
proc.c
processor_core.c
processor_driver.c
processor_idle.c ACPI: processor idle: Fix up C-state latency if not ordered 2021-07-14 16:55:57 +02:00
processor_pdc.c
processor_perflib.c
processor_thermal.c
processor_throttling.c
property.c
reboot.c
resource.c ACPI: resources: Add checks for ACPI IRQ override 2021-07-14 16:55:59 +02:00
sbs.c
sbshc.c
sbshc.h
scan.c ACPI: scan: Fix a memory leak in an error handling path 2021-05-19 10:13:13 +02:00
sleep.c Revert "ACPI: sleep: Put the FACS table after using it" 2021-06-16 12:01:39 +02:00
sleep.h
spcr.c
sysfs.c
tables.c ACPI: tables: x86: Reserve memory occupied by ACPI tables 2021-04-07 15:00:08 +02:00
thermal.c
tiny-power-button.c
utils.c
video_detect.c ACPI: video: use native backlight for GA401/GA502/GA503 2021-07-14 16:55:57 +02:00
wakeup.c