sanitizers: Avoid building genassym.c and genoffset.c with sanitizers

Some, particularly KASAN, may insert redzones around global symbols,
resulting in incorrect offset definitions because genassym.sh (ab)uses
symbol sizes to assign semantic meaning.

(Ideally I would be able to define this pattern in one place, but I
haven't found a way to define a GENSYM_CFLAGS that actually works for
all of the consumers (kern.post.mk, kmod.mk, sys/conf/files*).)

MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	Juniper Networks, Inc.
This commit is contained in:
Mark Johnston 2023-10-10 14:14:46 -04:00
parent d07acc58d8
commit 8e1a7e29b6
6 changed files with 17 additions and 11 deletions

View file

@ -25,7 +25,7 @@ elf-vdso32.so.o optional compat_freebsd32 \
#
ia32_genassym.o standard \
dependency "$S/compat/ia32/ia32_genassym.c offset.inc" \
compile-with "${CC} ${CFLAGS:N-flto*:N-fno-common} -fcommon -c ${.IMPSRC}" \
compile-with "${CC} ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} -fcommon -c ${.IMPSRC}" \
no-obj no-implicit-rule \
clean "ia32_genassym.o"
#

View file

@ -245,20 +245,22 @@ offset.inc: $S/kern/genoffset.sh genoffset.o
NM='${NM}' NMFLAGS='${NMFLAGS}' sh $S/kern/genoffset.sh genoffset.o > ${.TARGET}
genoffset.o: $S/kern/genoffset.c
${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon $S/kern/genoffset.c
${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \
-fcommon $S/kern/genoffset.c
# genoffset_test.o is not actually used for anything - the point of compiling it
# is to exercise the CTASSERT that checks that the offsets in the offset.inc
# _lite struct(s) match those in the original(s).
genoffset_test.o: $S/kern/genoffset.c offset.inc
${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon -DOFFSET_TEST \
$S/kern/genoffset.c -o ${.TARGET}
${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \
-fcommon -DOFFSET_TEST $S/kern/genoffset.c -o ${.TARGET}
assym.inc: $S/kern/genassym.sh genassym.o genoffset_test.o
NM='${NM}' NMFLAGS='${NMFLAGS}' sh $S/kern/genassym.sh genassym.o > ${.TARGET}
genassym.o: $S/$M/$M/genassym.c offset.inc
${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon $S/$M/$M/genassym.c
${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \
-fcommon $S/$M/$M/genassym.c
OBJS_DEPEND_GUESS+= opt_global.h
genoffset.o genassym.o vers.o: opt_global.h

View file

@ -524,13 +524,13 @@ assym.inc: ${SYSDIR}/kern/genassym.sh
sh ${SYSDIR}/kern/genassym.sh genassym.o > ${.TARGET}
genassym.o: ${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c offset.inc
genassym.o: ${SRCS:Mopt_*.h}
${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon \
${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} -fcommon \
${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c
offset.inc: ${SYSDIR}/kern/genoffset.sh genoffset.o
sh ${SYSDIR}/kern/genoffset.sh genoffset.o > ${.TARGET}
genoffset.o: ${SYSDIR}/kern/genoffset.c
genoffset.o: ${SRCS:Mopt_*.h}
${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon \
${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} -fcommon \
${SYSDIR}/kern/genoffset.c
CLEANDEPENDFILES+= ${_ILINKS}

View file

@ -135,7 +135,8 @@ linux${SFX}_support.o: linux${SFX}_support.S linux${SFX}_assym.h assym.inc
.endif
linux${SFX}_genassym.o: offset.inc
${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon ${.IMPSRC}
${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \
-fcommon ${.IMPSRC}
.if !defined(KERNBUILDDIR)
.warning Building Linuxulator outside of a kernel does not make sense

View file

@ -101,7 +101,8 @@ linux_support.o: linux_support.S assym.inc linux_assym.h
${.ALLSRC:M*.S:u} -o ${.TARGET}
linux_genassym.o: offset.inc
${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon ${.IMPSRC}
${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \
-fcommon ${.IMPSRC}
.if !defined(KERNBUILDDIR)
.warning Building Linuxulator outside of a kernel does not make sense

View file

@ -82,9 +82,11 @@ svm_support.o:
${.IMPSRC} -o ${.TARGET}
vmx_genassym.o: offset.inc
${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon ${.IMPSRC}
${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \
-fcommon ${.IMPSRC}
svm_genassym.o: offset.inc
${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon ${.IMPSRC}
${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \
-fcommon ${.IMPSRC}
.include <bsd.kmod.mk>