Skip to content

x86/mm/pti: close two Meltdown leaks with Global kernel mapping

Dave Hansen lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest7 patches 9 repliesIn review
  2. v15 patches 1 replySuperseded

Changes in v2 from the cover letter

* Modify set_memory_np() to avoid messing with the direct map by limiting its changes to the high kernel image map.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7x86/mm/pti: clear Global bit more aggressivelyarch/x86/mm/pageattr.c arch/x86/mm/pti.c+30 -100 replies
2/7mm: allow non-direct-map arguments to free_reserved_area()mm/page_alloc.c+14 -20 replies
3/7x86/mm/init: pass unconverted symbol addresses to free_init_pages()arch/x86/mm/init_64.c+2 -64 replies
4/7x86/mm/init: add helper for freeing kernel image pagesarch/x86/include/asm/processor.h arch/x86/mm/init.c arch/x86/mm/init_64.c+15 -50 replies
5/7x86/mm/init: remove freed kernel image areas from alias mappingarch/x86/include/asm/set_memory.h arch/x86/mm/init.c arch/x86/mm/pageattr.c+37 -23 replies
6/7x86/mm/pageattr: pass named flag instead of 0/1arch/x86/mm/pageattr.c+8 -62 replies
7/7x86/mm/pageattr: Remove implicit NX behaviorarch/x86/mm/pageattr.c+6 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH 0/7] [v2] x86/mm/pti: close two Meltdown leaks with Global kernel mapping

The fixes for the problem Hugh reported took a bit more surgery than I would have liked, but they do appear to work. Note that the last two patches are unnecessary cleanups that could be removed from backports.

Changes from v1:
* Modify set_memory_np() to avoid messing with the direct map by limiting its changes to the high kernel image map.

--

This applies to 4.17 and 4.18.

Thanks to Hugh Dickins for initially finding the r/w kernel text issue and coming up with an initial fix. I found the "unused hole" part and came up with different approach for fixing the mess.

--

Background:

Process Context IDentifiers (PCIDs) are a hardware feature that allows TLB entries to survive page table switches (CR3 writes). As an optimization, the PTI code currently allows the kernel image to be Global when running on hardware without PCIDs. This results in fewer TLB misses, especially upon entry.

The downside is that these Global areas are theoretically susceptible to Meltdown. The logic is that there are no secrets in the kernel image, so why pay the cost of TLB misses.

Problem:

The current PTI code leaves the entire area of the kernel binary between '_text' and '_end' as Global (on non-PCID hardware). However, that range contains both read-write kernel data, and two "unused" holes in addition to text. The areas which are not text or read-only might contain secrets once they are freed back into the allocator.

This issue affects systems which are susceptible to Meltdown, do not have PCIDs and which are using the default PTI_AUTO mode (no pti=on/off on the cmdline).

PCIDs became generally available for servers in ~2010 (Westmere) and desktop (client) parts in roughly 2011 (Sandybridge). This is not expected to affect anything newer than that.

Solution:

The solution for the read-write area is to clear the global bit for the area (patch #1).

The "unused" holes need a bit more work since we free them in a bit of an ad-hoc way, but we fix this up in patches 2-5.

Cc Kees Cook <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Juergen Gross <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Andi Kleen <[email protected]>