Skip to content

Instantly share code, notes, and snippets.

@eddyz87
Created December 14, 2023 16:21
Show Gist options
  • Save eddyz87/fb4d3c7d5aabdc2ae247ed73fefccd32 to your computer and use it in GitHub Desktop.
Save eddyz87/fb4d3c7d5aabdc2ae247ed73fefccd32 to your computer and use it in GitHub Desktop.
test + dead code removal disabled 2
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1863826a4ac3..80821a543c12 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -18283,6 +18283,8 @@ static void sanitize_dead_code(struct bpf_verifier_env *env)
const int insn_cnt = env->prog->len;
int i;
+ return;
+
for (i = 0; i < insn_cnt; i++) {
if (aux_data[i].seen)
continue;
@@ -18313,6 +18315,8 @@ static void opt_hard_wire_dead_code_branches(struct bpf_verifier_env *env)
const int insn_cnt = env->prog->len;
int i;
+ return;
+
for (i = 0; i < insn_cnt; i++, insn++) {
if (!insn_is_cond_jump(insn->code))
continue;
@@ -18337,6 +18341,8 @@ static int opt_remove_dead_code(struct bpf_verifier_env *env)
int insn_cnt = env->prog->len;
int i, err;
+ return 0;
+
for (i = 0; i < insn_cnt; i++) {
int j;
diff --git a/tools/testing/selftests/bpf/progs/verifier_and.c b/tools/testing/selftests/bpf/progs/verifier_and.c
index e97e518516b6..e7efe72fd0d7 100644
--- a/tools/testing/selftests/bpf/progs/verifier_and.c
+++ b/tools/testing/selftests/bpf/progs/verifier_and.c
@@ -2,6 +2,7 @@
/* Converted from tools/testing/selftests/bpf/verifier/and.c */
#include <linux/bpf.h>
+#include "../../../include/linux/filter.h"
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
@@ -104,4 +105,29 @@ l0_%=: r0 = 0; \
: __clobber_all);
}
+SEC("socket")
+__success
+__flag(BPF_F_TEST_STATE_FREQ)
+__retval(42)
+__naked void pruning_test(void)
+{
+ asm volatile (
+ " call %[bpf_get_prandom_u32];\n"
+ " r7 = r0;\n"
+ " call %[bpf_get_prandom_u32];\n"
+ " r8 = 2;\n"
+ " if r0 > 1 goto 1f;\n"
+ " r8 = r7;\n"
+ "1: r5 = r8;\n"
+ " if r8 >= r0 goto 2f;\n"
+ " r8 += r8;\n"
+ " if r5 == 0 goto 2f;\n"
+ " r0 /= 0;\n"
+ "2: r0 = 42;\n"
+ " exit;\n"
+ :
+ : __imm(bpf_get_prandom_u32)
+ : __clobber_all);
+}
+
char _license[] SEC("license") = "GPL";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment