From 4540af2a75f7c75e9cc4e3c766f1ff17b782168a Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Sun, 29 Nov 2026 23:10:54 -0500 Subject: [PATCH] build: keep the compiler handoff and probe files out of /tmp - install-build-pkgs runs as root and handed its compiler choice to build-mergerfs through /tmp/build-env, which another user could create before root writes it. Use /etc/mergerfs-build-env, written to a temporary name, made mode 0644 and renamed into place, so a normal user can source it regardless of root's umask and never reads it half written. - The C++20 probe compiles in a private temporary directory instead of at fixed names in /tmp. - yum hosts also consider an already installed devtoolset, which "yum list available" omits. - Document sourcing the handoff file before make deb. --- buildtools/build-mergerfs | 7 +++++-- buildtools/install-build-pkgs | 33 +++++++++++++++++++++++++-------- mkdocs/docs/setup/build.md | 1 + 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/buildtools/build-mergerfs b/buildtools/build-mergerfs index baea10db..a82d2364 100755 --- a/buildtools/build-mergerfs +++ b/buildtools/build-mergerfs @@ -1,8 +1,11 @@ #!/bin/sh set -e -if [ -e /tmp/build-env ]; then - . /tmp/build-env +# Written by install-build-pkgs. Never source a file from /tmp: any +# local user can create it. +BUILD_ENV=/etc/mergerfs-build-env +if [ -e "$BUILD_ENV" ]; then + . "$BUILD_ENV" fi rpmbuild_flags() diff --git a/buildtools/install-build-pkgs b/buildtools/install-build-pkgs index cadb38bf..497ec840 100755 --- a/buildtools/install-build-pkgs +++ b/buildtools/install-build-pkgs @@ -2,14 +2,29 @@ set -e -BUILD_ENV=/tmp/build-env +# Compiler selection for later build steps (sourced by build-mergerfs, +# possibly in a separate container RUN step). This script runs as root +# so the file must not live in a world-writable directory like /tmp +# where another user could pre-create or replace it. +BUILD_ENV=/etc/mergerfs-build-env + +# The env file is sourced later as a normal user, so publish it via a +# rename from a temp file in /etc with fixed 0644 permissions instead +# of trusting the root umask or letting it be read half-written. +write_build_env() +{ + tmp="$(mktemp "${BUILD_ENV}.XXXXXX")" + cat > "$tmp" + chmod 0644 "$tmp" + mv "$tmp" "$BUILD_ENV" +} write_gcc_env() { { printf 'export CC=%s\n' "$1" printf 'export CXX=%s\n' "$2" - } > "$BUILD_ENV" + } | write_build_env } write_toolset_env() @@ -18,7 +33,7 @@ write_toolset_env() printf '. %s\n' "$1" printf 'export CC=gcc\n' printf 'export CXX=g++\n' - } > "$BUILD_ENV" + } | write_build_env } latest_apt_gxx() @@ -39,7 +54,7 @@ latest_dnf_toolset() latest_yum_toolset() { - yum -q list available 'devtoolset-*-gcc-c++' 2>/dev/null \ + yum -q list 'devtoolset-*-gcc-c++' 2>/dev/null \ | sed -n 's/^devtoolset-\([0-9][0-9]*\)-gcc-c++\..*/\1/p' \ | sort -V \ | tail -n 1 @@ -54,8 +69,9 @@ version_gt() check_cxx20() { cxx="${CXX:-g++}" - test_src=/tmp/mergerfs-cxx20-check.cpp - test_bin=/tmp/mergerfs-cxx20-check + test_dir="$(mktemp -d)" + test_src="$test_dir/check.cpp" + test_bin="$test_dir/check" cat > "$test_src" <<'EOF' template @@ -70,14 +86,15 @@ int main() EOF if ! "$cxx" -std=c++20 "$test_src" -o "$test_bin" >/dev/null 2>&1; then + rm -rf "$test_dir" echo "error: $cxx does not support C++20" >&2 exit 1 fi - rm -f "$test_src" "$test_bin" + rm -rf "$test_dir" } -: > "$BUILD_ENV" +printf '' | write_build_env if [ -e /usr/bin/apt-get ]; then export DEBIAN_FRONTEND=noninteractive diff --git a/mkdocs/docs/setup/build.md b/mkdocs/docs/setup/build.md index 5f5bbb07..238c421b 100644 --- a/mkdocs/docs/setup/build.md +++ b/mkdocs/docs/setup/build.md @@ -19,6 +19,7 @@ $ wget https://github.com/trapexit/mergerfs/releases/download//mergerfs-_.deb ```