All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Chenjie (K)" <chenjie6@huawei.com>
To: Michal Hocko <mhocko@kernel.org>
Cc: linux-mm@kvack.org, akpm@linux-foundation.org,
	linux-kernel@vger.kernel.org, David.Woodhouse@intel.com,
	zhihui.gao@huawei.com,
	panxuesong@huawei.comakpm@linux-foundation.org
Subject: Re: [PATCH] memory:bugxfix panic on cat or write /dev/kmem
Date: Sat, 25 Jun 2016 09:20:06 +0800	[thread overview]
Message-ID: <576DDC46.6050607@huawei.com> (raw)
In-Reply-To: <20160623124257.GB30082@dhcp22.suse.cz>



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

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

WARNING: multiple messages have this Message-ID (diff)
From: "Chenjie (K)" <chenjie6@huawei.com>
To: Michal Hocko <mhocko@kernel.org>
Cc: <linux-mm@kvack.org>, <akpm@linux-foundation.org>,
	<linux-kernel@vger.kernel.org>, <David.Woodhouse@intel.com>,
	<zhihui.gao@huawei.com>, <panxuesong@huawei.com>,
	<akpm@linux-foundation.org>
Subject: Re: [PATCH] memory:bugxfix panic on cat or write /dev/kmem
Date: Sat, 25 Jun 2016 09:20:06 +0800	[thread overview]
Message-ID: <576DDC46.6050607@huawei.com> (raw)
In-Reply-To: <20160623124257.GB30082@dhcp22.suse.cz>



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

  reply	other threads:[~2016-06-25  1:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-23 17:30 [PATCH] memory:bugxfix panic on cat or write /dev/kmem chenjie6
2016-06-23 17:30 ` chenjie6
2016-06-23 12:42 ` Michal Hocko
2016-06-23 12:42   ` Michal Hocko
2016-06-25  1:20   ` Chenjie (K) [this message]
2016-06-25  1:20     ` Chenjie (K)
2016-06-27 11:37     ` Michal Hocko
2016-06-27 11:37       ` Michal Hocko

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=576DDC46.6050607@huawei.com \
    --to=chenjie6@huawei.com \
    --cc=David.Woodhouse@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=panxuesong@huawei.comakpm \
    --cc=zhihui.gao@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.