diff options
| author | Randolph <[email protected]> | 2026-07-29 17:23:17 +0800 |
|---|---|---|
| committer | Anup Patel <[email protected]> | 2026-09-01 10:59:55 +0530 |
| commit | 22a5f98b3965adb2c5b2224da7ec4590807a618a (patch) | |
| tree | cd3f9b5ac1e2d0abb8cc1843e6603b5004b9e79b /include | |
| parent | 06af8bd61b37bbf0db93adfa9902b176d0158ea1 (diff) | |
platform: generic/andes: fix 32-bit shift overflow in decode_pmaaddrx()
decode_pmaaddrx() reconstructs the NAPOT region start and size from a
pmaaddr CSR value using "1 << (k + 3)" and "1 << k". The integer
literal 1 has type int, so these shifts are performed in 32-bit
precision. Shifting a 32-bit value by 32 or more bits is undefined
behavior, and on RV64 the compiler emits sllw, which truncates the
shift amount modulo 32.
As a result, any PMA region with size >= 4 GiB (k >= 29) is decoded
incorrectly. For example, on the Andes QiLai SoC the PCIe region
0x1000000000 - 0x17ffffffff (pmaaddr = 0x4ffffffff, k = 32) is decoded
as an 8-byte region at 0x13fffffffc.
This is not merely cosmetic: decode_pmaaddrx() is used by
has_pma_region_overlap() and andes_sbi_free_pma(), so overlap checks
are performed against bogus ranges and freeing such an entry by its
physical address always fails.
Promote the shifts to unsigned long so they are performed in the
native register width.
Fixes: aa56084c4dfb ("platform: generic: andes: add a new Andes SBI call to set up a PMA entry")
Signed-off-by: Randolph Lin <[email protected]>
Tested-by: BenoƮt Monin <[email protected]>
Reviewed-by: Anup Patel <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Anup Patel <[email protected]>
Diffstat (limited to 'include')
0 files changed, 0 insertions, 0 deletions
