Commit 9af1bddf authored by Haimin Zhang's avatar Haimin Zhang Committed by Zheng Zengkai
Browse files

netdevsim: Zero-initialize memory for new map's value in function nsim_bpf_map_alloc

mainline inclusion
from mainline-v5.16-rc6
commit 48122177
category: bugfix
bugzilla: 185973 https://gitee.com/openeuler/kernel/issues/I4DDEL
CVE: CVE-2021-4135

Reference: https://lore.kernel.org/all/20211215111530.72103-1-tcs.kernel@gmail.com/
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=481221775d53d6215a6e5e9ce1cce6d2b4ab9a46



--------------------------------

Zero-initialize memory for new map's value in function nsim_bpf_map_alloc
since it may cause a potential kernel information leak issue, as follows:
1. nsim_bpf_map_alloc calls nsim_map_alloc_elem to allocate elements for
a new map.
2. nsim_map_alloc_elem uses kmalloc to allocate map's value, but doesn't
zero it.
3. A user application can use IOCTL BPF_MAP_LOOKUP_ELEM to get specific
element's information in the map.
4. The kernel function map_lookup_elem will call bpf_map_copy_value to get
the information allocated at step-2, then use copy_to_user to copy to the
user buffer.
This can only leak information for an array map.

Fixes: 395cacb5 ("netdevsim: bpf: support fake map offload")
Suggested-by: default avatarJakub Kicinski <kuba@kernel.org>
Acked-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarHaimin Zhang <tcs.kernel@gmail.com>
Link: https://lore.kernel.org/r/20211215111530.72103-1-tcs.kernel@gmail.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarHe Fengqing <hefengqing@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent b822cf23
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment