]> www.infradead.org Git - users/jedix/linux-maple.git/commit
cpufreq: sun50i: prevent out-of-bounds access
authorAndre Przywara <andre.przywara@arm.com>
Thu, 20 Mar 2025 15:55:57 +0000 (15:55 +0000)
committerViresh Kumar <viresh.kumar@linaro.org>
Tue, 8 Apr 2025 06:05:30 +0000 (11:35 +0530)
commit14c8a418159e541d70dbf8fc71225d1623beaf0f
tree3940593989152e15bc3c4cfa6e643d0f0e9dc66d
parent0af2f6be1b4281385b618cb86ad946eded089ac8
cpufreq: sun50i: prevent out-of-bounds access

A KASAN enabled kernel reports an out-of-bounds access when handling the
nvmem cell in the sun50i cpufreq driver:
==================================================================
BUG: KASAN: slab-out-of-bounds in sun50i_cpufreq_nvmem_probe+0x180/0x3d4
Read of size 4 at addr ffff000006bf31e0 by task kworker/u16:1/38

This is because the DT specifies the nvmem cell as covering only two
bytes, but we use a u32 pointer to read the value. DTs for other SoCs
indeed specify 4 bytes, so we cannot just shorten the variable to a u16.

Fortunately nvmem_cell_read() allows to return the length of the nvmem
cell, in bytes, so we can use that information to only access the valid
portion of the data.
To cover multiple cell sizes, use memcpy() to copy the information into a
zeroed u32 buffer, then also make sure we always read the data in little
endian fashion, as this is how the data is stored in the SID efuses.

Fixes: 6cc4bcceff9a ("cpufreq: sun50i: Refactor speed bin decoding")
Reported-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Jernej Škrabec <jernej.skrabec@gmail.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
drivers/cpufreq/sun50i-cpufreq-nvmem.c