Skip to content

Commit 4568af1

Browse files
ameryhungKernel Patches Daemon
authored andcommitted
bpf: Disallow tail call to programs that use cgroup storage
Mitigate a possible NULL pointer dereference in bpf_get_local_storage() by disallowing tail call to programs that use cgroup storage. Cgroup storage is allocated lazily when attaching a cgroup bpf program. With tail call, it is possible for a callee BPF program to see a NULL storage pointer if the caller prorgam does not use cgroup storage. Reported-by: Yinhao Hu <[email protected]> Reported-by: Kaiyan Mei <[email protected]> Reported-by: Dongliang Mu <[email protected]> Closes: https://lore.kernel.org/bpf/[email protected]/ Signed-off-by: Amery Hung <[email protected]>
1 parent ad17a83 commit 4568af1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

kernel/bpf/arraymap.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,9 @@ int bpf_fd_array_map_update_elem(struct bpf_map *map, struct file *map_file,
892892
void *key, void *value, u64 map_flags)
893893
{
894894
struct bpf_array *array = container_of(map, struct bpf_array, map);
895+
u32 i, index = *(u32 *)key, ufd;
895896
void *new_ptr, *old_ptr;
896-
u32 index = *(u32 *)key, ufd;
897+
struct bpf_prog *prog;
897898

898899
if (map_flags != BPF_ANY)
899900
return -EINVAL;
@@ -906,6 +907,14 @@ int bpf_fd_array_map_update_elem(struct bpf_map *map, struct file *map_file,
906907
if (IS_ERR(new_ptr))
907908
return PTR_ERR(new_ptr);
908909

910+
if (map->map_type == BPF_MAP_TYPE_PROG_ARRAY) {
911+
prog = (struct bpf_prog *)new_ptr;
912+
913+
for_each_cgroup_storage_type(i)
914+
if (prog->aux->cgroup_storage[i])
915+
return -EINVAL;
916+
}
917+
909918
if (map->ops->map_poke_run) {
910919
mutex_lock(&array->aux->poke_mutex);
911920
old_ptr = xchg(array->ptrs + index, new_ptr);

0 commit comments

Comments
 (0)