mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Baoquan He <bhe@redhat.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: tglx@linutronix.de, hpa@zytor.com, thgarnie@google.com,
	kirill.shutemov@linux.intel.com, x86@kernel.org,
	linux-kernel@vger.kernel.org,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH v2 2/3] x86/mm/KASLR: Calculate the actual size of vmemmap region
Date: Tue, 11 Sep 2018 16:18:11 +0800	[thread overview]
Message-ID: <20180911081811.GY1740@192.168.1.3> (raw)
In-Reply-To: <20180911075946.GA97454@gmail.com>

On 09/11/18 at 09:59am, Ingo Molnar wrote:
> 
> * Baoquan He <bhe@redhat.com> wrote:
> 
> >  /*
> > + * Memory regions randomized by KASLR (except modules that use a separate
> > + * logic earlier during boot). Currently they are the physical memory
> > + * mapping, vmalloc and vmemmap regions, are ordered based on virtual
> > + * addresses. The order is kept after randomization.
> > + *
> > + * @base: points to various global variables used by the MM to get the
> > + * virtual base address of the above regions, which base addresses can
> > + * thus be modified by the very early KASLR code to dynamically shape
> > + * the virtual memory layout of these kernel memory regions on a per
> > + * bootup basis.
> > + *
> > + * @size_tb: size in TB of each memory region. Thereinto, the size of
> > + * the physical memory mapping region is variable, calculated according
> > + * to the actual size of system RAM in order to save more space for
> > + * randomization. The rest are fixed values related to paging mode.
> >   */
> >  static __initdata struct kaslr_memory_region {
> >  	unsigned long *base;
> 
> LGTM mostly, except the @size_tb field, see my comments further below.
> 
> Here's an edited version:
> 
> /*
>  * 'struct kasl_memory_region' entries represent continuous chunks of
>  * kernel virtual memory regions, to be randomized by KASLR.
>  *
>  * ( The exception is the module space virtual memory window which
>  *   uses separate logic earlier during bootup. )
>  *
>  * Currently there are three such regions: the physical memory mapping,
>  * vmalloc and vmemmap regions.
>  *
>  * The array below has the entries ordered based on virtual addresses.
>  * The order is kept after randomization, i.e. the randomized
>  * virtual addresses of these regions are still ascending.
>  *
>  * Here are the fields:
>  *
>  * @base: points to a global variable used by the MM to get the
>  * virtual base address of any of the above regions. This allows the
>  * early KASLR code to modify these base addresses early during bootup,
>  * on a per bootup basis, without the MM code even being aware of whether
>  * it got changed and to what value.
>  *
>  * When KASLR is active then the MM code makes sure that for each region
>  * there's such a single, dynamic, global base address 'unsigned long'
>  * variable available for the KASLR code to point to and modify directly:

>  *
>  *       { &page_offset_base, 0 },
>  *       { &vmalloc_base,     0 },
>  *       { &vmemmap_base,     1 },
>  *
>  * @size_tb: size in TB of each memory region. Thereinto, the size of
>  * the physical memory mapping region is variable, calculated according
>  * to the actual size of system RAM in order to save more space for
>  * randomization. The rest are fixed values related to paging mode.
>  */
> 
> The role of @size_tb is still murky to me. What is it telling us?
> Maximum virtual memory range to randomize into? Why does this depend
> on system RAM at all - aren't these all virtual addresses in a 64-bit
> (well, 48-bit or 56-bit) address ranges?

* @size_tb: size in TB of each memory region. Thereinto, the size of
* the physical memory mapping region is variable, calculated according
* to the actual size of system RAM. Since most of systems own RAM memory
* which is much less than 64 TB which is reserved for mapping the maximum
* physical memory in 4-level paging mode, not to mention 5-level. The
* left space can be saved to enhance randomness.
* 
How about this? And please forgive my poor english.

Thanks
Baoquan

  reply	other threads:[~2018-09-11  8:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-09 12:49 [PATCH v2 1/3] x86/mm/KASLR: Fix the wrong calculation of kalsr region initial size Baoquan He
2018-09-09 12:49 ` [PATCH v2 2/3] x86/mm/KASLR: Calculate the actual size of vmemmap region Baoquan He
2018-09-10  6:11   ` Ingo Molnar
2018-09-11  7:30     ` Baoquan He
2018-09-11  7:59       ` Ingo Molnar
2018-09-11  8:18         ` Baoquan He [this message]
2018-09-11  9:28           ` Ingo Molnar
2018-09-11 12:08             ` Baoquan He
2018-09-12  3:18               ` Baoquan He
2018-09-12  6:31                 ` Ingo Molnar
2018-09-12  9:41                   ` Baoquan He
2018-09-12 10:01                     ` Ingo Molnar
2018-09-21  2:10                   ` Baoquan He
2018-09-09 12:49 ` [PATCH v2 3/3] mm: Add build time sanity chcek for struct page size Baoquan He
2018-09-10 13:41   ` kbuild test robot
2018-09-11  7:47     ` Baoquan He
2018-09-10  6:18 ` [PATCH v2 1/3] x86/mm/KASLR: Fix the wrong calculation of kalsr region initial size Ingo Molnar
2018-09-11  7:22   ` Baoquan He

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180911081811.GY1740@192.168.1.3 \
    --to=bhe@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=hpa@zytor.com \
    --cc=keescook@chromium.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=thgarnie@google.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome