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 7CB96C433EF for ; Mon, 30 May 2022 10:02:28 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E3CFF843E5; Mon, 30 May 2022 12:01:38 +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="O9LDQnXy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3692D843A4; Mon, 30 May 2022 12:01:04 +0200 (CEST) Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) (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 97B5C843A7 for ; Mon, 30 May 2022 12:00:44 +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=3zJWUYgYKBmUDVFXOOJRRJOH.FRPX-ERRWOLVWV.GHQa.GH@flex--ascull.bounces.google.com Received: by mail-wm1-x349.google.com with SMTP id o3-20020a05600c510300b0039743540ac7so4330890wms.5 for ; Mon, 30 May 2022 03:00:44 -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=+bHAfzPQ7rehtdEGoW7kHs0vrVceLQiRx6L4HbtD7t0=; b=O9LDQnXywTpiCqRqy87/5pJEUjeyV+ACAffmjXW0md4Yzz0AyD2rQpDg1HvJl8P2xx x2poLy0VCrK56Y6rwMX/1S/XD/QcgvoZfe+r6gkECKeGQoPScaKDplUnLonEBa19H0YM CY/xxzODOucmjdwM+UkTCfj0sWamfVujSDVywUcMRs5pMVkTpeKn9k2n8sJfHlZ0fdlG fpcXPFn9HDPlUY+lYoqcykaZ/wTnXZVe9zRAIh64sp8vkN8a/FEiY4x9uk7VLmFJMWIo 1X6MbxVOOc34Eb5jItCyxQLoN4we+HWA29z5KzxOa5nhO0ZY+SopaOxaD5HnGoE/FEUx jwqQ== 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=+bHAfzPQ7rehtdEGoW7kHs0vrVceLQiRx6L4HbtD7t0=; b=hCCl4eDNF9C2QeOkre9asblXon05dhqwkYo8OHg6ul6adMi0rEpcnRtPg83QLsaUA6 1G6a/dSgWJQvqBmXwt8biKdE4qMXgNs3GDgYnJ3z2dt7/94vG9JCpBNkwH1UAf0V7ZWo Lw4WutmxY5a1SNTLRiQJ9wmowpUbKvPankP3uYvfsRHCpsvkAtrmaZETDnFxlvg90Jxp JmuwO8vrw+gS5KjLjT9D27qMm3iX4WSXMhZU+OqI04PUwbdOfxUyj6NU6afLft5DpM3G zTDIC8mg+GeeW+ZJgX2KTZS1nQfUlzoiyOBotVOOIzPVVugP0aEH5Ba4XtM9BvhX2XPS /gfg== X-Gm-Message-State: AOAM532SEZ2f1RYqnsgTNzTcdk8PC3qIBYM2a/xo69YKWpj9IWPObiiH oqCxdNPCIpNJoZQEYQ0slIEsfhtV55QrNh649OVGCRyOwiwgEOv1MaTqwzSy7fGbq2w/jdj25/s bzHhI3WYSUZBdHdIlrByy8r1yaYIiGcopGsJg43orlPAwRyEqjM159VXiQYo= X-Google-Smtp-Source: ABdhPJyA7wyqOrQFl1DDlX+m6H/itXGUQCueKRugzEICRkXOS4bXHMpdNJIE+S+YA4kYrLvgR3AyfC+S/BM= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:600c:1d0f:b0:397:4b61:8784 with SMTP id l15-20020a05600c1d0f00b003974b618784mr18017707wms.103.1653904844341; Mon, 30 May 2022 03:00:44 -0700 (PDT) Date: Mon, 30 May 2022 10:00:08 +0000 In-Reply-To: <20220530100013.3753780-1-ascull@google.com> Message-Id: <20220530100013.3753780-9-ascull@google.com> Mime-Version: 1.0 References: <20220530100013.3753780-1-ascull@google.com> X-Mailer: git-send-email 2.36.1.124.g0e6072fb45-goog Subject: [PATCH v3 08/13] fuzzing_engine: Add fuzzing engine uclass From: Andrew Scull To: u-boot@lists.denx.de Cc: sjg@chromium.org, trini@konsulko.com, xypron.glpk@gmx.de, jonbottarini@google.com, seanga2@gmail.com, 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 This new class of device will provide fuzzing inputs from a fuzzing engine. Signed-off-by: Andrew Scull Reviewed-by: Simon Glass --- drivers/Kconfig | 2 ++ drivers/Makefile | 1 + drivers/fuzz/Kconfig | 9 +++++ drivers/fuzz/Makefile | 7 ++++ drivers/fuzz/fuzzing_engine-uclass.c | 28 +++++++++++++++ include/dm/uclass-id.h | 1 + include/fuzzing_engine.h | 51 ++++++++++++++++++++++++++++ 7 files changed, 99 insertions(+) create mode 100644 drivers/fuzz/Kconfig create mode 100644 drivers/fuzz/Makefile create mode 100644 drivers/fuzz/fuzzing_engine-uclass.c create mode 100644 include/fuzzing_engine.h diff --git a/drivers/Kconfig b/drivers/Kconfig index b26ca8cf70..8b6fead351 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -40,6 +40,8 @@ source "drivers/fastboot/Kconfig" source "drivers/firmware/Kconfig" +source "drivers/fuzz/Kconfig" + source "drivers/fpga/Kconfig" source "drivers/gpio/Kconfig" diff --git a/drivers/Makefile b/drivers/Makefile index 67c8af7442..d63fd1c04d 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -115,6 +115,7 @@ obj-$(CONFIG_W1) += w1/ obj-$(CONFIG_W1_EEPROM) += w1-eeprom/ obj-$(CONFIG_MACH_PIC32) += ddr/microchip/ +obj-$(CONFIG_FUZZ) += fuzz/ obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock/ obj-$(CONFIG_DM_RNG) += rng/ endif diff --git a/drivers/fuzz/Kconfig b/drivers/fuzz/Kconfig new file mode 100644 index 0000000000..a03120f63a --- /dev/null +++ b/drivers/fuzz/Kconfig @@ -0,0 +1,9 @@ +config DM_FUZZING_ENGINE + bool "Driver support for fuzzing engine devices" + 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. diff --git a/drivers/fuzz/Makefile b/drivers/fuzz/Makefile new file mode 100644 index 0000000000..acd894999c --- /dev/null +++ b/drivers/fuzz/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (c) 2022 Google, Inc. +# Written by Andrew Scull +# + +obj-$(CONFIG_DM_FUZZING_ENGINE) += fuzzing_engine-uclass.o diff --git a/drivers/fuzz/fuzzing_engine-uclass.c b/drivers/fuzz/fuzzing_engine-uclass.c new file mode 100644 index 0000000000..b16f1c4cfb --- /dev/null +++ b/drivers/fuzz/fuzzing_engine-uclass.c @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2022 Google, Inc. + * Written by Andrew Scull + */ + +#define LOG_CATEGORY UCLASS_FUZZING_ENGINE + +#include +#include +#include + +int dm_fuzzing_engine_get_input(struct udevice *dev, + const uint8_t **data, + size_t *size) +{ + const struct dm_fuzzing_engine_ops *ops = device_get_ops(dev); + + if (!ops->get_input) + return -ENOSYS; + + return ops->get_input(dev, data, size); +} + +UCLASS_DRIVER(fuzzing_engine) = { + .name = "fuzzing_engine", + .id = UCLASS_FUZZING_ENGINE, +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 3ba69ad9a0..a432e43871 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -56,6 +56,7 @@ enum uclass_id { UCLASS_ETH, /* Ethernet device */ UCLASS_ETH_PHY, /* Ethernet PHY device */ UCLASS_FIRMWARE, /* Firmware */ + UCLASS_FUZZING_ENGINE, /* Fuzzing engine */ UCLASS_FS_FIRMWARE_LOADER, /* Generic loader */ UCLASS_GPIO, /* Bank of general-purpose I/O pins */ UCLASS_HASH, /* Hash device */ diff --git a/include/fuzzing_engine.h b/include/fuzzing_engine.h new file mode 100644 index 0000000000..357346e93d --- /dev/null +++ b/include/fuzzing_engine.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2022 Google, Inc. + * Written by Andrew Scull + */ + +#ifndef __FUZZING_ENGINE_H +#define __FUZZING_ENGINE_H + +struct udevice; + +/** + * dm_fuzzing_engine_get_input() - get an input from the fuzzing engine device + * + * The function will return a pointer to the input data and the size of the + * data pointed to. The pointer will remain valid until the next invocation of + * this function. + * + * @dev: fuzzing engine device + * @data: output pointer to input data + * @size output size of input data + * Return: 0 if OK, -ve on error + */ +int dm_fuzzing_engine_get_input(struct udevice *dev, + const uint8_t **data, + size_t *size); + +/** + * struct dm_fuzzing_engine_ops - operations for the fuzzing engine uclass + * + * This contains the functions implemented by a fuzzing engine device. + */ +struct dm_fuzzing_engine_ops { + /** + * @get_input() - get an input + * + * The function will return a pointer to the input data and the size of + * the data pointed to. The pointer will remain valid until the next + * invocation of this function. + * + * @get_input.dev: fuzzing engine device + * @get_input.data: output pointer to input data + * @get_input.size output size of input data + * @get_input.Return: 0 if OK, -ve on error + */ + int (*get_input)(struct udevice *dev, + const uint8_t **data, + size_t *size); +}; + +#endif /* __FUZZING_ENGINE_H */ -- 2.36.1.124.g0e6072fb45-goog