Skip to content

Commit ee4908f

Browse files
Xu Kuohaigregkh
authored andcommitted
bpf: Fix error usage of map_fd and fdget() in generic_map_update_batch()
commit fda7a38 upstream. 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 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent dd2260e commit ee4908f

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
@@ -1309,12 +1309,11 @@ int generic_map_update_batch(struct bpf_map *map,
13091309
void __user *values = u64_to_user_ptr(attr->batch.values);
13101310
void __user *keys = u64_to_user_ptr(attr->batch.keys);
13111311
u32 value_size, cp, max_count;
1312-
int ufd = attr->map_fd;
1312+
int ufd = attr->batch.map_fd;
13131313
void *key, *value;
13141314
struct fd f;
13151315
int err = 0;
13161316

1317-
f = fdget(ufd);
13181317
if (attr->batch.elem_flags & ~BPF_F_LOCK)
13191318
return -EINVAL;
13201319

@@ -1339,6 +1338,7 @@ int generic_map_update_batch(struct bpf_map *map,
13391338
return -ENOMEM;
13401339
}
13411340

1341+
f = fdget(ufd); /* bpf_map_do_batch() guarantees ufd is valid */
13421342
for (cp = 0; cp < max_count; cp++) {
13431343
err = -EFAULT;
13441344
if (copy_from_user(key, keys + cp * map->key_size,
@@ -1358,6 +1358,7 @@ int generic_map_update_batch(struct bpf_map *map,
13581358

13591359
kfree(value);
13601360
kfree(key);
1361+
fdput(f);
13611362
return err;
13621363
}
13631364

0 commit comments

Comments
 (0)