mirror of
https://github.com/rust-osdev/uefi-rs
synced 2026-08-26 18:26:05 -04:00
mem/memory_map: validate desc_size in MemoryMapOwned constructor
`from_initialized_mem` only checked that `desc_size` was large enough, unlike the `MemoryMapRef`/`MemoryMapRefMut` constructors, which also require it to be a multiple of the descriptor alignment. With an unaligned `desc_size`, every entry but the first was accessed through a misaligned `&MemoryDescriptor`. Reuse `validate_meta` so all constructors enforce the same invariant.
This commit is contained in:
parent
b17551c70e
commit
4f8ca7069c
1 changed files with 4 additions and 2 deletions
|
|
@ -402,8 +402,10 @@ impl MemoryMapOwned {
|
|||
/// (stored inside the provided buffer) and the corresponding
|
||||
/// [`MemoryMapMeta`].
|
||||
pub(crate) fn from_initialized_mem(buf: MemoryMapBackingMemory, meta: MemoryMapMeta) -> Self {
|
||||
assert!(meta.desc_size >= size_of::<MemoryDescriptor>());
|
||||
let len = meta.entry_count();
|
||||
// Validate `desc_size` fully: besides being large enough, it must be a
|
||||
// multiple of the descriptor alignment. Otherwise descriptors past the
|
||||
// first would be accessed through misaligned references.
|
||||
let len = validate_meta(meta).expect("The memory map metadata should be valid");
|
||||
Self { buf, meta, len }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue