From: Wu Fengguang <fengguang.wu@intel.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Wu Fengguang <fengguang.wu@intel.com>,
LKML <linux-kernel@vger.kernel.org>, Kelly Bowa <kmb@tuxedu.org>,
Greg KH <greg@kroah.com>, Andi Kleen <andi@firstfloor.org>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Christoph Lameter <cl@linux-foundation.org>,
Ingo Molnar <mingo@elte.hu>, Tejun Heo <tj@kernel.org>,
Nick Piggin <npiggin@suse.de>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
Hugh Dickins <hugh.dickins@tiscali.co.uk>,
Linux Memory Management List <linux-mm@kvack.org>
Subject: [PATCH 6/8] hwpoison: prevent /dev/kmem from accessing hwpoison pages
Date: Wed, 13 Jan 2010 21:53:11 +0800 [thread overview]
Message-ID: <20100113135957.985957389@intel.com> (raw)
In-Reply-To: 20100113135305.013124116@intel.com
[-- Attachment #1: hwpoison-dev-kmem.patch --]
[-- Type: text/plain, Size: 3986 bytes --]
When /dev/kmem read()/write() encounters hwpoison page, stop it
and return the amount of work done till now, or return -EIO if
nothing have been copied.
CC: Kelly Bowa <kmb@tuxedu.org>
CC: Greg KH <greg@kroah.com>
CC: Andi Kleen <andi@firstfloor.org>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: Christoph Lameter <cl@linux-foundation.org>
CC: Ingo Molnar <mingo@elte.hu>
CC: Tejun Heo <tj@kernel.org>
CC: Nick Piggin <npiggin@suse.de>
CC: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
drivers/char/mem.c | 26 ++++++++++++++++++++------
mm/vmalloc.c | 8 ++++++++
2 files changed, 28 insertions(+), 6 deletions(-)
--- linux-mm.orig/drivers/char/mem.c 2010-01-11 10:32:39.000000000 +0800
+++ linux-mm/drivers/char/mem.c 2010-01-11 10:32:42.000000000 +0800
@@ -426,6 +426,9 @@ static ssize_t read_kmem(struct file *fi
*/
kbuf = xlate_dev_kmem_ptr((char *)p);
+ if (unlikely(virt_addr_valid(kbuf) &&
+ PageHWPoison(virt_to_page(kbuf))))
+ return -EIO;
if (copy_to_user(buf, kbuf, sz))
return -EFAULT;
buf += sz;
@@ -447,8 +450,10 @@ static ssize_t read_kmem(struct file *fi
break;
}
sz = vread_page(kbuf, (char *)p, sz);
- if (!sz)
+ if (sz <= 0) {
+ err = sz;
break;
+ }
if (copy_to_user(buf, kbuf, sz)) {
err = -EFAULT;
break;
@@ -471,6 +476,7 @@ do_write_kmem(unsigned long p, const cha
{
ssize_t written, sz;
unsigned long copied;
+ int err = 0;
written = 0;
#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
@@ -497,13 +503,19 @@ do_write_kmem(unsigned long p, const cha
*/
ptr = xlate_dev_kmem_ptr((char *)p);
+ if (unlikely(virt_addr_valid(ptr) &&
+ PageHWPoison(virt_to_page(ptr)))) {
+ err = -EIO;
+ break;
+ }
+
copied = copy_from_user(ptr, buf, sz);
if (copied) {
written += sz - copied;
- if (written)
- break;
- return -EFAULT;
+ err = -EFAULT;
+ break;
}
+
buf += sz;
p += sz;
count -= sz;
@@ -511,7 +523,7 @@ do_write_kmem(unsigned long p, const cha
}
*ppos += written;
- return written;
+ return written ? written : err;
}
@@ -555,7 +567,9 @@ static ssize_t write_kmem(struct file *
err = -EFAULT;
break;
}
- vwrite_page(kbuf, (char *)p, sz);
+ err = vwrite_page(kbuf, (char *)p, sz);
+ if (err < 0)
+ break;
count -= sz;
buf += sz;
virtr += sz;
--- linux-mm.orig/mm/vmalloc.c 2010-01-11 10:32:39.000000000 +0800
+++ linux-mm/mm/vmalloc.c 2010-01-11 10:33:21.000000000 +0800
@@ -1654,6 +1654,7 @@ EXPORT_SYMBOL(vmalloc_32_user);
*
* Returns # of bytes copied on success.
* Returns 0 if @addr is not vmalloc'ed, or is mapped to non-RAM.
+ * Returns -EIO if the mapped page is corrupted.
*
* This function checks that addr is a valid vmalloc'ed area, and
* copy data from that area to a given buffer. If the given memory range
@@ -1684,6 +1685,10 @@ int vread_page(char *buf, char *addr, un
memset(buf, 0, count);
return 0;
}
+ if (PageHWPoison(p)) {
+ memset(buf, 0, count);
+ return -EIO;
+ }
/*
* To do safe access to this _mapped_ area, we need
@@ -1707,6 +1712,7 @@ int vread_page(char *buf, char *addr, un
*
* Returns # of bytes copied on success.
* Returns 0 if @addr is not vmalloc'ed, or is mapped to non-RAM.
+ * Returns -EIO if the mapped page is corrupted.
*
* This function checks that addr is a valid vmalloc'ed area, and
* copy data from a buffer to the given addr. If specified range of
@@ -1736,6 +1742,8 @@ int vwrite_page(char *buf, char *addr, u
return 0;
if (!page_is_ram(page_to_pfn(p)))
return 0;
+ if (PageHWPoison(p))
+ return -EIO;
map = kmap_atomic(p, KM_USER0);
memcpy(map + offset, buf, count);
--
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:[~2010-01-13 14:00 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-13 13:53 [PATCH 0/8] devmem/kmem/kcore fixes, cleanups and hwpoison checks Wu Fengguang
2010-01-13 13:53 ` [PATCH 1/8] vfs: fix too big f_pos handling Wu Fengguang
2010-01-13 13:53 ` [PATCH 2/8] devmem: check vmalloc address on kmem read/write Wu Fengguang
2010-01-13 13:53 ` [PATCH 3/8] devmem: fix kmem write bug on memory holes Wu Fengguang
2010-01-13 13:53 ` [PATCH 4/8] resources: introduce generic page_is_ram() Wu Fengguang
2010-01-13 14:29 ` Américo Wang
2010-01-14 3:29 ` Wu Fengguang
2010-01-13 13:53 ` [PATCH 5/8] vmalloc: simplify vread()/vwrite() Wu Fengguang
2010-01-14 12:45 ` Nick Piggin
2010-01-18 13:35 ` Wu Fengguang
2010-01-18 14:23 ` Nick Piggin
2010-01-19 1:33 ` Wu Fengguang
2010-01-19 2:23 ` KAMEZAWA Hiroyuki
2010-01-21 5:05 ` Wu Fengguang
2010-01-21 5:21 ` KAMEZAWA Hiroyuki
2010-01-21 5:49 ` Wu Fengguang
2010-01-13 13:53 ` Wu Fengguang [this message]
2010-01-13 13:53 ` [PATCH 7/8] hwpoison: prevent /dev/mem from accessing hwpoison pages Wu Fengguang
2010-01-13 13:53 ` [PATCH 8/8] hwpoison: prevent /dev/kcore " Wu Fengguang
2010-01-13 14:23 ` Américo Wang
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=20100113135957.985957389@intel.com \
--to=fengguang.wu@intel.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=benh@kernel.crashing.org \
--cc=cl@linux-foundation.org \
--cc=greg@kroah.com \
--cc=hugh.dickins@tiscali.co.uk \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kmb@tuxedu.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@elte.hu \
--cc=npiggin@suse.de \
--cc=tj@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;
as well as URLs for NNTP newsgroup(s).