[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aAtZZgeF5GKdPcaB@google.com>
Date: Fri, 25 Apr 2025 09:44:06 +0000
From: Alice Ryhl <aliceryhl@...gle.com>
To: Danilo Krummrich <dakr@...nel.org>
Cc: Miguel Ojeda <ojeda@...nel.org>, Andrew Morton <akpm@...ux-foundation.org>,
Alexander Viro <viro@...iv.linux.org.uk>, Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
"Björn Roy Baron" <bjorn3_gh@...tonmail.com>, Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>, Trevor Gross <tmgross@...ch.edu>,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] uaccess: rust: add strncpy_from_user
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.
Alice
Powered by blists - more mailing lists