Skip to contentSkip to conversation

PM / devfreq: Fix buffer overflow in trans_stat_show

PATCH In review Koichiro Den 1 participant 2 messages Aug 28, 2024 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 PM / devfreq: Fix buffer overflow in trans_stat_show

From: Christian Marangi <[email protected]>

Fix buffer overflow in trans_stat_show().

Convert simple snprintf to the more secure scnprintf with size of PAGE_SIZE.

Add condition checking if we are exceeding PAGE_SIZE and exit early from loop. Also add at the end a warning that we exceeded PAGE_SIZE and that stats is disabled.

Return -EFBIG in the case where we don't have enough space to write the full transition table.

Also document in the ABI that this function can return -EFBIG error.

Fixes e552bbaf5b98 ("PM / devfreq: Add sysfs node for representing frequency transition information.")
(backported from commit 08e23d05fa6dc4fc13da0ccf09defdd4bbc92ff4)

[koichiroden: Adjusted context due to missing commits:
commit b5d281f6c16d ("PM / devfreq: Rework freq_table to be local to devfreq struct") commit a03dacb0316f ("PM / devfreq: Add cpu based scaling support to passive governor") commit 483d557ee9a3 ("PM / devfreq: Clean up the devfreq instance name in sysfs attr") commit 1ebd0bc0e8ad ("PM / devfreq: Move statistics to separate struct devfreq_stats") commit 14a343968199 ("PM / devfreq: Add clearing transitions stats") commit b76b3479dab9 ("PM / devfreq: Change time stats to 64-bit")
commit 5c0f6c795957 ("PM / devfreq: Add new interrupt_driven flag for governors")]
CVE-2023-52614

---
 Documentation/ABI/testing/sysfs-class-devfreq |  2 +
 drivers/devfreq/devfreq.c                     | 60 +++++++++++++------
 2 files changed, 43 insertions(+), 19 deletions(-)
Documentation/ABI/testing/sysfs-class-devfreq +2 -0
index 75897e2fde43..f95b69551b60 100644
@@ -61,6 +61,8 @@ Description:
 		In order to activate this ABI, the devfreq target device
 		driver should provide the list of available frequencies
 		with its profile.
+		If the transition table is bigger than PAGE_SIZE, reading
+		this will return an -EFBIG error.
 
 What:		/sys/class/devfreq/.../userspace/set_freq
 Date:		September 2011
drivers/devfreq/devfreq.c +41 -19

85 lines not on this page · raw message

Signature · 1 line
2.43.0