From: Borislav Petkov <bp@alien8.de>
To: Dave Hansen <dave@sr71.net>
Cc: hpa@linux.intel.com, linux-kernel@vger.kernel.org, x86@kernel.org
Subject: Re: [PATCH 2/5] make /dev/kmem return error for highmem
Date: Thu, 11 Apr 2013 11:58:31 +0200 [thread overview]
Message-ID: <20130411095831.GB15924@pd.tnic> (raw)
In-Reply-To: <20130410233252.81839D50@viggo.jf.intel.com>
Just nitpicks:
On Wed, Apr 10, 2013 at 04:32:52PM -0700, Dave Hansen wrote:
>
> I was auding the /dev/mem code for more questionable uses of
auditing
> __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/
This is an upstream commit so you probably might want to state the
commit id here instead of some website which may or may not exist in the
future.
> Signed-off-by: Dave Hansen <dave@linux.vnet.ibm.com>
> Signed-off-by: Dave Hansen <dave.hansen@linux.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;
drivers/char/mem.c: In function ‘mmap_kmem’:
drivers/char/mem.c:348:19: warning: comparison between pointer and integer [enabled by default]
> /* 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
> _
>
--
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--
next prev parent reply other threads:[~2013-04-11 9:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-10 23:32 [PATCH 0/5] [RFC] rework /dev/mem code vs. highmem and DEBUG_VIRTUAL Dave Hansen
2013-04-10 23:32 ` [PATCH 1/5] clean up checks against "high_memory" variable Dave Hansen
2013-04-11 0:44 ` Borislav Petkov
2013-04-10 23:32 ` [PATCH 2/5] make /dev/kmem return error for highmem Dave Hansen
2013-04-11 9:58 ` Borislav Petkov [this message]
2013-04-10 23:32 ` [PATCH 3/5] avoid /dev/kmem oopses with DEBUG_VIRTUAL Dave Hansen
2013-04-10 23:32 ` [PATCH 4/5] break up slow_virt_to_phys() Dave Hansen
2013-04-11 12:29 ` Borislav Petkov
2013-04-11 16:28 ` Dave Hansen
2013-04-11 17:12 ` Borislav Petkov
2013-04-10 23:32 ` [PATCH 5/5] keep /dev/kmem from triggering BUG_ON() with DEBUG_VIRTUAL Dave Hansen
2013-04-11 12:37 ` Borislav Petkov
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=20130411095831.GB15924@pd.tnic \
--to=bp@alien8.de \
--cc=dave@sr71.net \
--cc=hpa@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=x86@kernel.org \
/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
all inboxes | Powered by JetHome®