]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sandbox: Implement fuzzing engine driver
authorAndrew Scull <ascull@google.com>
Mon, 30 May 2022 10:00:12 +0000 (10:00 +0000)
committerTom Rini <trini@konsulko.com>
Thu, 23 Jun 2022 16:58:19 +0000 (12:58 -0400)
Add a fuzzing engine driver for the sandbox to take inputs from
libfuzzer and expose them to the fuzz tests.

Signed-off-by: Andrew Scull <ascull@google.com>
arch/Kconfig
arch/sandbox/dts/test.dts
drivers/fuzz/Kconfig
drivers/fuzz/Makefile
drivers/fuzz/sandbox_fuzzing_engine.c [new file with mode: 0644]

index b396263e3b0e35df79c43e1caf47fe7fc2d8768a..eab89f255b6a81832e2538012255c21bf8bd1411 100644 (file)
@@ -135,6 +135,7 @@ config SANDBOX
        select BZIP2
        select CMD_POWEROFF
        select DM
+       select DM_FUZZING_ENGINE
        select DM_GPIO
        select DM_I2C
        select DM_KEYBOARD
@@ -170,6 +171,7 @@ config SANDBOX
        imply CRC32_VERIFY
        imply FAT_WRITE
        imply FIRMWARE
+       imply FUZZING_ENGINE_SANDBOX
        imply HASH_VERIFY
        imply LZMA
        imply TEE
index e068d0c8c562ed00ae584aa0fbf1c7aee0ad01a5..0194b9b30ef8d30e6912f83886734e2f2a101b00 100644 (file)
                };
        };
 
+       fuzzing-engine {
+               compatible = "sandbox,fuzzing-engine";
+       };
+
        reboot-mode0 {
                compatible = "reboot-mode-gpio";
                gpios = <&gpio_c 0 GPIO_ACTIVE_HIGH>, <&gpio_c 1 GPIO_ACTIVE_HIGH>;
index a03120f63abc4b474b7eb117cfe88e30d5166e31..6311385222f3577864d465b5b0e7731b0ef6ebb7 100644 (file)
@@ -3,7 +3,15 @@ config DM_FUZZING_ENGINE
        depends on DM
        help
          Enable driver model for fuzzing engine devices. This interface is
-         used to get successive inputs from a fuzzing engine that aims to
-         explore different code paths in a fuzz test. The fuzzing engine may
-         be instrumenting the execution in order to more effectively generate
-         inputs that explore different code paths.
+         used to get fuzzing inputs from a fuzzing engine.
+
+if DM_FUZZING_ENGINE
+
+config FUZZING_ENGINE_SANDBOX
+       bool "Sanbox fuzzing engine"
+       depends on SANDBOX
+       default y
+       help
+         Enable fuzzing engine for sandbox.
+
+endif
index acd894999c9e701e3256027129112e48117f7fd6..073743ba9468080d704d8cfa5c7a93b40420b9ca 100644 (file)
@@ -5,3 +5,4 @@
 #
 
 obj-$(CONFIG_DM_FUZZING_ENGINE) += fuzzing_engine-uclass.o
+obj-$(CONFIG_FUZZING_ENGINE_SANDBOX) += sandbox_fuzzing_engine.o
diff --git a/drivers/fuzz/sandbox_fuzzing_engine.c b/drivers/fuzz/sandbox_fuzzing_engine.c
new file mode 100644 (file)
index 0000000..ebb938e
--- /dev/null
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2022 Google, Inc.
+ * Written by Andrew Scull <ascull@google.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <fuzzing_engine.h>
+#include <asm/fuzzing_engine.h>
+
+static int get_input(struct udevice *dev,
+                    const uint8_t **data,
+                    size_t *size)
+{
+       return sandbox_fuzzing_engine_get_input(data, size);
+}
+
+static const struct dm_fuzzing_engine_ops sandbox_fuzzing_engine_ops = {
+       .get_input = get_input,
+};
+
+static const struct udevice_id sandbox_fuzzing_engine_match[] = {
+       {
+               .compatible = "sandbox,fuzzing-engine",
+       },
+       {},
+};
+
+U_BOOT_DRIVER(sandbox_fuzzing_engine) = {
+       .name = "sandbox-fuzzing-engine",
+       .id = UCLASS_FUZZING_ENGINE,
+       .of_match = sandbox_fuzzing_engine_match,
+       .ops = &sandbox_fuzzing_engine_ops,
+};