netdevsim: Zero-initialize memory for new map's value in function nsim_bpf_map_alloc
Subsystems (3)
PATCH v4 1/1 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.
--- drivers/net/netdevsim/bpf.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/netdevsim/bpf.c +1 -0
@@ -514,6 +514,7 @@ nsim_bpf_map_alloc(struct netdevsim *ns, struct bpf_offloaded_map *offmap) goto err_free; key = nmap->entry[i].key; *key = i; +memset (nmap->entry[i].value,0 , offmap->map.value_size); } }
Signature · 1 line
2.30.1 (Apple Git-130)
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:
Quoted 13 lines · On Wed, 15 Dec 2021 19:15:30 +0800 you wrote:
Zero-initialize memory for new map's value in function
nsim_bpf_map_allocsince it may cause a potential kernel information leak issue, as follows:
1.nsim_bpf_map_alloccallsnsim_map_alloc_elemto allocate elements for a new map.
2.nsim_map_alloc_elemuses kmalloc to allocate map's value, but doesn't zero it.
3. A user application can use IOCTLBPF_MAP_LOOKUP_ELEMto get specific element's information in the map.
4. The kernel functionmap_lookup_elemwill callbpf_map_copy_valueto get the information allocated at step-2, then usecopy_to_userto copy to the user buffer.
This can only leak information for an array map.
Quoted 1 line
[...]
Here is the summary with links:
- [v4] netdevsim: Zero-initialize memory for new map's value in function nsim_bpf_map_alloc
https://git.kernel.org/netdev/net/c/481221775d53
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html