From 21e1276561e5f75ebea72b995c6c6e2a1ddd1e91 Mon Sep 17 00:00:00 2001 From: Dave Thaler Date: Tue, 2 Apr 2024 09:13:12 -0700 Subject: [PATCH] Update verifier to latest (#3329) * Update verifier to latest Signed-off-by: Dave Thaler * Update tests Signed-off-by: Dave Thaler * Update bpf_conformance to latest release Signed-off-by: Dave Thaler --------- Signed-off-by: Dave Thaler --- .github/workflows/cicd-release-validation.yml | 2 +- .github/workflows/cicd.yml | 4 +- docs/isa-support.rst | 43 ++++++++++--------- external/ebpf-verifier | 2 +- tests/end_to_end/netsh_test.cpp | 14 +++--- tests/unit/libbpf_test.cpp | 10 ++--- 6 files changed, 38 insertions(+), 37 deletions(-) diff --git a/.github/workflows/cicd-release-validation.yml b/.github/workflows/cicd-release-validation.yml index 8dc2375e39..fe5b1e92bb 100644 --- a/.github/workflows/cicd-release-validation.yml +++ b/.github/workflows/cicd-release-validation.yml @@ -117,7 +117,7 @@ jobs: if: github.event_name == 'workflow_dispatch' uses: ./.github/workflows/reusable-test.yml with: - pre_test: Invoke-WebRequest https://github.com/Alan-Jowett/bpf_conformance/releases/download/v0.0.5/bpf_conformance_runner.exe -OutFile bpf_conformance_runner.exe + pre_test: Invoke-WebRequest https://github.com/Alan-Jowett/bpf_conformance/releases/download/v0.0.6/bpf_conformance_runner.exe -OutFile bpf_conformance_runner.exe test_command: .\bpf_conformance_runner.exe --test_file_directory %SOURCE_ROOT%\external\ebpf-verifier\external\bpf_conformance\tests --cpu_version v4 --exclude_regex local --plugin_path bpf2c_plugin.exe --debug true --plugin_options "--include %SOURCE_ROOT%\include" name: bpf2c_conformance build_artifact: Build-x64 diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 9fd9ca7408..190b5deac0 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -164,7 +164,7 @@ jobs: if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' uses: ./.github/workflows/reusable-test.yml with: - pre_test: Invoke-WebRequest https://github.com/Alan-Jowett/bpf_conformance/releases/download/v0.0.5/bpf_conformance_runner.exe -OutFile bpf_conformance_runner.exe + pre_test: Invoke-WebRequest https://github.com/Alan-Jowett/bpf_conformance/releases/download/v0.0.6/bpf_conformance_runner.exe -OutFile bpf_conformance_runner.exe test_command: .\bpf_conformance_runner.exe --test_file_directory %SOURCE_ROOT%\external\ebpf-verifier\external\bpf_conformance\tests --cpu_version v4 --exclude_regex local --plugin_path bpf2c_plugin.exe --debug true --plugin_options "--include %SOURCE_ROOT%\include" name: bpf2c_conformance build_artifact: Build-x64 @@ -637,4 +637,4 @@ jobs: secrets: AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} - AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} \ No newline at end of file + AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} diff --git a/docs/isa-support.rst b/docs/isa-support.rst index 33f20db99d..0b2ad7f731 100644 --- a/docs/isa-support.rst +++ b/docs/isa-support.rst @@ -101,10 +101,11 @@ opcode src imm off description 0x7e any 0x00 any if (s32)dst s>= (s32)src goto +offset Y Y Y jsge32-reg 0x7f any 0x00 0 dst >>= src Y Y Y rsh-reg 0x84 0x0 0x00 0 dst = (u32)-dst Y Y Y neg -0x85 0x0 any 0 call helper function by address Y Y Y call_unwind_fail +0x85 0x0 any 0 call helper function by legacy ID Y Y Y call_unwind_fail 0x85 0x1 any 0 call PC += imm no no no call_local 0x85 0x2 any 0 call helper function by BTF ID no no no ??? 0x87 0x0 0x00 0 dst = -dst Y Y Y neg64 +0x8d 0x0 0x00 0 call helper function by legacy ID in register Y Y Y callx 0x94 0x0 any 0 dst = (u32)((imm != 0) ? ((u32)dst % (u32)imm) : dst) Y Y Y mod 0x94 0x0 any 1 dst = (u32)((imm != 0) ? ((s32)dst s% imm) : dst) Y no Y smod32-neg-by-neg-imm 0x95 0x0 0x00 0 return Y Y Y exit @@ -135,16 +136,16 @@ opcode src imm off description 0xbf any 0x00 8 dst = (s64) (s8) src Y no Y movsx864-reg 0xbf any 0x00 16 dst = (s64) (s16) src Y no Y movsx1664-reg 0xbf any 0x00 32 dst = (s64) (s32) src Y no Y movsx3264-reg -0xc3 any 0x00 any lock \*(u32 \*)(dst + offset) += src no no Y lock_add32 -0xc3 any 0x01 any src = atomic_fetch_add_32((u32 \*)(dst + offset), src) no no Y lock_fetch_add32 -0xc3 any 0x40 any lock \*(u32 \*)(dst + offset) \|= src no no Y lock_or32 -0xc3 any 0x41 any src = atomic_fetch_or_32((u32 \*)(dst + offset), src) no no Y lock_fetch_or32 -0xc3 any 0x50 any lock \*(u32 \*)(dst + offset) &= src no no Y lock_and32 -0xc3 any 0x51 any src = atomic_fetch_and_32((u32 \*)(dst + offset), src) no no Y lock_fetch_and32 -0xc3 any 0xa0 any lock \*(u32 \*)(dst + offset) ^= src no no Y lock_xor32 -0xc3 any 0xa1 any src = atomic_fetch_xor_32((u32 \*)(dst + offset), src) no no Y lock_fetch_xor32 -0xc3 any 0xe1 any src = xchg_32((u32 \*)(dst + offset), src) no no Y lock_xchg32 -0xc3 any 0xf1 any r0 = cmpxchg_32((u32 \*)(dst + offset), r0, src) no no Y lock_cmpxchg32 +0xc3 any 0x00 any lock \*(u32 \*)(dst + offset) += src Y no Y lock_add32 +0xc3 any 0x01 any src = atomic_fetch_add_32((u32 \*)(dst + offset), src) Y no Y lock_fetch_add32 +0xc3 any 0x40 any lock \*(u32 \*)(dst + offset) \|= src Y no Y lock_or32 +0xc3 any 0x41 any src = atomic_fetch_or_32((u32 \*)(dst + offset), src) Y no Y lock_fetch_or32 +0xc3 any 0x50 any lock \*(u32 \*)(dst + offset) &= src Y no Y lock_and32 +0xc3 any 0x51 any src = atomic_fetch_and_32((u32 \*)(dst + offset), src) Y no Y lock_fetch_and32 +0xc3 any 0xa0 any lock \*(u32 \*)(dst + offset) ^= src Y no Y lock_xor32 +0xc3 any 0xa1 any src = atomic_fetch_xor_32((u32 \*)(dst + offset), src) Y no Y lock_fetch_xor32 +0xc3 any 0xe1 any src = xchg_32((u32 \*)(dst + offset), src) Y no Y lock_xchg32 +0xc3 any 0xf1 any r0 = cmpxchg_32((u32 \*)(dst + offset), r0, src) Y no Y lock_cmpxchg32 0xc4 0x0 any 0 dst = (u32)(dst s>> imm) Y Y Y arsh 0xc5 0x0 any any if dst s< imm goto +offset Y Y Y jslt-imm 0xc6 0x0 any any if (s32)dst s< (s32)imm goto +offset Y Y Y jslt32-imm @@ -161,16 +162,16 @@ opcode src imm off description 0xd7 0x0 0x10 0 dst = bswap16(dst) Y no Y swap16 0xd7 0x0 0x20 0 dst = bswap32(dst) Y no Y swap32 0xd7 0x0 0x40 0 dst = bswap64(dst) Y no Y swap64 -0xdb any 0x00 any lock \*(u64 \*)(dst + offset) += src no no Y lock_add -0xdb any 0x01 any src = atomic_fetch_add_64((u64 \*)(dst + offset), src) no no Y lock_fetch_add -0xdb any 0x40 any lock \*(u64 \*)(dst + offset) \|= src no no Y lock_or -0xdb any 0x41 any src = atomic_fetch_or_64((u64 \*)(dst + offset), src) no no Y lock_fetch_or -0xdb any 0x50 any lock \*(u64 \*)(dst + offset) &= src no no Y lock_and -0xdb any 0x51 any src = atomic_fetch_and_64((u64 \*)(dst + offset), src) no no Y lock_fetch_and -0xdb any 0xa0 any lock \*(u64 \*)(dst + offset) ^= src no no Y lock_xor -0xdb any 0xa1 any src = atomic_fetch_xor_64((u64 \*)(dst + offset), src) no no Y lock_fetch_xor -0xdb any 0xe1 any src = xchg_64((u64 \*)(dst + offset), src) no no Y lock_xchg -0xdb any 0xf1 any r0 = cmpxchg_64((u64 \*)(dst + offset), r0, src) no no Y lock_cmpxchg +0xdb any 0x00 any lock \*(u64 \*)(dst + offset) += src Y no Y lock_add +0xdb any 0x01 any src = atomic_fetch_add_64((u64 \*)(dst + offset), src) Y no Y lock_fetch_add +0xdb any 0x40 any lock \*(u64 \*)(dst + offset) \|= src Y no Y lock_or +0xdb any 0x41 any src = atomic_fetch_or_64((u64 \*)(dst + offset), src) Y no Y lock_fetch_or +0xdb any 0x50 any lock \*(u64 \*)(dst + offset) &= src Y no Y lock_and +0xdb any 0x51 any src = atomic_fetch_and_64((u64 \*)(dst + offset), src) Y no Y lock_fetch_and +0xdb any 0xa0 any lock \*(u64 \*)(dst + offset) ^= src Y no Y lock_xor +0xdb any 0xa1 any src = atomic_fetch_xor_64((u64 \*)(dst + offset), src) Y no Y lock_fetch_xor +0xdb any 0xe1 any src = xchg_64((u64 \*)(dst + offset), src) Y no Y lock_xchg +0xdb any 0xf1 any r0 = cmpxchg_64((u64 \*)(dst + offset), r0, src) Y no Y lock_cmpxchg 0xdc 0x0 0x10 0 dst = htobe16(dst) Y Y Y be16 0xdc 0x0 0x20 0 dst = htobe32(dst) Y Y Y be32 0xdc 0x0 0x40 0 dst = htobe64(dst) Y Y Y be64 diff --git a/external/ebpf-verifier b/external/ebpf-verifier index 1056586f13..fbd98b0ea3 160000 --- a/external/ebpf-verifier +++ b/external/ebpf-verifier @@ -1 +1 @@ -Subproject commit 1056586f13b5f95f0f16b897197f3fd8bd1fe409 +Subproject commit fbd98b0ea33e8537eddc8cd8c667bbde31ba25f3 diff --git a/tests/end_to_end/netsh_test.cpp b/tests/end_to_end/netsh_test.cpp index 4d9bee7030..7cc9eb767e 100644 --- a/tests/end_to_end/netsh_test.cpp +++ b/tests/end_to_end/netsh_test.cpp @@ -398,20 +398,20 @@ TEST_CASE("show verification xdp_datasize_unsafe.o", "[netsh][verification]") "\n" "; ./tests/sample/unsafe/xdp_datasize_unsafe.c:32\n" "; if (next_header + sizeof(ETHERNET_HEADER) > (char*)ctx->data_end) {\n" - "4: (r3.type in {number, ctx, stack, packet, shared})\n" + "4: Invalid type (r3.type in {number, ctx, stack, packet, shared})\n" "; ./tests/sample/unsafe/xdp_datasize_unsafe.c:32\n" "; if (next_header + sizeof(ETHERNET_HEADER) > (char*)ctx->data_end) {\n" "5: Invalid type (valid_access(r3.offset) for comparison/subtraction)\n" "; ./tests/sample/unsafe/xdp_datasize_unsafe.c:32\n" "; if (next_header + sizeof(ETHERNET_HEADER) > (char*)ctx->data_end) {\n" - "5: (r3.type == non_map_fd)\n" + "5: Invalid type (r3.type == non_map_fd)\n" "; ./tests/sample/unsafe/xdp_datasize_unsafe.c:32\n" "; if (next_header + sizeof(ETHERNET_HEADER) > (char*)ctx->data_end) {\n" "5: Cannot subtract pointers to different regions (r3.type == r1.type in {ctx, stack, packet})\n" "; ./tests/sample/unsafe/xdp_datasize_unsafe.c:38\n" "; if (ethernet_header->Type != ntohs(ETHERNET_TYPE_IPV4) && ethernet_header->Type != " "ntohs(ETHERNET_TYPE_IPV6)) {\n" - "6: (r2.type in {ctx, stack, packet, shared})\n" + "6: Invalid type (r2.type in {ctx, stack, packet, shared})\n" "; ./tests/sample/unsafe/xdp_datasize_unsafe.c:38\n" "; if (ethernet_header->Type != ntohs(ETHERNET_TYPE_IPV4) && ethernet_header->Type != " "ntohs(ETHERNET_TYPE_IPV6)) {\n" @@ -419,14 +419,14 @@ TEST_CASE("show verification xdp_datasize_unsafe.o", "[netsh][verification]") "; ./tests/sample/unsafe/xdp_datasize_unsafe.c:38\n" "; if (ethernet_header->Type != ntohs(ETHERNET_TYPE_IPV4) && ethernet_header->Type != " "ntohs(ETHERNET_TYPE_IPV6)) {\n" - "7: (r1.type == number)\n" + "7: Invalid type (r1.type == number)\n" "; ./tests/sample/unsafe/xdp_datasize_unsafe.c:38\n" "; if (ethernet_header->Type != ntohs(ETHERNET_TYPE_IPV4) && ethernet_header->Type != " "ntohs(ETHERNET_TYPE_IPV6)) {\n" - "8: (r1.type == number)\n" + "8: Invalid type (r1.type == number)\n" "; ./tests/sample/unsafe/xdp_datasize_unsafe.c:43\n" "; return rc;\n" - "10: (r0.type == number)\n" + "10: Invalid type (r0.type == number)\n" "\n" "9 errors\n" "\n"); @@ -449,7 +449,7 @@ TEST_CASE("show verification printk_unsafe.o", "[netsh][verification]") "\n" "; ./tests/sample/unsafe/printk_unsafe.c:22\n" "; bpf_printk(\"ctx: %u\", (uint64_t)ctx);\n" - "7: (r3.type == number)\n" + "7: Invalid type (r3.type == number)\n" "\n" "1 errors\n" "\n"); diff --git a/tests/unit/libbpf_test.cpp b/tests/unit/libbpf_test.cpp index 1accdb21d0..a1e0329095 100644 --- a/tests/unit/libbpf_test.cpp +++ b/tests/unit/libbpf_test.cpp @@ -220,7 +220,7 @@ TEST_CASE("invalid bpf_load_program", "[libbpf][deprecated]") REQUIRE(program_fd < 0); #if !defined(CONFIG_BPF_JIT_DISABLED) REQUIRE(errno == EACCES); - REQUIRE(strcmp(log_buffer, "\n0: (r0.type == number)\n\n") == 0); + REQUIRE(strcmp(log_buffer, "\n0: Invalid type (r0.type == number)\n\n") == 0); #else REQUIRE(errno == ENOTSUP); #endif @@ -244,7 +244,7 @@ TEST_CASE("invalid bpf_prog_load", "[libbpf]") REQUIRE(program_fd < 0); #if !defined(CONFIG_BPF_JIT_DISABLED) REQUIRE(errno == EACCES); - REQUIRE(strcmp(log_buffer, "\n0: (r0.type == number)\n\n") == 0); + REQUIRE(strcmp(log_buffer, "\n0: Invalid type (r0.type == number)\n\n") == 0); #else REQUIRE(errno == ENOTSUP); #endif @@ -407,9 +407,9 @@ TEST_CASE("valid bpf_load_program_xattr", "[libbpf][deprecated]") { \ INST_OP_CALL, 0, 0, 0, (imm) \ } -#define BPF_STX_MEM(sz, dst, src, off) \ - { \ - INST_CLS_STX | (INST_MEM << 5) | (sz), (dst), (src), (off), 0 \ +#define BPF_STX_MEM(sz, dst, src, off) \ + { \ + INST_CLS_STX | INST_MODE_MEM | (sz), (dst), (src), (off), 0 \ } #define BPF_W INST_SIZE_W #define BPF_REG_1 R1_ARG