From: Alice Ryhl <aliceryhl@google.com>
To: Borislav Petkov <bp@alien8.de>
Cc: Fushuai Wang <fushuai.wang@linux.dev>,
akpm@linux-foundation.org, brauner@kernel.org,
cyphar@cyphar.com, dave.hansen@linux.intel.com, hpa@zytor.com,
jack@suse.cz, kees@kernel.org, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, luto@kernel.org,
mathieu.desnoyers@efficios.com, mhiramat@kernel.org,
mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org,
tglx@kernel.org, vmalik@redhat.com, wangfushuai@baidu.com,
x86@kernel.org, yury.norov@gmail.com
Subject: Re: [PATCH v2 1/6] uaccess: Add copy_from_user_nul helper
Date: Mon, 12 Jan 2026 15:40:53 +0000 [thread overview]
Message-ID: <aWUWBfKhP8DvzhDl@google.com> (raw)
In-Reply-To: <20260112132238.GDaWT1ntPxY8VD1hlH@fat_crate.local>
On Mon, Jan 12, 2026 at 02:22:38PM +0100, Borislav Petkov wrote:
> On Mon, Jan 12, 2026 at 08:22:36PM +0800, Fushuai Wang wrote:
> > > strncpy_from_user() succeeds even if userspace data does not contain a
> > > nul. Then it reads length bytes.
> >
> > Yes, but if there is no NUL byte in the user buf, whether you use
> > strncpy_from_user() or copy_from_user(), you need to manually add
> > a '\0' in the kernel buf to ensure it is properly NUL-terminated.
>
> This looks like a bunch of churn to save a "= \0" line.
>
> The more important question, IMO, would be whether there are cases in the
> kernel which *miss* a NUL termination, audit them and fix them.
>
> That'll give you a better idea whether such a *_nul() helper is even needed.
>
> Because converting only a handful of obvious places in the face of thousands
> of copy_from_user() invocations in the kernel is not doing anything useful.
I'm getting the impression that strncpy_from_user() is the real problem
here. It should append a nul byte.
That would also be a lot less error-prone than the suggested new API.
Requiring a length of N+1 is not the most immediately-obvious API.
Alice
next prev parent reply other threads:[~2026-01-12 15:40 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 [this message]
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
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=aWUWBfKhP8DvzhDl@google.com \
--to=aliceryhl@google.com \
--cc=akpm@linux-foundation.org \
--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