Skip to content

Commit 50c6dbd

Browse files
max8rr8hansendc
authored andcommitted
x86/ioremap: Improve iounmap() address range checks
Allowing iounmap() on memory that was not ioremap()'d in the first place is obviously a bad idea. There is currently a feeble attempt to avoid errant iounmap()s by checking to see if the address is below "high_memory". But that's imprecise at best because there are plenty of high addresses that are also invalid to call iounmap() on. Thankfully, there is a more precise helper: is_ioremap_addr(). x86 just does not use it in iounmap(). Restrict iounmap() to addresses in the ioremap region, by using is_ioremap_addr(). This aligns x86 closer to the generic iounmap() implementation. Additionally, add a warning in case there is an attempt to iounmap() invalid memory. This replaces an existing silent return and will help alert folks to any incorrect usage of iounmap(). Due to VMALLOC_START on i386 not being present in asm/pgtable.h, include for asm/vmalloc.h had to be added to include/linux/ioremap.h. [ dhansen: tweak subject and changelog ] Signed-off-by: Max Ramanouski <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Alistair Popple <[email protected]> Link: https://lore.kernel.org/all/20240824220111.84441-1-max8rr8%40gmail.com
1 parent d4245fd commit 50c6dbd

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

arch/x86/mm/ioremap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/init.h>
1212
#include <linux/io.h>
1313
#include <linux/ioport.h>
14+
#include <linux/ioremap.h>
1415
#include <linux/slab.h>
1516
#include <linux/vmalloc.h>
1617
#include <linux/mmiotrace.h>
@@ -457,7 +458,7 @@ void iounmap(volatile void __iomem *addr)
457458
{
458459
struct vm_struct *p, *o;
459460

460-
if ((void __force *)addr <= high_memory)
461+
if (WARN_ON_ONCE(!is_ioremap_addr((void __force *)addr)))
461462
return;
462463

463464
/*

include/linux/ioremap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <linux/kasan.h>
66
#include <asm/pgtable.h>
7+
#include <asm/vmalloc.h>
78

89
#if defined(CONFIG_HAS_IOMEM) || defined(CONFIG_GENERIC_IOREMAP)
910
/*

0 commit comments

Comments
 (0)