Skip to content

Commit 3348835

Browse files
mykyta5Kernel Patches Daemon
authored andcommitted
bpf: verifier: refactor bpf_wq handling
Move bpf_wq map-field validation into the common helper by adding a BPF_WORKQUEUE case that maps to record->wq_off, and switch process_wq_func() to use it instead of doing its own offset math. 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]>
1 parent 5ba1e72 commit 3348835

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
@@ -8464,6 +8464,9 @@ static int check_map_field_pointer(struct bpf_verifier_env *env, u32 regno,
84648464
case BPF_TASK_WORK:
84658465
field_off = map->record->task_work_off;
84668466
break;
8467+
case BPF_WORKQUEUE:
8468+
field_off = map->record->wq_off;
8469+
break;
84678470
default:
84688471
verifier_bug(env, "unsupported BTF field type: %s\n", struct_name);
84698472
return -EINVAL;
@@ -8505,13 +8508,17 @@ static int process_wq_func(struct bpf_verifier_env *env, int regno,
85058508
{
85068509
struct bpf_reg_state *regs = cur_regs(env), *reg = &regs[regno];
85078510
struct bpf_map *map = reg->map_ptr;
8508-
u64 val = reg->var_off.value;
8511+
int err;
85098512

8510-
if (map->record->wq_off != val + reg->off) {
8511-
verbose(env, "off %lld doesn't point to 'struct bpf_wq' that is at %d\n",
8512-
val + reg->off, map->record->wq_off);
8513-
return -EINVAL;
8513+
err = check_map_field_pointer(env, regno, BPF_WORKQUEUE);
8514+
if (err)
8515+
return err;
8516+
8517+
if (meta->map.ptr) {
8518+
verifier_bug(env, "Two map pointers in a bpf_wq helper");
8519+
return -EFAULT;
85148520
}
8521+
85158522
meta->map.uid = reg->map_uid;
85168523
meta->map.ptr = map;
85178524
return 0;

0 commit comments

Comments
 (0)