]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
efi/libstub: Fix boundary checking in efi_high_alloc()
authorYinghai Lu <yinghai@kernel.org>
Fri, 20 Feb 2015 04:18:03 +0000 (20:18 -0800)
committerSasha Levin <sasha.levin@oracle.com>
Tue, 24 Mar 2015 01:02:50 +0000 (21:02 -0400)
commite16752a8d31bebed4719d869f39f1d6a00e09c89
treea7b2d7634a8dfd8fa3c40d925f1bbba5706064b9
parentf3b9a854c406ce44342bca393930a429cdb6d241
efi/libstub: Fix boundary checking in efi_high_alloc()

commit 7ed620bb343f434f8a85f830020c04988df2a140 upstream.

While adding support loading kernel and initrd above 4G to grub2 in legacy
mode, I was referring to efi_high_alloc().
That will allocate buffer for kernel and then initrd, and initrd will
use kernel buffer start as limit.

During testing found two buffers will be overlapped when initrd size is
very big like 400M.

It turns out efi_high_alloc() boundary checking is not right.
end - size will be the new start, and should not compare new
start with max, we need to make sure end is smaller than max.

[ Basically, with the current efi_high_alloc() code it's possible to
  allocate memory above 'max', because efi_high_alloc() doesn't check
  that the tail of the allocation is below 'max'.

  If you have an EFI memory map with a single entry that looks like so,

   [0xc0000000-0xc0004000]

  And want to allocate 0x3000 bytes below 0xc0003000 the current code
  will allocate [0xc0001000-0xc0004000], not [0xc0000000-0xc0003000]
  like you would expect. - Matt ]

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Tested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/firmware/efi/libstub/efi-stub-helper.c