TSI: bind(port 0) + listen() lands the VMM proxy on a different ephemeral port than the guest — ephemeral listeners unreachable
Los mantenedores suelen responder en 4 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Área
- networking, operating-systems
Línea de trabajo
Start with net/tsi/af_tsi.c:tsi_listen(), src/devices/src/virtio/vsock/tsi_stream.rs:try_listen(), and TsiListenRsp in src/devices/src/virtio/vsock/packet.rs. Trace how port 0 is passed and how the VMM's bound address is represented, then run the supplied Python repro and fixed-port control. Done means guest and VMM use the same ephemeral port and the listener accepts connections through the guest-reported address.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Environment
- libkrun 1.19.4 (Arch package
libkrun 1.19.4-1), libkrunfw 5.5.0-1,
crun-based krun 1.29.1-1 - Host: Arch Linux x86_64, kernel 6.12.91, KVM; rootless podman 5.x with pasta
- Guest:
python:3.12-slim(bookworm, glibc 2.36) - Networking: default — no NIC, so implicit TSI with
TsiFlags::HIJACK_INET
(tsi_hijackon the guest kernel command line) - Verified still present in current
main(2.0 dev):
TsiListenRsp { result: i32 }insrc/devices/src/virtio/vsock/packet.rs
is identical there — no address is communicated back in either version.
Summary
bind(port 0) followed by listen() under TSI leaves the listener
unreachable at its own port, including for the process that created it:
- Guest app calls
bind(127.0.0.1:0); the guest kernel assigns port X. listen()sendsTSI_LISTENto the VMM with the recorded request
address (port 0) —net/tsi/af_tsi.c:tsi_listen()sendstsk->bound_addr,
which still contains port 0.- The VMM (
src/devices/src/virtio/vsock/tsi_stream.rs:try_listen()) binds
that address in the VMM process's own netns, wherebind(0)gets a
different port Y from that netns's ephemeral allocator. TsiListenRspreturns only a result code — Y is never communicated
back, so the guest keeps reporting X ingetsockname().
Result: connect(127.0.0.1:X) gets ECONNREFUSED. The listener is alive at
port Y, unreachable and unknown.
Minimal repro (bare krun container; tested 3/3)
cat > t.py <<'EOF'
import socket, time
s = socket.socket(); s.bind(('127.0.0.1', 0))
port = s.getsockname()[1]; s.listen(1)
print('bound:', port)
time.sleep(0.5)
c = socket.socket(); c.settimeout(5)
c.connect(('127.0.0.1', port)) # -> ConnectionRefusedError
EOF
podman run --rm --runtime=krun \
--annotation krun.ram_mib=1024 --annotation krun.cpus=2 \
--mount type=bind,src=$PWD/t.py,target=/t.py \
python:3.12-slim python3 /t.py
Output:
bound: 43859
ConnectionRefusedError: [Errno 111] Connection refused
Control: the same script with a fixed port
(bind(('127.0.0.1', 45677)), connect to 45677) succeeds — fixed-port binds
do not diverge, which confirms the mechanism.
Direct proof of the divergence
Run the same ephemeral listener inside a --network host krun container and
inspect the host side while the guest sleeps on accept():
guest: bound 127.0.0.1:53603 (X)
host: ss -ltn → LISTEN 127.0.0.1:45551 (Y — assigned by the VMM's netns)
connect to X → refused; connect to Y → accepted, guest accept() fires
Real-world impact
debugpy (python -m debugpy --listen 0.0.0.0:5678 …) always creates a
127.0.0.1:0 endpoints listener whose adapter child connects back, so every
debugpy session dies after 30 s with
RuntimeError: timed out waiting for adapter to connect. Reproduced in a
bare krun container with debugpy alone. Anything else using ephemeral
listeners is similarly affected.
Suggested fix directions
Return the actually-bound address/port in TsiListenRsp and have the guest
update the socket's local address; or have the guest request a concrete port
for the shadow bind (it already knows X). We currently carry a userspace
workaround (LD_PRELOAD rewriting port-0 binds to concrete ports) and are
happy to contribute a VMM/kernel fix if this direction sounds right.
Related: #819 — same investigation, TSI locking bug
- Lenguaje dominante
- Rust
- Estrellas
- 2.8k
- Forks
- 279
- Merge medio
- 5 d 18 h
- PR fusionados (30 d)
- 29
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de libkrun/libkrun
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
libkrun/libkrun#895 · 2 comentarios ·
Los mantenedores suelen responder en 4 días
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
Los mantenedores suelen responder en 4 días
-
virtio-fs: any open() drops the guest page cache of the file, including pages other processes have mapped (CachePolicy::Auto)Posiblemente ocupada @jgoyvaerts la tomó hace 10 días. Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
Los mantenedores suelen responder en 4 días
-
macOS/HVF: anonymous guest RAM is counted twice in phys_footprint after host and guest accessAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
Los mantenedores suelen responder en 4 días
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Los mantenedores suelen responder en 4 días
Todos los issues de libkrun/libkrun
Issues similares
-
area:docs documentation good first issue priority:medium
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
rtk-ai/rtk#4958 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
calagopus/panel#285 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Bug]: streamed Responses API flex_unavailable error maps to 500 InternalServerError instead of 429Abiertollm translation
Dificultad 2/5 Menos de una hora Aptitud para principiantes 85/100
BerriAI/litellm#49736 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
question
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
autoindex tests: denied loopback bind shows only PermissionDenied (255 failures), not the causeAbiertofield-report
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día