Skip to content

Commit

Permalink
Kernel Undefined Behavior Sanitizer initial support tested and functi…
Browse files Browse the repository at this point in the history
…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 94f7d95
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
7 changes: 3 additions & 4 deletions sys/arch/amd64/amd64/kubsan.c
Expand Up @@ -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) {}
6 changes: 6 additions & 0 deletions sys/arch/amd64/conf/GENERIC_KUBSAN
@@ -0,0 +1,6 @@
# $NetBSD$

include "arch/amd64/conf/GENERIC"

makeoptions KUBSAN=1 # Kernel Undefined Behavior Sanitizer
options KUBSAN
9 changes: 5 additions & 4 deletions sys/arch/amd64/conf/Makefile.amd64
@@ -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
#
Expand All @@ -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

Expand Down Expand Up @@ -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

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

9 changes: 7 additions & 2 deletions sys/arch/amd64/conf/files.amd64
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

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

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

2 changes: 2 additions & 0 deletions sys/sys/ubsan.h
@@ -1,3 +1,4 @@

#ifndef _LIB_UBSAN_H
#define _LIB_UBSAN_H

Expand Down Expand Up @@ -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.