From a9e48c2760b082365612f7fe6f5ad36ccfb4ade4 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Thu, 1 Aug 2024 15:17:58 -0400 Subject: [PATCH] uefi: Fix lifetimes in device_path TryFrom<&[u8]> impls The missing lifetime means that the &[u8] buffer could be freed while the &DevicePath still exists, which is UB. --- uefi/CHANGELOG.md | 8 ++++++++ uefi/src/proto/device_path/mod.rs | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/uefi/CHANGELOG.md b/uefi/CHANGELOG.md index 1853e6c92..126fd1720 100644 --- a/uefi/CHANGELOG.md +++ b/uefi/CHANGELOG.md @@ -39,6 +39,14 @@ > use uefi::table::boot::BootServices; ``` + +# uefi - 0.30.0 (unreleased) +## Changed +- **Breaking:**: Fixed a bug in the impls of `TryFrom<&[u8]>` for + `&DevicePathHeader`, `&DevicePathNode` and `&DevicePath` that could lead to + memory unsafety. See . + + # uefi - 0.29.0 (2024-07-02) ## Added diff --git a/uefi/src/proto/device_path/mod.rs b/uefi/src/proto/device_path/mod.rs index 444f54330..feae09d97 100644 --- a/uefi/src/proto/device_path/mod.rs +++ b/uefi/src/proto/device_path/mod.rs @@ -119,7 +119,7 @@ pub struct DevicePathHeader { pub length: u16, } -impl<'a> TryFrom<&[u8]> for &'a DevicePathHeader { +impl<'a> TryFrom<&'a [u8]> for &'a DevicePathHeader { type Error = ByteConversionError; fn try_from(bytes: &[u8]) -> Result { @@ -265,7 +265,7 @@ impl PartialEq for DevicePathNode { } } -impl<'a> TryFrom<&[u8]> for &'a DevicePathNode { +impl<'a> TryFrom<&'a [u8]> for &'a DevicePathNode { type Error = ByteConversionError; fn try_from(bytes: &[u8]) -> Result { @@ -516,7 +516,7 @@ impl PartialEq for DevicePath { } } -impl<'a> TryFrom<&[u8]> for &'a DevicePath { +impl<'a> TryFrom<&'a [u8]> for &'a DevicePath { type Error = ByteConversionError; fn try_from(bytes: &[u8]) -> Result {