Skip to content

Commit 06e5c99

Browse files
Hou TaoAlexei Starovoitov
authored andcommitted
bpf: Set uattr->batch.count as zero before batched update or deletion
generic_map_{delete,update}_batch() doesn't set uattr->batch.count as zero before it tries to allocate memory for key. If the memory allocation fails, the value of uattr->batch.count will be incorrect. Fix it by setting uattr->batch.count as zero beore batched update or deletion. Signed-off-by: Hou Tao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 67ad2c7 commit 06e5c99

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

kernel/bpf/syscall.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,9 @@ int generic_map_delete_batch(struct bpf_map *map,
17311731
if (!max_count)
17321732
return 0;
17331733

1734+
if (put_user(0, &uattr->batch.count))
1735+
return -EFAULT;
1736+
17341737
key = kvmalloc(map->key_size, GFP_USER | __GFP_NOWARN);
17351738
if (!key)
17361739
return -ENOMEM;
@@ -1787,6 +1790,9 @@ int generic_map_update_batch(struct bpf_map *map, struct file *map_file,
17871790
if (!max_count)
17881791
return 0;
17891792

1793+
if (put_user(0, &uattr->batch.count))
1794+
return -EFAULT;
1795+
17901796
key = kvmalloc(map->key_size, GFP_USER | __GFP_NOWARN);
17911797
if (!key)
17921798
return -ENOMEM;

0 commit comments

Comments
 (0)