Uninitialized `mnt` dereferenced on `mount_with_flags` failure path (src/nvc_mount.c)

Abierto Apto para principiantes
#408 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
1/5
Tiempo estimado
Menos de una hora
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c
Área
backend

Línea de trabajo

Lee mount_with_flags() en src/nvc_mount.c, especialmente su ruta de limpieza fail:, y compárala con las funciones auxiliares de montaje adyacentes que inicializan mnt. El issue proporciona una reproducción con AddressSanitizer e identifica errores tempranos que hay que comprobar. La tarea estará terminada cuando la ruta de error gestione de forma segura un montaje no establecido y la reproducción ya no provoque un fallo.

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

Descripción

needs-triage

mount_with_flags() in src/nvc_mount.c declares char *mnt without an initializer (:82) and the fail path does unmount(mnt) at :99. All the early exits — file_mode(src), file_create(dst), xmount returning EPERM — jump to fail: before mnt is ever assigned, so cleanup runs on a garbage stack pointer: str_empty() dereferences it (utils.c:171), and if the garbage is non-NULL it also umount2()s and file_remove()/nftw()s a random pointer.

Every other mount helper in the file handles this. mount_procfs_gpu/mount_procfs_mig use char *mnt = NULL, mount_device/mount_ipc fail with unmount(dst), nvc_imex_channel_mount initializes to NULL. mount_with_flags looks like it was missed in the same sweep that fixed the nvc_ldcache.c pointer UB in 1.17.8 (#316/#318) — this one is still broken in v1.20.2 (c7727e5) and on current main.

Deterministic repro: small harness that #includes nvc_mount.c and links the repo's own make debug objects, compiled with -ftrivial-auto-var-init=pattern, calling the function with a failing src:

==469703==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x5583f862b232 bp 0x7fff18909f90 sp 0x7fff18909f78 T0)
==469703==The signal is caused by a READ memory access.
    #0 str_empty          src/utils.c:171
    #1 unmount            src/nvc_mount.c:512
    #2 mount_with_flags   src/nvc_mount.c:99
    #3 t_mount_with_flags harness/h2_path.c:103
    #4 main               harness/h2_path.c:218
SUMMARY: AddressSanitizer: SEGV src/utils.c:171 in str_empty

Exactly where it should fault: unmount(mnt) at :99 reading the never-assigned mnt.

Also hit it end-to-end on the release build: nvidia-container-cli configure with the container rootfs bind-mounted read-only dies at file_create with "read-only file system", which is the same goto fail. In that run the stack slot happened to be benign, so it quietly umount2()d a garbage pointer and exited normally. So in default builds the outcome depends on stack contents: crash, or silent bogus cleanup — never a correct one.

Fix is one line, same as the siblings:

-    char *mnt;
+    char *mnt = NULL;

(For clarity vs #377: that one is about the cleanup being harmful when it runs correctly on a shared rootfs. Here the cleanup argument itself is uninitialized memory. Different bug, same code region.)

Lenguaje dominante
C
Estrellas
1.1k
Forks
278
Merge medio
3 d 7 h
PR fusionados (30 d)
2

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 NVIDIA/libnvidia-container

Todos los issues de NVIDIA/libnvidia-container

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.