hostnet: a port-0 bind can collide with another listener's guest port under the listener redirect

Abierto
#294 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
70/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
networking

Línea de trabajo

Start with the port-0 bind branch and the implicit-bind None branch in src/hostnet.rs, then read guest_port_taken and bind_at_redirect. Reproduce the collision using the issue's two-socket sequence with redirect enabled and port 50000 allowed. Done when the second listener cannot acquire guest port 50000 and both listeners remain addressable or the bind returns EADDRINUSE.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

Follow-up from Copilot's review on #291 (comment 2), which wasn't addressed before merge.

Problem

Under the listener redirect, a listener bound to a non-zero guest port G is assigned a different host port at listen (via bind_at_redirect), so host port G stays free. A later bind(0.0.0.0:0) can then be handed host port G by the OS, giving it guest port G too. Both sockets then report the same guest port, and listen_addr(G) (src/hostnet.rs:980-994) resolves by min_by_key(fd) and exposes only one — the other guest listener becomes unaddressable by the embedder.

The non-zero-port bind path checks guest_port_taken (src/hostnet.rs:662), but the port-0 branch (src/hostnet.rs:655-660) and the implicit-bind path in redirect_listener's None branch (src/hostnet.rs:709) do not.

Severity

Low. Not a security bypass — both sockets sit at the redirect address; nothing is exposed on an unredirected address. It is a bookkeeping/correctness defect. It only triggers when an allowed guest listen port falls in the host ephemeral range (Linux 32768–60999) and the OS picks it — unlikely for 80/443/8080, realistic for high-numbered ports common in test harnesses.

Repro

Redirect on, listen_ports allow 50000.

  1. bind(a, 0.0.0.0:50000); listen(a) → host port e.g. 37000, guest port 50000.
  2. bind(b, 0.0.0.0:0) → OS assigns host port 50000 → b guest port 50000.
  3. getsockname(a) == getsockname(b) == 0.0.0.0:50000; after listen(b), listen_addr(50000) returns only a, so b's listener is unreachable.

Suggested fix

In the port-0 branch (and the None branch at :709), after bind_at_redirect returns the port, call guest_port_taken(fd, port); on collision, rebind the host socket (recreate to avoid leaving it partially bound) and retry for a fresh port, or return EADDRINUSE.

Lenguaje dominante
Rust
Estrellas
77
Forks
14
Merge medio
1 d 22 h
PR fusionados (30 d)
27

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de hyperlight-dev/hyperlight-unikraft

Todos los issues de hyperlight-dev/hyperlight-unikraft

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.