Skip to content

Commit fda7a38

Browse files
Xu KuohaiAlexei Starovoitov
authored andcommitted
bpf: Fix error usage of map_fd and fdget() in generic_map_update_batch()
1. The ufd in generic_map_update_batch() should be read from batch.map_fd; 2. A call to fdget() should be followed by a symmetric call to fdput(). Fixes: aa2e93b ("bpf: Add generic support for update and delete batch ops") Signed-off-by: Xu Kuohai <xukuohai@huawei.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20211019032934.1210517-1-xukuohai@huawei.com
1 parent 22a1279 commit fda7a38

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎kernel/bpf/syscall.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,12 +1337,11 @@ int generic_map_update_batch(struct bpf_map *map,
13371337
void __user *values = u64_to_user_ptr(attr->batch.values);
13381338
void __user *keys = u64_to_user_ptr(attr->batch.keys);
13391339
u32 value_size, cp, max_count;
1340-
int ufd = attr->map_fd;
1340+
int ufd = attr->batch.map_fd;
13411341
void *key, *value;
13421342
struct fd f;
13431343
int err = 0;
13441344

1345-
f = fdget(ufd);
13461345
if (attr->batch.elem_flags & ~BPF_F_LOCK)
13471346
return -EINVAL;
13481347

@@ -1367,6 +1366,7 @@ int generic_map_update_batch(struct bpf_map *map,
13671366
return -ENOMEM;
13681367
}
13691368

1369+
f = fdget(ufd); /* bpf_map_do_batch() guarantees ufd is valid */
13701370
for (cp = 0; cp < max_count; cp++) {
13711371
err = -EFAULT;
13721372
if (copy_from_user(key, keys + cp * map->key_size,
@@ -1386,6 +1386,7 @@ int generic_map_update_batch(struct bpf_map *map,
13861386

13871387
kvfree(value);
13881388
kvfree(key);
1389+
fdput(f);
13891390
return err;
13901391
}
13911392

0 commit comments

Comments
 (0)