Skip to content

Commit afedc31

Browse files
Alexandre Ghitipalmer-dabbelt
authored andcommitted
riscv: Do not use fortify in early code
Early code designates the code executed when the MMU is not yet enabled, and this comes with some limitations (see Documentation/arch/riscv/boot.rst, section "Pre-MMU execution"). FORTIFY_SOURCE must be disabled then since it can trigger kernel panics as reported in [1]. Reported-by: Jason Montleon <[email protected]> Closes: https://lore.kernel.org/linux-riscv/CAJD_bPJes4QhmXY5f63GHV9B9HFkSCoaZjk-qCT2NGS7Q9HODg@mail.gmail.com/ [1] Fixes: a35707c ("riscv: add memory-type errata for T-Head") Fixes: 26e7aac ("riscv: Allow to downgrade paging mode from the command line") Cc: [email protected] Signed-off-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 1966db6 commit afedc31

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

arch/riscv/errata/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ ifdef CONFIG_RELOCATABLE
22
KBUILD_CFLAGS += -fno-pie
33
endif
44

5+
ifdef CONFIG_RISCV_ALTERNATIVE_EARLY
6+
ifdef CONFIG_FORTIFY_SOURCE
7+
KBUILD_CFLAGS += -D__NO_FORTIFY
8+
endif
9+
endif
10+
511
obj-$(CONFIG_ERRATA_ANDES) += andes/
612
obj-$(CONFIG_ERRATA_SIFIVE) += sifive/
713
obj-$(CONFIG_ERRATA_THEAD) += thead/

arch/riscv/kernel/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ KASAN_SANITIZE_alternative.o := n
3636
KASAN_SANITIZE_cpufeature.o := n
3737
KASAN_SANITIZE_sbi_ecall.o := n
3838
endif
39+
ifdef CONFIG_FORTIFY_SOURCE
40+
CFLAGS_alternative.o += -D__NO_FORTIFY
41+
CFLAGS_cpufeature.o += -D__NO_FORTIFY
42+
CFLAGS_sbi_ecall.o += -D__NO_FORTIFY
43+
endif
3944
endif
4045

4146
extra-y += vmlinux.lds

arch/riscv/kernel/pi/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO), $(KBUILD_CFLAGS))
1616
KBUILD_CFLAGS += -mcmodel=medany
1717

1818
CFLAGS_cmdline_early.o += -D__NO_FORTIFY
19-
CFLAGS_lib-fdt_ro.o += -D__NO_FORTIFY
2019
CFLAGS_fdt_early.o += -D__NO_FORTIFY
20+
# lib/string.c already defines __NO_FORTIFY
21+
CFLAGS_ctype.o += -D__NO_FORTIFY
22+
CFLAGS_lib-fdt.o += -D__NO_FORTIFY
23+
CFLAGS_lib-fdt_ro.o += -D__NO_FORTIFY
24+
CFLAGS_archrandom_early.o += -D__NO_FORTIFY
2125

2226
$(obj)/%.pi.o: OBJCOPYFLAGS := --prefix-symbols=__pi_ \
2327
--remove-section=.note.gnu.property \

0 commit comments

Comments
 (0)