@@ -85,12 +85,23 @@ function extension_prepare_config__netboot_defaults_and_validate() {
8585 " " | gzip | zstd | zst | none) ;;
8686 * ) exit_with_error " ${EXTENSION} : unknown ROOTFS_COMPRESSION: '${ROOTFS_COMPRESSION} ' (expected: gzip|zstd|zst|none)" ;;
8787 esac
88- if [[ -n " ${ROOTFS_EXPORT_DIR} " && " ${ROOTFS_EXPORT_DIR} " != /* ]]; then
89- exit_with_error " ${EXTENSION} : ROOTFS_EXPORT_DIR must be an absolute path (got '${ROOTFS_EXPORT_DIR} ')"
90- fi
9188 if [[ " ${ROOTFS_COMPRESSION} " == " none" && -z " ${ROOTFS_EXPORT_DIR} " ]]; then
9289 exit_with_error " ${EXTENSION} : ROOTFS_COMPRESSION=none requires ROOTFS_EXPORT_DIR (otherwise nothing is produced)"
9390 fi
91+
92+ # Keep ROOTFS_EXPORT_DIR confined to a fixed base under ${SRC}/output, so a
93+ # stray typo or accidental absolute path can never let rsync --delete touch
94+ # the host filesystem outside that subtree. Any user value (relative or
95+ # absolute) is treated as a sub-path of the base; an absolute `/srv/nfs`
96+ # becomes `${SRC}/output/netboot-export//srv/nfs` (the ordinary path-join
97+ # semantics make this a plain sub-directory). If a NFS server on the build
98+ # host expects `/srv/...`, symlink `${SRC}/output/netboot-export` there.
99+ if [[ -n " ${ROOTFS_EXPORT_DIR} " ]]; then
100+ case " ${ROOTFS_EXPORT_DIR} " in
101+ * ..* ) exit_with_error " ${EXTENSION} : ROOTFS_EXPORT_DIR must not contain '..'" " ${ROOTFS_EXPORT_DIR} " ;;
102+ esac
103+ declare -g ROOTFS_EXPORT_DIR=" ${SRC} /output/netboot-export/${ROOTFS_EXPORT_DIR} "
104+ fi
94105}
95106
96107# Ensure NFS-root client support is built into the kernel.
@@ -126,27 +137,20 @@ function post_customize_image__netboot_skip_firstlogin_wizard() {
126137 run_host_command_logged rm -f " ${SDCARD} /root/.not_logged_in_yet"
127138}
128139
129- # ROOTFS_EXPORT_DIR must be visible inside the build container at the same path the
130- # in-container rsync writes to — otherwise data lands in the container's private
131- # filesystem and disappears on umount. Two cases:
132- # 1) Path already under ${SRC}: core already bind-mounts ${SRC} at
133- # ${DOCKER_ARMBIAN_TARGET_PATH} (/armbian) inside the container, so the data
134- # path IS host-visible — but the env var still holds the host path, which
135- # does not exist in the container. Translate the env var to the container
136- # path so rsync writes into the bind-mounted volume.
137- # 2) Path outside ${SRC}: add an explicit bind-mount at the same path.
140+ # Expose the host export directory inside the container at a fixed, known-safe
141+ # mount point so the in-container rsync cannot be tricked into overwriting a
142+ # system path. The host side is already confined under ${SRC}/output/netboot-export/
143+ # by extension_prepare_config; bind that host path onto a dedicated container
144+ # target and point ROOTFS_EXPORT_DIR at the container path for rsync.
138145function host_pre_docker_launch__netboot_mount_export_dir() {
139146 [[ -z " ${ROOTFS_EXPORT_DIR} " ]] && return 0
140- if [[ " ${ROOTFS_EXPORT_DIR} " == " ${SRC} " || " ${ROOTFS_EXPORT_DIR} " == " ${SRC} /" * ]]; then
141- declare container_export_dir=" ${DOCKER_ARMBIAN_TARGET_PATH:-/ armbian}${ROOTFS_EXPORT_DIR# " ${SRC} " } "
142- display_alert " ${EXTENSION} : translating ROOTFS_EXPORT_DIR for container" " ${ROOTFS_EXPORT_DIR} -> ${container_export_dir} " " info"
143- mkdir -p " ${ROOTFS_EXPORT_DIR} "
144- DOCKER_EXTRA_ARGS+=(" --env" " ROOTFS_EXPORT_DIR=${container_export_dir} " )
145- return 0
146- fi
147+ declare container_export_dir=" /armbian/netboot-export"
147148 mkdir -p " ${ROOTFS_EXPORT_DIR} "
148- display_alert " ${EXTENSION} : bind-mounting ROOTFS_EXPORT_DIR into container" " ${ROOTFS_EXPORT_DIR} " " info"
149- DOCKER_EXTRA_ARGS+=(" --mount" " type=bind,source=${ROOTFS_EXPORT_DIR} ,target=${ROOTFS_EXPORT_DIR} " )
149+ display_alert " ${EXTENSION} : bind-mounting ROOTFS_EXPORT_DIR into container" " ${ROOTFS_EXPORT_DIR} -> ${container_export_dir} " " info"
150+ DOCKER_EXTRA_ARGS+=(
151+ " --mount" " type=bind,source=${ROOTFS_EXPORT_DIR} ,target=${container_export_dir} "
152+ " --env" " ROOTFS_EXPORT_DIR=${container_export_dir} "
153+ )
150154}
151155
152156function pre_umount_final_image__900_collect_netboot_artifacts() {
0 commit comments