bpf: Do not copy spin lock field from user in bpf_selem_alloc
authorXu Kuohai <xukuohai@huawei.com>
Mon, 14 Nov 2022 13:47:19 +0000 (08:47 -0500)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 21 Nov 2022 19:45:37 +0000 (11:45 -0800)
commit836e49e103dfeeff670c934b7d563cbd982fce87
tree772f4efa9994c16c279f777a42f2d5b7df5431fc
parent6f04180ca64b6cd5e404951bd042a1852f0598f1
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: 6ac99e8f23d4 ("bpf: Introduce bpf sk local storage")
Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
Link: https://lore.kernel.org/r/20221114134720.1057939-2-xukuohai@huawei.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/bpf_local_storage.c