devices: fix out-of-bounds write in BPF_PROG_QUERY - #69
Open
kolyshkin wants to merge 1 commit into
Open
Conversation
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>
Contributor
Author
|
@opencontainers/cgroups-maintainers I want to release v0.0.9 once this is in. For analysis and repro, see #64 (comment) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.