linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] memory:bugxfix panic on cat or write /dev/kmem
  2016-06-23 17:30 [PATCH] memory:bugxfix panic on cat or write /dev/kmem chenjie6
@ 2016-06-23 12:42 ` Michal Hocko
  2016-06-25  1:20   ` Chenjie (K)
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Hocko @ 2016-06-23 12:42 UTC (permalink / raw)
  To: chenjie6
  Cc: linux-mm, linux-kernel, David.Woodhouse, zhihui.gao, panxuesong, akpm

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] memory:bugxfix panic on cat or write /dev/kmem
@ 2016-06-23 17:30 chenjie6
  2016-06-23 12:42 ` Michal Hocko
  0 siblings, 1 reply; 4+ messages in thread
From: chenjie6 @ 2016-06-23 17:30 UTC (permalink / raw)
  To: linux-mm, linux-kernel, David.Woodhouse, zhihui.gao, panxuesong
  Cc: akpm, chenjie

From: chenjie <chenjie6@huawei.com>

cat /dev/kmem and echo > /dev/kmem will lead panic

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] memory:bugxfix panic on cat or write /dev/kmem
  2016-06-23 12:42 ` Michal Hocko
@ 2016-06-25  1:20   ` Chenjie (K)
  2016-06-27 11:37     ` Michal Hocko
  0 siblings, 1 reply; 4+ messages in thread
From: Chenjie (K) @ 2016-06-25  1:20 UTC (permalink / raw)
  To: Michal Hocko
  Cc: linux-mm, akpm, linux-kernel, David.Woodhouse, zhihui.gao,
	panxuesong, akpm



On 2016/6/23 20:42, Michal Hocko wrote:
> 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
>

cat /dev/mem not panic. cat /dev/kmem, just the user's operation for 
nothing.

>>
>> 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>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] memory:bugxfix panic on cat or write /dev/kmem
  2016-06-25  1:20   ` Chenjie (K)
@ 2016-06-27 11:37     ` Michal Hocko
  0 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2016-06-27 11:37 UTC (permalink / raw)
  To: Chenjie (K)
  Cc: linux-mm, akpm, linux-kernel, David.Woodhouse, zhihui.gao, panxuesong

On Sat 25-06-16 09:20:06, Chenjie (K) wrote:
> 
> 
> On 2016/6/23 20:42, Michal Hocko wrote:
> > 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
> > 
> 
> cat /dev/mem not panic. cat /dev/kmem, just the user's operation for
> nothing.

I am sorry, but I do not follow. Could you be more specific please?
-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-06-27 11:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-23 17:30 [PATCH] memory:bugxfix panic on cat or write /dev/kmem chenjie6
2016-06-23 12:42 ` Michal Hocko
2016-06-25  1:20   ` Chenjie (K)
2016-06-27 11:37     ` Michal Hocko

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).