From: Danilo Krummrich <dakr@kernel.org>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] uaccess: rust: add strncpy_from_user
Date: Fri, 25 Apr 2025 16:14:33 +0200 [thread overview]
Message-ID: <aAuYyXq1FLOhKDX3@pollux> (raw)
In-Reply-To: <aAtZZgeF5GKdPcaB@google.com>
On Fri, Apr 25, 2025 at 09:44:06AM +0000, Alice Ryhl wrote:
> On Thu, Apr 24, 2025 at 06:32:08PM +0200, Danilo Krummrich wrote:
> > On Thu, Apr 24, 2025 at 03:17:48PM +0000, Alice Ryhl wrote:
> > >
> > > +/// Reads a nul-terminated string into `buf` and returns the length.
> > > +///
> > > +/// Fails with [`EFAULT`] if the read happens on a bad address. If the end of `buf` is reached,
> > > +/// then the buffer will not be nul-terminated.
> > > +#[inline]
> > > +pub fn strncpy_from_user(ptr: UserPtr, buf: &mut [u8]) -> Result<usize> {
> >
> > Should probably be named strcpy_from_user() instead.
>
> See my reply to Boqun.
>
> > > + // CAST: Slice lengths are guaranteed to be `<= isize::MAX`.
> > > + let len = buf.len() as isize;
> > > +
> > > + // SAFETY: `buf` is valid for writing `buf.len()` bytes.
> > > + let res = unsafe {
> > > + bindings::strncpy_from_user(
> > > + buf.as_mut_ptr(),
> > > + ptr as *const u8,
> >
> > kernel::ffi::c_char should always match u8, but should we use the FFI type
> > regardless?
>
> Hmm. Should we? I don't mind changing it, but I guess this could be an
> interesting discussion point.
I think we should stick to the FFI type, even if we know the types are
guaranteed to match. But I also won't object with how it is.
next prev parent reply other threads:[~2025-04-25 14:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-24 15:17 [PATCH] uaccess: rust: add strncpy_from_user Alice Ryhl
2025-04-24 15:57 ` Boqun Feng
2025-04-25 9:43 ` Alice Ryhl
2025-04-25 13:39 ` Boqun Feng
2025-04-25 13:52 ` Greg Kroah-Hartman
2025-04-25 14:35 ` Boqun Feng
2025-04-25 14:45 ` Greg Kroah-Hartman
2025-04-24 16:32 ` Danilo Krummrich
2025-04-25 9:44 ` Alice Ryhl
2025-04-25 14:14 ` Danilo Krummrich [this message]
2025-04-24 16:38 ` Miguel Ojeda
2025-04-25 9:45 ` Alice Ryhl
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=aAuYyXq1FLOhKDX3@pollux \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=viro@zeniv.linux.org.uk \
/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