Skip to content

Commit 9f3330a

Browse files
eddyz87Alexei Starovoitov
authored andcommitted
selftests/bpf: test widening for iterating callbacks
A test case to verify that imprecise scalars widening is applied to callback entering state, when callback call is simulated repeatedly. Signed-off-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent cafe2c2 commit 9f3330a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct buf_context {
2525

2626
struct num_context {
2727
__u64 i;
28+
__u64 j;
2829
};
2930

3031
__u8 choice_arr[2] = { 0, 1 };
@@ -69,6 +70,25 @@ int unsafe_on_zero_iter(void *unused)
6970
return choice_arr[loop_ctx.i];
7071
}
7172

73+
static int widening_cb(__u32 idx, struct num_context *ctx)
74+
{
75+
++ctx->i;
76+
return 0;
77+
}
78+
79+
SEC("?raw_tp")
80+
__success
81+
int widening(void *unused)
82+
{
83+
struct num_context loop_ctx = { .i = 0, .j = 1 };
84+
85+
bpf_loop(100, widening_cb, &loop_ctx, 0);
86+
/* loop_ctx.j is not changed during callback iteration,
87+
* verifier should not apply widening to it.
88+
*/
89+
return choice_arr[loop_ctx.j];
90+
}
91+
7292
static int loop_detection_cb(__u32 idx, struct num_context *ctx)
7393
{
7494
for (;;) {}

0 commit comments

Comments
 (0)