Skip to content

Commit

Permalink
Merge tag 'core-build-2020-10-12' of git://git.kernel.org/pub/scm/lin…
Browse files Browse the repository at this point in the history
…ux/kernel/git/tip/tip

Pull orphan section checking from Ingo Molnar:
 "Orphan link sections were a long-standing source of obscure bugs,
  because the heuristics that various linkers & compilers use to handle
  them (include these bits into the output image vs discarding them
  silently) are both highly idiosyncratic and also version dependent.

  Instead of this historically problematic mess, this tree by Kees Cook
  (et al) adds build time asserts and build time warnings if there's any
  orphan section in the kernel or if a section is not sized as expected.

  And because we relied on so many silent assumptions in this area, fix
  a metric ton of dependencies and some outright bugs related to this,
  before we can finally enable the checks on the x86, ARM and ARM64
  platforms"

* tag 'core-build-2020-10-12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (36 commits)
  x86/boot/compressed: Warn on orphan section placement
  x86/build: Warn on orphan section placement
  arm/boot: Warn on orphan section placement
  arm/build: Warn on orphan section placement
  arm64/build: Warn on orphan section placement
  x86/boot/compressed: Add missing debugging sections to output
  x86/boot/compressed: Remove, discard, or assert for unwanted sections
  x86/boot/compressed: Reorganize zero-size section asserts
  x86/build: Add asserts for unwanted sections
  x86/build: Enforce an empty .got.plt section
  x86/asm: Avoid generating unused kprobe sections
  arm/boot: Handle all sections explicitly
  arm/build: Assert for unwanted sections
  arm/build: Add missing sections
  arm/build: Explicitly keep .ARM.attributes sections
  arm/build: Refactor linker script headers
  arm64/build: Assert for unwanted sections
  arm64/build: Add missing DWARF sections
  arm64/build: Use common DISCARDS in linker script
  arm64/build: Remove .eh_frame* sections due to unwind tables
  ...
  • Loading branch information
torvalds committed Oct 12, 2020
2 parents e6412f9 + 6e0bf0e commit 34eb62d
Show file tree
Hide file tree
Showing 41 changed files with 378 additions and 253 deletions.
1 change: 1 addition & 0 deletions arch/alpha/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ SECTIONS

STABS_DEBUG
DWARF_DEBUG
ELF_DETAILS

DISCARDS
}
1 change: 1 addition & 0 deletions arch/arc/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ SECTIONS
_end = . ;

STABS_DEBUG
ELF_DETAILS
DISCARDS

.arcextmap 0 : {
Expand Down
4 changes: 4 additions & 0 deletions arch/arm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ LDFLAGS_vmlinux += --be8
KBUILD_LDFLAGS_MODULE += --be8
endif

# We never want expected sections to be placed heuristically by the
# linker. All sections should be explicitly named in the linker script.
LDFLAGS_vmlinux += $(call ld-option, --orphan-handling=warn)

ifeq ($(CONFIG_ARM_MODULE_PLTS),y)
KBUILD_LDS_MODULE += $(srctree)/arch/arm/kernel/module.lds
endif
Expand Down
2 changes: 2 additions & 0 deletions arch/arm/boot/compressed/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ endif
LDFLAGS_vmlinux += --no-undefined
# Delete all temporary local symbols
LDFLAGS_vmlinux += -X
# Report orphan sections
LDFLAGS_vmlinux += $(call ld-option, --orphan-handling=warn)
# Next argument is a linker script
LDFLAGS_vmlinux += -T

Expand Down
20 changes: 10 additions & 10 deletions arch/arm/boot/compressed/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/*
* Copyright (C) 2000 Russell King
*/
#include <asm/vmlinux.lds.h>

#ifdef CONFIG_CPU_ENDIAN_BE8
#define ZIMAGE_MAGIC(x) ( (((x) >> 24) & 0x000000ff) | \
Expand All @@ -17,8 +18,11 @@ ENTRY(_start)
SECTIONS
{
/DISCARD/ : {
COMMON_DISCARDS
*(.ARM.exidx*)
*(.ARM.extab*)
*(.note.*)
*(.rel.*)
/*
* Discard any r/w data - this produces a link error if we have any,
* which is required for PIC decompression. Local data generates
Expand All @@ -36,9 +40,7 @@ SECTIONS
*(.start)
*(.text)
*(.text.*)
*(.gnu.warning)
*(.glue_7t)
*(.glue_7)
ARM_STUBS_TEXT
}
.table : ALIGN(4) {
_table_start = .;
Expand Down Expand Up @@ -128,12 +130,10 @@ SECTIONS
PROVIDE(__pecoff_data_size = ALIGN(512) - ADDR(.data));
PROVIDE(__pecoff_end = ALIGN(512));

.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
STABS_DEBUG
DWARF_DEBUG
ARM_DETAILS

ARM_ASSERTS
}
ASSERT(_edata_real == _edata, "error: zImage file size is incorrect");
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* SPDX-License-Identifier: GPL-2.0 */
#include <asm-generic/vmlinux.lds.h>

#ifdef CONFIG_HOTPLUG_CPU
#define ARM_CPU_DISCARD(x)
Expand Down Expand Up @@ -49,8 +50,29 @@
EXIT_CALL \
ARM_MMU_DISCARD(*(.text.fixup)) \
ARM_MMU_DISCARD(*(__ex_table)) \
*(.discard) \
*(.discard.*)
COMMON_DISCARDS

/*
* Sections that should stay zero sized, which is safer to explicitly
* check instead of blindly discarding.
*/
#define ARM_ASSERTS \
.plt : { \
*(.iplt) *(.rel.iplt) *(.iplt) *(.igot.plt) \
} \
ASSERT(SIZEOF(.plt) == 0, \
"Unexpected run-time procedure linkages detected!")

#define ARM_DETAILS \
ELF_DETAILS \
.ARM.attributes 0 : { *(.ARM.attributes) }

#define ARM_STUBS_TEXT \
*(.gnu.warning) \
*(.glue_7) \
*(.glue_7t) \
*(.vfp11_veneer) \
*(.v4_bx)

#define ARM_TEXT \
IDMAP_TEXT \
Expand All @@ -64,9 +86,7 @@
CPUIDLE_TEXT \
LOCK_TEXT \
KPROBES_TEXT \
*(.gnu.warning) \
*(.glue_7) \
*(.glue_7t) \
ARM_STUBS_TEXT \
. = ALIGN(4); \
*(.got) /* Global offset table */ \
ARM_CPU_KEEP(PROC_INFO)
Expand Down
8 changes: 5 additions & 3 deletions arch/arm/kernel/vmlinux-xip.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

#include <linux/sizes.h>

#include <asm-generic/vmlinux.lds.h>
#include <asm/vmlinux.lds.h>
#include <asm/cache.h>
#include <asm/thread_info.h>
#include <asm/memory.h>
#include <asm/mpu.h>
#include <asm/page.h>

#include "vmlinux.lds.h"

OUTPUT_ARCH(arm)
ENTRY(stext)

Expand Down Expand Up @@ -152,6 +150,10 @@ SECTIONS
_end = .;

STABS_DEBUG
DWARF_DEBUG
ARM_DETAILS

ARM_ASSERTS
}

/*
Expand Down
8 changes: 5 additions & 3 deletions arch/arm/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
#else

#include <linux/pgtable.h>
#include <asm-generic/vmlinux.lds.h>
#include <asm/vmlinux.lds.h>
#include <asm/cache.h>
#include <asm/thread_info.h>
#include <asm/memory.h>
#include <asm/mpu.h>
#include <asm/page.h>

#include "vmlinux.lds.h"

OUTPUT_ARCH(arm)
ENTRY(stext)

Expand Down Expand Up @@ -151,6 +149,10 @@ SECTIONS
_end = .;

STABS_DEBUG
DWARF_DEBUG
ARM_DETAILS

ARM_ASSERTS
}

#ifdef CONFIG_STRICT_KERNEL_RWX
Expand Down
9 changes: 8 additions & 1 deletion arch/arm64/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ LDFLAGS_vmlinux += --fix-cortex-a53-843419
endif
endif

# We never want expected sections to be placed heuristically by the
# linker. All sections should be explicitly named in the linker script.
LDFLAGS_vmlinux += $(call ld-option, --orphan-handling=warn)

ifeq ($(CONFIG_ARM64_USE_LSE_ATOMICS), y)
ifneq ($(CONFIG_ARM64_LSE_ATOMICS), y)
$(warning LSE atomics not supported by binutils)
Expand All @@ -46,13 +50,16 @@ endif

KBUILD_CFLAGS += -mgeneral-regs-only \
$(compat_vdso) $(cc_has_k_constraint)
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
KBUILD_CFLAGS += $(call cc-disable-warning, psabi)
KBUILD_AFLAGS += $(compat_vdso)

KBUILD_CFLAGS += $(call cc-option,-mabi=lp64)
KBUILD_AFLAGS += $(call cc-option,-mabi=lp64)

# Avoid generating .eh_frame* sections.
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables

ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
prepare: stack_protector_prepare
stack_protector_prepare: prepare0
Expand Down
2 changes: 0 additions & 2 deletions arch/arm64/kernel/smccc-call.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <asm/assembler.h>

.macro SMCCC instr
.cfi_startproc
\instr #0
ldr x4, [sp]
stp x0, x1, [x4, #ARM_SMCCC_RES_X0_OFFS]
Expand All @@ -21,7 +20,6 @@
b.ne 1f
str x6, [x4, ARM_SMCCC_QUIRK_STATE_OFFS]
1: ret
.cfi_endproc
.endm

/*
Expand Down
28 changes: 24 additions & 4 deletions arch/arm64/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#define RO_EXCEPTION_TABLE_ALIGN 8
#define RUNTIME_DISCARD_EXIT

#include <asm-generic/vmlinux.lds.h>
#include <asm/cache.h>
Expand Down Expand Up @@ -96,13 +97,10 @@ SECTIONS
* matching the same input section name. There is no documented
* order of matching.
*/
DISCARDS
/DISCARD/ : {
EXIT_CALL
*(.discard)
*(.discard.*)
*(.interp .dynamic)
*(.dynsym .dynstr .hash .gnu.hash)
*(.eh_frame)
}

. = KIMAGE_VADDR;
Expand Down Expand Up @@ -131,6 +129,14 @@ SECTIONS
*(.got) /* Global offset table */
}

/*
* Make sure that the .got.plt is either completely empty or it
* contains only the lazy dispatch entries.
*/
.got.plt : { *(.got.plt) }
ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18,
"Unexpected GOT/PLT entries detected!")

. = ALIGN(SEGMENT_ALIGN);
_etext = .; /* End of text section */

Expand Down Expand Up @@ -249,8 +255,22 @@ SECTIONS
_end = .;

STABS_DEBUG
DWARF_DEBUG
ELF_DETAILS

HEAD_SYMBOLS

/*
* Sections that should stay zero sized, which is safer to
* explicitly check instead of blindly discarding.
*/
.plt : {
*(.plt) *(.plt.*) *(.iplt) *(.igot)
}
ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")

.data.rel.ro : { *(.data.rel.ro) }
ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!")
}

#include "image-vars.h"
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/mm/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
u64 idmap_t0sz = TCR_T0SZ(VA_BITS);
u64 idmap_ptrs_per_pgd = PTRS_PER_PGD;

u64 __section(".mmuoff.data.write") vabits_actual;
u64 __section(.mmuoff.data.write) vabits_actual;
EXPORT_SYMBOL(vabits_actual);

u64 kimage_voffset __ro_after_init;
Expand Down
1 change: 1 addition & 0 deletions arch/csky/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ SECTIONS

STABS_DEBUG
DWARF_DEBUG
ELF_DETAILS

DISCARDS
}
1 change: 1 addition & 0 deletions arch/hexagon/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ SECTIONS

STABS_DEBUG
DWARF_DEBUG
ELF_DETAILS

}
1 change: 1 addition & 0 deletions arch/ia64/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ SECTIONS {

STABS_DEBUG
DWARF_DEBUG
ELF_DETAILS

/* Default discards */
DISCARDS
Expand Down
1 change: 1 addition & 0 deletions arch/mips/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ SECTIONS

STABS_DEBUG
DWARF_DEBUG
ELF_DETAILS

/* These must appear regardless of . */
.gptab.sdata : {
Expand Down
1 change: 1 addition & 0 deletions arch/nds32/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ SECTIONS

STABS_DEBUG
DWARF_DEBUG
ELF_DETAILS

DISCARDS
}
1 change: 1 addition & 0 deletions arch/nios2/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ SECTIONS

STABS_DEBUG
DWARF_DEBUG
ELF_DETAILS

DISCARDS
}
1 change: 1 addition & 0 deletions arch/openrisc/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ SECTIONS
/* Throw in the debugging sections */
STABS_DEBUG
DWARF_DEBUG
ELF_DETAILS

/* Sections to be discarded -- must be last */
DISCARDS
Expand Down
1 change: 1 addition & 0 deletions arch/parisc/boot/compressed/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ SECTIONS
}

STABS_DEBUG
ELF_DETAILS
.note 0 : { *(.note) }

/* Sections to be discarded */
Expand Down
1 change: 1 addition & 0 deletions arch/parisc/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ SECTIONS
_end = . ;

STABS_DEBUG
ELF_DETAILS
.note 0 : { *(.note) }

/* Sections to be discarded */
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ SECTIONS
PROVIDE32 (end = .);

STABS_DEBUG

DWARF_DEBUG
ELF_DETAILS

DISCARDS
/DISCARD/ : {
Expand Down
1 change: 1 addition & 0 deletions arch/riscv/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ SECTIONS

STABS_DEBUG
DWARF_DEBUG
ELF_DETAILS

DISCARDS
}
Loading

0 comments on commit 34eb62d

Please sign in to comment.