Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

getpgid: UB when the kernel returns process group 0 (kernel threads / other PID namespace)

未关闭
#1,696 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
rust

调研方向

Read src/backend/linux_raw/process/syscalls.rs and src/backend/libc/process/syscalls.rs, starting at getpgid and comparing how each handles the kernel result. Then check the public Pid API and related wrappers such as getsid to understand the impact of the proposed choices. Done means a safe, consistent way to represent or handle a returned 0 is agreed on and applied; the issue does not specify which fix to choose.

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

描述

getpgid can return a process group ID of 0 on Linux. rustix then builds a Pid from that value with Pid::from_raw_unchecked, which calls NonZeroI32::new_unchecked(0). That is undefined behavior in release builds. Debug builds hit the debug_assert!(pgid > 0) instead.

Where: src/backend/linux_raw/process/syscalls.rs, getpgid, unchanged in 1.1.4 and on main. The libc backend (src/backend/libc/process/syscalls.rs) does the same without the debug assertion.

When the kernel returns 0: getpgid(2) reports the group ID as seen from the caller's PID namespace. Two cases give 0:

  • kernel threads, for example PID 2 (kthreadd) and its children;
  • any process whose process group is not visible in the caller's namespace.

A process that scans /proc and calls getpgid on every PID will meet both cases.

Reproduction (Linux, debug build):

let pgid = rustix::process::getpgid(rustix::process::Pid::from_raw(2));
// panics on the debug_assert; in release it creates a Pid holding 0 (UB)

Possible fixes:

  • return Result<Option<Pid>>, with None for 0;
  • map 0 to an error;
  • document it and return a type that may hold 0.

Other wrappers that hand a kernel-provided ID to from_raw_unchecked (for example getsid) may have the same issue.

We found this while running a test suite natively on Ubuntu 26.04. As a workaround we now call libc::getpgid directly and treat 0 as "no visible group".

主要语言
Rust
星标
2.1k
派生
301
平均合并
10 天 1 小时
30 天内合并 PR
1

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

bytecodealliance/rustix 的其他 Issue

查看 bytecodealliance/rustix 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

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