From: Dave Hansen <dave@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, bp@alien8.de, hpa@zytor.com,
mingo@kernel.org, tglx@linutronix.de,
Dave Hansen <dave@linux.vnet.ibm.com>
Subject: [PATCH 2/2] make /dev/kmem return error for highmem
Date: Fri, 08 Feb 2013 12:28:14 -0800 [thread overview]
Message-ID: <20130208202814.E1196596@kernel.stglabs.ibm.com> (raw)
In-Reply-To: <20130208202813.62965F25@kernel.stglabs.ibm.com>
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@linux.vnet.ibm.com>
---
linux-2.6.git-dave/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-2.6.git/drivers/char/mem.c~make-kmem-return-error-for-highmem 2013-02-08 12:27:57.033770045 -0800
+++ linux-2.6.git-dave/drivers/char/mem.c 2013-02-08 12:27:57.041770125 -0800
@@ -337,10 +337,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
diff -puN mm/nommu.c~make-kmem-return-error-for-highmem mm/nommu.c
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2013-02-08 20:28 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-08 20:28 [PATCH 1/2] add helper for highmem checks Dave Hansen
2013-02-08 20:28 ` Dave Hansen [this message]
2013-02-08 20:48 ` [PATCH 2/2] make /dev/kmem return error for highmem H. Peter Anvin
2013-02-08 20:50 ` [PATCH 1/2] add helper for highmem checks H. Peter Anvin
2013-02-08 23:16 ` Dave Hansen
2013-02-09 9:41 ` Borislav Petkov
2013-02-09 10:47 ` Borislav Petkov
2013-02-11 17:32 ` Dave Hansen
2013-02-11 18:09 ` H. Peter Anvin
2013-02-11 18:28 ` Borislav Petkov
2013-02-11 19:44 ` H. Peter Anvin
2013-02-11 22:34 ` Borislav Petkov
2013-02-11 22:46 ` H. Peter Anvin
2013-02-11 23:00 ` Borislav Petkov
2013-02-11 23:02 ` H. Peter Anvin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130208202814.E1196596@kernel.stglabs.ibm.com \
--to=dave@linux.vnet.ibm.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox