]> git.baikalelectronics.ru Git - kernel.git/commit
netdevsim: Zero-initialize memory for new map's value in function nsim_bpf_map_alloc
authorHaimin Zhang <tcs.kernel@gmail.com>
Wed, 15 Dec 2021 11:15:30 +0000 (19:15 +0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 16 Dec 2021 01:49:13 +0000 (17:49 -0800)
commit27e5055adb1f7fcdc9253cb0c4e8630ec2d62520
tree3e90ccb18df415c98980ff8a0f7bc92f658bd20b
parent99bbcae837be5d47953c91fc74f7d8cf42458fdd
netdevsim: Zero-initialize memory for new map's value in function nsim_bpf_map_alloc

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: c9b65671a324 ("netdevsim: bpf: support fake map offload")
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Haimin Zhang <tcs.kernel@gmail.com>
Link: https://lore.kernel.org/r/20211215111530.72103-1-tcs.kernel@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/netdevsim/bpf.c