linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Cc: cgel.zte@gmail.com, Kees Cook <keescook@chromium.org>,
	Matthew Wilcox <willy@infradead.org>,
	Yang Yang <yang.yang29@zte.com.cn>,
	Ran Xiaokai <ran.xiaokai@zte.com.cn>,
	Yunkai Zhang <zhang.yunkai@zte.com.cn>,
	xu xin <xu.xin16@zte.com.cn>, wangyong <wang.yong12@zte.com.cn>,
	Linux MM Mailing List <linux-mm@kvack.org>,
	Linux fsdevel Mailing List <linux-fsdevel@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5] mm/ksm: introduce ksm_force for each process
Date: Tue, 10 May 2022 13:30:16 -0700	[thread overview]
Message-ID: <20220510133016.9feff1aeec1a7a9ae137a8c3@linux-foundation.org> (raw)
In-Reply-To: <435b5f7a-fcbd-f7ae-b66f-670e5997aa1b@gnuweeb.org>

On Wed, 11 May 2022 03:10:31 +0700 Ammar Faizi <ammarfaizi2@gnuweeb.org> wrote:

> On 5/8/22 4:27 PM, cgel.zte@gmail.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()?

Can this code use proc_dointvec_minmax() or similar?

  reply	other threads:[~2022-05-10 20:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-07  5:47 [PATCH v3] mm/ksm: introduce ksm_force for each process cgel.zte
2022-05-07 17:59 ` Andrew Morton
2022-05-08  9:14   ` [PATCH v4] " cgel.zte
2022-05-08  9:27   ` [PATCH v5] " cgel.zte
2022-05-08 18:03     ` Matthew Wilcox
2022-05-09  6:57       ` CGEL
2022-05-09 15:40         ` Matthew Wilcox
2022-05-10  2:23           ` CGEL
2022-05-10 20:10     ` Ammar Faizi
2022-05-10 20:30       ` Andrew Morton [this message]
2022-05-11  7:58         ` Ammar Faizi
2022-05-12  7:03           ` [PATCH v7] " cgel.zte
2022-05-12 20:41             ` Andrew Morton

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=20220510133016.9feff1aeec1a7a9ae137a8c3@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=ammarfaizi2@gnuweeb.org \
    --cc=cgel.zte@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ran.xiaokai@zte.com.cn \
    --cc=wang.yong12@zte.com.cn \
    --cc=willy@infradead.org \
    --cc=xu.xin16@zte.com.cn \
    --cc=yang.yang29@zte.com.cn \
    --cc=zhang.yunkai@zte.com.cn \
    /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 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).