lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <68113707.050a0220.17967c.36c7@mx.google.com>
Date: Tue, 29 Apr 2025 13:31:00 -0700
From: Boqun Feng <boqun.feng@...il.com>
To: John Hubbard <jhubbard@...dia.com>
Cc: Alice Ryhl <aliceryhl@...gle.com>, Miguel Ojeda <ojeda@...nel.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Alexander Viro <viro@...iv.linux.org.uk>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	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>,
	Danilo Krummrich <dakr@...nel.org>, rust-for-linux@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/2] uaccess: rust: add strncpy_from_user

On Tue, Apr 29, 2025 at 01:28:09PM -0700, John Hubbard wrote:
> On 4/29/25 10:30 AM, Boqun Feng wrote:
> > On Tue, Apr 29, 2025 at 09:02:22AM +0000, Alice Ryhl wrote:
> ...
> >> +#[inline]
> >> +pub fn raw_strncpy_from_user(ptr: UserPtr, buf: &mut [MaybeUninit<u8>]) -> Result<usize> {
> >> +    // 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().cast::<c_char>(), ptr as *const c_char, len)
> >> +    };
> >> +
> >> +    if res < 0 {
> >> +        return Err(Error::from_errno(res as i32));
> >> +    }
> >> +
> > 
> > Nit: this can be a
> > 
> > 	let copy_len = kernel::error::to_result(res)?;
> > 
> 
> Doesn't that discard the length, though, by returning Ok(()) ?
> 

Oh, you're right, so probably we need a to_result_i32():

    pub fn to_result_i32() -> Result<i32>

, so we don't have to open-code "if res < 0" every time.

Regards,
Boqun

> 
> thanks,
> -- 
> John Hubbard
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ