summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVasily Gorbik <gor@linux.ibm.com>2019-08-11 14:55:18 -0400
committerVasily Gorbik <gor@linux.ibm.com>2019-08-21 06:58:52 -0400
commit2e83e0eb85ca62985406920f97ece36d822d421f (patch)
treeb4d13c99106c0f44bb7c1e9b8465a00386e489ff
parent19413fe04f49b32c63b470079afef8d1c7995cc1 (diff)
s390: clean .bss before running uncompressed kernel
Clean uncompressed kernel .bss section in the startup code before the uncompressed kernel is executed. At this point of time initrd and certificates have been already rescued. Uncompressed kernel .bss size is known from vmlinux_info. It is also taken into consideration during uncompressed kernel positioning by kaslr (so it is safe to clean it). With that uncompressed kernel is starting with .bss section zeroed and no .bss section usage restrictions apply. Which makes chkbss checks for uncompressed kernel objects obsolete and they can be removed. early_nobss.c is also not needed anymore. Parts of it which are still relevant are moved to early.c. Kasan initialization code is now called directly from head64 (early.c is instrumented and should not be executed before kasan shadow memory is set up). Reviewed-by: Philipp Rudo <prudo@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
-rw-r--r--arch/s390/boot/startup.c6
-rw-r--r--arch/s390/kernel/Makefile13
-rw-r--r--arch/s390/kernel/early.c16
-rw-r--r--arch/s390/kernel/early_nobss.c45
-rw-r--r--arch/s390/kernel/head64.S8
-rw-r--r--arch/s390/lib/Makefile3
-rw-r--r--drivers/s390/char/Makefile3
7 files changed, 26 insertions, 68 deletions
diff --git a/arch/s390/boot/startup.c b/arch/s390/boot/startup.c
index 7b0d05414618..596ca7cc4d7b 100644
--- a/arch/s390/boot/startup.c
+++ b/arch/s390/boot/startup.c
@@ -112,6 +112,11 @@ static void handle_relocs(unsigned long offset)
112 } 112 }
113} 113}
114 114
115static void clear_bss_section(void)
116{
117 memset((void *)vmlinux.default_lma + vmlinux.image_size, 0, vmlinux.bss_size);
118}
119
115void startup_kernel(void) 120void startup_kernel(void)
116{ 121{
117 unsigned long random_lma; 122 unsigned long random_lma;
@@ -151,6 +156,7 @@ void startup_kernel(void)
151 } else if (__kaslr_offset) 156 } else if (__kaslr_offset)
152 memcpy((void *)vmlinux.default_lma, img, vmlinux.image_size); 157 memcpy((void *)vmlinux.default_lma, img, vmlinux.image_size);
153 158
159 clear_bss_section();
154 copy_bootdata(); 160 copy_bootdata();
155 if (IS_ENABLED(CONFIG_RELOCATABLE)) 161 if (IS_ENABLED(CONFIG_RELOCATABLE))
156 handle_relocs(__kaslr_offset); 162 handle_relocs(__kaslr_offset);
diff --git a/arch/s390/kernel/Makefile b/arch/s390/kernel/Makefile
index 0f255b54b051..7edbbcd8228a 100644
--- a/arch/s390/kernel/Makefile
+++ b/arch/s390/kernel/Makefile
@@ -10,20 +10,12 @@ CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
10 10
11# Do not trace early setup code 11# Do not trace early setup code
12CFLAGS_REMOVE_early.o = $(CC_FLAGS_FTRACE) 12CFLAGS_REMOVE_early.o = $(CC_FLAGS_FTRACE)
13CFLAGS_REMOVE_early_nobss.o = $(CC_FLAGS_FTRACE)
14 13
15endif 14endif
16 15
17GCOV_PROFILE_early.o := n 16GCOV_PROFILE_early.o := n
18GCOV_PROFILE_early_nobss.o := n
19
20KCOV_INSTRUMENT_early.o := n 17KCOV_INSTRUMENT_early.o := n
21KCOV_INSTRUMENT_early_nobss.o := n
22
23UBSAN_SANITIZE_early.o := n 18UBSAN_SANITIZE_early.o := n
24UBSAN_SANITIZE_early_nobss.o := n
25
26KASAN_SANITIZE_early_nobss.o := n
27KASAN_SANITIZE_ipl.o := n 19KASAN_SANITIZE_ipl.o := n
28KASAN_SANITIZE_machine_kexec.o := n 20KASAN_SANITIZE_machine_kexec.o := n
29 21
@@ -48,7 +40,7 @@ CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"'
48 40
49obj-y := traps.o time.o process.o base.o early.o setup.o idle.o vtime.o 41obj-y := traps.o time.o process.o base.o early.o setup.o idle.o vtime.o
50obj-y += processor.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o nmi.o 42obj-y += processor.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o nmi.o
51obj-y += debug.o irq.o ipl.o dis.o diag.o vdso.o early_nobss.o 43obj-y += debug.o irq.o ipl.o dis.o diag.o vdso.o
52obj-y += sysinfo.o lgr.o os_info.o machine_kexec.o pgm_check.o 44obj-y += sysinfo.o lgr.o os_info.o machine_kexec.o pgm_check.o
53obj-y += runtime_instr.o cache.o fpu.o dumpstack.o guarded_storage.o sthyi.o 45obj-y += runtime_instr.o cache.o fpu.o dumpstack.o guarded_storage.o sthyi.o
54obj-y += entry.o reipl.o relocate_kernel.o kdebugfs.o alternative.o 46obj-y += entry.o reipl.o relocate_kernel.o kdebugfs.o alternative.o
@@ -90,6 +82,3 @@ obj-$(CONFIG_TRACEPOINTS) += trace.o
90# vdso 82# vdso
91obj-y += vdso64/ 83obj-y += vdso64/
92obj-$(CONFIG_COMPAT_VDSO) += vdso32/ 84obj-$(CONFIG_COMPAT_VDSO) += vdso32/
93
94chkbss := head64.o early_nobss.o
95include $(srctree)/arch/s390/scripts/Makefile.chkbss
diff --git a/arch/s390/kernel/early.c b/arch/s390/kernel/early.c
index 6312fed48530..b432d63d0b37 100644
--- a/arch/s390/kernel/early.c
+++ b/arch/s390/kernel/early.c
@@ -32,6 +32,21 @@
32#include <asm/boot_data.h> 32#include <asm/boot_data.h>
33#include "entry.h" 33#include "entry.h"
34 34
35static void __init reset_tod_clock(void)
36{
37 u64 time;
38
39 if (store_tod_clock(&time) == 0)
40 return;
41 /* TOD clock not running. Set the clock to Unix Epoch. */
42 if (set_tod_clock(TOD_UNIX_EPOCH) != 0 || store_tod_clock(&time) != 0)
43 disabled_wait();
44
45 memset(tod_clock_base, 0, 16);
46 *(__u64 *) &tod_clock_base[1] = TOD_UNIX_EPOCH;
47 S390_lowcore.last_update_clock = TOD_UNIX_EPOCH;
48}
49
35/* 50/*
36 * Initialize storage key for kernel pages 51 * Initialize storage key for kernel pages
37 */ 52 */
@@ -301,6 +316,7 @@ static void __init check_image_bootable(void)
301 316
302void __init startup_init(void) 317void __init startup_init(void)
303{ 318{
319 reset_tod_clock();
304 check_image_bootable(); 320 check_image_bootable();
305 time_early_init(); 321 time_early_init();
306 init_kernel_storage_key(); 322 init_kernel_storage_key();
diff --git a/arch/s390/kernel/early_nobss.c b/arch/s390/kernel/early_nobss.c
deleted file mode 100644
index 52a3ef959341..000000000000
--- a/arch/s390/kernel/early_nobss.c
+++ /dev/null
@@ -1,45 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright IBM Corp. 2007, 2018
4 */
5
6/*
7 * Early setup functions which may not rely on an initialized bss
8 * section. The last thing that is supposed to happen here is
9 * initialization of the bss section.
10 */
11
12#include <linux/processor.h>
13#include <linux/string.h>
14#include <asm/sections.h>
15#include <asm/lowcore.h>
16#include <asm/timex.h>
17#include <asm/kasan.h>
18#include "entry.h"
19
20static void __init reset_tod_clock(void)
21{
22 u64 time;
23
24 if (store_tod_clock(&time) == 0)
25 return;
26 /* TOD clock not running. Set the clock to Unix Epoch. */
27 if (set_tod_clock(TOD_UNIX_EPOCH) != 0 || store_tod_clock(&time) != 0)
28 disabled_wait();
29
30 memset(tod_clock_base, 0, 16);
31 *(__u64 *) &tod_clock_base[1] = TOD_UNIX_EPOCH;
32 S390_lowcore.last_update_clock = TOD_UNIX_EPOCH;
33}
34
35static void __init clear_bss_section(void)
36{
37 memset(__bss_start, 0, __bss_stop - __bss_start);
38}
39
40void __init startup_init_nobss(void)
41{
42 reset_tod_clock();
43 clear_bss_section();
44 kasan_early_init();
45}
diff --git a/arch/s390/kernel/head64.S b/arch/s390/kernel/head64.S
index 5aea1a527443..143ed71221fe 100644
--- a/arch/s390/kernel/head64.S
+++ b/arch/s390/kernel/head64.S
@@ -34,11 +34,9 @@ ENTRY(startup_continue)
34 larl %r14,init_task 34 larl %r14,init_task
35 stg %r14,__LC_CURRENT 35 stg %r14,__LC_CURRENT
36 larl %r15,init_thread_union+THREAD_SIZE-STACK_FRAME_OVERHEAD 36 larl %r15,init_thread_union+THREAD_SIZE-STACK_FRAME_OVERHEAD
37# 37#ifdef CONFIG_KASAN
38# Early setup functions that may not rely on an initialized bss section, 38 brasl %r14,kasan_early_init
39# like moving the initrd. Returns with an initialized bss section. 39#endif
40#
41 brasl %r14,startup_init_nobss
42# 40#
43# Early machine initialization and detection functions. 41# Early machine initialization and detection functions.
44# 42#
diff --git a/arch/s390/lib/Makefile b/arch/s390/lib/Makefile
index a1ec63abfb95..d7c218e8b559 100644
--- a/arch/s390/lib/Makefile
+++ b/arch/s390/lib/Makefile
@@ -11,6 +11,3 @@ lib-$(CONFIG_UPROBES) += probes.o
11# Instrumenting memory accesses to __user data (in different address space) 11# Instrumenting memory accesses to __user data (in different address space)
12# produce false positives 12# produce false positives
13KASAN_SANITIZE_uaccess.o := n 13KASAN_SANITIZE_uaccess.o := n
14
15chkbss := mem.o
16include $(srctree)/arch/s390/scripts/Makefile.chkbss
diff --git a/drivers/s390/char/Makefile b/drivers/s390/char/Makefile
index b8a8816d94e7..845e12ac5954 100644
--- a/drivers/s390/char/Makefile
+++ b/drivers/s390/char/Makefile
@@ -49,6 +49,3 @@ obj-$(CONFIG_CRASH_DUMP) += sclp_sdias.o zcore.o
49 49
50hmcdrv-objs := hmcdrv_mod.o hmcdrv_dev.o hmcdrv_ftp.o hmcdrv_cache.o diag_ftp.o sclp_ftp.o 50hmcdrv-objs := hmcdrv_mod.o hmcdrv_dev.o hmcdrv_ftp.o hmcdrv_cache.o diag_ftp.o sclp_ftp.o
51obj-$(CONFIG_HMC_DRV) += hmcdrv.o 51obj-$(CONFIG_HMC_DRV) += hmcdrv.o
52
53chkbss := sclp_early_core.o
54include $(srctree)/arch/s390/scripts/Makefile.chkbss