]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
efi/memattr: Fix thinko in table size sanity check
authorArd Biesheuvel <ardb@kernel.org>
Thu, 26 Mar 2026 13:26:57 +0000 (14:26 +0100)
committerArd Biesheuvel <ardb@kernel.org>
Thu, 9 Apr 2026 14:27:52 +0000 (16:27 +0200)
commit5d0faa8e8369b9a48498f6f132c2ced5f0549acc
treebcc00a6d986ec493a5db3018644e5e1caff4121d
parent56e2ef8f5f9161d08d45656d373da83d4a789be1
efi/memattr: Fix thinko in table size sanity check

While it is true that each PE/COFF runtime driver in memory can
generally be split into 3 different regions (the header, the code/rodata
region and the data/bss region), each with different permissions, it
does not mean that 3x the size of the memory map is a suitable upper
bound. This is due to the fact that all runtime drivers could be
coalesced into a single EFI runtime code region by the firmware, and if
the firmware does a good job of keeping the fragmentation down, it is
conceivable that the memory attributes table has more entries than the
EFI memory map itself.

So instead, base the sanity check on whether the descriptor size matches
the EFI memory map's descriptor size closely enough (which is not
mandated by the spec but extremely unlikely to differ in practice), and
whether the size of the whole table does not exceed 64k entries.

Reviewed-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/memattr.c