Skip to content

Commit a44ca8f

Browse files
hansendcKAGA-KOKO
authored andcommitted
x86/pti: Reduce amount of kernel text allowed to be Global
commit abb67605203687c8b7943d760638d0301787f8d9 Kees reported to me that I made too much of the kernel image global. It was far more than just text: I think this is too much set global: _end is after data, bss, and brk, and all kinds of other stuff that could hold secrets. I think this should match what mark_rodata_ro() is doing. This does exactly that. We use __end_rodata_hpage_align as our marker both because it is huge-page-aligned and it does not contain any sections we expect to hold secrets. Kees's logic was that r/o data is in the kernel image anyway and, in the case of traditional distributions, can be freely downloaded from the web, so there's no reason to hide it. Fixes: 8c06c77 (x86/pti: Leave kernel text global for !PCID) Reported-by: Kees Cook <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: 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: David Woodhouse <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: [email protected] Cc: Linus Torvalds <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Nadav Amit <[email protected]> Cc: Dan Williams <[email protected]> Cc: Arjan van de Ven <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 58e65b5 commit a44ca8f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

arch/x86/mm/pti.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,24 @@ static inline bool pti_kernel_image_global_ok(void)
430430
*/
431431
void pti_clone_kernel_text(void)
432432
{
433+
/*
434+
* rodata is part of the kernel image and is normally
435+
* readable on the filesystem or on the web. But, do not
436+
* clone the areas past rodata, they might contain secrets.
437+
*/
433438
unsigned long start = PFN_ALIGN(_text);
434-
unsigned long end = ALIGN((unsigned long)_end, PMD_PAGE_SIZE);
439+
unsigned long end = (unsigned long)__end_rodata_hpage_align;
435440

436441
if (!pti_kernel_image_global_ok())
437442
return;
438443

444+
pr_debug("mapping partial kernel image into user address space\n");
445+
446+
/*
447+
* Note that this will undo _some_ of the work that
448+
* pti_set_kernel_image_nonglobal() did to clear the
449+
* global bit.
450+
*/
439451
pti_clone_pmds(start, end, _PAGE_RW);
440452
}
441453

@@ -458,8 +470,6 @@ void pti_set_kernel_image_nonglobal(void)
458470
if (pti_kernel_image_global_ok())
459471
return;
460472

461-
pr_debug("set kernel image non-global\n");
462-
463473
set_memory_nonglobal(start, (end - start) >> PAGE_SHIFT);
464474
}
465475

0 commit comments

Comments
 (0)