Stack buffer overflow in PrivilegedService::ProtocolServer::serve() during BPF map lookup
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 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時間
- マージ済み PR(30日)
- 36
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cilium/proxy のほかの issue
-
Enable opt-in io_uring support in Cilium proxy再び着手できるかも @nezdolik が 40 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
cilium/proxy#2104 · リアクション 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
cilium/proxy#1824 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
-
question
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
cilium/proxy#1742 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
cilium/proxy#1027 · コメント 14 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 87/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ros-navigation/navigation2#6883 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
`libdbgshim` crashes in `MachOModule::ReadSymbolTable` on macOS 27 when a Metal app is attachedオープン
難易度 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 件 ·
メンテナーはふだん 1 日以内に返信