]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: fix argument type in bpf_loop documentation
authorMatteo Croce <teknoraver@meta.com>
Thu, 10 Oct 2024 03:56:52 +0000 (04:56 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 10 Oct 2024 15:52:36 +0000 (08:52 -0700)
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

Signed-off-by: Matteo Croce <teknoraver@meta.com>
Link: https://lore.kernel.org/r/20241010035652.17830-1-technoboy85@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/uapi/linux/bpf.h
kernel/bpf/verifier.c
tools/include/uapi/linux/bpf.h

index 8ab4d8184b9d23b5a09a632d3d807891e2062b66..874af0186fe84357988a50cc5dec6c2d45d3ccba 100644 (file)
@@ -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.
index 7d9b38ffd2204a207116abbb091034f7149be373..cfc62e0776bff2c84b1292d228781941e2c33cef 100644 (file)
@@ -9917,7 +9917,7 @@ static int set_loop_callback_state(struct bpf_verifier_env *env,
 {
        /* bpf_loop(u32 nr_loops, void *callback_fn, void *callback_ctx,
         *          u64 flags);
-        * callback_fn(u32 index, void *callback_ctx);
+        * callback_fn(u64 index, void *callback_ctx);
         */
        callee->regs[BPF_REG_1].type = SCALAR_VALUE;
        callee->regs[BPF_REG_2] = caller->regs[BPF_REG_3];
index 7610883c81910d8bd6e56cc6e1a4e488c523d8b1..5937c39069ba6eb45b93921e24aba9fe25626007 100644 (file)
@@ -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.