linux/drivers/acpi
Krzysztof Wilczyński 888be6067b ACPI: sysfs: Fix a buffer overrun problem with description_show()
Currently, a device description can be obtained using ACPI, if the _STR
method exists for a particular device, and then exposed to the userspace
via a sysfs object as a string value.

If the _STR method is available for a given device then the data
(usually a Unicode string) is read and stored in a buffer (of the
ACPI_TYPE_BUFFER type) with a pointer to said buffer cached in the
struct acpi_device_pnp for later access.

The description_show() function is responsible for exposing the device
description to the userspace via a corresponding sysfs object and
internally calls the utf16s_to_utf8s() function with a pointer to the
buffer that contains the Unicode string so that it can be converted from
UTF16 encoding to UTF8 and thus allowing for the value to be safely
stored and later displayed.

When invoking the utf16s_to_utf8s() function, the description_show()
function also sets a limit of the data that can be saved into a provided
buffer as a result of the character conversion to be a total of
PAGE_SIZE, and upon completion, the utf16s_to_utf8s() function returns
an integer value denoting the number of bytes that have been written
into the provided buffer.

Following the execution of the utf16s_to_utf8s() a newline character
will be added at the end of the resulting buffer so that when the value
is read in the userspace through the sysfs object then it would include
newline making it more accessible when working with the sysfs file
system in the shell, etc.  Normally, this wouldn't be a problem, but if
the function utf16s_to_utf8s() happens to return the number of bytes
written to be precisely PAGE_SIZE, then we would overrun the buffer and
write the newline character outside the allotted space which can have
undefined consequences or result in a failure.

To fix this buffer overrun, ensure that there always is enough space
left for the newline character to be safely appended.

Fixes: d1efe3c324 ("ACPI: Add new sysfs interface to export device description")
Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
Reviewed-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2021-06-07 16:27:44 +02:00
..
acpica ACPICA: Clean up context mutex during object deletion 2021-05-31 13:56:33 +02:00
apei Merge branch 'acpi-misc' 2021-04-26 17:04:41 +02:00
arm64 Assorted arm64 fixes and clean-ups, the most important: 2021-05-07 12:11:05 -07:00
dptf ACPI: DPTF: Support Alder Lake 2020-11-10 18:52:51 +01:00
nfit ACPI: NFIT: Fix support for variable 'SPA' structure size 2021-05-12 12:38:25 -07:00
numa CFI on arm64 series for v5.13-rc1 2021-04-27 10:16:46 -07:00
pmic ACPI: fix various typos in comments 2021-03-19 17:45:49 +01:00
x86 ACPI: PM: s2idle: Drop unused local variables and related code 2021-01-07 17:41:28 +01:00
ac.c ACPI: AC: fix some coding style issues 2021-04-08 16:17:32 +02:00
acpi_adxl.c
acpi_amba.c Merge 5.2-rc6 into char-misc-next 2019-06-23 09:23:33 +02:00
acpi_apd.c serial: 8250_dw: Add device HID for new AMD UART controller 2021-05-13 17:08:42 +02:00
acpi_cmos_rtc.c ACPI: cmos_rtc: Remove leftover ACPI_MODULE_NAME() 2020-09-25 18:25:51 +02:00
acpi_configfs.c ACPI: configfs: add missing check after configfs_register_default_group() 2021-01-22 16:35:34 +01:00
acpi_dbg.c ACPI: debug: Remove the not used function 2020-11-17 18:12:34 +01:00
acpi_extlog.c ACPI / extlog: Check for RDMSR failure 2020-10-02 19:01:55 +02:00
acpi_fpdt.c ACPI: tables: introduce support for FPDT table 2021-01-29 19:24:13 +01:00
acpi_ipmi.c ACPI: ipmi: remove useless return statement for void function 2021-04-08 16:27:02 +02:00
acpi_lpat.c
acpi_lpit.c ACPI: LPIT: Put the low power idle table after using it 2020-05-09 11:29:16 +02:00
acpi_lpss.c ACPI: LPSS: add a missed blank line after declarations 2021-04-08 16:27:02 +02:00
acpi_memhotplug.c acpi,memhotplug: enable MHP_MEMMAP_ON_MEMORY when supported 2021-05-05 11:27:27 -07:00
acpi_pad.c ACPI: acpi_pad: add a missed blank line after declarations 2021-04-08 16:27:02 +02:00
acpi_platform.c ACPI: platform: Remove ACPI_MODULE_NAME() 2020-09-25 18:25:51 +02:00
acpi_pnp.c ACPI: PNP: compare the string length in the matching_id() 2020-12-15 19:30:49 +01:00
acpi_processor.c Merge branch 'acpi-misc' 2021-04-26 17:04:41 +02:00
acpi_tad.c ACPI: Use DEVICE_ATTR_<RW|RO|WO> macros 2021-01-22 16:17:19 +01:00
acpi_video.c Merge branch 'acpi-misc' 2021-04-26 17:04:41 +02:00
acpi_watchdog.c ACPI: watchdog: Replace open coded variant of resource_union() 2020-11-17 18:06:29 +01:00
battery.c ACPI: battery: fix some coding style issues 2021-04-08 16:27:02 +02:00
bgrt.c ACPI: Use DEVICE_ATTR_<RW|RO|WO> macros 2021-01-22 16:17:19 +01:00
blacklist.c ACPI: blacklist: fix clang warning for unused DMI table 2019-07-11 22:45:00 +02:00
bus.c ACPI updates for 5.12-rc1 2021-02-20 21:50:59 -08:00
button.c ACPI: button: fix some coding style issues 2021-04-08 16:27:02 +02:00
container.c ACPI: container: Remove leftover ACPICA debug functionality 2020-09-25 18:25:51 +02:00
cppc_acpi.c Merge branch 'acpi-misc' 2021-04-26 17:04:41 +02:00
custom_method.c ACPI: custom_method: fix a possible memory leak 2021-04-28 19:17:54 +02:00
debugfs.c ACPI: debugfs: Remove dead ACPICA debug code 2020-09-25 18:25:51 +02:00
device_pm.c Merge branch 'acpi-pm' 2021-05-13 20:39:58 +02:00
device_sysfs.c ACPI: sysfs: Fix a buffer overrun problem with description_show() 2021-06-07 16:27:44 +02:00
dock.c ACPI: dock: fix some coding style issues 2021-04-08 16:27:03 +02:00
ec_sys.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 482 2019-06-19 17:09:52 +02:00
ec.c ACPI: EC: Clean up status flags checks in advance_transaction() 2020-11-23 20:01:01 +01:00
event.c ACPI: Fix whitespace inconsistencies 2020-11-09 19:08:06 +01:00
evged.c ACPI: GED: fix -Wformat 2020-11-09 19:25:20 +01:00
fan.c ACPI: fan: Initialize performance state sysfs attribute 2020-11-16 15:18:38 +01:00
glue.c ACPI: bus: Introduce acpi_dev_get() and reuse it in ACPI code 2021-04-13 15:41:11 +02:00
hed.c ACPI: HED: Drop unused ACPI_MODULE_NAME() definition 2021-03-08 16:51:48 +01:00
internal.h ACPI: power: Refine turning off unused power resources 2021-05-24 16:08:17 +02:00
ioapic.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
irq.c ACPI: irq: Prevent unregistering of GIC SGIs 2021-04-23 18:00:52 +01:00
Kconfig Merge branch 'acpi-tables' 2021-02-25 18:57:40 +01:00
Makefile Merge branch 'acpi-tables' 2021-02-25 18:57:40 +01:00
nvs.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 428 2019-06-05 17:37:16 +02:00
osi.c ACPI: OSI: Shoot duplicate word 2019-11-13 11:12:08 +01:00
osl.c ACPI: OSL: Clean up printing messages 2021-02-10 19:09:43 +01:00
pci_irq.c ACPI: PCI: IRQ: Consolidate printing diagnostic messages 2021-03-08 16:51:08 +01:00
pci_link.c ACPI: utils: Introduce acpi_evaluation_failure_warn() 2021-03-08 19:10:30 +01:00
pci_mcfg.c PCI: tegra: Add Tegra194 MCFG quirks for ECAM errata 2021-04-16 11:34:17 -05:00
pci_root.c PCI/ACPI: Clarify message about _OSC failure 2021-01-27 09:38:36 -06:00
pci_slot.c ACPI: PCI: Remove unused ACPICA debug code 2020-09-25 18:25:51 +02:00
platform_profile.c ACPI: platform: Add balanced-performance platform profile 2021-02-24 14:52:41 +01:00
power.c ACPI: power: Refine turning off unused power resources 2021-05-24 16:08:17 +02:00
pptt.c ACPI: PPTT: Consistently use unsigned int as parameter type 2020-01-07 11:46:36 +01:00
proc.c ACPI: proc: Remove dead ACPICA debug code 2020-09-25 18:25:51 +02:00
processor_core.c ACPI: processor: Remove dead ACPICA debug code 2020-09-25 18:25:51 +02:00
processor_driver.c ACPI: processor: Get rid of ACPICA message printing 2021-03-08 16:51:19 +01:00
processor_idle.c Merge branches 'acpi-pci' and 'acpi-processor' 2021-04-26 17:03:05 +02:00
processor_pdc.c ACPI: processor: Get rid of ACPICA message printing 2021-03-08 16:51:19 +01:00
processor_perflib.c Merge branch 'acpi-misc' 2021-04-26 17:04:41 +02:00
processor_thermal.c ACPI: processor: Remove the duplicated ACPI_PROCESSOR_CLASS macro 2020-11-17 18:12:34 +01:00
processor_throttling.c ACPI: utils: Introduce acpi_evaluation_failure_warn() 2021-03-08 19:10:30 +01:00
property.c ACPI: property: Satisfy kernel doc validator (part 2) 2021-02-12 15:34:14 +01:00
reboot.c ACPI: reboot: Avoid racing after writing to ACPI RESET_REG 2020-10-16 18:04:52 +02:00
resource.c ACPI: fix various typos in comments 2021-03-19 17:45:49 +01:00
sbs.c ACPI: SBS: Simplify the code using module_acpi_driver() 2020-11-17 18:12:34 +01:00
sbshc.c ACPI: Fix whitespace inconsistencies 2020-11-09 19:08:06 +01:00
sbshc.h ACPI: Fix whitespace inconsistencies 2020-11-09 19:08:06 +01:00
scan.c ACPI: power: Refine turning off unused power resources 2021-05-24 16:08:17 +02:00
sleep.c ACPI: power: Refine turning off unused power resources 2021-05-24 16:08:17 +02:00
sleep.h Revert "Revert "ACPI: scan: Turn off unused power resources during initialization"" 2021-05-10 14:02:17 +02:00
spcr.c ACPI: Use fallthrough pseudo-keyword 2020-07-09 14:09:28 +02:00
sysfs.c Merge branches 'acpi-pci' and 'acpi-processor' 2021-04-26 17:03:05 +02:00
tables.c ACPI: tables: x86: Reserve memory occupied by ACPI tables 2021-03-29 19:26:04 +02:00
thermal.c - Use the newly introduced 'hot' and 'critical' ops for the acpi 2021-02-22 09:39:11 -08:00
tiny-power-button.c ACPI: tiny-power-button: Simplify the code using module_acpi_driver() 2020-11-17 18:12:34 +01:00
utils.c Merge branches 'acpi-cppc', 'acpi-video' and 'acpi-utils' 2021-04-26 17:04:27 +02:00
video_detect.c ACPI: video: use native backlight for GA401/GA502/GA503 2021-04-21 18:54:41 +02:00
wakeup.c ACPI: Fix whitespace inconsistencies 2020-11-09 19:08:06 +01:00