Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d5f3b1a
refactor: msan stack
linsyking Nov 7, 2024
449a3f5
feat: vm script
linsyking Nov 12, 2024
b4ac7db
feat: add evaluation tests
Nov 12, 2024
01b477a
Merge branch 'main' into dev
Nov 12, 2024
b2967a9
fix: add compile option for epass libbpf
linsyking Nov 12, 2024
76c7ecc
feat: check pass
linsyking Nov 12, 2024
0c68754
chore: error pass name
linsyking Nov 12, 2024
fb54764
fix: kernel utils
linsyking Nov 12, 2024
94956f9
refactor: naming
linsyking Nov 12, 2024
18aa485
fix: epasstool
linsyking Nov 12, 2024
0c3a991
feat: ignore prog check option
linsyking Nov 13, 2024
ac08155
feat: add tests
linsyking Nov 13, 2024
4c2d256
feat: eval compile speed
linsyking Nov 13, 2024
2fc6156
chore: evaluation color
linsyking Nov 13, 2024
d7f56f4
feat: add counter test
linsyking Nov 13, 2024
58f5428
chore: clean files
linsyking Nov 13, 2024
04ee2c2
feat: evaluation framework
linsyking Nov 13, 2024
42543fc
feat: add 2 buggy programs
linsyking Nov 13, 2024
426c5dc
fix: bb gen
linsyking Nov 13, 2024
9cd8c4a
fix: reduced complex bug
linsyking Nov 13, 2024
653b1e9
refactor: main API exported
linsyking Nov 13, 2024
512114d
feat: bb reach
linsyking Nov 13, 2024
5498ea8
fix: temporarily fix normalization bug
linsyking Nov 14, 2024
6148405
feat: eval
linsyking Nov 14, 2024
6114784
fix: normalize r=r
linsyking Nov 14, 2024
512f77b
chore: remove unused function
linsyking Nov 14, 2024
ea79681
feat: evaluation counter
Nov 14, 2024
2e8387f
feat: add_counter
linsyking Nov 14, 2024
32f0186
feat: eval
Nov 14, 2024
102b470
feat: improve test
linsyking Nov 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ To start with, a simple constraint would be "range constraint", meaning a regist

One opinion, one benefit of designing the raw constraint from is that our runtime-check system will not depend heavily on the current linux verifier and will be portable to other verifiers.

## Future work

Rewrite Normalization. Plain the IR.

Just store the allocated position in value. Not track users. No references.

All VRs are changed to Real Registers.

## Bugs

### SplitBB operation may not work properly if it's at the top of a BB

Resolved.

### Coalesce has some bugs

Found root cause: you may not directly remove instructions like r1 = r1.

## Errors

Reproduce: `ringbuf.c` enable coalesce will cause some error in CG
Expand Down
9 changes: 9 additions & 0 deletions core/aux/kern_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ static int apply_pass_opt(struct bpf_ir_env *env, const char *opt)
}
}
}
if (!found_pass) {
PRINT_LOG_ERROR(env, "Pass %s not found\n", pass_name);
return -EINVAL;
}
return 0;
}

Expand All @@ -97,6 +101,8 @@ static int apply_global_opt(struct bpf_ir_env *env, const char *opt)
env->opts.print_mode = BPF_IR_PRINT_DUMP;
} else if (strcmp(opt, "print_detail") == 0) {
env->opts.print_mode = BPF_IR_PRINT_DETAIL;
} else if (strcmp(opt, "no_prog_check") == 0) {
env->opts.disable_prog_check = true;
} else if (strcmp(opt, "print_bpf_detail") == 0) {
env->opts.print_mode = BPF_IR_PRINT_BPF_DETAIL;
} else if (strncmp(opt, "verbose=", 8) == 0) {
Expand Down Expand Up @@ -128,6 +134,9 @@ static int apply_global_opt(struct bpf_ir_env *env, const char *opt)
// Check if a builtin pass is enabled (by cfg)
bool bpf_ir_builtin_pass_enabled(struct bpf_ir_env *env, const char *pass_name)
{
if (!env) {
return false;
}
for (size_t i = 0; i < env->opts.builtin_pass_cfg_num; ++i) {
if (strcmp(env->opts.builtin_pass_cfg[i].name, pass_name) ==
0) {
Expand Down
80 changes: 0 additions & 80 deletions core/aux/prog_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,75 +390,6 @@ static void check_phi(struct bpf_ir_env *env, struct ir_function *fun)
}
}

static void bpf_ir_fix_bb_succ(struct bpf_ir_env *env, struct ir_function *fun)
{
struct ir_basic_block **pos;
array_for(pos, fun->all_bbs)
{
struct ir_basic_block *bb = *pos;
struct ir_insn *insn = bpf_ir_get_last_insn(bb);
if (insn && bpf_ir_is_cond_jmp(insn)) {
// Conditional jmp
if (bb->succs.num_elem != 2) {
print_ir_insn_err(env, insn,
"Jump instruction");
RAISE_ERROR(
"Conditional jmp with != 2 successors");
}
struct ir_basic_block **s1 = array_get(
&bb->succs, 0, struct ir_basic_block *);
struct ir_basic_block **s2 = array_get(
&bb->succs, 1, struct ir_basic_block *);
*s1 = insn->bb1;
*s2 = insn->bb2;
}
}
}

static void add_reach(struct bpf_ir_env *env, struct ir_function *fun,
struct ir_basic_block *bb)
{
if (bb->_visited) {
return;
}
bb->_visited = 1;
bpf_ir_array_push(env, &fun->reachable_bbs, &bb);

struct ir_basic_block **succ;
bool first = false;
array_for(succ, bb->succs)
{
if (!first && bb->succs.num_elem > 1) {
first = true;
// Check if visited
if ((*succ)->_visited) {
RAISE_ERROR("Loop BB detected");
}
}
add_reach(env, fun, *succ);
}
}

static void gen_reachable_bbs(struct bpf_ir_env *env, struct ir_function *fun)
{
bpf_ir_clean_visited(fun);
bpf_ir_array_clear(env, &fun->reachable_bbs);
add_reach(env, fun, fun->entry);
}

static void gen_end_bbs(struct bpf_ir_env *env, struct ir_function *fun)
{
struct ir_basic_block **pos;
bpf_ir_array_clear(env, &fun->end_bbs);
array_for(pos, fun->reachable_bbs)
{
struct ir_basic_block *bb = *pos;
if (bb->succs.num_elem == 0) {
bpf_ir_array_push(env, &fun->end_bbs, &bb);
}
}
}

// Interface Implementation

static void check_err_and_print(struct bpf_ir_env *env, struct ir_function *fun)
Expand All @@ -477,17 +408,6 @@ static void check_err_and_print(struct bpf_ir_env *env, struct ir_function *fun)
// Check that the program is valid and able to be compiled
void bpf_ir_prog_check(struct bpf_ir_env *env, struct ir_function *fun)
{
print_ir_err_init(fun);

bpf_ir_fix_bb_succ(env, fun);
CHECK_DUMP();

bpf_ir_clean_metadata_all(fun);
gen_reachable_bbs(env, fun);
CHECK_DUMP();
gen_end_bbs(env, fun);
CHECK_DUMP();

check_insn(env, fun);
CHECK_DUMP();

Expand Down
Loading