[Crash-utility] [PATCH v2 3/3] kaslr: get offset by walking page tree

d.hatayama at fujitsu.com d.hatayama at fujitsu.com
Thu Oct 29 00:13:53 UTC 2020


> > + */
> > +static int
> > +find_kernel_start(ulong *va, ulong *pa)
> > +{
> > +       int i, pgd_idx, pud_idx, pmd_idx, pte_idx;
> > +       uint64_t pgd_pte, pud_pte, pmd_pte, pte;
> > +
> > +       pgd_idx = pgd_index(__START_KERNEL_map);
> > +       pud_idx = pud_index(__START_KERNEL_map);
> > +       pmd_idx = pmd_index(__START_KERNEL_map);
> > +       pte_idx = pte_index(__START_KERNEL_map);
> > +
> > +       for (; pgd_idx < PTRS_PER_PGD; pgd_idx++) {
> > +               pgd_pte = ULONG(machdep->pgd + pgd_idx * sizeof(uint64_t));
> 
> machdep->pgd is not guaranteed to be aligned by PAGE_SIZE.
> This could refer to the pgd for userland that resides in the next page.
> I guess it's necessary to get the 1st pgd entry in the page machdep->pgd belongs to.
> Like this?
> 
>     pgd_pte = ULONG((machdep->pgd & PHYSICAL_PAGE_MASK) + pgd_idx * sizeof(uint64_t));

Please ignore this comment. I was confused with `pgd` here.

Thanks.
HATAYAMA, Daisuke







More information about the Crash-utility mailing list