Skip to content

Commit 34eb62d

Browse files
committed
Merge tag 'core-build-2020-10-12' of git://git.kernel.org/pub/scm/linux/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 ...
2 parents e6412f9 + 6e0bf0e commit 34eb62d

41 files changed

Lines changed: 378 additions & 253 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

arch/alpha/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ SECTIONS
7272

7373
STABS_DEBUG
7474
DWARF_DEBUG
75+
ELF_DETAILS
7576

7677
DISCARDS
7778
}

arch/arc/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ SECTIONS
122122
_end = . ;
123123

124124
STABS_DEBUG
125+
ELF_DETAILS
125126
DISCARDS
126127

127128
.arcextmap 0 : {

arch/arm/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ LDFLAGS_vmlinux += --be8
1616
KBUILD_LDFLAGS_MODULE += --be8
1717
endif
1818

19+
# We never want expected sections to be placed heuristically by the
20+
# linker. All sections should be explicitly named in the linker script.
21+
LDFLAGS_vmlinux += $(call ld-option, --orphan-handling=warn)
22+
1923
ifeq ($(CONFIG_ARM_MODULE_PLTS),y)
2024
KBUILD_LDS_MODULE += $(srctree)/arch/arm/kernel/module.lds
2125
endif

arch/arm/boot/compressed/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ endif
123123
LDFLAGS_vmlinux += --no-undefined
124124
# Delete all temporary local symbols
125125
LDFLAGS_vmlinux += -X
126+
# Report orphan sections
127+
LDFLAGS_vmlinux += $(call ld-option, --orphan-handling=warn)
126128
# Next argument is a linker script
127129
LDFLAGS_vmlinux += -T
128130

arch/arm/boot/compressed/vmlinux.lds.S

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/*
33
* Copyright (C) 2000 Russell King
44
*/
5+
#include <asm/vmlinux.lds.h>
56

67
#ifdef CONFIG_CPU_ENDIAN_BE8
78
#define ZIMAGE_MAGIC(x) ( (((x) >> 24) & 0x000000ff) | \
@@ -17,8 +18,11 @@ ENTRY(_start)
1718
SECTIONS
1819
{
1920
/DISCARD/ : {
21+
COMMON_DISCARDS
2022
*(.ARM.exidx*)
2123
*(.ARM.extab*)
24+
*(.note.*)
25+
*(.rel.*)
2226
/*
2327
* Discard any r/w data - this produces a link error if we have any,
2428
* which is required for PIC decompression. Local data generates
@@ -36,9 +40,7 @@ SECTIONS
3640
*(.start)
3741
*(.text)
3842
*(.text.*)
39-
*(.gnu.warning)
40-
*(.glue_7t)
41-
*(.glue_7)
43+
ARM_STUBS_TEXT
4244
}
4345
.table : ALIGN(4) {
4446
_table_start = .;
@@ -128,12 +130,10 @@ SECTIONS
128130
PROVIDE(__pecoff_data_size = ALIGN(512) - ADDR(.data));
129131
PROVIDE(__pecoff_end = ALIGN(512));
130132

131-
.stab 0 : { *(.stab) }
132-
.stabstr 0 : { *(.stabstr) }
133-
.stab.excl 0 : { *(.stab.excl) }
134-
.stab.exclstr 0 : { *(.stab.exclstr) }
135-
.stab.index 0 : { *(.stab.index) }
136-
.stab.indexstr 0 : { *(.stab.indexstr) }
137-
.comment 0 : { *(.comment) }
133+
STABS_DEBUG
134+
DWARF_DEBUG
135+
ARM_DETAILS
136+
137+
ARM_ASSERTS
138138
}
139139
ASSERT(_edata_real == _edata, "error: zImage file size is incorrect");
Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
2+
#include <asm-generic/vmlinux.lds.h>
23

34
#ifdef CONFIG_HOTPLUG_CPU
45
#define ARM_CPU_DISCARD(x)
@@ -49,8 +50,29 @@
4950
EXIT_CALL \
5051
ARM_MMU_DISCARD(*(.text.fixup)) \
5152
ARM_MMU_DISCARD(*(__ex_table)) \
52-
*(.discard) \
53-
*(.discard.*)
53+
COMMON_DISCARDS
54+
55+
/*
56+
* Sections that should stay zero sized, which is safer to explicitly
57+
* check instead of blindly discarding.
58+
*/
59+
#define ARM_ASSERTS \
60+
.plt : { \
61+
*(.iplt) *(.rel.iplt) *(.iplt) *(.igot.plt) \
62+
} \
63+
ASSERT(SIZEOF(.plt) == 0, \
64+
"Unexpected run-time procedure linkages detected!")
65+
66+
#define ARM_DETAILS \
67+
ELF_DETAILS \
68+
.ARM.attributes 0 : { *(.ARM.attributes) }
69+
70+
#define ARM_STUBS_TEXT \
71+
*(.gnu.warning) \
72+
*(.glue_7) \
73+
*(.glue_7t) \
74+
*(.vfp11_veneer) \
75+
*(.v4_bx)
5476

5577
#define ARM_TEXT \
5678
IDMAP_TEXT \
@@ -64,9 +86,7 @@
6486
CPUIDLE_TEXT \
6587
LOCK_TEXT \
6688
KPROBES_TEXT \
67-
*(.gnu.warning) \
68-
*(.glue_7) \
69-
*(.glue_7t) \
89+
ARM_STUBS_TEXT \
7090
. = ALIGN(4); \
7191
*(.got) /* Global offset table */ \
7292
ARM_CPU_KEEP(PROC_INFO)

arch/arm/kernel/vmlinux-xip.lds.S

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
#include <linux/sizes.h>
1111

12-
#include <asm-generic/vmlinux.lds.h>
12+
#include <asm/vmlinux.lds.h>
1313
#include <asm/cache.h>
1414
#include <asm/thread_info.h>
1515
#include <asm/memory.h>
1616
#include <asm/mpu.h>
1717
#include <asm/page.h>
1818

19-
#include "vmlinux.lds.h"
20-
2119
OUTPUT_ARCH(arm)
2220
ENTRY(stext)
2321

@@ -152,6 +150,10 @@ SECTIONS
152150
_end = .;
153151

154152
STABS_DEBUG
153+
DWARF_DEBUG
154+
ARM_DETAILS
155+
156+
ARM_ASSERTS
155157
}
156158

157159
/*

arch/arm/kernel/vmlinux.lds.S

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
#else
1010

1111
#include <linux/pgtable.h>
12-
#include <asm-generic/vmlinux.lds.h>
12+
#include <asm/vmlinux.lds.h>
1313
#include <asm/cache.h>
1414
#include <asm/thread_info.h>
1515
#include <asm/memory.h>
1616
#include <asm/mpu.h>
1717
#include <asm/page.h>
1818

19-
#include "vmlinux.lds.h"
20-
2119
OUTPUT_ARCH(arm)
2220
ENTRY(stext)
2321

@@ -151,6 +149,10 @@ SECTIONS
151149
_end = .;
152150

153151
STABS_DEBUG
152+
DWARF_DEBUG
153+
ARM_DETAILS
154+
155+
ARM_ASSERTS
154156
}
155157

156158
#ifdef CONFIG_STRICT_KERNEL_RWX

arch/arm64/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ LDFLAGS_vmlinux += --fix-cortex-a53-843419
2828
endif
2929
endif
3030

31+
# We never want expected sections to be placed heuristically by the
32+
# linker. All sections should be explicitly named in the linker script.
33+
LDFLAGS_vmlinux += $(call ld-option, --orphan-handling=warn)
34+
3135
ifeq ($(CONFIG_ARM64_USE_LSE_ATOMICS), y)
3236
ifneq ($(CONFIG_ARM64_LSE_ATOMICS), y)
3337
$(warning LSE atomics not supported by binutils)
@@ -46,13 +50,16 @@ endif
4650

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

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

59+
# Avoid generating .eh_frame* sections.
60+
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
61+
KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
62+
5663
ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
5764
prepare: stack_protector_prepare
5865
stack_protector_prepare: prepare0

arch/arm64/kernel/smccc-call.S

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <asm/assembler.h>
1010

1111
.macro SMCCC instr
12-
.cfi_startproc
1312
\instr #0
1413
ldr x4, [sp]
1514
stp x0, x1, [x4, #ARM_SMCCC_RES_X0_OFFS]
@@ -21,7 +20,6 @@
2120
b.ne 1f
2221
str x6, [x4, ARM_SMCCC_QUIRK_STATE_OFFS]
2322
1: ret
24-
.cfi_endproc
2523
.endm
2624

2725
/*

0 commit comments

Comments
 (0)