lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Sat, 18 Jun 2022 10:08:09 +0800
From:   Yuntao Wang <ytcoode@...il.com>
To:     kirill@...temov.name
Cc:     bhe@...hat.com, bp@...en8.de, dave.hansen@...ux.intel.com,
        hpa@...or.com, linux-kernel@...r.kernel.org, luto@...nel.org,
        mingo@...hat.com, peterz@...radead.org, stable@...r.kernel.org,
        tglx@...utronix.de, x86@...nel.org, ytcoode@...il.com
Subject: Re: [PATCH] x86/mm: Fix possible index overflow when creating page table mapping

On Sat, 18 Jun 2022 03:22:20 +0300, Kirill A. Shutemov wrote:
> On Thu, Jun 16, 2022 at 09:55:10PM +0800, Yuntao Wang wrote:
> > There are two issues in phys_p4d_init():
> > 
> > - The __kernel_physical_mapping_init() does not do boundary-checking for
> >   paddr_end and passes it directly to phys_p4d_init(), phys_p4d_init() does
> >   not do bounds checking either, so if the physical memory to be mapped is
> >   large enough, 'p4d_page + p4d_index(vaddr)' will wrap around to the
> >   beginning entry of the P4D table and its data will be overwritten.
> > 
> > - The for loop body will be executed only when 'vaddr < vaddr_end'
> >   evaluates to true, but if that condition is true, 'paddr >= paddr_end'
> >   will evaluate to false, thus the 'if (paddr >= paddr_end) {}' block will
> >   never be executed and become dead code.
> > 
> > To fix these issues, use 'i < PTRS_PER_P4D' instead of 'vaddr < vaddr_end'
> > as the for loop condition, this also make it more consistent with the logic
> > of the phys_{pud,pmt,pte}_init() functions.
> 
> Hm. I don't see why you changed phys_p4d_init(), but not
> __kernel_physical_mapping_init(). It does exactly the same thing, just
> pgd_index() is hidden a bit deeper than p4d_index().

The reason I chose to change phys_p4d_init() is that:

- Currently the 'if (paddr >= paddr_end) {}' block in phys_p4d_init() is
  dead code, changing __kernel_physical_mapping_init() does not fix that.

- Changing phys_p4d_init() to the 'for (i < PTRS_PER_P4D) {}' form makes
  it more consistent with phys_pud/pmt/pte_init() as they are all using
  the 'for (i < PTRS_PER_PUD/PMD/PTE) {}' forms. Meanwhile, this change
  also fixes the dead code issue.

thanks,

Yuntao Wang

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ