Skip to content

Commit 23b809e

Browse files
Walk VM: mask the field index at each use; a 32-bit fill loses its bound
Every kernel rejected the per-CPU-state object at insn 670: "R4 unbounded memory access" on fcount[key]. clang spilled key as a 4-byte slot and the verifier treats that fill as unknown. Mask where it is used, as before.
1 parent b97c6c2 commit 23b809e

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎bpf/walk/walk.bpf.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,11 @@ static long walk_node(__u32 it, void *pctx)
354354
run_section(c, st, 1, p->n_body, st->node);
355355
if (!st->live || st->wrote == 0)
356356
return 1;
357-
c->e->elen[idx] = st->wrote;
358-
c->e->fcount[key] = it + 1;
359-
c->e->ok |= (1u << key);
357+
/* Masked again at each use: clang spills `key` as a 32-bit slot and
358+
* the verifier forgets the bound on the fill. */
359+
c->e->elen[idx & (MAX_FIELDS * MAX_ITERS - 1)] = st->wrote;
360+
c->e->fcount[key & (MAX_FIELDS - 1)] = it + 1;
361+
c->e->ok |= (1u << (key & (MAX_FIELDS - 1)));
360362
if (p->next_off == 0)
361363
return 1;
362364
__u64 adv = 0;

0 commit comments

Comments
 (0)