Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1429778
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] memory:bugxfix panic on cat or write /dev/kmem |
| Date | 2016-06-23 14:50 +0200 |
| Message-ID | <rNceZ-1AV-9@gated-at.bofh.it> (permalink) |
| References | <rN97r-7UZ-9@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Fri 24-06-16 01:30:10, chenjie6@huawei.com wrote:
> From: chenjie <chenjie6@huawei.com>
>
> cat /dev/kmem and echo > /dev/kmem will lead panic
Writing to /dev/kmem without being extremely careful is a disaster AFAIK
and even reading from the file can lead to unexpected results. Anyway
I am trying to understand what exactly you are trying to fix here. Why
writing to/reading from zero pfn should be any special wrt. any other
potentially dangerous addresses
>
> Signed-off-by: chenjie <chenjie6@huawei.com>
> ---
> drivers/char/mem.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/char/mem.c b/drivers/char/mem.c
> index 71025c2..4bdde28 100644
> --- a/drivers/char/mem.c
> +++ b/drivers/char/mem.c
> @@ -412,6 +412,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
> * by the kernel or data corruption may occur
> */
> kbuf = xlate_dev_kmem_ptr((void *)p);
> + if (!kbuf)
> + return -EFAULT;
>
> if (copy_to_user(buf, kbuf, sz))
> return -EFAULT;
> @@ -482,6 +484,11 @@ static ssize_t do_write_kmem(unsigned long p, const char __user *buf,
> * corruption may occur.
> */
> ptr = xlate_dev_kmem_ptr((void *)p);
> + if (!ptr) {
> + if (written)
> + break;
> + return -EFAULT;
> + }
>
> copied = copy_from_user(ptr, buf, sz);
> if (copied) {
> --
> 1.8.0
>
> --
> 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>
--
Michal Hocko
SUSE Labs
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH] memory:bugxfix panic on cat or write /dev/kmem <chenjie6@huawei.com> - 2016-06-23 11:30 +0200
Re: [PATCH] memory:bugxfix panic on cat or write /dev/kmem Michal Hocko <mhocko@kernel.org> - 2016-06-23 14:50 +0200
Re: [PATCH] memory:bugxfix panic on cat or write /dev/kmem "Chenjie (K)" <chenjie6@huawei.com> - 2016-06-25 03:30 +0200
Re: [PATCH] memory:bugxfix panic on cat or write /dev/kmem Michal Hocko <mhocko@kernel.org> - 2016-06-27 13:40 +0200
csiph-web