[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20130410233252.81839D50@viggo.jf.intel.com>
Date: Wed, 10 Apr 2013 16:32:52 -0700
From: Dave Hansen <dave@...1.net>
To: bp@...en8.de
Cc: hpa@...ux.intel.com, linux-kernel@...r.kernel.org, x86@...nel.org,
Dave Hansen <dave@...1.net>
Subject: [PATCH 2/5] make /dev/kmem return error for highmem
I was auding the /dev/mem code for more questionable uses of
__pa(), and ran across this.
My assumption is that if you use /dev/kmem, you expect to be
able to read the kernel virtual mappings. However, those
mappings _stop_ as soon as we hit high memory. The
pfn_valid() check in here is good for memory holes, but since
highmem pages are still valid, it does no good for those.
Also, since we are now checking that __pa() is being done on
valid virtual addresses, this might have tripped the new
check. Even with the new check, this code would have been
broken with the NUMA remapping code had we not ripped it
out:
https://patchwork.kernel.org/patch/2075911/
Signed-off-by: Dave Hansen <dave@...ux.vnet.ibm.com>
Signed-off-by: Dave Hansen <dave.hansen@...ux.intel.com>
---
linux.git-davehans/drivers/char/mem.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff -puN drivers/char/mem.c~make-kmem-return-error-for-highmem drivers/char/mem.c
--- linux.git/drivers/char/mem.c~make-kmem-return-error-for-highmem 2013-04-10 16:23:45.151087081 -0700
+++ linux.git-davehans/drivers/char/mem.c 2013-04-10 16:23:45.154087084 -0700
@@ -336,10 +336,19 @@ static int mmap_mem(struct file *file, s
#ifdef CONFIG_DEVKMEM
static int mmap_kmem(struct file *file, struct vm_area_struct *vma)
{
+ unsigned long kernel_vaddr;
unsigned long pfn;
+ kernel_vaddr = (u64)vma->vm_pgoff << PAGE_SHIFT;
+ /*
+ * pfn_valid() (below) does not trip for highmem addresses. This
+ * essentially means that we will be mapping gibberish in for them
+ * instead of what the _kernel_ has mapped at the requested address.
+ */
+ if (kernel_vaddr >= high_memory)
+ return -EIO;
/* Turn a kernel-virtual address into a physical page frame */
- pfn = __pa((u64)vma->vm_pgoff << PAGE_SHIFT) >> PAGE_SHIFT;
+ pfn = __pa(kernel_vaddr) >> PAGE_SHIFT;
/*
* RED-PEN: on some architectures there is more mapped memory than
_
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists