The branch main has been updated by jrtc27:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=8a6ab0f71f1857037233fae19991b972b430d83c

commit 8a6ab0f71f1857037233fae19991b972b430d83c
Author:     Jessica Clarke <jrt...@freebsd.org>
AuthorDate: 2023-07-28 04:08:43 +0000
Commit:     Jessica Clarke <jrt...@freebsd.org>
CommitDate: 2023-07-28 04:08:43 +0000

    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 commit ec41a96daaa6 ("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:  ec41a96daaa6 ("sys: Switch the kernel's C standard from C99 to 
GNU99.")
---
 sys/conf/kern.post.mk        | 2 +-
 sys/conf/kern.pre.mk         | 2 +-
 sys/conf/kmod.mk             | 2 +-
 sys/dev/md/embedfs.S         | 2 +-
 sys/kern/firmw.S             | 2 +-
 sys/tools/amd64_ia32_vdso.sh | 2 +-
 sys/tools/amd64_vdso.sh      | 2 +-
 sys/tools/vdso_wrap.S        | 2 +-
 8 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/sys/conf/kern.post.mk b/sys/conf/kern.post.mk
index 45df83e2d16b..5a9ac7ad2ed3 100644
--- a/sys/conf/kern.post.mk
+++ b/sys/conf/kern.post.mk
@@ -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
diff --git a/sys/conf/kern.pre.mk b/sys/conf/kern.pre.mk
index 8314f4489ca8..33b7120144b8 100644
--- a/sys/conf/kern.pre.mk
+++ b/sys/conf/kern.pre.mk
@@ -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)
diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk
index be571c2bcf10..e706b73c3d32 100644
--- a/sys/conf/kmod.mk
+++ b/sys/conf/kmod.mk
@@ -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}
 
diff --git a/sys/dev/md/embedfs.S b/sys/dev/md/embedfs.S
index f7574631a0c6..94b21e51f86e 100644
--- a/sys/dev/md/embedfs.S
+++ b/sys/dev/md/embedfs.S
@@ -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
diff --git a/sys/kern/firmw.S b/sys/kern/firmw.S
index 7a4ca1e45808..64d614684df6 100644
--- a/sys/kern/firmw.S
+++ b/sys/kern/firmw.S
@@ -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
diff --git a/sys/tools/amd64_ia32_vdso.sh b/sys/tools/amd64_ia32_vdso.sh
index e64c964219c3..59923749042f 100644
--- a/sys/tools/amd64_ia32_vdso.sh
+++ b/sys/tools/amd64_ia32_vdso.sh
@@ -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} \
diff --git a/sys/tools/amd64_vdso.sh b/sys/tools/amd64_vdso.sh
index 1a0203e3e0a4..aec0694ebdb1 100644
--- a/sys/tools/amd64_vdso.sh
+++ b/sys/tools/amd64_vdso.sh
@@ -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 | \
diff --git a/sys/tools/vdso_wrap.S b/sys/tools/vdso_wrap.S
index 807dcf9c06f4..5a815fd6f499 100644
--- a/sys/tools/vdso_wrap.S
+++ b/sys/tools/vdso_wrap.S
@@ -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

Reply via email to