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: Mon, 15 Apr 2024 09:51:47 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Alice Ryhl <aliceryhl@...gle.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>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, 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>, linux-mm@...ck.org, linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org, Christian Brauner <brauner@...nel.org>
Subject: Re: [PATCH v5 1/4] rust: uaccess: add userspace pointers

On 15.04.24 11:44, Alice Ryhl wrote:
> On Mon, Apr 15, 2024 at 11:37 AM Benno Lossin <benno.lossin@...ton.me> wrote:
>>
>> On 15.04.24 09:13, Alice Ryhl wrote:
>>> +impl UserSlice {
>>> +    /// Constructs a user slice from a raw pointer and a length in bytes.
>>> +    ///
>>> +    /// Constructing a [`UserSlice`] performs no checks on the provided address and length, it can
>>> +    /// safely be constructed inside a kernel thread with no current userspace process. Reads and
>>> +    /// writes wrap the kernel APIs `copy_from_user` and `copy_to_user`, which check the memory map
>>> +    /// of the current process and enforce that the address range is within the user range (no
>>> +    /// additional calls to `access_ok` are needed).
>>> +    ///
>>> +    /// Callers must be careful to avoid time-of-check-time-of-use (TOCTOU) issues. The simplest way
>>> +    /// is to create a single instance of [`UserSlice`] per user memory block as it reads each byte
>>> +    /// at most once.
>>> +    pub fn new(ptr: *mut c_void, length: usize) -> Self {
>>
>> What would happen if I call this with a kernel pointer and then
>> read/write to it? For example
>>
>>       let mut arr = [MaybeUninit::uninit(); 64];
>>       let ptr: *mut [MaybeUninit<u8>] = &mut arr;
>>       let ptr = ptr.cast::<c_void>();
>>
>>       let slice = UserSlice::new(ptr, 64);
>>       let (mut r, mut w) = slice.reader_writer();
>>
>>       r.read_raw(&mut arr)?;
>>       // SAFETY: `arr` was initialized above.
>>       w.write_slice(unsafe { MaybeUninit::slice_assume_init_ref(&arr) })?;
>>
>> I think this would violate the exclusivity of `&mut` without any
>> `unsafe` code. (the `unsafe` block at the end cannot possibly be wrong)
> 
> This will fail with an EFAULT error. There is a check on the C side
> that verifies that the address is in userspace. (The access_ok call.)

I see, that makes a lot of sense.

Regardless of whether you fix the nit about the guarantees section:

Reviewed-by: Benno Lossin <benno.lossin@...ton.me>

-- 
Cheers,
Benno


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ