run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, smash the startup code with traps so that
it does not point to the other randomly placed code. It has be smashed,
because sgi runs in the kseg0 or xkphys space.
As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker.
Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.
-# $OpenBSD: Makefile.sgi,v 1.80 2017/06/05 12:43:59 deraadt Exp $
+# $OpenBSD: Makefile.sgi,v 1.81 2017/06/08 11:47:24 visa Exp $
# For instructions on building kernels consult the config(8) and options(4)
# manual pages.
CMACHFLAGS= -mno-abicalls ${ABI} -msoft-float -G 0
CMACHFLAGS+= -ffreestanding ${NOPIE_FLAGS}
+SORTR= sort -R
.if ${IDENT:M-DNO_PROPOLICE}
CMACHFLAGS+= -fno-stack-protector
.endif
+.if ${IDENT:M-DSMALL_KERNEL}
+SORTR= cat
+.endif
DEBUG?= -g
COPTS?= -O2
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
-SYSTEM_HEAD= locore.o param.o ioconf.o
-SYSTEM_OBJ= ${SYSTEM_HEAD} ${OBJS}
+SYSTEM_HEAD= locore0.o gap.o
+SYSTEM_OBJ= ${SYSTEM_HEAD} ${OBJS} param.o ioconf.o
SYSTEM_DEP= Makefile ${SYSTEM_OBJ} ld.script
SYSTEM_LD_HEAD= @rm -f $@
SYSTEM_LD= @echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_HEAD} vers.o $${OBJS}'; \
umask 007; \
- ${LD} ${LINKFLAGS} -o $@ ${SYSTEM_HEAD} vers.o ${OBJS}
+ echo ${OBJS} param.o ioconf.o vers.o | tr " " "\n" | ${SORTR} > lorder; \
+ ${LD} ${LINKFLAGS} -o $@ ${SYSTEM_HEAD} `cat lorder`
SYSTEM_LD_TAIL= @${SIZE} $@
.if ${DEBUG} == "-g"
sh $S/conf/newvers.sh
${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
+gap.S: ${SYSTEM_SWAP_DEP} Makefile $S/conf/makegap.sh
+ umask 007; sh $S/conf/makegap.sh 0xef > gap.S
+
+gap.o: gap.S
+ umask 007; ${CC} ${AFLAGS} ${CPPFLAGS} ${PROF} -c gap.S
+
clean:
- rm -f *bsd *bsd.gdb *.[dio] [a-z]*.s assym.* ${DB_STRUCTINFO} param.c
+ rm -f *bsd *bsd.gdb *.[dio] [a-z]*.s assym.* ${DB_STRUCTINFO} \
+ gap.S lorder param.c
cleandir: clean
rm -f Makefile *.h ioconf.c options machine ${_mach} vers.c
objdump -g db_structinfo.o | perl $S/ddb/parse_structinfo.pl > $@
rm -f db_structinfo.o
-locore.o: ${_machdir}/${_mach}/locore.S assym.h
+locore0.o: ${_machdir}/${_mach}/locore0.S assym.h
context.o cp0access.o exception.o exception_tfp.o: assym.h
-lcore_access.o lcore_ddb.o lcore_float.o tlb_tfp.o tlbhandler.o: assym.h
+lcore_access.o lcore_ddb.o lcore_float.o locore.o: assym.h
+tlb_tfp.o tlbhandler.o: assym.h
cache_tfp_subr.o ip30_nmi.o: assym.h
# The install target can be redefined by putting a
-# $OpenBSD: files.sgi,v 1.55 2016/01/08 15:54:13 jcs Exp $
+# $OpenBSD: files.sgi,v 1.56 2017/06/08 11:47:24 visa Exp $
#
# maxpartitions must be first item in files.${ARCH}
#
file arch/sgi/sgi/ip30_nmi.S tgt_octane & ddb
file arch/sgi/sgi/ip32_machdep.c tgt_o2
file arch/sgi/sgi/l1.c tgt_origin
+file arch/sgi/sgi/locore.S
file arch/sgi/sgi/machdep.c
file arch/sgi/sgi/mainbus.c
file arch/sgi/sgi/sginode.c tgt_origin
-/* $OpenBSD: autoconf.c,v 1.40 2015/01/02 22:38:46 sebastia Exp $ */
+/* $OpenBSD: autoconf.c,v 1.41 2017/06/08 11:47:25 visa Exp $ */
/*
* Copyright (c) 2009, 2010 Miodrag Vallat.
*
char osloadpartition[256];
char osloadoptions[129];
+void
+unmap_startup(void)
+{
+ extern uint32_t kernel_text[], endboot[];
+ uint32_t *word = kernel_text;
+
+ /* Cannot unmap kseg0 or xkphys; smash with trap. */
+ while (word < endboot)
+ *word++ = 0x00000034u; /* TEQ zero, zero */
+}
+
/*
* Configure all devices found that we know about.
* This is done at boot time.
panic("no mainbus found");
}
+ unmap_startup();
+
splinit(); /* Initialized, fire up interrupt system */
cold = 0;
}
-/* $OpenBSD: locore.S,v 1.17 2015/12/25 09:02:57 visa Exp $ */
+/* $OpenBSD: locore.S,v 1.18 2017/06/08 11:47:25 visa Exp $ */
/*
* Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com)
.set mips3
.set noreorder # Noreorder is default style!
- .globl start
- .globl kernel_text
-kernel_text = start
-start:
- /*
- * On at least the O2, when netbooting the bsd.rd kernel, the
- * kernel image gets loaded in CKSEG1, which causes the kernel
- * text to be uncached. Just to be on the safe side, jump to
- * our intended execution address.
- */
- LA v0, 1f
- jr v0
- NOP
-1:
-
+ .globl locore_start
+ .ent locore_start, 0
+locore_start:
MFC0 v0, COP_0_STATUS_REG
LI v1, ~SR_INT_ENAB
and v0, v1
jal main # main(regs)
move a0, zero
PANIC("Startup failed!")
+ .end locore_start
#if defined(MULTIPROCESSOR)
LEAF(hw_cpu_spinup_trampoline, 0)
--- /dev/null
+/* $OpenBSD: locore0.S,v 1.1 2017/06/08 11:47:25 visa Exp $ */
+
+/*
+ * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <machine/param.h>
+#include <machine/asm.h>
+
+#include "assym.h"
+
+ .set mips3
+ .set noreorder # Noreorder is default style!
+
+ .globl kernel_text
+ .globl start
+ .ent start, 0
+kernel_text = start
+start:
+ /*
+ * On at least the O2, when netbooting the bsd.rd kernel, the
+ * kernel image gets loaded in CKSEG1, which causes the kernel
+ * text to be uncached. Just to be on the safe side, jump to
+ * our intended execution address.
+ */
+ LA v0, 1f
+ jr v0
+ NOP
+1:
+ j locore_start
+ NOP
+ .end start