|
208 | 208 | (/|/dev|/proc|/sys) continue;; |
209 | 209 | esac |
210 | 210 |
|
| 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 | +
|
211 | 227 | # Try mounting everything normally |
212 | 228 | make_overlay "$SANDBOX_DIR" "$mountpoint" "$pure_mountpoint" 2>>"$try_mount_log" |
213 | 229 | # 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" || \ |
254 | 270 | printf "%s: Warning: Failed bind-mounting /sys into sandbox, see \"$try_mount_log\"\n" "$TRY_COMMAND" >&2 |
255 | 271 |
|
256 | 272 | ## 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. |
257 | 277 | for bind_spec in $EXTRA_BIND_MOUNTS; do |
258 | 278 | bind_src="${bind_spec%%:*}" |
259 | 279 | bind_dst="${bind_spec##*:}" |
260 | 280 | 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" || \ |
262 | 282 | printf "%s: Warning: Failed bind-mounting %s into sandbox, see \"$try_mount_log\"\n" "$TRY_COMMAND" "$bind_spec" >&2 |
263 | 283 | done |
264 | 284 |
|
|
0 commit comments