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]
Date: Fri, 19 Apr 2024 20:12:24 +0200
From: Alice Ryhl <aliceryhl@...gle.com>
To: Boqun Feng <boqun.feng@...il.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Matthew Wilcox <willy@...radead.org>, 
	Al Viro <viro@...iv.linux.org.uk>, Andrew Morton <akpm@...ux-foundation.org>, 
	Kees Cook <keescook@...omium.org>, Alex Gaynor <alex.gaynor@...il.com>, 
	Wedson Almeida Filho <wedsonaf@...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@...sung.com>, 
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>, Arve Hjønnevåg <arve@...roid.com>, 
	Todd Kjos <tkjos@...roid.com>, Martijn Coenen <maco@...roid.com>, 
	Joel Fernandes <joel@...lfernandes.org>, Carlos Llamas <cmllamas@...gle.com>, 
	Suren Baghdasaryan <surenb@...gle.com>, Arnd Bergmann <arnd@...db.de>, Trevor Gross <tmgross@...ch.edu>, 
	linux-mm@...ck.org, linux-kernel@...r.kernel.org, 
	rust-for-linux@...r.kernel.org, Christian Brauner <brauner@...nel.org>
Subject: Re: [PATCH v6 1/4] rust: uaccess: add userspace pointers

On Fri, Apr 19, 2024 at 7:11 PM Boqun Feng <boqun.feng@...il.com> wrote:
>
> On Thu, Apr 18, 2024 at 08:59:17AM +0000, Alice Ryhl wrote:
> [...]
> > +    /// Reads the entirety of the user slice, appending it to the end of the provided buffer.
> > +    ///
> > +    /// Fails with `EFAULT` if the read happens on a bad address.
> > +    pub fn read_all(mut self, buf: &mut Vec<u8>, flags: Flags) -> Result {
> > +        let len = self.length;
> > +        buf.reserve(len, flags)?;
>
> (Reportedy by Miguel)
>
> When compile with `make rusttest`, kernel crate is compiled as userspace
> program, so we need to explicitly pick where the `reserve` comes from
> (Vec or VecExt), the current version will hit the following error:
>
>         error[E0061]: this method takes 1 argument but 2 arguments were supplied
>            --> rust/kernel/uaccess.rs:296:13
>             |
>         296 |         buf.reserve(len, flags)?;
>             |             ^^^^^^^    -------
>             |                        | |
>             |                        | unexpected argument of type `Flags`
>             |                        help: remove the extra argument
>             |
>         note: method defined here
>            --> /home/boqun/linux-rust/rust/test/sysroot/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:910:12
>             |
>         910 |     pub fn reserve(&mut self, additional: usize) {
>             |            ^^^^^^^
>
>         error[E0277]: the `?` operator can only be applied to values that implement `Try`
>            --> rust/kernel/uaccess.rs:296:9
>             |
>         296 |         buf.reserve(len, flags)?;
>             |         ^^^^^^^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `()`
>             |
>             = help: the trait `Try` is not implemented for `()`
>
>         error: aborting due to 2 previous errors
>
>         Some errors have detailed explanations: E0061, E0277.
>         For more information about an error, try `rustc --explain E0061`.
>
> and we need to the following fix
>
> diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs
> index 39481e374c40..80f7e7ca2f5e 100644
> --- a/rust/kernel/uaccess.rs
> +++ b/rust/kernel/uaccess.rs
> @@ -293,7 +293,7 @@ pub fn read<T: FromBytes>(&mut self) -> Result<T> {
>      /// Fails with `EFAULT` if the read happens on a bad address.
>      pub fn read_all(mut self, buf: &mut Vec<u8>, flags: Flags) -> Result {
>          let len = self.length;
> -        buf.reserve(len, flags)?;
> +        VecExt::<u8>::reserve(buf, len, flags)?;
>
>          // The call to `try_reserve` was successful, so the spare capacity is at least `len` bytes
>          // long.

I'm sorry, what? This seems like a problem with `make rusttest`.

Alice

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ