Possible memory leak in mount on OpenBSD: C strings passed to mount(2) are never freed
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 62/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
从 mount/mounter_openbsd.go 开始:阅读 createUfsArgs(约第 42 行)以及调用 C.mount 的 mount 函数(约第 66 行),然后与 mounter_freebsd.go(第 46-49 行)中的 defer C.free 模式进行比较。当每个 C.CString 分配都被释放,并且 cgo 前导代码包含 stdlib.h 时,即完成。OpenBSD 构建无法在本地运行,因此请检查该文件在使用 cgo 的 openbsd 目标下是否仍能编译。
由索引模型根据 Issue 内容生成。
描述
On OpenBSD with cgo, every mount.Mount(..., "ffs", ...) call allocates three C strings that are never freed: fspec: C.CString(device) in createUfsArgs (mount/mounter_openbsd.go:42), and C.CString(mType) / C.CString(target) passed inline to C.mount (:66). mount(2) copies its arguments, so they can be freed right after the call; mounter_freebsd.go:46-49 already does this with defer C.free.
Details
Commit: 0922b4fee15d (//go:build openbsd && cgo). The file has no C.free and does not include <stdlib.h>. The leak is on both the success and the error path, len(device)+len(target)+6 bytes per call.
I don't have an OpenBSD machine. I copied createExportInfo, createUfsArgs and mount verbatim into a small program with a stub mount() that copies its string arguments and keeps nothing, and measured on macOS:
100,000 calls, current code: +4,800,448 bytes (48 bytes per call)
100,000 calls, with the change below: +0 bytes
With device="/dev/sd0a" and target="/mnt/data" the three strings are 24 bytes; the allocator reports 48 bytes per call because each small allocation is rounded up to 16 bytes.
Possible change in mount(), replacing the createUfsArgs call (and adding #include <stdlib.h> to the existing cgo preamble):
cdev := C.CString(device)
defer C.free(unsafe.Pointer(cdev))
args := C.struct_ufs_args{fspec: cdev, export_info: createExportInfo(readOnly)}
ctype := C.CString(mType)
defer C.free(unsafe.Pointer(ctype))
ctarget := C.CString(target)
defer C.free(unsafe.Pointer(ctarget))
if errno := C.mount(ctype, ctarget, C.int(flag), unsafe.Pointer(&args)); errno != 0 {
Separately (not part of this issue): :66 treats the return value of mount as an errno. mount(2) returns -1 and sets errno, so the error currently reads "errno -1" instead of the real error. mounter_freebsd.go does the same with nmount. Happy to open a separate issue for that if useful.
AI disclosure: I found and analysed this with AI assistance (Claude); the reproduction above was run, and I reviewed and edited this report before posting.
If you could credit me as a reporter for my contributions to security advisory I will be thankful.
- 主要语言
- Go
- 星标
- 102
- 派生
- 62
- 平均合并
- 3 分钟
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
moby/sys 的其他 Issue
-
devices: ignore .incus-mounts in GetDevices可能已有人在做 @SashaMIT 于 6 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
-
[userns-remap] Bug: ToHost incorrectly maps non-root container UID to root when it collides with RootPair可能已有人在做 @okhowang 于 73 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 3/5 1-2 天 新手友好度 74/100
-
难度 3/5 1-2 天 新手友好度 68/100
-
难度 3/5 1-2 天 新手友好度 68/100
相似的 Issue
-
documentation hacktoberfest priority: low skill: good first issue status: ready for dev
难度 2/5 半天 新手友好度 85/100
hyperledger-labs/fabric-smart-client#2142 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
numberly/vault-db-injector#107 ·
维护者通常 1 天内回复
-
area/import kind/bug
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
[DOC] Wrong sg_egress_ports range in the Terraform Databricks Guide for AWS Hub & Spoke with Network Firewall可能已有人在做 @akhil9tiet 今天认领。 未关闭docs
难度 1/5 1 小时以内 新手友好度 72/100
databricks/terraform-provider-databricks#6080 · 1 条评论 ·
维护者通常 3 天内回复
-
spqr-coordinator usage shows 'run --config', but 'run' is not a subcommand (unknown command "run")未关闭
难度 2/5 1-3 小时 新手友好度 72/100
pg-sharding/spqr#3092 · 1 条评论 ·
维护者通常 1 天内回复