From c1c3f83b609b3f7772d97a8302162eff21cc2ad5 Mon Sep 17 00:00:00 2001 From: Patrick Thompson Date: Fri, 14 Mar 2025 16:00:39 -0400 Subject: [PATCH 1/4] uefi runtime: Increase default size of name buffer Some firmware fails to update the "VariableNameSize" parameter passed into GetNextVariableName(). To work around this we will use a large default buffer size. --- uefi/src/runtime.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uefi/src/runtime.rs b/uefi/src/runtime.rs index a61dee296..11a88716c 100644 --- a/uefi/src/runtime.rs +++ b/uefi/src/runtime.rs @@ -7,6 +7,7 @@ //! functions after exiting boot services; see the "Calling Convention" section //! of the UEFI specification for details. +use alloc::vec; use crate::data_types::PhysicalAddress; use crate::table::{self, Revision}; use crate::{CStr16, Error, Result, Status, StatusExt}; @@ -270,8 +271,7 @@ impl VariableKeys { fn new() -> Self { // Create a the name buffer with a reasonable default capacity, and // initialize it to an empty null-terminated string. - let mut name = Vec::with_capacity(32); - name.push(0); + let name = vec![0;512]; Self { // Give the name buffer a reasonable default capacity. From f13749144db9bc4ecea00a5d3054af8b18d359bc Mon Sep 17 00:00:00 2001 From: Patrick Thompson Date: Thu, 20 Mar 2025 18:38:55 -0400 Subject: [PATCH 2/4] uefi runtime: Fixup increase default size of name buffer Address PR comments: update code comments, move `use alloc::vec` into appropriate cfg block. --- uefi/src/runtime.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/uefi/src/runtime.rs b/uefi/src/runtime.rs index 11a88716c..111cdbed1 100644 --- a/uefi/src/runtime.rs +++ b/uefi/src/runtime.rs @@ -7,7 +7,6 @@ //! functions after exiting boot services; see the "Calling Convention" section //! of the UEFI specification for details. -use alloc::vec; use crate::data_types::PhysicalAddress; use crate::table::{self, Revision}; use crate::{CStr16, Error, Result, Status, StatusExt}; @@ -18,7 +17,7 @@ use uefi_raw::table::boot::MemoryDescriptor; #[cfg(feature = "alloc")] use { crate::mem::make_boxed, crate::CString16, crate::Guid, alloc::borrow::ToOwned, - alloc::boxed::Box, alloc::vec::Vec, + alloc::boxed::Box, alloc::{vec, vec::Vec} }; #[cfg(all(feature = "unstable", feature = "alloc"))] @@ -269,12 +268,14 @@ pub struct VariableKeys { #[cfg(feature = "alloc")] impl VariableKeys { fn new() -> Self { - // Create a the name buffer with a reasonable default capacity, and - // initialize it to an empty null-terminated string. - let name = vec![0;512]; + // Create a name buffer with a large default size and zero + // initialize it. A Toshiba Satellite Pro R50-B-12P was found + // to not correctly update the VariableNameSize passed into + // GetNextVariableName and starting with a large buffer works + // around this issue. + let name = vec![0; 512]; Self { - // Give the name buffer a reasonable default capacity. name, // The initial vendor GUID is arbitrary. vendor: VariableVendor(Guid::default()), From 8f1db3086bf15a1b345323d871e3a4657ff66336 Mon Sep 17 00:00:00 2001 From: Patrick Thompson Date: Thu, 20 Mar 2025 18:50:11 -0400 Subject: [PATCH 3/4] uefi runtime: cargo xtask fmt --- uefi/src/runtime.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/uefi/src/runtime.rs b/uefi/src/runtime.rs index 111cdbed1..2d2450265 100644 --- a/uefi/src/runtime.rs +++ b/uefi/src/runtime.rs @@ -16,8 +16,12 @@ use uefi_raw::table::boot::MemoryDescriptor; #[cfg(feature = "alloc")] use { - crate::mem::make_boxed, crate::CString16, crate::Guid, alloc::borrow::ToOwned, - alloc::boxed::Box, alloc::{vec, vec::Vec} + crate::mem::make_boxed, + crate::CString16, + crate::Guid, + alloc::borrow::ToOwned, + alloc::boxed::Box, + alloc::{vec, vec::Vec}, }; #[cfg(all(feature = "unstable", feature = "alloc"))] From b43d34c456d6c6b8fa846cc4976ce76d0495aaf2 Mon Sep 17 00:00:00 2001 From: Patrick Thompson Date: Fri, 21 Mar 2025 09:32:58 -0400 Subject: [PATCH 4/4] uefi: Update CHANGELOG.md Describe VariableKeys name buffer change. --- uefi/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/uefi/CHANGELOG.md b/uefi/CHANGELOG.md index 8848c7abd..630462fb9 100644 --- a/uefi/CHANGELOG.md +++ b/uefi/CHANGELOG.md @@ -22,6 +22,8 @@ zero. The allocation is retried instead, and in all failure cases an error is returned rather than panicking. - The `Display` impl for `CStr8` now excludes the trailing null character. +- `VariableKeys` initializes with a larger name buffer to work around firmware + bugs on some devices. # uefi - 0.34.1 (2025-02-07)