Files
linux/include/linux
Eduard Zingerman bb124da69c bpf: keep track of max number of bpf_loop callback iterations
In some cases verifier can't infer convergence of the bpf_loop()
iteration. E.g. for the following program:

    static int cb(__u32 idx, struct num_context* ctx)
    {
        ctx->i++;
        return 0;
    }

    SEC("?raw_tp")
    int prog(void *_)
    {
        struct num_context ctx = { .i = 0 };
        __u8 choice_arr[2] = { 0, 1 };

        bpf_loop(2, cb, &ctx, 0);
        return choice_arr[ctx.i];
    }

Each 'cb' simulation would eventually return to 'prog' and reach
'return choice_arr[ctx.i]' statement. At which point ctx.i would be
marked precise, thus forcing verifier to track multitude of separate
states with {.i=0}, {.i=1}, ... at bpf_loop() callback entry.

This commit allows "brute force" handling for such cases by limiting
number of callback body simulations using 'umax' value of the first
bpf_loop() parameter.

For this, extend bpf_func_state with 'callback_depth' field.
Increment this field when callback visiting state is pushed to states
traversal stack. For frame #N it's 'callback_depth' field counts how
many times callback with frame depth N+1 had been executed.
Use bpf_func_state specifically to allow independent tracking of
callback depths when multiple nested bpf_loop() calls are present.

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20231121020701.26440-11-eddyz87@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2023-11-20 18:36:40 -08:00
..
2023-10-05 09:13:42 -07:00
2023-10-24 13:08:14 -07:00
2023-11-04 10:22:52 +01:00
2023-09-18 09:28:22 +01:00
2023-08-23 08:21:37 +01:00
2023-09-11 08:13:18 +00:00
2023-11-10 13:54:58 +00:00
2023-10-11 08:46:01 -07:00
2023-08-09 08:21:22 +02:00
2023-09-22 08:52:13 -06:00
2023-11-01 22:33:53 -07:00
2023-10-30 21:48:22 -04:00
2023-10-04 10:41:56 -07:00
2023-10-04 10:41:56 -07:00
2023-09-11 23:59:47 -04:00
2023-10-25 20:19:00 +02:00
2023-09-13 10:48:48 +02:00
2023-08-04 11:02:46 +01:00
2023-10-12 09:58:02 +02:00
2023-10-11 10:11:54 -07:00
2023-08-18 10:12:10 -07:00
2023-10-18 14:43:21 -07:00
2023-10-04 10:41:57 -07:00
2023-10-16 12:44:06 -04:00
2023-10-16 12:44:06 -04:00
2023-08-18 10:18:59 -07:00
2023-11-13 11:02:30 +00:00
2023-10-18 10:01:33 +02:00
2023-08-18 10:12:25 -07:00
2023-10-18 14:34:16 -07:00
2023-09-29 17:20:46 -07:00
2023-10-03 21:18:13 +02:00
2023-08-12 09:18:47 -07:00
2023-11-10 09:20:55 +01:00
2023-10-06 11:01:23 +02:00
2023-10-06 11:01:23 +02:00
2023-09-11 22:10:47 +02:00
2023-10-15 13:19:42 +01:00
2023-11-01 10:02:18 +00:00
2023-10-18 14:43:21 -07:00
2023-08-21 13:37:26 -07:00
2023-11-03 09:16:42 +00:00
2023-10-18 14:43:21 -07:00
2023-08-07 17:55:54 +00:00
2023-08-11 21:12:47 +02:00
2023-09-14 16:16:36 +02:00
2023-10-27 18:04:28 +08:00
2023-08-24 13:27:47 -05:00
2023-10-18 14:34:18 -07:00
2023-08-21 14:52:16 +02:00
2023-08-21 13:37:27 -07:00