mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-13 05:41:26 +01:00
Pre-quote macros passed to .incbin to avoid unwanted substitution
Currently for the MFS, firmware and VDSO template assembly files we pass the path to include with .incbin unquoted and use __XSTRING within the assembly file to stringify it. However, __XSTRING doesn't just perform a single level of expansion, it performs the normal full expansion of the macro, and so if the path itself happens to tokenise to something that includes a defined macro in it that will itself be substituted. For example, with #define MACRO 1, a path like /path/containing/MACRO/in/it will expand to /path/containing/1/in/it and then, when stringified, end up as "/path/containing/1/in/it", not the intended string. Normally, macros have names that start or end witih underscores and are unlikely to appear in a tokenised path (even if technically they could), but now that we've switched to GNU C as of commitec41a96daa
("sys: Switch the kernel's C standard from C99 to GNU99.") there are a few new macros defined which don't start or end with underscores: unix, which is always defined to 1, and i386, which is defined to 1 on i386. The former probably doesn't appear in user paths in practice, but the latter has been seen to and is likely quite common in the wild. Fix this by defining the macro pre-quoted instead of using __XSTRING. Note that technically we don't need to do this for vdso_wrap.S today as all the paths passed to it are safe file names with no user-controlled prefix but we should do it anyway for consistency and robustness against future changes. This allows make tinderbox to pass when built with source and object directories inside ~/path-with-unix, which would otherwise expand to ~/path-with-1 and break. PR: 272744 Fixes:ec41a96daa
("sys: Switch the kernel's C standard from C99 to GNU99.")
This commit is contained in:
parent
9f81119276
commit
8a6ab0f71f
@ -466,7 +466,7 @@ vnode_if_typedef.h:
|
||||
.if ${MFS_IMAGE:Uno} != "no"
|
||||
.if empty(MD_ROOT_SIZE_CONFIGURED)
|
||||
embedfs_${MFS_IMAGE:T:R}.o: ${MFS_IMAGE} $S/dev/md/embedfs.S
|
||||
${CC} ${CFLAGS} ${ACFLAGS} -DMFS_IMAGE="${MFS_IMAGE}" -c \
|
||||
${CC} ${CFLAGS} ${ACFLAGS} -DMFS_IMAGE=\""${MFS_IMAGE}"\" -c \
|
||||
$S/dev/md/embedfs.S -o ${.TARGET}
|
||||
.endif
|
||||
.endif
|
||||
|
@ -200,7 +200,7 @@ NORMAL_M= ${AWK} -f $S/tools/makeobjops.awk ${.IMPSRC} -c ; \
|
||||
|
||||
NORMAL_FW= uudecode -o ${.TARGET} ${.ALLSRC}
|
||||
NORMAL_FWO= ${CC:N${CCACHE_BIN}} -c ${ASM_CFLAGS} ${WERROR} -o ${.TARGET} \
|
||||
$S/kern/firmw.S -DFIRMW_FILE="${.ALLSRC:M*.fw}" \
|
||||
$S/kern/firmw.S -DFIRMW_FILE=\""${.ALLSRC:M*.fw}"\" \
|
||||
-DFIRMW_SYMBOL="${.ALLSRC:M*.fw:C/[-.\/]/_/g}"
|
||||
|
||||
# for ZSTD in the kernel (include zstd/lib/freebsd before other CFLAGS)
|
||||
|
@ -210,7 +210,7 @@ ${_firmw:C/\:.*$/.fwo/:T}: ${_firmw:C/\:.*$//} ${SYSDIR}/kern/firmw.S
|
||||
@${ECHO} ${_firmw:C/\:.*$//} ${.ALLSRC:M*${_firmw:C/\:.*$//}}
|
||||
${CC:N${CCACHE_BIN}} -c -x assembler-with-cpp -DLOCORE \
|
||||
${CFLAGS} ${WERROR} \
|
||||
-DFIRMW_FILE="${.ALLSRC:M*${_firmw:C/\:.*$//}}" \
|
||||
-DFIRMW_FILE=\""${.ALLSRC:M*${_firmw:C/\:.*$//}}"\" \
|
||||
-DFIRMW_SYMBOL="${_firmw:C/\:.*$//:C/[-.\/@]/_/g}" \
|
||||
${SYSDIR}/kern/firmw.S -o ${.TARGET}
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
.globl mfs_root
|
||||
.type mfs_root, %object
|
||||
mfs_root:
|
||||
.incbin __XSTRING(MFS_IMAGE)
|
||||
.incbin MFS_IMAGE
|
||||
.size mfs_root, . - mfs_root
|
||||
.globl mfs_root_end
|
||||
.type mfs_root_end, %object
|
||||
|
@ -41,7 +41,7 @@
|
||||
.globl FIRMW_START(FIRMW_SYMBOL)
|
||||
.type FIRMW_START(FIRMW_SYMBOL), %object
|
||||
FIRMW_START(FIRMW_SYMBOL):
|
||||
.incbin __XSTRING(FIRMW_FILE)
|
||||
.incbin FIRMW_FILE
|
||||
.size FIRMW_START(FIRMW_SYMBOL), . - FIRMW_START(FIRMW_SYMBOL)
|
||||
.globl FIRMW_END(FIRMW_SYMBOL)
|
||||
.type FIRMW_END(FIRMW_SYMBOL), %object
|
||||
|
@ -55,7 +55,7 @@ fi
|
||||
|
||||
${CC} ${DEBUG} -x assembler-with-cpp -DLOCORE -fPIC -nostdinc -c \
|
||||
-o elf-vdso32.so.o -I. -I"${S}" -include opt_global.h \
|
||||
-DVDSO_NAME=elf_vdso32_so_1 -DVDSO_FILE=elf-vdso32.so.1 \
|
||||
-DVDSO_NAME=elf_vdso32_so_1 -DVDSO_FILE=\"elf-vdso32.so.1\" \
|
||||
"${S}"/tools/vdso_wrap.S
|
||||
|
||||
${NM} -D elf-vdso32.so.1 | ${AWK} \
|
||||
|
@ -64,7 +64,7 @@ fi
|
||||
|
||||
${CC} ${DEBUG} -x assembler-with-cpp -DLOCORE -fPIC -nostdinc -c \
|
||||
-o elf-vdso.so.o -I. -I"${S}" -include opt_global.h \
|
||||
-DVDSO_NAME=elf_vdso_so_1 -DVDSO_FILE=elf-vdso.so.1 \
|
||||
-DVDSO_NAME=elf_vdso_so_1 -DVDSO_FILE=\"elf-vdso.so.1\" \
|
||||
"${S}"/tools/vdso_wrap.S
|
||||
|
||||
${NM} -D elf-vdso.so.1 | \
|
||||
|
@ -39,7 +39,7 @@
|
||||
.type VDSO_BLOB_START(VDSO_NAME), %object
|
||||
.size VDSO_BLOB_START(VDSO_NAME), 0
|
||||
VDSO_BLOB_START(VDSO_NAME):
|
||||
.incbin __XSTRING(VDSO_FILE)
|
||||
.incbin VDSO_FILE
|
||||
.globl VDSO_BLOB_END(VDSO_NAME)
|
||||
.type VDSO_BLOB_END(VDSO_NAME), %object
|
||||
.size VDSO_BLOB_END(VDSO_NAME), 0
|
||||
|
Loading…
Reference in New Issue
Block a user