Stack buffer overflow in PrivilegedService::ProtocolServer::serve() during BPF map lookup
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 12/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- cpp, linux
调研方向
The report points at starter/privileged_service_server.cc, lines 85-101, in ProtocolServer::serve(), where the BPF_MAP_LOOKUP_ELEM copy is bounded by the client-claimed value size rather than the map's real value size. A newcomer should not work on this publicly: it describes a potential privilege-escalation path, so it should go through the project's private security reporting channel. Done would mean a maintainer-approved fix that validates the fd's real value size before the kernel copy, plus a regression test.
由索引模型根据 Issue 内容生成。
描述
I found a stack buffer overflow in the Cilium Envoy starter's privileged service. For BPF map lookups, the server checks the value size claimed by the client, but the kernel writes the map's actual value size, which the server doesn't check.
The bug is in starter/privileged_service_server.cc:85-101:
// For TypeBpfLookupRequest:
uint32_t value_size_ = ...; // line 91: CLIENT-CLAIMED size from the wire
if (buf_size < value_len) { // line 93: checked against the CLAIMED size
rc = -1; errno = EINVAL;
} else {
// ... BPF_MAP_LOOKUP_ELEM at line 101 with attr.value = buf
// (a pointer into the 4108-byte stack union `msg`)
The client passes a BPF map fd via SCM_RIGHTS over the normal protocol channel; the unprivileged cilium-envoy child is the peer on the socketpair. BPF_MAP_LOOKUP_ELEM copies the map's actual value_size bytes into buf. That size is determined when the map is created, not by the request. The server only checks buf_size against the client's claimed value_size_. If the map's actual value size exceeds the remaining buffer, the copy overflows the privileged starter's stack.
Reproduce (ASan build; the harness creates the map on the server side, which holds CAP_BPF, and sends the request and fd from the child side):
./poc 8192 64 8 # real map value_size=8192, claimed=8 → 4KB past the stack
ASan:
==141==ERROR: AddressSanitizer: SEGV
#0 __asan_stack_free_7
#1 Envoy::Cilium::PrivilegedService::ProtocolServer::serve() privileged_service_server.cc:37
#2 main poc_main.cc:169
The harness (poc_main.cc in the zip) models the protocol: the child crafts the request bytes and passes the fd; the parent runs the pinned serve() code. Crash logs and a run verifying the fix are included.
Severity: the kernel writes map value bytes influenced by the attacker past the stack buffer in the privileged process. I verified this leads to control flow hijack in a test environment (details available on request).
Suggested fix: check the fd's actual value size as well as the client's claim:
// Read the map's actual value_size from /proc/self/fdinfo/<fd> (or use
// BPF_OBJ_GET_INFO_BY_FD) and reject if it exceeds the remaining buffer:
size_t real_value_size = /* from fdinfo or BPF_OBJ_GET_INFO_BY_FD */;
if (real_value_size > sizeof(msg) - offsetof(msg, bpf_lookup_reply.value)) {
rc = -1; errno = EINVAL;
}
With that, an fd for an oversized map is rejected before the kernel copy and legitimate lookups are unaffected.
I reproduced this at commit 2b268f09; the relevant code is unchanged at current HEAD. Thanks for checking!
- 主要语言
- C++
- 星标
- 192
- 派生
- 104
- 平均合并
- 1 天 18 小时
- 30 天内合并 PR
- 36
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
cilium/proxy 的其他 Issue
-
Enable opt-in io_uring support in Cilium proxy可能重新可做 @nezdolik 于 40 天前认领,目前没有进行中的 PR。 未关闭
cilium/proxy#2104 · 1 个 reaction · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
cilium/proxy#1824 · 2 个 reaction ·
维护者通常 1 天内回复
-
question
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 38/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
cilium/proxy#1027 · 14 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 87/100
-
难度 2/5 1-3 小时 新手友好度 78/100
ros-navigation/navigation2#6883 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
dotnet/diagnostics#6293 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
-
engaged enhancement
难度 2/5 1-3 小时 新手友好度 65/100
skeeto/prospero#118 · 1 个 reaction ·
维护者通常 1 天内回复