Skip to content

Commit 5f8d411

Browse files
mykyta5Alexei Starovoitov
authored andcommitted
bpf: Fix handling maps with no BTF and non-constant offsets for the bpf_wq
Fix handling maps with no BTF and non-constant offsets for the bpf_wq. This de-duplicates logic with other internal structs (task_work, timer), keeps error reporting consistent, and makes future changes to the layout handling centralized. Fixes: d940c9b ("bpf: add support for KF_ARG_PTR_TO_WORKQUEUE") Signed-off-by: Mykyta Yatsenko <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Acked-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 7dc484f commit 5f8d411

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

kernel/bpf/verifier.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8479,6 +8479,9 @@ static int check_map_field_pointer(struct bpf_verifier_env *env, u32 regno,
84798479
case BPF_TASK_WORK:
84808480
field_off = map->record->task_work_off;
84818481
break;
8482+
case BPF_WORKQUEUE:
8483+
field_off = map->record->wq_off;
8484+
break;
84828485
default:
84838486
verifier_bug(env, "unsupported BTF field type: %s\n", struct_name);
84848487
return -EINVAL;
@@ -8520,13 +8523,17 @@ static int process_wq_func(struct bpf_verifier_env *env, int regno,
85208523
{
85218524
struct bpf_reg_state *regs = cur_regs(env), *reg = &regs[regno];
85228525
struct bpf_map *map = reg->map_ptr;
8523-
u64 val = reg->var_off.value;
8526+
int err;
85248527

8525-
if (map->record->wq_off != val + reg->off) {
8526-
verbose(env, "off %lld doesn't point to 'struct bpf_wq' that is at %d\n",
8527-
val + reg->off, map->record->wq_off);
8528-
return -EINVAL;
8528+
err = check_map_field_pointer(env, regno, BPF_WORKQUEUE);
8529+
if (err)
8530+
return err;
8531+
8532+
if (meta->map.ptr) {
8533+
verifier_bug(env, "Two map pointers in a bpf_wq helper");
8534+
return -EFAULT;
85298535
}
8536+
85308537
meta->map.uid = reg->map_uid;
85318538
meta->map.ptr = map;
85328539
return 0;

0 commit comments

Comments
 (0)