| From stable+bounces-121515-greg=kroah.com@vger.kernel.org Fri Mar 7 23:53:26 2025 |
| From: Miguel Ojeda <ojeda@kernel.org> |
| Date: Fri, 7 Mar 2025 23:50:07 +0100 |
| Subject: rust: alloc: Fix `ArrayLayout` allocations |
| To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Sasha Levin <sashal@kernel.org>, stable@vger.kernel.org |
| Cc: Danilo Krummrich <dakr@kernel.org>, Alice Ryhl <aliceryhl@google.com>, Alyssa Ross <hi@alyssa.is>, NoisyCoil <noisycoil@disroot.org>, patches@lists.linux.dev, Miguel Ojeda <ojeda@kernel.org> |
| Message-ID: <20250307225008.779961-61-ojeda@kernel.org> |
| |
| From: Asahi Lina <lina@asahilina.net> |
| |
| commit b7ed2b6f4e8d7f64649795e76ee9db67300de8eb upstream. |
| |
| We were accidentally allocating a layout for the *square* of the object |
| size due to a variable shadowing mishap. |
| |
| Fixes memory bloat and page allocation failures in drm/asahi. |
| |
| Reported-by: Janne Grunau <j@jannau.net> |
| Fixes: 9e7bbfa18276 ("rust: alloc: introduce `ArrayLayout`") |
| Signed-off-by: Asahi Lina <lina@asahilina.net> |
| Acked-by: Danilo Krummrich <dakr@kernel.org> |
| Reviewed-by: Neal Gompa <neal@gompa.dev> |
| Link: https://lore.kernel.org/r/20241123-rust-fix-arraylayout-v1-1-197e64c95bd4@asahilina.net |
| Signed-off-by: Miguel Ojeda <ojeda@kernel.org> |
| Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| --- |
| rust/kernel/alloc/layout.rs | 2 +- |
| 1 file changed, 1 insertion(+), 1 deletion(-) |
| |
| --- a/rust/kernel/alloc/layout.rs |
| +++ b/rust/kernel/alloc/layout.rs |
| @@ -45,7 +45,7 @@ impl<T> ArrayLayout<T> { |
| /// When `len * size_of::<T>()` overflows or when `len * size_of::<T>() > isize::MAX`. |
| pub const fn new(len: usize) -> Result<Self, LayoutError> { |
| match len.checked_mul(core::mem::size_of::<T>()) { |
| - Some(len) if len <= ISIZE_MAX => { |
| + Some(size) if size <= ISIZE_MAX => { |
| // INVARIANT: We checked above that `len * size_of::<T>() <= isize::MAX`. |
| Ok(Self { |
| len, |