[PATCH] SoC: sdm845: find and save KASLR to env variables

Dzmitry Sankouski dsankouski at gmail.com
Wed Jan 11 13:15:58 CET 2023


Right.

ср, 11 янв. 2023 г. в 05:36, Peter Robinson <pbrobinson at gmail.com>:
>
> On Tue, Dec 27, 2022 at 7:47 PM Dzmitry Sankouski <dsankouski at gmail.com> wrote:
> >
> > KASLR address is needed to boot fully functional Android.
> > KASLR is set by primary bootloader, and since u-boot is used
> > as a secondary bootloader(replacing kernel) on sdm845 platform,
> > KASLR may be found by comparing memory chunks at relocaddr over
> > supposed KASLR range.
>
> By KASLR I presume  you mean the random seed? KASLR is a technology
> used in the kernel, but it's actually a random seed that's passed to
> the kernel to generate the random layout.
>
> > Signed-off-by: Dzmitry Sankouski <dsankouski at gmail.com>
> > ---
> >  arch/arm/mach-snapdragon/init_sdm845.c | 18 ++++++++++++++++++
> >  1 file changed, 18 insertions(+)
> >
> > diff --git a/arch/arm/mach-snapdragon/init_sdm845.c b/arch/arm/mach-snapdragon/init_sdm845.c
> > index 5f53c21947..1f88502394 100644
> > --- a/arch/arm/mach-snapdragon/init_sdm845.c
> > +++ b/arch/arm/mach-snapdragon/init_sdm845.c
> > @@ -78,5 +78,23 @@ __weak int misc_init_r(void)
> >                 env_set("key_power", "0");
> >         }
> >
> > +       /*
> > +        * search for kaslr address, set by primary bootloader by searching first
> > +        * 0x100 relocated bytes at u-boot's initial load address range
> > +        */
> > +       uintptr_t start = gd->ram_base;
> > +       uintptr_t end = start + 0x800000;
> > +       u8 *addr = (u8 *)start;
> > +       phys_addr_t *relocaddr = (phys_addr_t *)gd->relocaddr;
> > +       u32 block_size = 0x1000;
> > +
> > +       while (memcmp(addr, relocaddr, 0x100) && (uintptr_t)addr < end)
> > +               addr += block_size;
> > +
> > +       if ((uintptr_t)addr >= end)
> > +               printf("KASLR not found in range 0x%lx - 0x%lx", start, end);
> > +       else
> > +               env_set_addr("KASLR", addr);
> > +
> >         return 0;
> >  }
> > --
> > 2.30.2
> >


More information about the U-Boot mailing list