Skip to content

Commit b792058

Browse files
ADSWT518Kernel Patches Daemon
authored andcommitted
selftests/bpf: Add tests for BPF_DIV analysis
Now BPF_DIV has value tracking support via interval and tnum analysis. This patch adds selftests to cover various cases of signed and unsigned division operations, including edge cases like division by zero and signed division overflow. Specifically, these selftests are based on dead code elimination: If the BPF verifier can precisely analyze the result of a division operation, it can prune the path that leads to an error (here we use invalid memory access as the error case), allowing the program to pass verification. Co-developed-by: Shenghao Yuan <shenghaoyuan0928@163.com> Signed-off-by: Shenghao Yuan <shenghaoyuan0928@163.com> Co-developed-by: Tianci Cao <ziye@zju.edu.cn> Signed-off-by: Tianci Cao <ziye@zju.edu.cn> Signed-off-by: Yazhou Tang <tangyazhou518@outlook.com>
1 parent eeca3ca commit b792058

File tree

2 files changed

+406
-0
lines changed

2 files changed

+406
-0
lines changed

tools/testing/selftests/bpf/prog_tests/verifier.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "verifier_direct_packet_access.skel.h"
3434
#include "verifier_direct_stack_access_wraparound.skel.h"
3535
#include "verifier_div0.skel.h"
36+
#include "verifier_div_bounds.skel.h"
3637
#include "verifier_div_overflow.skel.h"
3738
#include "verifier_global_subprogs.skel.h"
3839
#include "verifier_global_ptr_args.skel.h"
@@ -174,6 +175,7 @@ void test_verifier_d_path(void) { RUN(verifier_d_path); }
174175
void test_verifier_direct_packet_access(void) { RUN(verifier_direct_packet_access); }
175176
void test_verifier_direct_stack_access_wraparound(void) { RUN(verifier_direct_stack_access_wraparound); }
176177
void test_verifier_div0(void) { RUN(verifier_div0); }
178+
void test_verifier_div_bounds(void) { RUN(verifier_div_bounds); }
177179
void test_verifier_div_overflow(void) { RUN(verifier_div_overflow); }
178180
void test_verifier_global_subprogs(void) { RUN(verifier_global_subprogs); }
179181
void test_verifier_global_ptr_args(void) { RUN(verifier_global_ptr_args); }

0 commit comments

Comments
 (0)