LibAFL icon indicating copy to clipboard operation
LibAFL copied to clipboard

fix(Dockerfile): setup for building libafl_qemu in Docker

Open vringar opened this issue 2 years ago • 9 comments

Closes #1895

vringar avatar Feb 29 '24 15:02 vringar

This is currently a draft, as llvm.sh doesn't install llvm-config and also doesn't support installing version 18 on Debian Bookworm which is the current base of the Rust images.

vringar avatar Feb 29 '24 15:02 vringar

llvm.sh doesn't install llvm-config

for this you can simply apt install llvm-config-18 after running llvm.sh

tokatoka avatar Feb 29 '24 15:02 tokatoka

But unfortunately ./llvm.sh 18 in line 24 of the docker file fails with the error message:

+ apt-get install -y clang-18 lldb-18 lld-18 clangd-18
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package clang-18
E: Unable to locate package lldb-18
E: Unable to locate package lld-18
E: Unable to locate package clangd-18

vringar avatar Feb 29 '24 15:02 vringar

Other people have had the same issue (the adding of the repository with add-apt-repository doesn't seem to work) and there is a workaround (https://github.com/llvm/llvm-project/issues/62475#issuecomment-1592651066) but I'm unsure if I should implement the workaround or if I should try and land the fix against the source repo. Would you be open to accept the workaround?

vringar avatar Feb 29 '24 15:02 vringar

For future reference: There is no need install llvm-config separately it is part of the llvm-18 package as llvm-config-18

vringar avatar Feb 29 '24 16:02 vringar

Okay, the build now gets to the point that new bindings get generated which differ from the current bindings (unsafe extern "C" vs extern "C") here. Do you consider resolving this in scope for this PR or should it be separate?

vringar avatar Feb 29 '24 16:02 vringar

you can just include it here if you found the fix

tokatoka avatar Mar 01 '24 18:03 tokatoka

Steps to verify this fix works:

docker build -t libafl . && docker run --name libafl --rm -it libafl
# In the now open shell
cargo build --no-default-features -p libafl_qemu && cargo build --no-default-features -p libafl_qemu --release

Also changed the dev container to use the new syntax.

I also tried to verify that this works by running the fuzzers/qemu_systemmode example but I'm not able to interpret the runtime output of the fuzzer. (It does build and start)

vringar avatar Mar 03 '24 14:03 vringar

error[E0308]: arguments to this function are incorrect
     --> /home/runner/work/LibAFL/LibAFL/libafl_qemu/src/emu.rs:1533:23
      |
1533  |             let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data);
      |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
note: expected normal fn, found unsafe fn
     --> /home/runner/work/LibAFL/LibAFL/libafl_qemu/src/emu.rs:1533:60
      |
1533  |             let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data);
      |                                                            ^^^
      = note: expected enum `std::option::Option<extern "C" fn(_, _, _) -> _>`
                 found enum `std::option::Option<unsafe extern "C" fn(_, _, _) -> _>`

still there's this error (in qemu_fuzzers CI build)

tokatoka avatar Mar 03 '24 18:03 tokatoka

is this ready?

tokatoka avatar Mar 06 '24 18:03 tokatoka