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

未关闭 适合新手
#408 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c
领域
backend

调研方向

阅读 src/nvc_mount.c 中的 mount_with_flags(),尤其是清理路径 fail:,并将其与初始化 mnt 的相邻挂载辅助函数进行比较。Issue 提供了 AddressSanitizer 复现,并指出需要检查的早期失败情况。完成标准是失败路径能够安全处理未设置的挂载,且复现不再导致崩溃。

由索引模型根据 Issue 内容生成。

描述

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.)

主要语言
C
星标
1.1k
派生
278
平均合并
3 天 7 小时
30 天内合并 PR
2

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NVIDIA/libnvidia-container 的其他 Issue

查看 NVIDIA/libnvidia-container 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。