public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yury Norov <ynorov@nvidia.com>
To: Fushuai Wang <fushuai.wang@linux.dev>
Cc: tglx@kernel.org, peterz@infradead.org,
	mathieu.desnoyers@efficios.com, akpm@linux-foundation.org,
	aliceryhl@google.com, yury.norov@gmail.com, vmalik@redhat.com,
	kees@kernel.org, dave.hansen@linux.intel.com, luto@kernel.org,
	mingo@redhat.com, bp@alien8.de, hpa@zytor.com,
	rostedt@goodmis.org, mhiramat@kernel.org, brauner@kernel.org,
	jack@suse.cz, cyphar@cyphar.com, linux-kernel@vger.kernel.org,
	x86@kernel.org, linux-trace-kernel@vger.kernel.org,
	wangfushuai@baidu.com
Subject: Re: [PATCH v2 3/6] tracing: Use copy_from_user_nul() instead of copy_from_user()
Date: Tue, 13 Jan 2026 12:05:13 -0500	[thread overview]
Message-ID: <aWZ7SXpUm8TwtUIT@yury> (raw)
In-Reply-To: <20260112073039.1185-4-fushuai.wang@linux.dev>

On Mon, Jan 12, 2026 at 03:30:36PM +0800, Fushuai Wang wrote:
> From: Fushuai Wang <wangfushuai@baidu.com>
> 
> Use copy_from_user_nul() instead of copy_from_user() to simplify
> the code.
> 
> No functional change.
> 
> Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
> ---
>  kernel/trace/trace.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index baec63134ab6..b6ffd006fcf9 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -11266,10 +11266,9 @@ ssize_t trace_parse_run_command(struct file *file, const char __user *buffer,
>  		if (size >= WRITE_BUFSIZE)
>  			size = WRITE_BUFSIZE - 1;
>  
> -		if (copy_from_user(kbuf, buffer + done, size))
> +		if (copy_from_user_nul(kbuf, buffer + done, size))
>  			return -EFAULT;

This hides the original error. Can you switch it to:

                err = copy_xxx();
                if (err)
                        return err;

I understand that in this case EFAULT is the only possible error, but
the above pattern is really error-prone, and is reproduced again and
again over the kernel.

> -		kbuf[size] = '\0';
>  		buf = kbuf;
>  		do {
>  			tmp = strchr(buf, '\n');
> -- 
> 2.36.1

  parent reply	other threads:[~2026-01-13 17:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-12  7:30 [PATCH v2 0/6] uaccess: Introduce copy_from_user_nul helper Fushuai Wang
2026-01-12  7:30 ` [PATCH v2 1/6] uaccess: Add " Fushuai Wang
2026-01-12  9:23   ` Alice Ryhl
2026-01-12 10:00     ` Fushuai Wang
2026-01-12 11:20       ` Alice Ryhl
2026-01-12 12:22         ` Fushuai Wang
2026-01-12 13:22           ` Borislav Petkov
2026-01-12 15:40             ` Alice Ryhl
2026-01-12 16:28               ` Steven Rostedt
2026-01-12 16:37                 ` Alice Ryhl
2026-01-13 18:00   ` Yury Norov
2026-01-13 18:17     ` Yury Norov
2026-01-16  8:42     ` Fushuai Wang
2026-01-12  7:30 ` [PATCH v2 2/6] x86/tlb: Use copy_from_user_nul() instead of copy_from_user() Fushuai Wang
2026-01-12  7:30 ` [PATCH v2 3/6] tracing: " Fushuai Wang
2026-01-12 15:43   ` Steven Rostedt
2026-01-13 17:05   ` Yury Norov [this message]
2026-01-13 18:03     ` Steven Rostedt
2026-01-12  7:30 ` [PATCH v2 4/6] userns: " Fushuai Wang
2026-01-12  7:30 ` [PATCH v2 5/6] time: " Fushuai Wang
2026-01-12  7:30 ` [PATCH v2 6/6] kstrtox: " Fushuai Wang

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=aWZ7SXpUm8TwtUIT@yury \
    --to=ynorov@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=aliceryhl@google.com \
    --cc=bp@alien8.de \
    --cc=brauner@kernel.org \
    --cc=cyphar@cyphar.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=fushuai.wang@linux.dev \
    --cc=hpa@zytor.com \
    --cc=jack@suse.cz \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@kernel.org \
    --cc=vmalik@redhat.com \
    --cc=wangfushuai@baidu.com \
    --cc=x86@kernel.org \
    --cc=yury.norov@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox