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: <ed3f5907-bc28-46b5-5a61-79dd2719349f@protonmail.com>
Date:   Thu, 30 Mar 2023 15:16:21 +0000
From:   Benno Lossin <y86-dev@...tonmail.com>
To:     David Laight <David.Laight@...LAB.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>,
        Alice Ryhl <alice@...l.io>
Cc:     "rust-for-linux@...r.kernel.org" <rust-for-linux@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "patches@...ts.linux.dev" <patches@...ts.linux.dev>
Subject: Re: [PATCH v3 12/13] rust: sync: reduce stack usage of `UniqueArc::try_new_uninit`

On 30.03.23 16:58, David Laight wrote:
> From: y86-dev@...tonmail.com
>> Sent: 29 March 2023 23:34
>>
>> `UniqueArc::try_new_uninit` calls `Arc::try_new(MaybeUninit::uninit())`.
>> This results in the uninitialized memory being placed on the stack,
>> which may be arbitrarily large due to the generic `T` and thus could
>> cause a stack overflow for large types.
>
> Does that mean rust is using (the equivalent of) alloca() ?

No, the compiler knows the size of `T` statically (this is a requirement
for calling `MaybeUninit::uninit()`). It would simply reserve stack
space for a stack variable (like the C compiler would also do) and since
the type is generic and user-specified, it could be larger than the
stack size. The problem is that the Rust compiler does not optimize the
stack variable away. This fix avoids creating a stack variable in the
first place.

--
Cheers,
Benno


>
> That is banned for C code in the kernel for any sizes.
>
> 	David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ