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 4D656C433EF for ; Thu, 14 Apr 2022 14:01:06 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9AF2F83EA3; Thu, 14 Apr 2022 16:00:36 +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="jT2o51dn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3B31D83EC3; Thu, 14 Apr 2022 16:00:02 +0200 (CEST) Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) (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 E02A883EA3 for ; Thu, 14 Apr 2022 15:59:57 +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=33ShYYgYKBqgIaKcTTOWWOTM.KWUc-JWWbTQaba.LMVf.LM@flex--ascull.bounces.google.com Received: by mail-wm1-x34a.google.com with SMTP id l41-20020a05600c1d2900b0038ec007ac7fso4561587wms.4 for ; Thu, 14 Apr 2022 06:59:57 -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=CNUl5tIc3rPMry6xMAKLnAau2vo2BS/lSAxOCXVvBDk=; b=jT2o51dnbT1UjagkaKrvV9hSQHsSGsxgp5AoxpoFzGDDaYJQrt66GcxVKAGPHzVm9X bW9Gb8buEMn7fLN9pywPn45PNdz+ZvnjIB5BvgWnQK7GnhI69RDPsKJU6K45Cn90iYd8 6VtCS733RMJCWviEmcKib7wWM0N751H6i3UCu5nazNtzoNkDkTHXHKch/DzuNuVKvxti Qfu54UOVDqx/fz9BWQ5M+tMDi9GeP0LcuZNos82dbOTtZM4RzYNb2nMqww2yvCV/xyMe V7getBiCBCE4qlYfXW/XKPJ8dxtDlyk2Spvp8ahfHcJRnMA5uAYk5+LFVaMj33Tz+27P VH/Q== 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=CNUl5tIc3rPMry6xMAKLnAau2vo2BS/lSAxOCXVvBDk=; b=qItyLz9TYwe4tjxPvIrC7Yzj0BjBoO58Dr72rqRihOD2GfI+vjsZRefd+8hi3Xg3oU JvvZFCKdKP8a2LCsTfzf0tcBpk1MyLlFLg6jkk6IDNHR4J2wIjHh7X8F88CcjPoITNPQ SDGTNeIxmUjiLwMrlxkyOBV5UkUrv+etyRivbeqmshP6QZBHini/1mRtXTYLWYXZ2oZD ZYTBTy6EwgByU8DjR0a2w7U/GbdSHinrvL6tgfy6zHoNs6p01qEyYSmRn31KDE8whHdT r7hBU6w6BawfxzGg59+D86iHqeAmfK970cL7/G93y0OUGqKdm8BUXuyWFr6urFYgVa94 XkCw== X-Gm-Message-State: AOAM530/AN2kAyS4BtKUrxYg1U6yCmNuWmtxuGcbOKlF3vmrtojMK0Zb VtpzIgcYOF8WxQ0+EKj9k5zjUraeCBxq+jQToaDRwvt1tigf/dzho1zW/UvzWyB0yZxp7eXn5B+ RzdxKKlo+F89HLi4I2ed8Y3k/A5hvhC9GhMBIfUhOeleulXOck/BbDIrwCOI= X-Google-Smtp-Source: ABdhPJyMD1nLf+nqBMs9R1VFWX86NlhWrGFMughaCYatbs9uW9iIzQSFjxlHTZPzuVuJ/vcWfzFvOTY1nvA= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:6000:1541:b0:207:8ee6:1417 with SMTP id 1-20020a056000154100b002078ee61417mr2232947wry.504.1649944797483; Thu, 14 Apr 2022 06:59:57 -0700 (PDT) Date: Thu, 14 Apr 2022 13:59:35 +0000 In-Reply-To: <20220414135941.1732585-1-ascull@google.com> Message-Id: <20220414135941.1732585-7-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 06/12] fuzzing_engine: Add fuzzing engine uclass 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 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 4e7cf28440..b66d72d361 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -113,6 +113,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 0e26e1d138..b9411f1d59 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -53,6 +53,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.35.1.1178.g4f1659d476-goog