All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Robin Murphy <robin.murphy@arm.com>
Cc: Jason@zx2c4.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] drivers: char: mem: Fix thinko in kmem address checks
Date: Wed, 4 Jan 2017 12:45:32 +0100	[thread overview]
Message-ID: <20170104114532.GA6449@kroah.com> (raw)
In-Reply-To: <641a72e66f81d1244d8420074bc5def88d3929d4.1483529604.git.robin.murphy@arm.com>

On Wed, Jan 04, 2017 at 11:37:49AM +0000, Robin Murphy wrote:
> When borrowing the pfn_valid() check from mmap_kmem(), somebody managed

"sombody"?  :)

> to get physical and virtual addresses spectacularly muddled up, such
> that we've ended up with checks for one being the other. Whilst this
> does indeed prevent out-of-bounds accesses crashing, on most systems it
> also prevents the more desirable use-case of working at all ever.
> 
> Check the *virtual* offset correctly for what it is.
> 
> Reported-by: Jason A. Donenfeld <Jason@zx2c4.com>
> CC: stable@vger.kernel.org
> Fixes: 148a1bc84398 ("drivers: char: mem: Check {read,write}_kmem() addresses")
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> ---
>  drivers/char/mem.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/mem.c b/drivers/char/mem.c
> index 5bb1985ec484..bdc6a4018604 100644
> --- a/drivers/char/mem.c
> +++ b/drivers/char/mem.c
> @@ -381,7 +381,7 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
>  	char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
>  	int err = 0;
>  
> -	if (!pfn_valid(PFN_DOWN(p)))
> +	if (!virt_addr_valid(p))
>  		return -EIO;
>  
>  	read = 0;
> @@ -512,7 +512,7 @@ static ssize_t write_kmem(struct file *file, const char __user *buf,
>  	char *kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
>  	int err = 0;
>  
> -	if (!pfn_valid(PFN_DOWN(p)))
> +	if (!virt_addr_valid(p))
>  		return -EIO;
>  
>  	if (p < (unsigned long) high_memory) {

Jason, can you verify this fixes your test case?

thanks,

greg k-h

  reply	other threads:[~2017-01-04 11:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-04 11:37 [PATCH] drivers: char: mem: Fix thinko in kmem address checks Robin Murphy
2017-01-04 11:45 ` Greg KH [this message]
2017-01-04 17:19   ` Greg KH
2017-01-04 16:46 ` kbuild test robot
2017-01-05 17:15 ` [PATCH v2] drivers: char: mem: Fix thinkos " Robin Murphy
2017-01-10 17:49   ` Greg KH
2017-01-11 19:18     ` Jason A. Donenfeld

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=20170104114532.GA6449@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=Jason@zx2c4.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=stable@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.