I'm struggling to compile the Linux kernel for usage in AOSP with KASAN & KCOV enabled. I then intend to flash it to a Pixel 2 XL (taimen) and use syzkaller to fuzz it.
This is what I did:
1. Build unmodified kernel (works)
My reference: https://source.android.com/setup/build/building-kernels
- Determine branch...
android-msm-wahoo-4.4-pie-qpr2
$ repo init -u https://android.googlesource.com/kernel/manifest -b android-msm-wahoo-4.4-pie-qpr2
$ repo sync -j8 -c
$ build/build.sh -j8
- Connect phone via USB
$ adb reboot bootloader
$ fastboot boot out/android-msm-wahoo-4.4/dist/Image.lz4-dtb
(Works fine)
2. Build kernel with KASAN & KCOV (fails)
- To change kernel config symbols, edit
POST_DEFCONFIG_CMDS
in build/build.config- Copy from https://source.android.com/setup/build/building-kernels#customize-config
- Modify as needed, use
-d
to disable,-e
to enable a config option - Result:
POST_DEFCONFIG_CMDS="check_defconfig && update_debug_config"
function update_debug_config() {
${KERNEL_DIR}/scripts/config --file ${OUT_DIR}/.config \
-d CONFIG_KERNEL_LZ4 \
-e CONFIG_KASAN \
-e CONFIG_KASAN_INLINE \
-e CONFIG_KCOV \
-e CONFIG_SLUB \
-e CONFIG_SLUB_DEBUG \
--set-val FRAME_WARN 0
(cd ${OUT_DIR} && \
make O=${OUT_DIR} $archsubarch CC=${CC} CROSS_COMPILE=${CROSS_COMPILE} olddefconfig)
}
$ build/build.sh -j8
But after
CHK include/generated/compile.h
I get many undefined reference errors to various asan-symbols, e.g.
undefined reference to __asan_alloca_poison
.
I did some research and read about adding -fsantitize=address
and -shared-libasan
(or -shared-libsan
) to CFLAGS
AND LDFLAGS
. I did that (for which I had to hard-code it into build/build.sh
, isn't there a more convenient way?), but to no avail:
I ended up with
aarch64-linux-android-ld: -f may not be used without -shared
.
So I tried reading up on ld's -shared
flag and adding it to LDFLAGS
(more like a guess really). Resulted in
aarch64-linux-android-ld: -r and -shared may not be used together
.
Really don't know where to go from here and what's going wrong in general?
Any help really appreciated!
Update: Using gcc
instead of clang
seemed to resolve the issue, but caused the touchscreen on the phone to be unusable (not responding). I am looking into the reasons...