From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2A6A6C433EF for ; Thu, 14 Apr 2022 14:01:37 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8A81583EE5; Thu, 14 Apr 2022 16:00:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="a2GB6aGe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 747C583EC3; Thu, 14 Apr 2022 16:00:16 +0200 (CEST) Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F021D83EA3 for ; Thu, 14 Apr 2022 16:00:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=35ShYYgYKBrAQiSkbbWeeWbU.Seck-ReejbYiji.TUdn.TU@flex--ascull.bounces.google.com Received: by mail-wr1-x449.google.com with SMTP id p18-20020adfba92000000b001e8f7697cc7so844035wrg.20 for ; Thu, 14 Apr 2022 07:00:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=32q5FpNqqqq6EoGKvuP46A6e46gYah8izOV/8xORLOk=; b=a2GB6aGeH5VNZsTRltRBnjeR7lya+03cvatuRPyB8Sxo58i8RCE0YskVgP5eXZqybS dFMKpaXVrd/T7zA4BT0LT4M150HUaBbJieFMUYG0OLMzIr1DW+jqof4nICDU+Goj4rbd E/R5k1pkdS5UyAwg4kBw9V7pq7ThdMzn5bqfk9D/mJQ3IlqyTKRn+VzPtRqIQVQab/NI uqnAluyv1GiTS3eOdOGlvRDkmBZA24Yq2n7SVleIzUnk8a6wNr4bnI0H5wC77iB5l8Wp A1ew0qfRfYvCweTIxjh64a+rr7hHyPfUDU3Ub5J9qltqmWIICmnt5brL1X2D2EmnRjPP X77w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=32q5FpNqqqq6EoGKvuP46A6e46gYah8izOV/8xORLOk=; b=dyMPNp9ncI0Iioy+es973BXNxIFkplrJd+6eHXGMQAEBsjkAQAYPtPy4mvGq3QvdYo j60ym8QALCBF064pQIDZsfTefsceZ8bOlo98k79GrUsS0oxVgynatcv7lNOTR5vHzG5r UYtByMnegU6Tf6Wzw7zEpLYm06sSUdcMc+imjd9eW8SKmRlLMMHr+BWyPHXrP/+z2hQD MuLxmUL5dtbwkyHfiKY5mwGEli1yApF3evzpYRwsbVMjR3wdwN3hWC1rJsViOeR3/Fw0 scYMEvJbvFUABkF2ZrByQrG73aqeTMG0vXFRH2Cy1wLCFwlPHOyDUI6CfGCz8BueNZP9 CuJQ== X-Gm-Message-State: AOAM532IEUMFZLvilRzXiJOhohuydBzrjp0prwGtMtnX+acS5+aKpzAM B1EYt71K/yy3V4LQsvcseydJewuet9tbuDGFR+w8u/axTCVzhy+Bv3wev87B1Hrf/bfE/hs2oUA lU6bNCqJSQQRQxL/dCoHWtVvphEi6cGHKstqm+YM8EqQsOiShbI8Ti2ET/0Q= X-Google-Smtp-Source: ABdhPJzMRRMl1r87Zwa4wc3JfyeQ+9nGw6BZq8QAuPBbQDfhyv50ZnoOIPdzi85UPMWjMyd8I1+mLDQYxbg= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:600c:3596:b0:38e:e9bf:5bfa with SMTP id p22-20020a05600c359600b0038ee9bf5bfamr3339116wmq.63.1649944805804; Thu, 14 Apr 2022 07:00:05 -0700 (PDT) Date: Thu, 14 Apr 2022 13:59:39 +0000 In-Reply-To: <20220414135941.1732585-1-ascull@google.com> Message-Id: <20220414135941.1732585-11-ascull@google.com> Mime-Version: 1.0 References: <20220414135941.1732585-1-ascull@google.com> X-Mailer: git-send-email 2.35.1.1178.g4f1659d476-goog Subject: [PATCH v2 10/12] sandbox: Implement fuzzing engine driver From: Andrew Scull To: u-boot@lists.denx.de Cc: sjg@chromium.org, xypron.glpk@gmx.de, Andrew Scull Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean 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 --- arch/Kconfig | 2 ++ arch/sandbox/dts/test.dts | 4 +++ drivers/fuzz/Kconfig | 16 +++++++++--- drivers/fuzz/Makefile | 1 + drivers/fuzz/sandbox_fuzzing_engine.c | 35 +++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 drivers/fuzz/sandbox_fuzzing_engine.c diff --git a/arch/Kconfig b/arch/Kconfig index 156567ed16..69f86c2f73 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -137,6 +137,7 @@ config SANDBOX select BZIP2 select CMD_POWEROFF select DM + select DM_FUZZING_ENGINE select DM_GPIO select DM_I2C select DM_KEYBOARD @@ -172,6 +173,7 @@ config SANDBOX imply CRC32_VERIFY imply FAT_WRITE imply FIRMWARE + imply FUZZING_ENGINE_SANDBOX imply HASH_VERIFY imply LZMA imply TEE diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 05c1cd5e1a..43908f3610 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -74,6 +74,10 @@ }; }; + 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>; diff --git a/drivers/fuzz/Kconfig b/drivers/fuzz/Kconfig index a03120f63a..6311385222 100644 --- a/drivers/fuzz/Kconfig +++ b/drivers/fuzz/Kconfig @@ -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 diff --git a/drivers/fuzz/Makefile b/drivers/fuzz/Makefile index acd894999c..073743ba94 100644 --- a/drivers/fuzz/Makefile +++ b/drivers/fuzz/Makefile @@ -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 index 0000000000..ebb938e5ba --- /dev/null +++ b/drivers/fuzz/sandbox_fuzzing_engine.c @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2022 Google, Inc. + * Written by Andrew Scull + */ + +#include +#include +#include +#include + +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, +}; -- 2.35.1.1178.g4f1659d476-goog