From: KAMEZAWA Hiroyuki Otherwise vmalloc_to_page() will BUG(). This also makes the kmem read/write implementation aligned with mem(4): "References to nonexistent locations cause errors to be returned." Here we return -ENXIO (inspired by Hugh) if no bytes have been transfered to/from user space, otherwise return partial read/write results. CC: Greg Kroah-Hartman CC: Hugh Dickins Signed-off-by: KAMEZAWA Hiroyuki Signed-off-by: Wu Fengguang --- drivers/char/mem.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- linux-mm.orig/drivers/char/mem.c 2009-09-16 08:52:17.000000000 +0800 +++ linux-mm/drivers/char/mem.c 2009-09-16 09:15:03.000000000 +0800 @@ -443,6 +443,10 @@ static ssize_t read_kmem(struct file *fi return -ENOMEM; while (count > 0) { sz = size_inside_page(p, count); + if (!is_vmalloc_or_module_addr((void *)p)) { + err = -ENXIO; + break; + } err = vread(kbuf, (char *)p, sz); if (err) break; @@ -543,6 +547,10 @@ 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)) { + err = -ENXIO; + break; + } n = copy_from_user(kbuf, buf, sz); if (n) { err = -EFAULT; -- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/