lkml.org 
[lkml]   [2020]   [Jul]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v2 6/8] x86/kaslr: Simplify process_gb_huge_pages
On Tue, Jul 28, 2020 at 12:27:17PM -0700, Kees Cook wrote:
> On Mon, Jul 27, 2020 at 07:07:59PM -0400, Arvind Sankar wrote:
> > Short-circuit the whole function on 32-bit.
> >
> > Replace the loop to determine the number of 1Gb pages with arithmetic.
> >
> > Fix one minor bug: if the end of the region is aligned on a 1Gb
> > boundary, the current code will not use the last available 1Gb page due
> > to an off-by-one error.
> >
> > Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
>
> Can you add some KUnit tests could be written to do validation of the
> refactorings? Touching this code is so painful. :)
>
> -Kees

Can I try to do that later -- I've never written a KUnit test, though
it's probably a good opportunity to learn how to do one.

>
> > +++ b/arch/x86/boot/compressed/kaslr.c
> > @@ -546,49 +546,43 @@ static void store_slot_info(struct mem_vector *region, unsigned long image_size)
> > static void
> > process_gb_huge_pages(struct mem_vector *region, unsigned long image_size)
> > {
> > - unsigned long addr, size = 0;
> > + unsigned long pud_start, pud_end, gb_huge_pages;
> > struct mem_vector tmp;
> > - int i = 0;
> >
> > - if (!max_gb_huge_pages) {
> > + if (IS_ENABLED(CONFIG_X86_32) || !max_gb_huge_pages) {
> > store_slot_info(region, image_size);
> > return;
> > }
>
> Won't max_gb_huge_pages always be false for 32-bit?
>
> --
> Kees Cook

It will, assuming someone doesn't pass bogus command-line arguments to
reserve Gb pages on 32-bit.

But the IS_ENABLED check allows the compiler to eliminate the entire
function at compile time.

\
 
 \ /
  Last update: 2020-07-28 21:46    [W:0.139 / U:0.456 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site