All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: Re: [PATCH] Revert "drivers: char: mem: Check {read,write}_kmem() addresses"
Date: Wed, 4 Jan 2017 10:22:11 +0100	[thread overview]
Message-ID: <20170104092211.GA31677@kroah.com> (raw)
In-Reply-To: <20170103205052.30517-1-Jason@zx2c4.com>

On Tue, Jan 03, 2017 at 09:50:52PM +0100, Jason A. Donenfeld wrote:
> This reverts commit 148a1bc84398039e2b96ff78678c4d9a67f81452.
> 
> This commit was intended to fix a problem, but it did not do so
> correctly, resulting in /dev/kmem being entirely broken. So, revert this
> commit until a different solution is found. The following PoC shows
> breakage bisecting to this commit. On working systems, it returns 0 and
> prints the last message. On broken systems containing this commit, it
> exits returning EIO.
> 
>   #define _FILE_OFFSET_BITS 64
>   #include <unistd.h>
>   #include <fcntl.h>
>   #include <stdio.h>
>   #include <string.h>
>   #include <stdlib.h>
>   #include <errno.h>
>   #include <sys/types.h>
>   #include <sys/socket.h>
>   #include <netinet/in.h>
> 
>   int main(int argc, char *argv[])
>   {
>   	int fd, sock;
>   	FILE *f;
>   	char line[256], *ptr;
>   	unsigned long addr = 0;
>   	struct sockaddr_in saddr = { .sin_family = AF_INET, .sin_port = 55193 };
> 
>   	sock = socket(AF_INET, SOCK_DGRAM, 0);
>   	if (sock < 0) {
>   		perror("socket");
>   		return errno;
>   	}
>   	if (bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
>   		perror("bind");
>   		return errno;
>   	}
>   	f = fopen("/proc/net/udp", "r");
>   	if (!f) {
>   		perror("fopen(/proc/net/udp)");
>   		return errno;
>   	}
>   	if (!fgets(line, 256, f) || !fgets(line, 256, f)) {
>   		perror("fgets");
>   		return errno;
>   	}
>   	fclose(f);
>   	ptr = line + strlen(line) - 1;
>   	while (*--ptr == ' ');
>   	while (*--ptr != ' ');
>   	while (*(--ptr - 1) != ' ');
>   	addr = strtoul(ptr, NULL, 16);
> 
>   	printf("Attempting to read from skbuff at 0x%lx\n", addr);
> 
>   	fd = open("/dev/kmem", O_RDONLY);
>   	if (fd < 0) {
>   		perror("open(/dev/kmem)");
>   		return errno;
>   	}
>   	if (lseek(fd, addr, SEEK_SET) == (off_t)-1) {
>   		perror("lseek");
>   		return errno;
>   	}
>   	if (read(fd, &addr, sizeof(addr)) != sizeof(addr)) {
>   		perror("read");
>   		return errno;
>   	}
> 
>   	printf("It worked, reading the value %lx!\n", addr);
>   	close(fd);
>   	close(sock);
>   	return 0;
>   }
> 
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  drivers/char/mem.c | 6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/drivers/char/mem.c b/drivers/char/mem.c
> index 5bb1985ec484..a33163dbb913 100644
> --- a/drivers/char/mem.c
> +++ b/drivers/char/mem.c
> @@ -381,9 +381,6 @@ 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)))
> -		return -EIO;
> -
>  	read = 0;
>  	if (p < (unsigned long) high_memory) {
>  		low_count = count;
> @@ -512,9 +509,6 @@ 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)))
> -		return -EIO;
> -
>  	if (p < (unsigned long) high_memory) {
>  		unsigned long to_write = min_t(unsigned long, count,
>  					       (unsigned long)high_memory - p);

Ick, I hate /dev/kmem...

Robin and Kefeng, any comments?  Reverting seems correct at this point
in time, any objection?

thanks,

greg k-h

  reply	other threads:[~2017-01-04  9:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-03 20:50 [PATCH] Revert "drivers: char: mem: Check {read,write}_kmem() addresses" Jason A. Donenfeld
2017-01-04  9:22 ` Greg KH [this message]
2017-01-04 11:32   ` Robin Murphy

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=20170104092211.GA31677@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=Jason@zx2c4.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=wangkefeng.wang@huawei.com \
    /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.