History

bpf: Check ARG_PTR_TO_SPINLOCK register type in check_func_arg

Move the check for PTR_TO_MAP_VALUE to check_func_arg, where all other checking is done as well. Move the invocation of process_spin_lock away from the register type checking, to allow a future refactoring.

Lorenz Bauer committed 6 years ago

Commit c18f0b61 parent a2bbe7c1 file · +14 −14Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/bpf/verifier.c+14−14
@@ -3828,10 +3828,6 @@ static int process_spin_lock(struct bpf_verifier_env *env, int regno, · 3827 unmodified lines
38283828 struct bpf_map *map = reg->map_ptr;
38293829 u64 val = reg->var_off.value;
38303830
3831− if (reg->type != PTR_TO_MAP_VALUE) {
3832− verbose(env, "R%d is not a pointer to map_value\n", regno);
3833− return -EINVAL;
3834− }
38353831 if (!is_const) {
38363832 verbose(env,
38373833 "R%d doesn't have constant offset. bpf_spin_lock has to be at the constant offset\n",
@@ -4040,16 +4036,9 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, · 202 unmodified lines
40404036 if (type != expected_type)
40414037 goto err_type;
40424038 } else if (arg_type == ARG_PTR_TO_SPIN_LOCK) {
4043− if (meta->func_id == BPF_FUNC_spin_lock) {
4044− if (process_spin_lock(env, regno, true))
4045− return -EACCES;
4046− } else if (meta->func_id == BPF_FUNC_spin_unlock) {
4047− if (process_spin_lock(env, regno, false))
4048− return -EACCES;
4049− } else {
4050− verbose(env, "verifier internal error\n");
4051− return -EFAULT;
4052− }
4039+ expected_type = PTR_TO_MAP_VALUE;
4040+ if (type != expected_type)
4041+ goto err_type;
40534042 } else if (arg_type_is_mem_ptr(arg_type)) {
40544043 expected_type = PTR_TO_STACK;
40554044 /* One exception here. In case function allows for NULL to be
@@ -4155,6 +4144,17 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, · 99 unmodified lines
41554144 err = check_helper_mem_access(env, regno,
41564145 meta->map_ptr->value_size, false,
41574146 meta);
4147+ } else if (arg_type == ARG_PTR_TO_SPIN_LOCK) {
4148+ if (meta->func_id == BPF_FUNC_spin_lock) {
4149+ if (process_spin_lock(env, regno, true))
4150+ return -EACCES;
4151+ } else if (meta->func_id == BPF_FUNC_spin_unlock) {
4152+ if (process_spin_lock(env, regno, false))
4153+ return -EACCES;
4154+ } else {
4155+ verbose(env, "verifier internal error\n");
4156+ return -EFAULT;
4157+ }
41584158 } else if (arg_type_is_mem_ptr(arg_type)) {
41594159 /* The access to this pointer is only checked when we hit the
41604160 * next is_mem_size argument below.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t