Skip to content

Commit d8fd9e1

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf: fix wrong helper enablement in cgroup local storage
Commit cd33943 ("bpf: introduce the bpf_get_local_storage() helper function") enabled the bpf_get_local_storage() helper also for BPF program types where it does not make sense to use them. They have been added both in sk_skb_func_proto() and sk_msg_func_proto() even though both program types are not invoked in combination with cgroups, and neither through BPF_PROG_RUN_ARRAY(). In the latter the bpf_cgroup_storage_set() is set shortly before BPF program invocation. Later, the helper bpf_get_local_storage() retrieves this prior set up per-cpu pointer and hands the buffer to the BPF program. The map argument in there solely retrieves the enum bpf_cgroup_storage_type from a local storage map associated with the program and based on the type returns either the global or per-cpu storage. However, there is no specific association between the program's map and the actual content in bpf_cgroup_storage[]. Meaning, any BPF program that would have been properly run from the cgroup side through BPF_PROG_RUN_ARRAY() where bpf_cgroup_storage_set() was performed, and that is later unloaded such that prog / maps are teared down will cause a use after free if that pointer is retrieved from programs that are not run through BPF_PROG_RUN_ARRAY() but have the cgroup local storage helper enabled in their func proto. Lets just remove it from the two sock_map program types to fix it. Auditing through the types where this helper is enabled, it appears that these are the only ones where it was mistakenly allowed. Fixes: cd33943 ("bpf: introduce the bpf_get_local_storage() helper function") Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Cc: Roman Gushchin <guro@fb.com> Acked-by: John Fastabend <john.fastabend@gmail.com> Acked-by: Roman Gushchin <guro@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent ede95a6 commit d8fd9e1

File tree

1 file changed

+0
-4
lines changed

1 file changed

+0
-4
lines changed

net/core/filter.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5264,8 +5264,6 @@ sk_msg_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
52645264
return &bpf_msg_pull_data_proto;
52655265
case BPF_FUNC_msg_push_data:
52665266
return &bpf_msg_push_data_proto;
5267-
case BPF_FUNC_get_local_storage:
5268-
return &bpf_get_local_storage_proto;
52695267
default:
52705268
return bpf_base_func_proto(func_id);
52715269
}
@@ -5296,8 +5294,6 @@ sk_skb_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
52965294
return &bpf_sk_redirect_map_proto;
52975295
case BPF_FUNC_sk_redirect_hash:
52985296
return &bpf_sk_redirect_hash_proto;
5299-
case BPF_FUNC_get_local_storage:
5300-
return &bpf_get_local_storage_proto;
53015297
#ifdef CONFIG_INET
53025298
case BPF_FUNC_sk_lookup_tcp:
53035299
return &bpf_sk_lookup_tcp_proto;

0 commit comments

Comments
 (0)