IntelLabs / kafl.targets

Target components for kAFL/Nyx Fuzzer
Other
26 stars 25 forks source link

examples: zephyr: Revive Zephyr's sample #29

Open ceolin opened 1 year ago

ceolin commented 1 year ago

Small fixes to use upstream Zephyr. The major change is removing instructions to fetch Zephyr and its tools since it is barely reproducible. Lets just assume that the host is capable of building a Zephyr application.

Wenzel commented 1 year ago

Thanks for this PR and reviving the Zephyr target @ceolin !

I tried to repro your work, but I'm unlucky so far. First I wanted to use the official Zephyr Docker image (which it turns out, contains all the dependencies + the SDK, but not Zephyr itself), so I build my own Dockerfile:

FROM zephyrprojectrtos/zephyr-build

ARG ZEPHYR_VER=v3.4.0
ENV ZEPHYR_BASE=/opt
ENV ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-0.16.3-rc1
USER root
# setup Zephyr
RUN west init --mr ${ZEPHYR_VER} $ZEPHYR_BASE
WORKDIR /workdir
RUN west update

And I ran it inside the zephyr_x86_32 directory: docker run -ti --rm -v $PWD:/workdir zephyr_test

And I tried to build the test app:

$ ./run.sh build TEST
# Detected Zephyr environment:
ZEPHYR_BASE=/opt
ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-0.16.3-rc1
ZEPHYR_TOOLCHAIN_VARIANT=zephyr
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
CMake Error at /opt/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include):
  include could not find requested file:

    zephyr_default
Call Stack (most recent call first):
  /opt/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
  CMakeLists.txt:5 (find_package)

-- The C compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at CMakeLists.txt:8 (set_property):
  set_property could not find TARGET app.  Perhaps it has not yet been
  created.

CMake Error at CMakeLists.txt:10 (target_sources):
  Cannot specify sources for target "app" which is not built by this project.

CMake Error at CMakeLists.txt:13 (target_sources_ifdef):
  Unknown CMake command "target_sources_ifdef".

-- Configuring incomplete, errors occurred!
See also "/workdir/build/CMakeFiles/CMakeOutput.log".
FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/workdir/build -GNinja -DBOARD=qemu_x86 -DKAFL_TEST=y -S/workdir

But I'm getting cmake errors.

Anything I'm doing wrong ?

Poke @il-steffen, if you know better how to setup Zephyr for these examples !

Thanks

Wenzel commented 11 months ago

I added a couple of fixes plus the Dockerfile image to compile the targets inside Docker, and avoid installing Zephyr locally.

cd zephyr_x86_64
docker build -t kafl_zephyr .
docker run -ti --rm -v $PWD:/workdir -v $PWD/../nyx_api.h:/usr/local/include/nyx_api.h kafl_zephyr
./run.sh build TEST
# CTRL-D (exit container)
./run.sh fuzz