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, 3 Apr 2023 19:56:27 +0200
From:   Alice Ryhl <alice@...l.io>
To:     Benno Lossin <y86-dev@...tonmail.com>
Cc:     rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
        patches@...ts.linux.dev, Alice Ryhl <aliceryhl@...gle.com>,
        Andreas Hindborg <a.hindborg@...sung.com>,
        Miguel Ojeda <ojeda@...nel.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>
Subject: Re: [PATCH v5 10/15] rust: init: add `stack_pin_init!` macro

On 4/3/23 18:05, Benno Lossin wrote:
> The `stack_pin_init!` macro allows pin-initializing a value on the
> stack. It accepts a `impl PinInit<T, E>` to initialize a `T`. It allows
> propagating any errors via `?` or handling it normally via `match`.
> 
> Signed-off-by: Benno Lossin <y86-dev@...tonmail.com>
> Cc: Alice Ryhl <aliceryhl@...gle.com>
> Cc: Andreas Hindborg <a.hindborg@...sung.com>
> Cc: Gary Guo <gary@...yguo.net>
> ---

If you fix the issue below, then you may add
Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>

> +    /// Initializes the contents and returns the result.
> +    #[inline]
> +    pub fn init<E>(self: Pin<&mut Self>, init: impl PinInit<T, E>) -> Result<Pin<&mut T>, E> {
> +        // SAFETY: We never move out of `this`.
> +        let this = unsafe { Pin::into_inner_unchecked(self) };
> +        // The value is currently initialized, so it needs to be dropped before we can reuse
> +        // the memory (this is a safety guarantee of `Pin`).
> +        if this.1 {
> +            // SAFETY: `this.1` is true and we set it to false after this.
> +            unsafe { this.0.assume_init_drop() };
> +            this.1 = false;
> +        }

This would double-free the value if `assume_init_drop` panics. I know 
that we configure panics to abort the kernel, but someone could copy 
this into another codebase and then they would have this issue.

You can fix it by setting `this.1` to false *before* calling 
`assume_init_drop`.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ