Commit ab839a58 authored by Eduard Zingerman's avatar Eduard Zingerman Committed by Alexei Starovoitov

selftests/bpf: verifier/uninit.c converted to inline assembly

Test verifier/uninit.c automatically converted to use inline assembly.
Signed-off-by: default avatarEduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20230325025524.144043-37-eddyz87@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent edff37b2
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "verifier_ringbuf.skel.h" #include "verifier_ringbuf.skel.h"
#include "verifier_spill_fill.skel.h" #include "verifier_spill_fill.skel.h"
#include "verifier_stack_ptr.skel.h" #include "verifier_stack_ptr.skel.h"
#include "verifier_uninit.skel.h"
__maybe_unused __maybe_unused
static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory) static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
...@@ -88,3 +89,4 @@ void test_verifier_raw_tp_writable(void) { RUN(verifier_raw_tp_writable); } ...@@ -88,3 +89,4 @@ void test_verifier_raw_tp_writable(void) { RUN(verifier_raw_tp_writable); }
void test_verifier_ringbuf(void) { RUN(verifier_ringbuf); } void test_verifier_ringbuf(void) { RUN(verifier_ringbuf); }
void test_verifier_spill_fill(void) { RUN(verifier_spill_fill); } void test_verifier_spill_fill(void) { RUN(verifier_spill_fill); }
void test_verifier_stack_ptr(void) { RUN(verifier_stack_ptr); } void test_verifier_stack_ptr(void) { RUN(verifier_stack_ptr); }
void test_verifier_uninit(void) { RUN(verifier_uninit); }
// SPDX-License-Identifier: GPL-2.0
/* Converted from tools/testing/selftests/bpf/verifier/uninit.c */
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "../../../include/linux/filter.h"
#include "bpf_misc.h"
SEC("socket")
__description("read uninitialized register")
__failure __msg("R2 !read_ok")
__failure_unpriv
__naked void read_uninitialized_register(void)
{
asm volatile (" \
r0 = r2; \
exit; \
" ::: __clobber_all);
}
SEC("socket")
__description("read invalid register")
__failure __msg("R15 is invalid")
__failure_unpriv
__naked void read_invalid_register(void)
{
asm volatile (" \
.8byte %[mov64_reg]; \
exit; \
" :
: __imm_insn(mov64_reg, BPF_MOV64_REG(BPF_REG_0, -1))
: __clobber_all);
}
SEC("socket")
__description("program doesn't init R0 before exit")
__failure __msg("R0 !read_ok")
__failure_unpriv
__naked void t_init_r0_before_exit(void)
{
asm volatile (" \
r2 = r1; \
exit; \
" ::: __clobber_all);
}
SEC("socket")
__description("program doesn't init R0 before exit in all branches")
__failure __msg("R0 !read_ok")
__msg_unpriv("R1 pointer comparison")
__naked void before_exit_in_all_branches(void)
{
asm volatile (" \
if r1 >= 0 goto l0_%=; \
r0 = 1; \
r0 += 2; \
l0_%=: exit; \
" ::: __clobber_all);
}
char _license[] SEC("license") = "GPL";
{
"read uninitialized register",
.insns = {
BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
BPF_EXIT_INSN(),
},
.errstr = "R2 !read_ok",
.result = REJECT,
},
{
"read invalid register",
.insns = {
BPF_MOV64_REG(BPF_REG_0, -1),
BPF_EXIT_INSN(),
},
.errstr = "R15 is invalid",
.result = REJECT,
},
{
"program doesn't init R0 before exit",
.insns = {
BPF_ALU64_REG(BPF_MOV, BPF_REG_2, BPF_REG_1),
BPF_EXIT_INSN(),
},
.errstr = "R0 !read_ok",
.result = REJECT,
},
{
"program doesn't init R0 before exit in all branches",
.insns = {
BPF_JMP_IMM(BPF_JGE, BPF_REG_1, 0, 2),
BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 2),
BPF_EXIT_INSN(),
},
.errstr = "R0 !read_ok",
.errstr_unpriv = "R1 pointer comparison",
.result = REJECT,
},
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment