Skip to content

Commit 854f326

Browse files
Liang Wangtorvalds
authored andcommitted
lib: use PFN_PHYS() in devmem_is_allowed()
The physical address may exceed 32 bits on 32-bit systems with more than 32 bits of physcial address. Use PFN_PHYS() in devmem_is_allowed(), or the physical address may overflow and be truncated. We found this bug when mapping a high addresses through devmem tool, when CONFIG_STRICT_DEVMEM is enabled on the ARM with ARM_LPAE and devmem is used to map a high address that is not in the iomem address range, an unexpected error indicating no permission is returned. This bug was initially introduced from v2.6.37, and the function was moved to lib in v5.11. Link: https://lkml.kernel.org/r/[email protected] Fixes: 087aaff ("ARM: implement CONFIG_STRICT_DEVMEM by disabling access to RAM via /dev/mem") Fixes: 527701e ("lib: Add a generic version of devmem_is_allowed()") Signed-off-by: Liang Wang <[email protected]> Reviewed-by: Luis Chamberlain <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Russell King <[email protected]> Cc: Liang Wang <[email protected]> Cc: Xiaoming Ni <[email protected]> Cc: Kefeng Wang <[email protected]> Cc: <[email protected]> [2.6.37+] Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7fa0dac commit 854f326

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/devmem_is_allowed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
int devmem_is_allowed(unsigned long pfn)
2121
{
22-
if (iomem_is_exclusive(pfn << PAGE_SHIFT))
22+
if (iomem_is_exclusive(PFN_PHYS(pfn)))
2323
return 0;
2424
if (!page_is_ram(pfn))
2525
return 1;

0 commit comments

Comments
 (0)