Skip to content

Commit f34d885

Browse files
committed
bpf: Add BPF_PROG_TYPE_CGROUP_SKB attach type enforcement in BPF_LINK_CREATE
jira LE-2177 cve CVE-2024-38564 Rebuild_History Non-Buildable kernel-5.14.0-503.19.1.el9_5 commit-author Stanislav Fomichev <[email protected]> commit 543576e bpf_prog_attach uses attach_type_to_prog_type to enforce proper attach type for BPF_PROG_TYPE_CGROUP_SKB. link_create uses bpf_prog_get and relies on bpf_prog_attach_check_attach_type to properly verify prog_type <> attach_type association. Add missing attach_type enforcement for the link_create case. Otherwise, it's currently possible to attach cgroup_skb prog types to other cgroup hooks. Fixes: af6eea5 ("bpf: Implement bpf_link-based cgroup BPF program attachment") Link: https://lore.kernel.org/bpf/[email protected]/ Reported-by: [email protected] Signed-off-by: Stanislav Fomichev <[email protected]> Acked-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]> (cherry picked from commit 543576e) Signed-off-by: Jonathan Maple <[email protected]>
1 parent fd1a95d commit f34d885

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

kernel/bpf/syscall.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3828,6 +3828,11 @@ static int bpf_prog_attach_check_attach_type(const struct bpf_prog *prog,
38283828
* check permissions at attach time.
38293829
*/
38303830
return -EPERM;
3831+
3832+
ptype = attach_type_to_prog_type(attach_type);
3833+
if (prog->type != ptype)
3834+
return -EINVAL;
3835+
38313836
return prog->enforce_expected_attach_type &&
38323837
prog->expected_attach_type != attach_type ?
38333838
-EINVAL : 0;

0 commit comments

Comments
 (0)