Skip to content
Permalink
Browse files

Kernel Undefined Behavior Sanitizer initial support tested and functi…

…onal. *Please build kernel with MKCTF=no flag in order for it to boot.

Fix of the previous
  • Loading branch information...
luserx0 committed Jun 14, 2018
1 parent d02265e commit 94f7d95384090d4d777d6b11e9246ff56dbee475
@@ -77,9 +77,8 @@ void __ubsan_handle_load_invalid_value(struct invalid_value_data *data,
{}

void __ubsan_handle_nonnull_return(void *data);
void __ubsan_handle_nonnull_return(void *data)
{}
void __ubsan_handle_nonnull_return(void *data) {}

/* Compiler moaning */
void __ubsan_handle_nonnull_arg(void *data);
void __ubsan_handle_nonnull_arg(void *data)
{}
void __ubsan_handle_nonnull_arg(void *data) {}
@@ -0,0 +1,6 @@
# $NetBSD$

include "arch/amd64/conf/GENERIC"

makeoptions KUBSAN=1 # Kernel Undefined Behavior Sanitizer
options KUBSAN
@@ -1,4 +1,4 @@
# $NetBSD: Makefile.amd64,v 1.70 2018/04/18 10:38:47 martin Exp $
# $NetBSD: Makefile.amd64,v 1.71 2018/06/02 15:09:37 christos Exp $

# Makefile for NetBSD
#
@@ -20,7 +20,7 @@
MACHINE_ARCH=x86_64
USETOOLS?= no
NEED_OWN_INSTALL_TARGET?=no
.include <bsd.own.mk>
.include <bsd.init.mk>

USE_SSP?= yes

@@ -48,9 +48,9 @@ CFLAGS+= -mindirect-branch=thunk-inline
CFLAGS+= -mindirect-branch-register
.endif

# Kernel Undefined Behavior Sanitizer
# Kernel Undefined Behavior Sanitizer options
.if ${KUBSAN:U0} > 0 && ${HAVE_GCC:U0} > 0
CFLAGS+= -fsanitize=undefined
CFLAGS+= -fsanitize=undefined
.endif

##
@@ -122,3 +122,4 @@ netbsd32_sigcode.o: assym.h
## (10) Appending make options.
##
%MAKEOPTIONSAPPEND

@@ -21,7 +21,9 @@ defparam opt_physmem.h PHYSMEM_MAX_ADDR PHYSMEM_MAX_SIZE

# Enable GCC spectre V2 mitigation options
defflag opt_spectre.h SPECTRE_V2_GCC_MITIGATION
defflag opt_kubsan.h KUBSAN

# Enable Kernel Undefined Behavior Sanitizer options
defflag opt_kubsan.h KUBSAN

#
# XXX these are just here at the moment so that we can share files
@@ -38,6 +40,7 @@ file arch/amd64/amd64/locore.S machdep
file arch/amd64/amd64/vector.S machdep
file arch/amd64/amd64/copy.S machdep
file arch/amd64/amd64/spl.S machdep

file arch/amd64/amd64/amd64func.S machdep
file arch/amd64/amd64/amd64_trap.S machdep
file arch/amd64/amd64/autoconf.c machdep
@@ -48,6 +51,7 @@ file arch/amd64/amd64/db_disasm.c ddb
file arch/amd64/amd64/db_interface.c ddb
file arch/amd64/amd64/db_machdep.c ddb
file arch/amd64/amd64/kobj_machdep.c modular
file arch/amd64/amd64/kubsan.c kubsan
file kern/subr_disk_mbr.c disk
file arch/amd64/amd64/gdt.c machdep
file arch/amd64/amd64/machdep.c machdep
@@ -59,7 +63,7 @@ file arch/x86/x86/dbregs.c machdep
file arch/x86/x86/spectre.c machdep
file arch/amd64/amd64/lock_stubs.S machdep
file dev/cons.c machdep
file arch/amd64/amd64/kubsan.c machdep

file arch/amd64/amd64/mptramp.S multiprocessor

#
@@ -190,3 +194,4 @@ file arch/amd64/acpi/acpi_wakeup_low.S acpi

include "arch/amd64/conf/majors.amd64"
endif #xen

@@ -1,3 +1,4 @@

#ifndef _LIB_UBSAN_H
#define _LIB_UBSAN_H

@@ -88,3 +89,4 @@ typedef intmax_t s_max;
typedef uintmax_t u_max;

#endif

0 comments on commit 94f7d95

Please sign in to comment.
You can’t perform that action at this time.