Skip to content

Commit a8bf658

Browse files
committed
-B: use --rbind and skip bound mountpoints in the overlay loop, avoiding the FUSE union fallback for caller-passthrough paths
1 parent 9557c94 commit a8bf658

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

‎try‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,22 @@ do
208208
(/|/dev|/proc|/sys) continue;;
209209
esac
210210
211+
## Skip mountpoints the caller asked to bind into the sandbox (-B): the
212+
## bind applied after this loop supersedes anything mounted here, and for
213+
## mountpoints with (locked) nested submounts this avoids falling back to
214+
## a FUSE union helper for a path the caller wants passed through anyway.
215+
bound=0
216+
for bind_spec in $EXTRA_BIND_MOUNTS; do
217+
bind_dst="${bind_spec##*:}"
218+
case "$pure_mountpoint" in
219+
("$bind_dst"|"$bind_dst"/*) bound=1; break;;
220+
esac
221+
done
222+
if [ "$bound" -eq 1 ]
223+
then
224+
continue
225+
fi
226+
211227
# Try mounting everything normally
212228
make_overlay "$SANDBOX_DIR" "$mountpoint" "$pure_mountpoint" 2>>"$try_mount_log"
213229
# If mounting everything normally fails, we try using either using mergerfs or unionfs to mount them.
@@ -254,11 +270,15 @@ mount --rbind /sys "$SANDBOX_DIR/temproot/sys" 2>>"$try_mount_log" || \
254270
printf "%s: Warning: Failed bind-mounting /sys into sandbox, see \"$try_mount_log\"\n" "$TRY_COMMAND" >&2
255271
256272
## Apply caller-specified bind mounts (-B src:dst).
273+
## --rbind (recursive) rather than --bind: a non-recursive bind of a mount
274+
## that has locked children (e.g. /run with /run/user/*) is rejected inside
275+
## an unprivileged user namespace; the recursive bind carries the submounts
276+
## along and is always permitted.
257277
for bind_spec in $EXTRA_BIND_MOUNTS; do
258278
bind_src="${bind_spec%%:*}"
259279
bind_dst="${bind_spec##*:}"
260280
mkdir -p "$bind_src" "$SANDBOX_DIR/temproot/$bind_dst"
261-
mount --bind "$bind_src" "$SANDBOX_DIR/temproot/$bind_dst" 2>>"$try_mount_log" || \
281+
mount --rbind "$bind_src" "$SANDBOX_DIR/temproot/$bind_dst" 2>>"$try_mount_log" || \
262282
printf "%s: Warning: Failed bind-mounting %s into sandbox, see \"$try_mount_log\"\n" "$TRY_COMMAND" "$bind_spec" >&2
263283
done
264284

0 commit comments

Comments
 (0)