Skip to content

x86: updated patches for kaslr and setup_data etc for v4.3

Yinghai Lu kernel-hardening linux-efi linux-pci lkml stable 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest42 patches 31 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/42x86, kasl: Remove not needed parameter for choose_kernel_locationarch/x86/boot/compressed/aslr.c arch/x86/boot/compressed/misc.c arch/x86/boot/compressed/misc.h+5 -81 reply
2/42x86, boot: Move compressed kernel to end of buffer before decompressingarch/x86/boot/compressed/head_32.S arch/x86/boot/compressed/head_64.S arch/x86/boot/compressed/mkpiggy.c +4 more+21 -101 reply
3/42x86, boot: Fix run_size calculationarch/x86/boot/Makefile arch/x86/boot/compressed/Makefile arch/x86/boot/compressed/misc.c+16 -101 reply
4/42x86, kaslr: Kill not needed and wrong run_size calculation code.arch/x86/boot/compressed/Makefile arch/x86/boot/compressed/head_32.S arch/x86/boot/compressed/head_64.S +3 more+6 -611 reply
5/42x86, kaslr: rename output_size to output_run_sizearch/x86/boot/compressed/aslr.c arch/x86/boot/compressed/misc.c arch/x86/boot/compressed/misc.h+11 -90 replies
6/42x86, kaslr: Consolidate mem_avoid array fillingarch/x86/boot/compressed/aslr.c+13 -161 reply
7/42x86, boot: Move z_extract_offset calculation to header.Sarch/x86/boot/Makefile arch/x86/boot/compressed/misc.c arch/x86/boot/compressed/mkpiggy.c +1 more+32 -200 replies
8/42x86, kaslr: Get correct max_addr for relocs pointerarch/x86/boot/compressed/Makefile arch/x86/boot/compressed/misc.c+2 -21 reply
9/42x86, boot: Split kernel_ident_mapping_init to another filearch/x86/include/asm/page.h arch/x86/mm/ident_map.c arch/x86/mm/init_64.c+80 -730 replies
10/42x86, 64bit: Set ident_mapping for kaslrarch/x86/boot/compressed/Makefile arch/x86/boot/compressed/aslr.c arch/x86/boot/compressed/head_64.S +3 more+140 -20 replies
11/42x86, boot: Add checking for memcpyarch/x86/boot/compressed/misc.c arch/x86/boot/compressed/misc.h arch/x86/boot/compressed/string.c+35 -90 replies
12/42x86, kaslr: Fix a bug that relocation can not be handled when kernel is loaded above 2Garch/x86/boot/compressed/misc.c+1 -11 reply
13/42x86, kaslr: Introduce struct slot_area to manage randomization slot infoarch/x86/boot/compressed/aslr.c+12 -00 replies
14/42x86, kaslr: Add two functions which will be used laterarch/x86/boot/compressed/aslr.c+51 -00 replies
15/42x86, kaslr: Introduce fetch_random_virt_offset to randomize the kernel text mapping addressarch/x86/boot/compressed/aslr.c+21 -00 replies
16/42x86, kaslr: Randomize physical and virtual address of kernel separatelyarch/x86/boot/compressed/aslr.c arch/x86/boot/compressed/misc.c arch/x86/boot/compressed/misc.h+58 -460 replies
17/42x86, kaslr: Add support of kernel physical address randomization above 4Garch/x86/boot/compressed/aslr.c+51 -170 replies
18/42x86, kaslr: Remove useless codesarch/x86/boot/compressed/aslr.c+0 -240 replies
19/42x86, kaslr: Allow random address could be below loaded addressarch/x86/boot/compressed/aslr.c+8 -20 replies
20/42x86, boot: Add printf support for early console in compressed/misc.carch/x86/boot/compressed/Makefile arch/x86/boot/compressed/misc.c arch/x86/boot/compressed/misc.h +1 more+51 -10 replies
21/42x86, boot: Add more debug printout in compressed/misc.carch/x86/boot/compressed/misc.c+11 -10 replies
22/42x86, setup: Check early serial console per string instead of one chararch/x86/boot/tty.c+10 -41 reply
23/42x86, setup: Use puts() instead of printf() in edd codearch/x86/boot/edd.c+2 -20 replies
24/42x86: Setup early console as early as possible in x86_start_kernel()arch/x86/include/asm/setup.h arch/x86/kernel/head.c arch/x86/kernel/head32.c +3 more+57 -50 replies
25/42x86, boot: print compression suffix in decompress stagearch/x86/boot/compressed/misc.c+8 -01 reply
26/42x86: remove not needed clear_page callingarch/x86/kernel/head64.c+0 -11 reply
27/42x86: restore end_of_ram to E820_RAMarch/x86/kernel/e820.c+4 -84 replies
28/42x86, boot: Allow 64bit EFI kernel to be loaded above 4GDocumentation/x86/boot.txt arch/x86/boot/compressed/eboot.c arch/x86/boot/compressed/head_64.S +3 more+39 -72 replies
29/42x86: Find correct 64 bit ramdisk address for microcode early updatearch/x86/include/asm/setup.h arch/x86/kernel/cpu/microcode/amd_early.c arch/x86/kernel/cpu/microcode/intel_early.c +1 more+26 -231 reply
30/42x86: Kill E820_RESERVED_KERNarch/x86/include/uapi/asm/e820.h arch/x86/kernel/e820.c arch/x86/kernel/setup.c +2 more+7 -460 replies
31/42x86, efi: Copy SETUP_EFI data and access directlyarch/x86/include/asm/efi.h arch/x86/platform/efi/efi.c arch/x86/platform/efi/efi_64.c +1 more+18 -302 replies
32/42x86, of: Let add_dtb reserve setup_data locallyarch/x86/include/asm/prom.h arch/x86/kernel/devicetree.c+27 -210 replies
33/42x86, boot: Add add_pci handler for SETUP_PCIarch/x86/include/asm/pci.h arch/x86/kernel/setup.c arch/x86/pci/common.c+38 -141 reply
34/42x86: Kill not used setup_data handling codearch/x86/kernel/kdebugfs.c arch/x86/kernel/setup.c+0 -1590 replies
35/42x86, boot, PCI: Convert SETUP_PCI data to listarch/x86/include/asm/pci.h arch/x86/kernel/setup.c arch/x86/pci/common.c+65 -152 replies
36/42x86, boot, PCI: Copy SETUP_PCI rom to kernel spacearch/x86/pci/common.c+45 -20 replies
37/42x86, boot, PCI: Export SETUP_PCI data via sysfsarch/x86/pci/common.c+175 -00 replies
38/42x86: Fix typo in mark_rodata_roarch/x86/mm/init_64.c+2 -21 reply
39/42x86, 64bit: add pfn_range_is_highmapped()arch/x86/include/asm/pgtable_64.h arch/x86/mm/init_64.c arch/x86/mm/pageattr.c+25 -150 replies
40/42x86, 64bit: remove highmap for not needed rangesarch/x86/mm/init_64.c+62 -01 reply
41/42x86, 64bit: Add __pa_high/__va_higharch/x86/kernel/head64.c+9 -60 replies
42/42x86: fix msr print againarch/x86/include/asm/processor.h arch/x86/kernel/cpu/common.c+32 -300 replies

Reviews trailers per patch

5 of 42 patches have a Reviewed-by or Acked-by.

PatchLee, Chun-YiKees CookMel GormanSeth Forshee
SeriesT-b
1/42A-b
2/42
3/42
4/42
5/42
6/42
7/42
8/42A-b
9/42R-b
10/42
11/42
12/42A-b
13/42
14/42
15/42
16/42
17/42
18/42
19/42
20/42
21/42
22/42
23/42
24/42
25/42
26/42
27/42
28/42
29/42A-b
30/42T-b
31/42
32/42
33/42
34/42
35/42T-b
36/42
37/42
38/42
39/42
40/42
41/42
42/42

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v1 thread

Cover letter [PATCH 00/42] x86: updated patches for kaslr and setup_data etc for v4.3

Those patches are rebased on v4.2-rc1 that I sent before but were rejected by Ingo on changelog.

Kees Cook said that he would like to give a try to make improvement on changelog to get things moving.

First part are kaslr related:
1. First put compressed kernel ZO near end of the buffer before decompressing so we can find the ZO position easily for kaslr buffer searchin
2. kill run_size calculation shell scripts.
3. create new ident mapping for kasl 64bit, so we can cover
above 4G random kernel base
4. 7 patches from He that support random random, as I already used his patches to test the ident mapping code.
5. some debug patches for boot/kaslr.

Second part are setup_data related:
Now setup_data is reserved via memblock and e820 and different handlers have different ways, and it is confusing.
1. SETUP_E820_EXT: is consumed early and will not copy or access again. have memory wasted.
2. SETUP_EFI: is accessed via ioremap every time at early stage. have memory wasted.
3. SETUP_DTB: is copied locally.
have memory wasted.
4. SETUP_PCI: is accessed via ioremap for every pci devices, even run-time. Also setup_data is exported to debugfs for debug purpose.
Here will convert to let every handler to decide how to handle it. and will not reserve the setup_data generally, so will not waste memory and also make memblock/e820 keep page aligned.
1. not touch E820 anymore.
2. copy SETUP_EFI to __initdata variable and access it without ioremap.
3. SETUP_DTB: reserver and copy to local and free.
4. SETUP_PCI: reverve localy and convert to list, to avoid keeping ioremap.
5. export SETUP_PCI via sysfs.

Third part are some small cleanup patches.

put those patches at
git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-x86-v4.3-next

Thanks

Yinghai

Baoquan He (7):
x86, kaslr: Fix a bug that relocation can not be handled when kernel is loaded above 2G x86, kaslr: Introduce struct slot_area to manage randomization slot info x86, kaslr: Add two functions which will be used later
x86, kaslr: Introduce fetch_random_virt_offset to randomize the kernel text mapping address x86, kaslr: Randomize physical and virtual address of kernel separately
x86, kaslr: Add support of kernel physical address randomization above 4G x86, kaslr: Remove useless codes

Yinghai Lu (35):
x86, kasl: Remove not needed parameter for choose_kernel_location x86, boot: Move compressed kernel to end of buffer before decompressing x86, boot: Fix run_size calculation
x86, kaslr: Kill not needed and wrong run_size calculation code. x86, kaslr: rename output_size to output_run_size
x86, kaslr: Consolidate mem_avoid array filling
x86, boot: Move z_extract_offset calculation to header.S x86, kaslr: Get correct max_addr for relocs pointer
x86, boot: Split kernel_ident_mapping_init to another file x86, 64bit: Set ident_mapping for kaslr
x86, boot: Add checking for memcpy
x86, kaslr: Allow random address could be below loaded address x86, boot: Add printf support for early console in compressed/misc.c x86, boot: Add more debug printout in compressed/misc.c x86, setup: Check early serial console per string instead of one char x86, setup: Use puts() instead of printf() in edd code
x86: Setup early console as early as possible in x86_start_kernel() x86, boot: print compression suffix in decompress stage
x86: remove not needed clear_page calling
x86: restore end_of_ram to E820_RAM
x86, boot: Allow 64bit EFI kernel to be loaded above 4G
x86: Find correct 64 bit ramdisk address for microcode early update
x86: Kill E820_RESERVED_KERN
x86, efi: Copy SETUP_EFI data and access directly
x86, of: Let add_dtb reserve setup_data locally
x86, boot: Add add_pci handler for SETUP_PCI
x86: Kill not used setup_data handling code
x86, boot, PCI: Convert SETUP_PCI data to list
x86, boot, PCI: Copy SETUP_PCI rom to kernel space
x86, boot, PCI: Export SETUP_PCI data via sysfs
x86: Fix typo in mark_rodata_ro
x86, 64bit: add pfn_range_is_highmapped()
x86, 64bit: remove highmap for not needed ranges
x86, 64bit: Add __pa_high/__va_high
x86: fix msr print again

 Documentation/x86/boot.txt                  |  19 ++
 arch/x86/boot/Makefile                      |  13 +-
 arch/x86/boot/compressed/Makefile           |  21 +-
 arch/x86/boot/compressed/aslr.c             | 258 ++++++++++++++++-------
 arch/x86/boot/compressed/eboot.c            |  15 +-
 arch/x86/boot/compressed/head_32.S          |  14 +-
 arch/x86/boot/compressed/head_64.S          |  22 +-
 arch/x86/boot/compressed/misc.c             | 129 +++++++++---
 arch/x86/boot/compressed/misc.h             |  41 +++-
 arch/x86/boot/compressed/misc_pgt.c         |  91 ++++++++
 arch/x86/boot/compressed/mkpiggy.c          |  28 +--
 arch/x86/boot/compressed/printf.c           |   5 +
 arch/x86/boot/compressed/string.c           |  28 ++-
 arch/x86/boot/compressed/vmlinux.lds.S      |   1 +
 arch/x86/boot/edd.c                         |   4 +-
 arch/x86/boot/header.S                      |  34 ++-
 arch/x86/boot/tty.c                         |  14 +-
 arch/x86/include/asm/boot.h                 |  19 ++
 arch/x86/include/asm/efi.h                  |   2 +-
 arch/x86/include/asm/page.h                 |   5 +
 arch/x86/include/asm/pci.h                  |   4 +
 arch/x86/include/asm/pgtable_64.h           |   2 +
 arch/x86/include/asm/processor.h            |   1 -
 arch/x86/include/asm/prom.h                 |   9 +-
 arch/x86/include/asm/setup.h                |   5 +
 arch/x86/include/uapi/asm/bootparam.h       |   1 +
 arch/x86/include/uapi/asm/e820.h            |   8 -
 arch/x86/kernel/asm-offsets.c               |   2 +
 arch/x86/kernel/cpu/common.c                |  61 +++---
 arch/x86/kernel/cpu/microcode/amd_early.c   |  10 +-
 arch/x86/kernel/cpu/microcode/intel_early.c |   8 +-
 arch/x86/kernel/devicetree.c                |  39 ++--
 arch/x86/kernel/e820.c                      |  18 +-
 arch/x86/kernel/head.c                      |  26 +++
 arch/x86/kernel/head32.c                    |   1 +
 arch/x86/kernel/head64.c                    |  21 +-
 arch/x86/kernel/kdebugfs.c                  | 142 -------------
 arch/x86/kernel/setup.c                     |  79 ++-----
 arch/x86/kernel/tboot.c                     |   3 +-
 arch/x86/kernel/vmlinux.lds.S               |   1 +
 arch/x86/mm/ident_map.c                     |  74 +++++++
 arch/x86/mm/init_64.c                       | 173 +++++++--------
 arch/x86/mm/pageattr.c                      |  16 +-
 arch/x86/pci/common.c                       | 313 ++++++++++++++++++++++++++--
 arch/x86/platform/efi/efi.c                 |  13 +-
 arch/x86/platform/efi/efi_64.c              |  10 +-
 arch/x86/platform/efi/quirks.c              |  23 +-
 arch/x86/tools/calc_run_size.sh             |  42 ----
 drivers/tty/serial/8250/8250_early.c        |  17 ++
 kernel/printk/printk.c                      |  11 +-
 50 files changed, 1235 insertions(+), 661 deletions(-)
 create mode 100644 arch/x86/boot/compressed/misc_pgt.c
 create mode 100644 arch/x86/boot/compressed/printf.c
 create mode 100644 arch/x86/mm/ident_map.c
 delete mode 100644 arch/x86/tools/calc_run_size.sh
Signature · 1 line
1.8.4.5