Skip to content

devices: fix out-of-bounds write in BPF_PROG_QUERY - #69

Open
kolyshkin wants to merge 1 commit into
opencontainers:mainfrom
kolyshkin:fix-oob
Open

devices: fix out-of-bounds write in BPF_PROG_QUERY#69
kolyshkin wants to merge 1 commit into
opencontainers:mainfrom
kolyshkin:fix-oob

Conversation

@kolyshkin

Copy link
Copy Markdown
Contributor

bpfAttrQuery only described the query member of union bpf_attr up to prog_cnt, and that size (32 bytes) is what is passed to bpf(2). Since Linux 6.16 (kernel commit 120933984460, "bpf: Implement mprog API on top of existing cgroup progs"), __cgroup_bpf_query copies query.revision back to userspace unconditionally, without looking at the size we passed. As revision sits at offset 56, the kernel writes 8 bytes past the end of the struct on every BPF_PROG_QUERY.

Depending on how the compiler lays out the frame, those 8 bytes either land on unused stack space, and nothing happens, or on live data. In runc this showed up as corrupted defer records, crashing "runc restore" in runtime.copystack, and as garbled strings.

Kernel commit 21c4b99b27f3 ("bpf: fix BPF_PROG_QUERY OOB write and cgroup backward compat") added the missing size check, but we have to keep working on kernels that lack it, so describe the query struct in full.

bpfAttrQuery only described the query member of union bpf_attr up to
prog_cnt, and that size (32 bytes) is what is passed to bpf(2). Since
Linux 6.16 (kernel commit 120933984460, "bpf: Implement mprog API on top
of existing cgroup progs"), __cgroup_bpf_query copies query.revision
back to userspace unconditionally, without looking at the size we
passed. As revision sits at offset 56, the kernel writes 8 bytes past
the end of the struct on every BPF_PROG_QUERY.

Depending on how the compiler lays out the frame, those 8 bytes either
land on unused stack space, and nothing happens, or on live data. In
runc this showed up as corrupted defer records, crashing "runc restore"
in runtime.copystack, and as garbled strings.

Kernel commit 21c4b99b27f3 ("bpf: fix BPF_PROG_QUERY OOB write and cgroup
backward compat") added the missing size check, but we have to keep
working on kernels that lack it, so describe the query struct in full.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
kolyshkin requested a review from a team as a code owner August 1, 2026 22:50
@kolyshkin

Copy link
Copy Markdown
Contributor Author

@opencontainers/cgroups-maintainers I want to release v0.0.9 once this is in. For analysis and repro, see #64 (comment)

@kolyshkin kolyshkin added this to the 0.0.9 milestone Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant