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]
Date:   Wed, 11 May 2022 14:58:56 +0700
From:   Ammar Faizi <ammarfaizi2@...weeb.org>
To:     Andrew Morton <akpm@...ux-foundation.org>
Cc:     cgel.zte@...il.com, Kees Cook <keescook@...omium.org>,
        Matthew Wilcox <willy@...radead.org>,
        Yang Yang <yang.yang29@....com.cn>,
        Ran Xiaokai <ran.xiaokai@....com.cn>,
        Yunkai Zhang <zhang.yunkai@....com.cn>,
        xu xin <xu.xin16@....com.cn>,
        wangyong <wang.yong12@....com.cn>,
        Linux MM Mailing List <linux-mm@...ck.org>,
        Linux fsdevel Mailing List <linux-fsdevel@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v5] mm/ksm: introduce ksm_force for each process

On 5/11/22 3:30 AM, Andrew Morton wrote:
> On Wed, 11 May 2022 03:10:31 +0700 Ammar Faizi <ammarfaizi2@...weeb.org> wrote:
> 
>> On 5/8/22 4:27 PM, cgel.zte@...il.com wrote:
>>> +static ssize_t ksm_force_write(struct file *file, const char __user *buf,
>>> +				size_t count, loff_t *ppos)
>>> +{
>>> +	struct task_struct *task;
>>> +	struct mm_struct *mm;
>>> +	char buffer[PROC_NUMBUF];
>>> +	int force;
>>> +	int err = 0;
>>> +
>>> +	memset(buffer, 0, sizeof(buffer));
>>> +	if (count > sizeof(buffer) - 1)
>>> +		count = sizeof(buffer) - 1;
>>> +	if (copy_from_user(buffer, buf, count)) {
>>> +		err = -EFAULT;
>>> +		goto out_return;
>>> +	}
>>
>> This one looks like over-zeroing to me. You don't need to zero
>> all elements in the array. You're going to overwrite it with
>> `copy_from_user()` anyway.
>>
>> Just zero the last potentially useful element by using @count
>> as the index. It can be like this:
>>
>> ```
>> 	char buffer[PROC_NUMBUF];
>>
>> 	if (count > sizeof(buffer) - 1)
>> 		count = sizeof(buffer) - 1;
>> 	if (copy_from_user(buffer, buf, count))
>> 		return -EFAULT;
>> 	buffer[count] = '\0';
>> ```
> 
> Use strncpy_from_user()?

Sounds better.

> Can this code use proc_dointvec_minmax() or similar?

Not familiar with that API at all. Leaving it to other participants...

-- 
Ammar Faizi

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ