selftests/bpf: Remove stand-along test_verifier_log test binary
test_prog's prog_tests/verifier_log.c is superseding test_verifier_log stand-alone test. It cover same checks and adds more, and is also integrated into test_progs test runner. Just remove test_verifier_log.c. Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20230412170655.1866831-1-andrii@kernel.org
This commit is contained in:
parent
2995f9a8d4
commit
ee5059a64d
@ -36,7 +36,7 @@ endif
|
|||||||
|
|
||||||
# Order correspond to 'make run_tests' order
|
# Order correspond to 'make run_tests' order
|
||||||
TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
|
TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
|
||||||
test_verifier_log test_dev_cgroup \
|
test_dev_cgroup \
|
||||||
test_sock test_sockmap get_cgroup_id_user \
|
test_sock test_sockmap get_cgroup_id_user \
|
||||||
test_cgroup_storage \
|
test_cgroup_storage \
|
||||||
test_tcpnotify_user test_sysctl \
|
test_tcpnotify_user test_sysctl \
|
||||||
|
@ -1,175 +0,0 @@
|
|||||||
#include <errno.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#include <linux/bpf.h>
|
|
||||||
#include <linux/filter.h>
|
|
||||||
#include <linux/unistd.h>
|
|
||||||
|
|
||||||
#include <bpf/bpf.h>
|
|
||||||
|
|
||||||
#define LOG_SIZE (1 << 20)
|
|
||||||
|
|
||||||
#define err(str...) printf("ERROR: " str)
|
|
||||||
|
|
||||||
static const struct bpf_insn code_sample[] = {
|
|
||||||
/* We need a few instructions to pass the min log length */
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
|
|
||||||
BPF_FUNC_map_lookup_elem),
|
|
||||||
BPF_EXIT_INSN(),
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline __u64 ptr_to_u64(const void *ptr)
|
|
||||||
{
|
|
||||||
return (__u64) (unsigned long) ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int load(char *log, size_t log_len, int log_level)
|
|
||||||
{
|
|
||||||
union bpf_attr attr;
|
|
||||||
|
|
||||||
bzero(&attr, sizeof(attr));
|
|
||||||
attr.prog_type = BPF_PROG_TYPE_SOCKET_FILTER;
|
|
||||||
attr.insn_cnt = (__u32)(sizeof(code_sample) / sizeof(struct bpf_insn));
|
|
||||||
attr.insns = ptr_to_u64(code_sample);
|
|
||||||
attr.license = ptr_to_u64("GPL");
|
|
||||||
attr.log_buf = ptr_to_u64(log);
|
|
||||||
attr.log_size = log_len;
|
|
||||||
attr.log_level = log_level;
|
|
||||||
|
|
||||||
return syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void check_ret(int ret, int exp_errno)
|
|
||||||
{
|
|
||||||
if (ret > 0) {
|
|
||||||
close(ret);
|
|
||||||
err("broken sample loaded successfully!?\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ret || errno != exp_errno) {
|
|
||||||
err("Program load returned: ret:%d/errno:%d, expected ret:%d/errno:%d\n",
|
|
||||||
ret, errno, -1, exp_errno);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void check_ones(const char *buf, size_t len, const char *msg)
|
|
||||||
{
|
|
||||||
while (len--)
|
|
||||||
if (buf[len] != 1) {
|
|
||||||
err("%s", msg);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_log_good(char *log, size_t buf_len, size_t log_len,
|
|
||||||
size_t exp_len, int exp_errno, const char *full_log)
|
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
memset(log, 1, buf_len);
|
|
||||||
|
|
||||||
ret = load(log, log_len, 1);
|
|
||||||
check_ret(ret, exp_errno);
|
|
||||||
|
|
||||||
len = strnlen(log, buf_len);
|
|
||||||
if (len == buf_len) {
|
|
||||||
err("verifier did not NULL terminate the log\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if (exp_len && len != exp_len) {
|
|
||||||
err("incorrect log length expected:%zd have:%zd\n",
|
|
||||||
exp_len, len);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strchr(log, 1)) {
|
|
||||||
err("verifier leaked a byte through\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
check_ones(log + len + 1, buf_len - len - 1,
|
|
||||||
"verifier wrote bytes past NULL termination\n");
|
|
||||||
|
|
||||||
if (memcmp(full_log, log, LOG_SIZE)) {
|
|
||||||
err("log did not match expected output\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_log_bad(char *log, size_t log_len, int log_level)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = load(log, log_len, log_level);
|
|
||||||
check_ret(ret, EINVAL);
|
|
||||||
if (log)
|
|
||||||
check_ones(log, LOG_SIZE,
|
|
||||||
"verifier touched log with bad parameters\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
char full_log[LOG_SIZE];
|
|
||||||
char log[LOG_SIZE];
|
|
||||||
size_t want_len;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
memset(log, 1, LOG_SIZE);
|
|
||||||
|
|
||||||
/* Use libbpf 1.0 API mode */
|
|
||||||
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
|
|
||||||
|
|
||||||
/* Test incorrect attr */
|
|
||||||
printf("Test log_level 0...\n");
|
|
||||||
test_log_bad(log, LOG_SIZE, 0);
|
|
||||||
|
|
||||||
printf("Test log_size < 128...\n");
|
|
||||||
test_log_bad(log, 15, 1);
|
|
||||||
|
|
||||||
printf("Test log_buff = NULL...\n");
|
|
||||||
test_log_bad(NULL, LOG_SIZE, 1);
|
|
||||||
|
|
||||||
/* Test with log big enough */
|
|
||||||
printf("Test oversized buffer...\n");
|
|
||||||
test_log_good(full_log, LOG_SIZE, LOG_SIZE, 0, EACCES, full_log);
|
|
||||||
|
|
||||||
want_len = strlen(full_log);
|
|
||||||
|
|
||||||
printf("Test exact buffer...\n");
|
|
||||||
test_log_good(log, LOG_SIZE, want_len + 2, want_len, EACCES, full_log);
|
|
||||||
|
|
||||||
printf("Test undersized buffers...\n");
|
|
||||||
for (i = 0; i < 64; i++) {
|
|
||||||
full_log[want_len - i + 1] = 1;
|
|
||||||
full_log[want_len - i] = 0;
|
|
||||||
|
|
||||||
test_log_good(log, LOG_SIZE, want_len + 1 - i, want_len - i,
|
|
||||||
ENOSPC, full_log);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("test_verifier_log: OK\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user