Skip to contentSkip to conversation

bpf: fix argument type in bpf_loop documentation

PATCH Superseded Matteo Croce 2 participants 2 messages Oct 9, 2024 BPF

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: fix argument type in bpf_loop documentation

From: Matteo Croce <[email protected]>

The index argument to bpf_loop() is threaded as an u64. This lead in a subtle verifier denial where clang cloned the argument in another register[1].

[1] https://github.com/systemd/systemd/pull/34650#issuecomment-2401092895

---
 include/uapi/linux/bpf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/bpf.h +1 -1
index 8ab4d8184b9d..874af0186fe8 100644
@@ -5371,7 +5371,7 @@ union bpf_attr {
  *		Currently, the **flags** must be 0. Currently, nr_loops is
  *		limited to 1 << 23 (~8 million) loops.
  *
- *		long (\*callback_fn)(u32 index, void \*ctx);
+ *		long (\*callback_fn)(u64 index, void \*ctx);
  *
  *		where **index** is the current index in the loop. The index
  *		is zero-indexed.
Signature · 1 line
2.46.0
#1 lore raw
Quoted 19 lines · Matteo Croce

From: Matteo Croce <[email protected]>

The index argument to bpf_loop() is threaded as an u64. This lead in a subtle verifier denial where clang cloned the argument in another register[1].

[1] https://github.com/systemd/systemd/pull/34650#issuecomment-2401092895

---
 include/uapi/linux/bpf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/bpf.h +0 -0
index 8ab4d8184b9d..874af0186fe8 100644

include/uapi/linux/bpf.h union bpf_attr { · line 5374

Quoted 5 lines
include/uapi/linux/bpf.h +1 -1
@@ -5371,7 +5371,7 @@ union bpf_attr {
  *             Currently, the **flags** must be 0. Currently, nr_loops is
  *             limited to 1 << 23 (~8 million) loops.
  *
- *             long (\*callback_fn)(u32 index, void \*ctx);
+ *             long (\*callback_fn)(u64 index, void \*ctx);

Good catch.
Please update other places too:
static int set_loop_callback_state(struct bpf_verifier_env *env,
struct bpf_func_state *caller, struct bpf_func_state *callee, int insn_idx)

{
        /* bpf_loop(u32 nr_loops, void *callback_fn, void *callback_ctx,
         *          u64 flags);
         * callback_fn(u32 index, void *callback_ctx);
         */
        callee->regs[BPF_REG_1].type = SCALAR_VALUE;

..

tools/include/uapi/linux/bpf.h

pw-bot: cr