bpf: don't open-code memdup_user()
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
38b41cc73d
commit
aa3b6e3d41
1 changed files with 16 additions and 29 deletions
|
@ -338,14 +338,11 @@ static int map_lookup_elem(union bpf_attr *attr)
|
|||
if (IS_ERR(map))
|
||||
return PTR_ERR(map);
|
||||
|
||||
err = -ENOMEM;
|
||||
key = kmalloc(map->key_size, GFP_USER);
|
||||
if (!key)
|
||||
key = memdup_user(ukey, map->key_size);
|
||||
if (IS_ERR(key)) {
|
||||
err = PTR_ERR(key);
|
||||
goto err_put;
|
||||
|
||||
err = -EFAULT;
|
||||
if (copy_from_user(key, ukey, map->key_size) != 0)
|
||||
goto free_key;
|
||||
}
|
||||
|
||||
if (map->map_type == BPF_MAP_TYPE_PERCPU_HASH ||
|
||||
map->map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH ||
|
||||
|
@ -417,14 +414,11 @@ static int map_update_elem(union bpf_attr *attr)
|
|||
if (IS_ERR(map))
|
||||
return PTR_ERR(map);
|
||||
|
||||
err = -ENOMEM;
|
||||
key = kmalloc(map->key_size, GFP_USER);
|
||||
if (!key)
|
||||
key = memdup_user(ukey, map->key_size);
|
||||
if (IS_ERR(key)) {
|
||||
err = PTR_ERR(key);
|
||||
goto err_put;
|
||||
|
||||
err = -EFAULT;
|
||||
if (copy_from_user(key, ukey, map->key_size) != 0)
|
||||
goto free_key;
|
||||
}
|
||||
|
||||
if (map->map_type == BPF_MAP_TYPE_PERCPU_HASH ||
|
||||
map->map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH ||
|
||||
|
@ -501,14 +495,11 @@ static int map_delete_elem(union bpf_attr *attr)
|
|||
if (IS_ERR(map))
|
||||
return PTR_ERR(map);
|
||||
|
||||
err = -ENOMEM;
|
||||
key = kmalloc(map->key_size, GFP_USER);
|
||||
if (!key)
|
||||
key = memdup_user(ukey, map->key_size);
|
||||
if (IS_ERR(key)) {
|
||||
err = PTR_ERR(key);
|
||||
goto err_put;
|
||||
|
||||
err = -EFAULT;
|
||||
if (copy_from_user(key, ukey, map->key_size) != 0)
|
||||
goto free_key;
|
||||
}
|
||||
|
||||
preempt_disable();
|
||||
__this_cpu_inc(bpf_prog_active);
|
||||
|
@ -518,7 +509,6 @@ static int map_delete_elem(union bpf_attr *attr)
|
|||
__this_cpu_dec(bpf_prog_active);
|
||||
preempt_enable();
|
||||
|
||||
free_key:
|
||||
kfree(key);
|
||||
err_put:
|
||||
fdput(f);
|
||||
|
@ -547,14 +537,11 @@ static int map_get_next_key(union bpf_attr *attr)
|
|||
return PTR_ERR(map);
|
||||
|
||||
if (ukey) {
|
||||
err = -ENOMEM;
|
||||
key = kmalloc(map->key_size, GFP_USER);
|
||||
if (!key)
|
||||
key = memdup_user(ukey, map->key_size);
|
||||
if (IS_ERR(key)) {
|
||||
err = PTR_ERR(key);
|
||||
goto err_put;
|
||||
|
||||
err = -EFAULT;
|
||||
if (copy_from_user(key, ukey, map->key_size) != 0)
|
||||
goto free_key;
|
||||
}
|
||||
} else {
|
||||
key = NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue