mirror of
https://github.com/torvalds/linux.git
synced 2026-06-01 02:53:36 +02:00
selftests/bpf: Add tests for BPF_DIV and BPF_MOD range tracking
Now BPF_DIV has range tracking support via interval analysis. This patch adds selftests to cover various cases of BPF_DIV and BPF_MOD operations when the divisor is a constant, also covering both signed and unsigned variants. This patch includes several types of tests in 32-bit and 64-bit variants: 1. For UDIV - positive divisor - zero divisor 2. For SDIV - positive divisor, positive dividend - positive divisor, negative dividend - positive divisor, mixed sign dividend - negative divisor, positive dividend - negative divisor, negative dividend - negative divisor, mixed sign dividend - zero divisor - overflow (SIGNED_MIN/-1), normal dividend - overflow (SIGNED_MIN/-1), constant dividend 3. For UMOD - positive divisor - positive divisor, small dividend - zero divisor 4. For SMOD - positive divisor, positive dividend - positive divisor, negative dividend - positive divisor, mixed sign dividend - positive divisor, mixed sign dividend, small dividend - negative divisor, positive dividend - negative divisor, negative dividend - negative divisor, mixed sign dividend - negative divisor, mixed sign dividend, small dividend - zero divisor - overflow (SIGNED_MIN/-1), normal dividend - overflow (SIGNED_MIN/-1), constant dividend Specifically, these selftests are based on dead code elimination: If the BPF verifier can precisely analyze the result of BPF_DIV/BPF_MOD instruction, 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> Link: https://lore.kernel.org/r/20260119085458.182221-3-tangyazhou@zju.edu.cn Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
44fdd581d2
commit
c9e440bf25
|
|
@ -33,6 +33,7 @@
|
|||
#include "verifier_direct_packet_access.skel.h"
|
||||
#include "verifier_direct_stack_access_wraparound.skel.h"
|
||||
#include "verifier_div0.skel.h"
|
||||
#include "verifier_div_mod_bounds.skel.h"
|
||||
#include "verifier_div_overflow.skel.h"
|
||||
#include "verifier_global_subprogs.skel.h"
|
||||
#include "verifier_global_ptr_args.skel.h"
|
||||
|
|
@ -175,6 +176,7 @@ void test_verifier_d_path(void) { RUN(verifier_d_path); }
|
|||
void test_verifier_direct_packet_access(void) { RUN(verifier_direct_packet_access); }
|
||||
void test_verifier_direct_stack_access_wraparound(void) { RUN(verifier_direct_stack_access_wraparound); }
|
||||
void test_verifier_div0(void) { RUN(verifier_div0); }
|
||||
void test_verifier_div_mod_bounds(void) { RUN(verifier_div_mod_bounds); }
|
||||
void test_verifier_div_overflow(void) { RUN(verifier_div_overflow); }
|
||||
void test_verifier_global_subprogs(void) { RUN(verifier_global_subprogs); }
|
||||
void test_verifier_global_ptr_args(void) { RUN(verifier_global_ptr_args); }
|
||||
|
|
|
|||
1149
tools/testing/selftests/bpf/progs/verifier_div_mod_bounds.c
Normal file
1149
tools/testing/selftests/bpf/progs/verifier_div_mod_bounds.c
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user