lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20090915120939.bcc571e1.kamezawa.hiroyu@jp.fujitsu.com>
Date:	Tue, 15 Sep 2009 12:09:39 +0900
From:	KAMEZAWA Hiroyuki <kamezawa.hiroyu@...fujitsu.com>
To:	Wu Fengguang <fengguang.wu@...el.com>
Cc:	Andrew Morton <akpm@...ux-foundation.org>,
	Benjamin Herrenschmidt <benh@...nel.crashing.org>,
	Ingo Molnar <mingo@...e.hu>, Tejun Heo <tj@...nel.org>,
	Nick Piggin <npiggin@...e.de>,
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 0/3] /proc/kmem cleanups and hwpoison bits

On Tue, 15 Sep 2009 10:18:51 +0800
Wu Fengguang <fengguang.wu@...el.com> wrote:

> Hi Kame,
> 
> Here are 3 more kmem patches in my queue. Comments are welcome.
> If you feel good about them, I can send all recent kmem cleanup
> patches for you.
> 

This is my quick hack. But I don't want to be an obstacle for you.
So, I'll wait for your updates.

==
Now, /dev/kmem's read/write vmalloc area doesn't do
range-check. Because vread/vwrite traverse vmalloc area list
under system-wide spinlock, it's better to avoid unnecessary
to do unnecessary calls to vread/vwrite.

And, vread/vwrite returns 0 if we accessed memory holes.
We can avoid copy-to-user in read side, we just ignore at write.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@...fujitsu.com>
---
 drivers/char/mem.c |   27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

Index: linux-2.6.31/drivers/char/mem.c
===================================================================
--- linux-2.6.31.orig/drivers/char/mem.c
+++ linux-2.6.31/drivers/char/mem.c
@@ -437,17 +437,19 @@ static ssize_t read_kmem(struct file *fi
 	}
 
 	if (count > 0) {
-		kbuf = (char *)__get_free_page(GFP_KERNEL);
+		kbuf = (char *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
 		if (!kbuf)
 			return -ENOMEM;
 		while (count > 0) {
 			sz = size_inside_page(p, count);
-			sz = vread(kbuf, (char *)p, sz);
-			if (!sz)
-				break;
-			if (copy_to_user(buf, kbuf, sz)) {
-				free_page((unsigned long)kbuf);
-				return -EFAULT;
+			if (is_vmalloc_or_module_addr((void*)p)) {
+				/* returns Non-zero if a page is found */
+				if (vread(kbuf, (char *)p, sz))
+					if (copy_to_user(buf, kbuf, sz)) {
+						free_page((unsigned long)kbuf);
+						return -EFAULT;
+					}
+				}
 			}
 			count -= sz;
 			buf += sz;
@@ -541,6 +543,11 @@ static ssize_t write_kmem(struct file * 
 			unsigned long sz = size_inside_page(p, count);
 			unsigned long n;
 
+			if (is_vmalloc_or_module_addr((void*)p)) {
+				free_page((unsignedl long)kbuf);
+				retrun -EFAULT;
+			}
+
 			n = copy_from_user(kbuf, buf, sz);
 			if (n) {
 				if (wrote + virtr)
@@ -548,7 +555,11 @@ static ssize_t write_kmem(struct file * 
 				free_page((unsigned long)kbuf);
 				return -EFAULT;
 			}
-			sz = vwrite(kbuf, (char *)p, sz);
+			/*
+			 * returns non-zero if copied successfully....
+			 * But we don't care it. just make a progress.
+			 */
+			vwrite(kbuf, (char *)p, sz);
 			count -= sz;
 			buf += sz;
 			virtr += sz;


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ