Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject BPF program if uninitialized stack or registers are accessed during interpret path #445

Merged
merged 4 commits into from May 21, 2024

Conversation

Alan-Jowett
Copy link
Collaborator

@Alan-Jowett Alan-Jowett commented May 7, 2024

This pull request includes changes to improve the ubpf library. The most important changes include adding a new libfuzzer based fuzzer, modifying the LLVMFuzzerTestOneInput function to compare the results of the interpreter and JIT compiler, adding a bash script to split the fuzzer input into a program and memory, and adding bounds checking for memory accesses.

Improvements to fuzzing:

  • libfuzzer/README.md: Added instructions for building and running a new libfuzzer based fuzzer.
  • libfuzzer/libfuzz_harness.cc: Modified the LLVMFuzzerTestOneInput function to compare the results of the interpreter and JIT compiler, and to ensure the program length is a multiple of sizeof(ebpf_inst). [1] [2]
  • libfuzzer/split.sh: Added a bash script to split the fuzzer input into a program and memory, and to disassemble the program.

Improvements to disassembler:

  • ubpf/disassembler.py: Modified the disassemble_one function to append " local" to the opcode name if the source register is 1. [1] [2]

Improvements to JIT compiler:

  • vm/ubpf_jit_x86_64.c: Added code to truncate the target register to 32 bits for ALU32 instructions.
  • vm/ubpf_jit_x86_64.h: Added the emit_truncate_u32 function to emit instructions to truncate a register to 32 bits.

Improvements to VM:

  • vm/ubpf_vm.c: Added bounds checking for memory accesses, and added checks to ensure registers are initialized before they are read. Also fixed a bug in the EBPF_OP_JEQ32_REG instruction. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Resolves: #480

@Alan-Jowett Alan-Jowett marked this pull request as ready for review May 7, 2024 20:05
@Alan-Jowett Alan-Jowett marked this pull request as draft May 7, 2024 20:35
@Alan-Jowett Alan-Jowett force-pushed the ub_check branch 2 times, most recently from d83a876 to 2491e7d Compare May 7, 2024 23:18
@coveralls
Copy link

coveralls commented May 8, 2024

Coverage Status

coverage: 81.261% (-0.9%) from 82.171%
when pulling f295857 on Alan-Jowett:ub_check
into 6789eee on iovisor:main.

Reject programs if registers are used before intialized
Make undefined behavior check optional

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Copy link
Collaborator

@hawkinsw hawkinsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really, really great!! I think that the infrastructure you have built around fuzzing and making it reproducible is going to really be very helpful!

libfuzzer/README.md Outdated Show resolved Hide resolved
libfuzzer/README.md Show resolved Hide resolved
libfuzzer/README.md Show resolved Hide resolved
libfuzzer/libfuzz_harness.cc Outdated Show resolved Hide resolved
libfuzzer/libfuzz_harness.cc Show resolved Hide resolved
vm/ubpf_vm.c Outdated Show resolved Hide resolved
vm/ubpf_vm.c Outdated Show resolved Hide resolved
vm/ubpf_vm.c Outdated Show resolved Hide resolved
vm/inc/ubpf.h Outdated Show resolved Hide resolved
libfuzzer/split.sh Show resolved Hide resolved
Alan-Jowett and others added 2 commits May 20, 2024 19:59
Co-authored-by: Will Hawkins <whh8b@obs.cr>
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Copy link
Collaborator

@hawkinsw hawkinsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!

@Alan-Jowett Alan-Jowett disabled auto-merge May 21, 2024 04:45
@Alan-Jowett Alan-Jowett merged commit 2868ce4 into iovisor:main May 21, 2024
38 checks passed
@Alan-Jowett Alan-Jowett deleted the ub_check branch May 21, 2024 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash if call target is not start of a function
3 participants