mirror of
https://gitlab.com/buildroot.org/buildroot.git
synced 2026-09-30 05:51:45 -09:00
testing/tests: CLANG compiler-rt runtime test
This patch adds a test case that
1) Builds the complete LLVM and CLANG set of host tools
2) Cross-compiles the compiler-rt runtime using CLANG
3) Builds a cross-compiled application using CLANG and the libfuzzer
compiler-rt library.
4) Executes the fuzz application (part of the libfuzzer package) on
target and checks expected output for a heap-buffer-overflow.
Note: The libfuzzer package is just a tutorial example of how to use
the toolkit provided by llvm (Thus not adding it as a full
Buildroot package).
Signed-off-by: Matt Weber <matthew.weber@rockwellcollins.com>
Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Cc: Romain Naour <romain.naour@smile.fr>
[Arnout: add Matt to DEVELOPERS]
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
This commit is contained in:
committed by
Arnout Vandecappelle (Essensium/Mind)
parent
5e9417e3b4
commit
570aa42559
@@ -1985,7 +1985,9 @@ F: package/wireless_tools/
|
|||||||
F: package/xen/
|
F: package/xen/
|
||||||
F: package/xml-security-c/
|
F: package/xml-security-c/
|
||||||
F: support/testing/tests/fs/test_oci.py
|
F: support/testing/tests/fs/test_oci.py
|
||||||
|
F: support/testing/tests/package/br2-external/clang-compiler-rt/
|
||||||
F: support/testing/tests/package/br2-external/openjdk/
|
F: support/testing/tests/package/br2-external/openjdk/
|
||||||
|
F: support/testing/tests/package/test_clang.py
|
||||||
F: support/testing/tests/package/test_openjdk.py
|
F: support/testing/tests/package/test_openjdk.py
|
||||||
F: support/testing/tests/package/test_opkg/
|
F: support/testing/tests/package/test_opkg/
|
||||||
F: support/testing/tests/package/test_opkg.py
|
F: support/testing/tests/package/test_opkg.py
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
source "$BR2_EXTERNAL_CLANG_COMPILER_RT_PATH/package/libfuzzer/Config.in"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
name: CLANG_COMPILER_RT
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
include $(sort $(wildcard $(BR2_EXTERNAL_CLANG_COMPILER_RT_PATH)/package/*/*.mk))
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
config BR2_PACKAGE_LIBFUZZER
|
||||||
|
bool "libfuzzer"
|
||||||
|
help
|
||||||
|
This project aims at hosting tutorials,
|
||||||
|
examples, discussions, research proposals,
|
||||||
|
and other resources related to fuzzing.
|
||||||
|
|
||||||
|
https://github.com/google/fuzzing
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
sha256 c71360c3b1ba1d88b28b0b3cb3a1744d251b87a12f2881224cc53ec26eb7a2db libfuzzer-cec02db916d21baa4db5b8d262d78848b3a35f4b.tar.gz
|
||||||
|
sha256 cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30 LICENSE
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
################################################################################
|
||||||
|
#
|
||||||
|
# libfuzzer
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
LIBFUZZER_VERSION = cec02db916d21baa4db5b8d262d78848b3a35f4b
|
||||||
|
LIBFUZZER_SITE = $(call github,google,fuzzing,$(LIBFUZZER_VERSION))
|
||||||
|
LIBFUZZER_LICENSE = Apache-2.0
|
||||||
|
LIBFUZZER_LICENSE_FILES = LICENSE
|
||||||
|
LIBFUZZER_DEPENDENCIES = compiler-rt
|
||||||
|
|
||||||
|
define LIBFUZZER_BUILD_CMDS
|
||||||
|
$(HOST_DIR)/bin/clang++ --sysroot=$(STAGING_DIR) \
|
||||||
|
-fsanitize=address,fuzzer \
|
||||||
|
$(@D)/tutorial/libFuzzer/fuzz_me.cc \
|
||||||
|
-o $(@D)/fuzz_me
|
||||||
|
endef
|
||||||
|
|
||||||
|
define LIBFUZZER_INSTALL_TARGET_CMDS
|
||||||
|
$(INSTALL) -D -m 755 $(@D)/fuzz_me $(TARGET_DIR)/usr/bin/fuzz_me
|
||||||
|
endef
|
||||||
|
|
||||||
|
$(eval $(generic-package))
|
||||||
46
support/testing/tests/package/test_clang.py
Normal file
46
support/testing/tests/package/test_clang.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
import infra.basetest
|
||||||
|
|
||||||
|
FUZZ_TIMEOUT = 120
|
||||||
|
|
||||||
|
|
||||||
|
class TestClangCompilerRT(infra.basetest.BRTest):
|
||||||
|
br2_external = [infra.filepath("tests/package/br2-external/clang-compiler-rt")]
|
||||||
|
config = \
|
||||||
|
"""
|
||||||
|
BR2_aarch64=y
|
||||||
|
BR2_TOOLCHAIN_EXTERNAL=y
|
||||||
|
BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
|
||||||
|
BR2_LINUX_KERNEL=y
|
||||||
|
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
|
||||||
|
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.16.7"
|
||||||
|
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
|
||||||
|
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
|
||||||
|
BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
|
||||||
|
BR2_PACKAGE_COMPILER_RT=y
|
||||||
|
BR2_PACKAGE_LLVM=y
|
||||||
|
BR2_TARGET_ROOTFS_CPIO=y
|
||||||
|
BR2_TARGET_ROOTFS_CPIO_GZIP=y
|
||||||
|
# BR2_TARGET_ROOTFS_TAR is not set
|
||||||
|
BR2_PACKAGE_LIBFUZZER=y
|
||||||
|
"""
|
||||||
|
|
||||||
|
def login(self):
|
||||||
|
img = os.path.join(self.builddir, "images", "rootfs.cpio.gz")
|
||||||
|
kern = os.path.join(self.builddir, "images", "Image")
|
||||||
|
# Sanitizers overallocate memory and the minimum that seemed to work was 512MB
|
||||||
|
self.emulator.boot(arch="aarch64",
|
||||||
|
kernel=kern,
|
||||||
|
kernel_cmdline=["console=ttyAMA0"],
|
||||||
|
options=["-M", "virt", "-cpu", "cortex-a53", "-m", "512", "-initrd", img])
|
||||||
|
self.emulator.login()
|
||||||
|
|
||||||
|
def test_run(self):
|
||||||
|
self.login()
|
||||||
|
|
||||||
|
# The test case verifies the application executes and that
|
||||||
|
# the symbolizer is working to decode the stack trace.
|
||||||
|
cmd = "fuzz_me 2>&1 | grep heap-buffer-overflow"
|
||||||
|
_, exit_code = self.emulator.run(cmd, FUZZ_TIMEOUT)
|
||||||
|
self.assertEqual(exit_code, 0)
|
||||||
Reference in New Issue
Block a user