Skip to content

Commit fcabf7b

Browse files
Haimin Zhangmaqiao-mq
authored andcommitted
netdevsim: Zero-initialize memory for new map's value in function nsim_bpf_map_alloc
ANBZ: torvalds#415 commit 4812217 upstream 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: 395cacb ("netdevsim: bpf: support fake map offload") Suggested-by: Jakub Kicinski <[email protected]> Acked-by: Jakub Kicinski <[email protected]> Signed-off-by: Haimin Zhang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Fixes: CVE-2021-4135 Signed-off-by: Qiao Ma <[email protected]> Acked-by: Tony Lu <[email protected]>
1 parent b65491f commit fcabf7b

File tree

1 file changed

+1
-0
lines changed
  • drivers/net/netdevsim

1 file changed

+1
-0
lines changed

drivers/net/netdevsim/bpf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ nsim_bpf_map_alloc(struct netdevsim *ns, struct bpf_offloaded_map *offmap)
493493
goto err_free;
494494
key = nmap->entry[i].key;
495495
*key = i;
496+
memset(nmap->entry[i].value, 0, offmap->map.value_size);
496497
}
497498
}
498499

0 commit comments

Comments
 (0)