|
@@ -410,14 +410,11 @@ static int map_lookup_elem(union bpf_attr *attr)
|
|
if (IS_ERR(map))
|
|
if (IS_ERR(map))
|
|
return PTR_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;
|
|
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 ||
|
|
if (map->map_type == BPF_MAP_TYPE_PERCPU_HASH ||
|
|
map->map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH ||
|
|
map->map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH ||
|
|
@@ -493,14 +490,11 @@ static int map_update_elem(union bpf_attr *attr)
|
|
if (IS_ERR(map))
|
|
if (IS_ERR(map))
|
|
return PTR_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;
|
|
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 ||
|
|
if (map->map_type == BPF_MAP_TYPE_PERCPU_HASH ||
|
|
map->map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH ||
|
|
map->map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH ||
|
|
@@ -579,14 +573,11 @@ static int map_delete_elem(union bpf_attr *attr)
|
|
if (IS_ERR(map))
|
|
if (IS_ERR(map))
|
|
return PTR_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;
|
|
goto err_put;
|
|
-
|
|
|
|
- err = -EFAULT;
|
|
|
|
- if (copy_from_user(key, ukey, map->key_size) != 0)
|
|
|
|
- goto free_key;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
preempt_disable();
|
|
preempt_disable();
|
|
__this_cpu_inc(bpf_prog_active);
|
|
__this_cpu_inc(bpf_prog_active);
|
|
@@ -598,7 +589,6 @@ static int map_delete_elem(union bpf_attr *attr)
|
|
|
|
|
|
if (!err)
|
|
if (!err)
|
|
trace_bpf_map_delete_elem(map, ufd, key);
|
|
trace_bpf_map_delete_elem(map, ufd, key);
|
|
-free_key:
|
|
|
|
kfree(key);
|
|
kfree(key);
|
|
err_put:
|
|
err_put:
|
|
fdput(f);
|
|
fdput(f);
|
|
@@ -627,14 +617,11 @@ static int map_get_next_key(union bpf_attr *attr)
|
|
return PTR_ERR(map);
|
|
return PTR_ERR(map);
|
|
|
|
|
|
if (ukey) {
|
|
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;
|
|
goto err_put;
|
|
-
|
|
|
|
- err = -EFAULT;
|
|
|
|
- if (copy_from_user(key, ukey, map->key_size) != 0)
|
|
|
|
- goto free_key;
|
|
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
key = NULL;
|
|
key = NULL;
|
|
}
|
|
}
|