Skip to content

Commit

Permalink
s390: clean .bss before running uncompressed kernel
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Vasily Gorbik committed Aug 21, 2019
1 parent 19413fe commit 2e83e0e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 68 deletions.
6 changes: 6 additions & 0 deletions arch/s390/boot/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ static void handle_relocs(unsigned long offset)
}
}

static void clear_bss_section(void)
{
memset((void *)vmlinux.default_lma + vmlinux.image_size, 0, vmlinux.bss_size);
}

void startup_kernel(void)
{
unsigned long random_lma;
Expand Down Expand Up @@ -151,6 +156,7 @@ void startup_kernel(void)
} else if (__kaslr_offset)
memcpy((void *)vmlinux.default_lma, img, vmlinux.image_size);

clear_bss_section();
copy_bootdata();
if (IS_ENABLED(CONFIG_RELOCATABLE))
handle_relocs(__kaslr_offset);
Expand Down
13 changes: 1 addition & 12 deletions arch/s390/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,12 @@ CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)

# Do not trace early setup code
CFLAGS_REMOVE_early.o = $(CC_FLAGS_FTRACE)
CFLAGS_REMOVE_early_nobss.o = $(CC_FLAGS_FTRACE)

endif

GCOV_PROFILE_early.o := n
GCOV_PROFILE_early_nobss.o := n

KCOV_INSTRUMENT_early.o := n
KCOV_INSTRUMENT_early_nobss.o := n

UBSAN_SANITIZE_early.o := n
UBSAN_SANITIZE_early_nobss.o := n

KASAN_SANITIZE_early_nobss.o := n
KASAN_SANITIZE_ipl.o := n
KASAN_SANITIZE_machine_kexec.o := n

Expand All @@ -48,7 +40,7 @@ CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"'

obj-y := traps.o time.o process.o base.o early.o setup.o idle.o vtime.o
obj-y += processor.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o nmi.o
obj-y += debug.o irq.o ipl.o dis.o diag.o vdso.o early_nobss.o
obj-y += debug.o irq.o ipl.o dis.o diag.o vdso.o
obj-y += sysinfo.o lgr.o os_info.o machine_kexec.o pgm_check.o
obj-y += runtime_instr.o cache.o fpu.o dumpstack.o guarded_storage.o sthyi.o
obj-y += entry.o reipl.o relocate_kernel.o kdebugfs.o alternative.o
Expand Down Expand Up @@ -90,6 +82,3 @@ obj-$(CONFIG_TRACEPOINTS) += trace.o
# vdso
obj-y += vdso64/
obj-$(CONFIG_COMPAT_VDSO) += vdso32/

chkbss := head64.o early_nobss.o
include $(srctree)/arch/s390/scripts/Makefile.chkbss
16 changes: 16 additions & 0 deletions arch/s390/kernel/early.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@
#include <asm/boot_data.h>
#include "entry.h"

static void __init reset_tod_clock(void)
{
u64 time;

if (store_tod_clock(&time) == 0)
return;
/* TOD clock not running. Set the clock to Unix Epoch. */
if (set_tod_clock(TOD_UNIX_EPOCH) != 0 || store_tod_clock(&time) != 0)
disabled_wait();

memset(tod_clock_base, 0, 16);
*(__u64 *) &tod_clock_base[1] = TOD_UNIX_EPOCH;
S390_lowcore.last_update_clock = TOD_UNIX_EPOCH;
}

/*
* Initialize storage key for kernel pages
*/
Expand Down Expand Up @@ -301,6 +316,7 @@ static void __init check_image_bootable(void)

void __init startup_init(void)
{
reset_tod_clock();
check_image_bootable();
time_early_init();
init_kernel_storage_key();
Expand Down
45 changes: 0 additions & 45 deletions arch/s390/kernel/early_nobss.c

This file was deleted.

8 changes: 3 additions & 5 deletions arch/s390/kernel/head64.S
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ ENTRY(startup_continue)
larl %r14,init_task
stg %r14,__LC_CURRENT
larl %r15,init_thread_union+THREAD_SIZE-STACK_FRAME_OVERHEAD
#
# Early setup functions that may not rely on an initialized bss section,
# like moving the initrd. Returns with an initialized bss section.
#
brasl %r14,startup_init_nobss
#ifdef CONFIG_KASAN
brasl %r14,kasan_early_init
#endif
#
# Early machine initialization and detection functions.
#
Expand Down
3 changes: 0 additions & 3 deletions arch/s390/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@ lib-$(CONFIG_UPROBES) += probes.o
# Instrumenting memory accesses to __user data (in different address space)
# produce false positives
KASAN_SANITIZE_uaccess.o := n

chkbss := mem.o
include $(srctree)/arch/s390/scripts/Makefile.chkbss
3 changes: 0 additions & 3 deletions drivers/s390/char/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,3 @@ obj-$(CONFIG_CRASH_DUMP) += sclp_sdias.o zcore.o

hmcdrv-objs := hmcdrv_mod.o hmcdrv_dev.o hmcdrv_ftp.o hmcdrv_cache.o diag_ftp.o sclp_ftp.o
obj-$(CONFIG_HMC_DRV) += hmcdrv.o

chkbss := sclp_early_core.o
include $(srctree)/arch/s390/scripts/Makefile.chkbss

0 comments on commit 2e83e0e

Please sign in to comment.