Skip to content

Commit

Permalink
tools/syz-declextract: parse Linux Headers to extract metadata about …
Browse files Browse the repository at this point in the history
…syscalls

Clang tool that uses AST matchers to extract relevant metadata about Linux system calls. The tool is to be extended
later to support more interfaces, collect more relevant metadata and to automatically generate syzkaller descriptions
  • Loading branch information
pimyn-girgis authored and dvyukov committed Jul 30, 2024
1 parent a4e01e1 commit 3d5fb49
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 259 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ format_go:
format_cpp:
clang-format --style=file -i executor/*.cc executor/*.h \
executor/android/android_seccomp.h \
tools/kcovtrace/*.c tools/kcovfuzzer/*.c tools/fops_probe/*.cc
tools/kcovtrace/*.c tools/kcovfuzzer/*.c tools/fops_probe/*.cc tools/syz-declextract/syz-declextract.cpp

format_sys: bin/syz-fmt
bin/syz-fmt all
Expand Down
2 changes: 2 additions & 0 deletions tools/syz-declextract/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: LLVM
ColumnLimit: 120
37 changes: 37 additions & 0 deletions tools/syz-declextract/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# syz-declextract
## Linux Kernel (For testing purposes)
```
export KERNEL=$PWD/linux-stable
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git $KERNEL
cd $KERNEL
make CC=clang defconfig # Having clang as the compiler is optional but removes erros later on
./scripts/config -e FTRACE_SYSCALLS
make CC=clang olddefconfig
make CC=clang -j`nproc` # kernel has to be built at least once for the script to work
./scripts/clang/gen_compile_commands.py
```
## LLVM Project
```
LLVM=$PWD/llvm-project
git clone https://github.com/llvm/llvm-project.git $LLVM
cd $LLVM
git checkout 0f231567719c99caa99164d8f91bad50883dab03 # In case of any breaking changes, this commit works
echo 'add_clang_executable(syz-declextract syz-declextract/syz-declextract.cpp)
target_link_libraries(syz-declextract PRIVATE clangTooling)' >> $LLVM/clang/CMakeLists.txt
```
## syz-declextract
```
mkdir $LLVM/clang/syz-declextract
```
Download `syz-declextract.cpp` file and add it to `$LLVM/clang/syz-declextract` directory
```
SYZ=$PWD/syz
mkdir $SYZ && cd $SYZ
cmake -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ $LLVM/llvm
make -j`nproc` syz-declextract
```
## Example
```
./bin/syz-declextract $KERNEL/fs/read_write.c | less # or any other .c file
```
Loading

0 comments on commit 3d5fb49

Please sign in to comment.