Commit 836e49e1 authored by Xu Kuohai's avatar Xu Kuohai Committed by Alexei Starovoitov

bpf: Do not copy spin lock field from user in bpf_selem_alloc

bpf_selem_alloc function is used by inode_storage, sk_storage and
task_storage maps to set map value, for these map types, there may
be a spin lock in the map value, so if we use memcpy to copy the whole
map value from user, the spin lock field may be initialized incorrectly.

Since the spin lock field is zeroed by kzalloc, call copy_map_value
instead of memcpy to skip copying the spin lock field to fix it.

Fixes: 6ac99e8f ("bpf: Introduce bpf sk local storage")
Signed-off-by: default avatarXu Kuohai <xukuohai@huawei.com>
Link: https://lore.kernel.org/r/20221114134720.1057939-2-xukuohai@huawei.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 6f04180c
...@@ -74,7 +74,7 @@ bpf_selem_alloc(struct bpf_local_storage_map *smap, void *owner, ...@@ -74,7 +74,7 @@ bpf_selem_alloc(struct bpf_local_storage_map *smap, void *owner,
gfp_flags | __GFP_NOWARN); gfp_flags | __GFP_NOWARN);
if (selem) { if (selem) {
if (value) if (value)
memcpy(SDATA(selem)->data, value, smap->map.value_size); copy_map_value(&smap->map, SDATA(selem)->data, value);
return selem; return selem;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment