--ro-bind-fd/--bind-fd: realpath() on /proc/self/fd/N fails for fds from another mount namespace (Flatpak sub-sandbox --usr-path/--app-path)

Aperta
#835 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
44/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
c, linux

Direzione di ricerca

Start in bubblewrap.c at the --bind-fd branch of parse_args_recurse() and trace how resolve_symlinks_in_ops() handles fd-backed bind operations. Check the setup path for SETUP_BIND_MOUNT and SETUP_RO_BIND_MOUNT; the issue suggests keeping /proc/self/fd/N or mounting from the saved fd. Done means these options work when the fd's path is unavailable in bwrap's mount namespace without mounting a different host path.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

--bind-fd / --ro-bind-fd fail with bwrap: Can't find source path /proc/self/fd/N when the fd was opened in another mount namespace and its path there does not exist in bwrap's view. The case where this shows up is Flatpak's sub-sandbox portal: inside an app, flatpak-spawn --sandbox --usr-path=/usr true (or --app-path=/app) fails, so pressure-vessel / the Steam Linux Runtime cannot start from a runtime kept under /app or /var/data.

Versions
  • bubblewrap 0.12.0 (Fedora 44, bubblewrap-0.12.0-1.fc44); the same code is in 0.13.1 and main
  • flatpak 1.18.4 (flatpak-1.18.4-1.fc44)
  • kernel 7.3.3-200.fc44.x86_64; SELinux permissive gives the same result
Reproduce

Inside any Flatpak app (we used com.valvesoftware.Steam from Flathub):

$ flatpak-spawn --sandbox --usr-path=/usr true
bwrap: Can't find source path /proc/self/fd/29
$ flatpak-spawn --sandbox --app-path=/app true
bwrap: Can't find source path /proc/self/fd/23

It depends on the path, not on the option:

--usr-path / --app-path argument (as the app sees it) Result
/usr, /app fails
/var/data/... (the sandbox alias of ~/.var/app/<id>/data) fails
/var/home/<user>/.var/app/<id>/data/..., /var/tmp/... (same path on the host and in the app) works

With the Steam Linux Runtime (sniper) unpacked to a host-identical path, _v2-entry-point --verb=waitforexitandrun -- true works and pressure-vessel reports "Using Flatpak sub-sandboxing", so the portal path itself is fine.

What bwrap receives

With FLATPAK_BWRAP pointed at a logging wrapper, the portal's flatpak run calls bwrap with, among others, --ro-bind-fd 22 /usr --ro-bind-fd 24 /app --ro-bind-fd 29 /etc/e2scrub.conf. The failing one is fd 29. In bwrap's process, readlink /proc/self/fd/29 gives /usr/etc/e2scrub.conf: the path as seen from the app's mount namespace, which does not exist on the host root.

Suspected cause

--bind-fd / --ro-bind-fd set op->source = "/proc/self/fd/N" and op->fd = N (bubblewrap.c, the --bind-fd branch of parse_args_recurse). resolve_symlinks_in_ops() then calls realpath() on that source for every SETUP_BIND_MOUNT / SETUP_RO_BIND_MOUNT. realpath() follows the magic link as a string, so the fd is turned back into a path in the wrong namespace: ENOENT here, and if that string happens to exist on the host (e.g. /usr), the host path would be mounted instead of the directory the caller passed.

A possible fix is to leave fd-backed ops out of the realpath() pass (keep /proc/self/fd/N, or mount from op->fd directly). We have not tested a patch.

Related
  • flatpak 1.18.4 already has 066babba ("run: Fix checking wrong variable in runtime fd selection", flatpak#6568), which is a different bug.
  • flatpak#6584 (the earlier 1.16.4 /proc/self/fd regression) looks related but is closed.
Lingua principale
C
Stelle
9.6k
Fork
418
Merge medio
4g 8h
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di containers/bubblewrap

Tutte le issue di containers/bubblewrap

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.