Re: [PATCH 0/2] Add support to relocate kernel image to mirrored region
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: mawupeng <mawupeng1@xxxxxxxxxx>
- Subject: Re: [PATCH 0/2] Add support to relocate kernel image to mirrored region
- From: Ard Biesheuvel <ardb@xxxxxxxxxx>
- Date: Fri, 20 May 2022 08:52:07 +0200
- Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>, Catalin Marinas <catalin.marinas@xxxxxxx>, Will Deacon <will@xxxxxxxxxx>, Jonathan Corbet <corbet@xxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Borislav Petkov <bp@xxxxxxxxx>, Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>, X86 ML <x86@xxxxxxxxxx>, Darren Hart <dvhart@xxxxxxxxxxxxx>, Andy Shevchenko <andy@xxxxxxxxxxxxx>, Mike Rapoport <rppt@xxxxxxxxxx>, "Paul E. McKenney" <paulmck@xxxxxxxxxx>, Peter Zijlstra <peterz@xxxxxxxxxxxxx>, Joerg Roedel <jroedel@xxxxxxx>, songmuchun@xxxxxxxxxxxxx, macro@xxxxxxxxxxx, Frederic Weisbecker <frederic@xxxxxxxxxx>, W_Armin@xxxxxx, John Garry <john.garry@xxxxxxxxxx>, Sean Christopherson <seanjc@xxxxxxxxxx>, Thomas Bogendoerfer <tsbogend@xxxxxxxxxxxxxxxx>, Anshuman Khandual <anshuman.khandual@xxxxxxx>, chenhuacai@xxxxxxxxxx, David Hildenbrand <david@xxxxxxxxxx>, gpiccoli@xxxxxxxxxx, Mark Rutland <mark.rutland@xxxxxxx>, Kefeng Wang <wangkefeng.wang@xxxxxxxxxx>, Linux Doc Mailing List <linux-doc@xxxxxxxxxxxxxxx>, Linux Kernel Mailing List <linux-kernel@xxxxxxxxxxxxxxx>, Linux ARM <linux-arm-kernel@xxxxxxxxxxxxxxxxxxx>, linux-efi <linux-efi@xxxxxxxxxxxxxxx>, linux-ia64@xxxxxxxxxxxxxxx, platform-driver-x86@xxxxxxxxxxxxxxx, Linux Memory Management List <linux-mm@xxxxxxxxx>
- In-reply-to: <7058b8d8-c0cb-108e-0db9-2fdf5fb154cf@huawei.com>
- References: <CAMj1kXGSStDgj9ABmUaTLnBmpQFksh3wx4tx=mJohum4GQe3Gg@mail.gmail.com> <20220419070150.254377-1-mawupeng1@huawei.com> <CAMj1kXHr2RdYSPor1st1ZnL=O42c8N6e=bNG+eFhatfefWLUrw@mail.gmail.com> <c65d22b4-f654-21aa-bd5f-d4f8b0939a25@huawei.com> <7058b8d8-c0cb-108e-0db9-2fdf5fb154cf@huawei.com>
On Thu, 19 May 2022 at 13:09, mawupeng <mawupeng1@xxxxxxxxxx> wrote:
>
>
>
> 在 2022/5/7 17:28, mawupeng 写道:
> >
> >
> > 在 2022/5/3 17:58, Ard Biesheuvel 写道:
> >> On Tue, 19 Apr 2022 at 08:43, Wupeng Ma <mawupeng1@xxxxxxxxxx> wrote:
> >>>
> >>> From: Ma Wupeng <mawupeng1@xxxxxxxxxx>
> >>>
> >>> Now system image will perfer to be located to mirrored regions both KASLR
> >>> on and off.
> >>>
> >>
> >> Hello Ma Wupeng,
> >>
> >> I wonder if we could simplify this as follows:
> >> - ignore the non-KASLR case for now, and rely on the bootloader > load the image into mirrored memory if it exists;
> >
> > In grub, memory for static image is allocated via the following path:
> >
> > grub_cmd_linux
> > kernel = grub_malloc(filelen)
> > kernel_alloc_addr = grub_efi_allocate_any_pages (kernel_alloc_pages)
> > grub_memcpy (kernel_addr, kernel, grub_min(filelen, kernel_size))
> > grub_loader_set (grub_linux_boot, grub_linux_unload, 0)
> >
> > Can we get memory from mirrored region by the following steps:
> > 1. get memory map by calling grub_efi_get_memory_map()
> > 2. iter all memory map to find a suitable mirrored memory area
> > 3. locate kernel image to this area
> >
> > So, if kaslr is not enabled
> > - grub will load kernel into mirrored region
> > else
> > - arm64-stub.c will relocate kernel image to mirrored region
> >
> > Is this feasible?
>
> Is this a feasible proposal to relocate the static kernel image itself
> into more reliable memory?
>
I'm not sure, it all depends on the firmware.
When GRUB calls LoadImage(), the firmware will reallocate the image
and unpack it there. So it is really the firmware's job to ensure that
the image is loaded into a suitable location.
I have some code here that implements a EFI based decompressor, and
which loads the kernel image into mirrored memory if it exists,
without the need to move it again. It could trivially be modified to
deal with non-randomized loads as well.
But the bottom line is that UEFI should expose the ability to target
mirrored memory, hacking around it like this is not a sustainable
approach.
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]