linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Alistair Popple <apopple@nvidia.com>
Cc: <x86@kernel.org>, Dan Williams <dan.j.williams@intel.com>,
	<dave.hansen@linux.intel.com>, <luto@kernel.org>,
	<peterz@infradead.org>, <max8rr8@gmail.com>,
	<linux-kernel@vger.kernel.org>, <jhubbard@nvidia.com>,
	Kees Cook <keescook@chromium.org>,
	Andrew Morton <akpm@linuxfoundation.org>,
	David Hildenbrand <david@redhat.com>,
	Oscar Salvador <osalvador@suse.de>, <linux-mm@kvack.org>
Subject: Re: x86/kaslr: Expose and use the end of the physical memory address space
Date: Wed, 14 Aug 2024 07:33:29 -0700	[thread overview]
Message-ID: <66bcc0396d8d1_1c182946e@dwillia2-mobl3.amr.corp.intel.com.notmuch> (raw)
In-Reply-To: <87ed6soy3z.ffs@tglx>

Thomas Gleixner wrote:
> iounmap() on x86 occasionally fails to unmap because the provided valid
> ioremap address is not below high_memory. It turned out that this
> happens due to KASLR.
> 
> KASLR uses the full address space between PAGE_OFFSET and vaddr_end to
> randomize the starting points of the direct map, vmalloc and vmemmap
> regions.  It thereby limits the size of the direct map by using the
> installed memory size plus an extra configurable margin for hot-plug
> memory.  This limitation is done to gain more randomization space
> because otherwise only the holes between the direct map, vmalloc,
> vmemmap and vaddr_end would be usable for randomizing.
> 
> The limited direct map size is not exposed to the rest of the kernel, so
> the memory hot-plug and resource management related code paths still
> operate under the assumption that the available address space can be
> determined with MAX_PHYSMEM_BITS.
> 
> request_free_mem_region() allocates from (1 << MAX_PHYSMEM_BITS) - 1
> downwards.  That means the first allocation happens past the end of the
> direct map and if unlucky this address is in the vmalloc space, which
> causes high_memory to become greater than VMALLOC_START and consequently
> causes iounmap() to fail for valid ioremap addresses.
> 
> MAX_PHYSMEM_BITS cannot be changed for that because the randomization
> does not align with address bit boundaries and there are other places
> which actually require to know the maximum number of address bits.  All
> remaining usage sites of MAX_PHYSMEM_BITS have been analyzed and found
> to be correct.
> 
> Cure this by exposing the end of the direct map via PHYSMEM_END and use
> that for the memory hot-plug and resource management related places
> instead of relying on MAX_PHYSMEM_BITS. In the KASLR case PHYSMEM_END
> maps to a variable which is initialized by the KASLR initialization and
> otherwise it is based on MAX_PHYSMEM_BITS as before.
> 
> To prevent future hickups add a check into add_pages() to catch callers
> trying to add memory above PHYSMEM_END.
> 
> Fixes: 0483e1fa6e09 ("x86/mm: Implement ASLR for kernel memory regions")
> Reported-by: Max Ramanouski <max8rr8@gmail.com>
> Reported-by: Alistair Popple <apopple@nvidia.com>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
[..]
> --- a/arch/x86/mm/kaslr.c
> +++ b/arch/x86/mm/kaslr.c
[..]
> @@ -134,6 +147,8 @@ void __init kernel_randomize_memory(void
>  		 */
>  		vaddr += get_padding(&kaslr_regions[i]);
>  		vaddr = round_up(vaddr + 1, PUD_SIZE);
> +		if (kaslr_regions[i].end)
> +			*kaslr_regions[i].end = __pa(vaddr) - 1;

In the context of the patch it is clear that this is physmem_end, when
someone comes to read this later maybe a comment like:

/* 
 * KASLR trims the maximum possible size of the direct-map record that
 * physmem_end boundary here
 */

With or without that the patch looks good to me:

Reviewed-by: Dan Williams <dan.j.williams@intel.com>


  parent reply	other threads:[~2024-08-14 14:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20230810100011.14552-1-max8rr8@gmail.com>
     [not found] ` <87wmkr4jgj.fsf@nvdebian.thelocal>
2024-08-12  6:15   ` [PATCH 1/1] x86/ioremap: Use is_vmalloc_addr in iounmap Christoph Hellwig
     [not found] ` <87le17yu5y.ffs@tglx>
     [not found]   ` <66b4eb2a62f6_c1448294b0@dwillia2-xfh.jf.intel.com.notmuch>
     [not found]     ` <877ccryor7.ffs@tglx>
     [not found]       ` <66b4f305eb227_c144829443@dwillia2-xfh.jf.intel.com.notmuch>
     [not found]         ` <66b4f4a522508_c1448294f2@dwillia2-xfh.jf.intel.com.notmuch>
     [not found]           ` <87zfpmyhvr.ffs@tglx>
     [not found]             ` <66b523ac448e2_c1448294ec@dwillia2-xfh.jf.intel.com.notmuch>
     [not found]               ` <87seve4e37.fsf@nvdebian.thelocal>
     [not found]                 ` <66b59314b3d4_c1448294d3@dwillia2-xfh.jf.intel.com.notmuch>
     [not found]                   ` <87zfpks23v.ffs@tglx>
     [not found]                     ` <87o75y428z.fsf@nvdebian.thelocal>
     [not found]                       ` <87ikw6rrau.ffs@tglx>
     [not found]                         ` <87frr9swmw.ffs@tglx>
     [not found]                           ` <87bk1x42vk.fsf@nvdebian.thelocal>
     [not found]                             ` <87sev8rfyx.ffs@tglx>
     [not found]                               ` <87le10p3ak.ffs@tglx>
2024-08-13 22:29                                 ` x86/kaslr: Expose and use the end of the physical memory address space Thomas Gleixner
2024-08-14  0:26                                   ` Alistair Popple
2024-08-14 14:33                                   ` Dan Williams [this message]
2024-08-15 16:11                                   ` Kees Cook
2024-08-15 22:48                                   ` Max R
2024-08-16  9:42                                   ` David Hildenbrand
2024-09-22 22:31                                   ` Guenter Roeck

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=66bcc0396d8d1_1c182946e@dwillia2-mobl3.amr.corp.intel.com.notmuch \
    --to=dan.j.williams@intel.com \
    --cc=akpm@linuxfoundation.org \
    --cc=apopple@nvidia.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@redhat.com \
    --cc=jhubbard@nvidia.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=max8rr8@gmail.com \
    --cc=osalvador@suse.de \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --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