From: Fushuai Wang <fushuai.wang@linux.dev>
To: ynorov@nvidia.com
Cc: akpm@linux-foundation.org, aliceryhl@google.com, bp@alien8.de,
brauner@kernel.org, cyphar@cyphar.com,
dave.hansen@linux.intel.com, fushuai.wang@linux.dev,
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: Fri, 16 Jan 2026 16:42:47 +0800 [thread overview]
Message-ID: <20260116084247.26024-1-fushuai.wang@linux.dev> (raw)
In-Reply-To: <aWaIOT_o-99G-_r-@yury>
> I checked the cases you've found, and all them clearly abuse
> copy_from_user(). For example, #2 in tlbflush_write_file():
>
> if (copy_from_user(buf, user_buf, len))
> return -EFAULT;
>
> buf[len] = '\0';
> if (kstrtoint(buf, 0, &ceiling))
> return -EINVAL;
>
> should be:
>
> len = strncpy_from_user(buf, user_buf, len);
> if (len < 0)
> return len;
>
> ret = kstrtoint(buf, 0, &ceiling);
> if (ret)
> return ret;
>
> See, if you use the right API, you don't need this weird
> copy_from_user_nul(). Also notice how nice the original version hides
> possible ERANGE in kstrtoint().
>
> Patches #3-5 in the series again copy strings with raw non-string API,
> so should be converted to some flavor of strcpy().
>
> #6 patches lib/kstrtox, which makes little sense because the whole
> purpose of that library is to handle raw pieces of memory as valid
> C strings. One would expect such patterns in library code, and I'd
> prefer having them explicit.
>
> I find copy_{from,to}_user_nul() useful for objects that must be
> null-terminated, and may have \0 somewhere in the middle. Those are
> not C strings. I suspect this isn't a popular format across the kernel.
>
> On the other hand, adding the _nul() version of copy_from_user() would
> make an API abuse like above simpler, which is a bad thing.
>
> Can you drop copy_from_user_nul() and submit a series that switches
> string manipulations to the dedicated string functions?
OK, I find some misuse of strncpy_from_user() + kstrtoXXX(). I will fix
them.
Regarding patches #3-5, as Steven mentioned, I believe we might need a
strscpy_from_user() for these cases that copy a non-NUL-terminated string
from userspace?
---
Regards,
WANG
> Thanks,
> Yury
next prev parent reply other threads:[~2026-01-16 8:43 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 [this message]
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=20260116084247.26024-1-fushuai.wang@linux.dev \
--to=fushuai.wang@linux.dev \
--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=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=ynorov@nvidia.com \
--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