forked from rlane/ubpf
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate specific atomic operation opcodes
The eBPF RFC specifies an enumerated list of valid "sub" opcodes for atomic operations. These subopcodes are stored in the imm field of the instruction. This patch adds support for validating that an atomic operation contains exactly one of the enumerated values in the RFC. Signed-off-by: Will Hawkins <[email protected]>
- Loading branch information
Showing
4 changed files
with
105 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
b4 00 00 00 00 00 00 00 db 01 00 00 42 00 00 00 95 00 00 00 00 00 00 00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## Test Description | ||
|
||
This test verifies that the check for to validate an instruction properly handles the case where an atomic operation's immediate field does not contain a valid operation (according to Table 11 in the [spec](https://www.ietf.org/archive/id/draft-thaler-bpf-isa-00.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Will Hawkins | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <cstdint> | ||
#include <iostream> | ||
#include <memory> | ||
#include <stdint.h> | ||
#include <string> | ||
|
||
extern "C" | ||
{ | ||
#include "ubpf.h" | ||
} | ||
|
||
#include "ubpf_custom_test_support.h" | ||
|
||
int | ||
main(int argc, char** argv) | ||
{ | ||
std::string program_string{}; | ||
std::string error{}; | ||
ubpf_jit_fn jit_fn; | ||
|
||
if (!get_program_string(argc, argv, program_string, error)) { | ||
std::cerr << error << std::endl; | ||
return 1; | ||
} | ||
|
||
uint64_t memory_expected{0x123456789}; | ||
uint64_t memory{0x123456789}; | ||
|
||
std::unique_ptr<ubpf_vm, decltype(&ubpf_destroy)> vm(ubpf_create(), ubpf_destroy); | ||
if (!ubpf_setup_custom_test( | ||
vm, program_string, [](ubpf_vm_up&, std::string&) { return true; }, jit_fn, error)) { | ||
if (error == "Failed to load program: Invalid immediate value 66 for opcode DB.") { | ||
return 0; | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
return 1; | ||
|
||
uint64_t bpf_return_value; | ||
if (ubpf_exec(vm.get(), &memory, sizeof(memory), &bpf_return_value)) { | ||
std::cerr << "Problem executing program" << std::endl; | ||
return 1; | ||
} | ||
|
||
return !(memory == memory_expected); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters