From patchwork Thu Oct 15 13:41:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 271232 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, HK_RANDOM_FROM, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92C1EC433DF for ; Thu, 15 Oct 2020 13:44:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AF0662078A for ; Thu, 15 Oct 2020 13:44:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="0xkRr4m8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AF0662078A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:51690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kT3YM-00010d-L9 for qemu-devel@archiver.kernel.org; Thu, 15 Oct 2020 09:44:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kT3WP-0007dd-Ip for qemu-devel@nongnu.org; Thu, 15 Oct 2020 09:42:21 -0400 Received: from mail-eopbgr750103.outbound.protection.outlook.com ([40.107.75.103]:37594 helo=NAM02-BL2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kT3WN-0000mT-Tc for qemu-devel@nongnu.org; Thu, 15 Oct 2020 09:42:21 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WXLWSKGluLznXOybzjqOkZkCcwnV0Z+TpiseNwiZQF7kt8cyBIWlIVYCmSak+yOficOt569Z+2Xkapbb1ECOENjpb+KhKF6eOIUCIh0KZ6CIxeqIWnGhfPdVTdNySBTyiH134VP5Y7J+OKi90xcWfIb+mVSAVVhqwd8KSnQJ99kwf8eQznqNp5Kp1acOx4STOx/bty8nIvqPCNPHDMtaQmbhFHdHjSi8ikCqbNQddcVHAEA+vpni+FIjPaT56kQdvCCafC9pw8xUWin5xZXYoVBfBy0CsaS90d4NG2KDbgMw8Ny8iSzAifibbZlzbkVX6JijRPb0GXkqlBkaNq8KKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TEdOBmV+jxI0q3dedgxQp2gssCkRU8p2it3ccaE/kOE=; b=ap0WYRykBEUynOvzYcyFjBCa8cQ4sxJ1po3l8/dyJLPOkRoxVyY+P1sgHj+tSIQMIGU0fxGokwj6N8xSoCEoZl4HeTK57hcL58woq30a2KpqjRiiq2a1PLag+b/6vRfeP0eYmx9tMG8bNXB33ixOOGTKEw5yPBvwHIbgYISBXFqfKjPSqHTXS5x6IGYW+AKqU5uvB1GZ1a8jTKObkVkDNj1IaUpKw76ErTt7u5WmeD4xYfX0bftyLoD4J4TzqSAmFpJsTtVssRUzqWzfonLTM5xjXpxi9vR94Ud0wGkF1GO/Im+dTfzpNdHDn8JEOax/9Fq17hxCDHSp5PLbxU7mUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TEdOBmV+jxI0q3dedgxQp2gssCkRU8p2it3ccaE/kOE=; b=0xkRr4m84awGXBtUzoBjvqUmHABDVk28aSzAukoEhJKz47Jltv+ko/xXB2avOtCXoBH0vNit1eScDa/8mjAEW/j47XUTsRCVwmgDkAmZ/mUriKvu5/rlMC+bU4qHeEVQBrMMFBSTIr+zFsZuQX9fInz5kSLzsRyzAekc3El5XFo= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=bu.edu; Received: from SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) by SA0PR03MB5465.namprd03.prod.outlook.com (2603:10b6:806:b5::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.21; Thu, 15 Oct 2020 13:42:03 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::61ae:93a8:b26c:77b8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::61ae:93a8:b26c:77b8%4]) with mapi id 15.20.3455.031; Thu, 15 Oct 2020 13:42:03 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v4 07/16] fuzz: Add support for custom crossover functions Date: Thu, 15 Oct 2020 09:41:27 -0400 Message-Id: <20201015134137.205958-8-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201015134137.205958-1-alxndr@bu.edu> References: <20201015134137.205958-1-alxndr@bu.edu> X-Originating-IP: [72.93.72.163] X-ClientProxiedBy: BL1PR13CA0055.namprd13.prod.outlook.com (2603:10b6:208:257::30) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from stormtrooper.vrmnet (72.93.72.163) by BL1PR13CA0055.namprd13.prod.outlook.com (2603:10b6:208:257::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.8 via Frontend Transport; Thu, 15 Oct 2020 13:42:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f62925d3-7fb7-4a89-b332-08d8711018e5 X-MS-TrafficTypeDiagnostic: SA0PR03MB5465: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cQyNYmESgtwDpfr9TrCRBMTgmvqELfOJqRvsBhfiQCHyetc3R0ZuUgiXKlLo2hEGQputnk9N3c4z0mze5XwJVo6f80ssgKt2KVXKzczUcqSMaIUOOYPeKHpvV5EHh/tYWjjPqCQo+oLsUREU80rT8AQwGYXmmK+6Dm74Ge57z3ncWxPoIWql6HlxZcsClHkHNl/DGVXBPjqd3mUIk3BvVYmCwmJ4k0B0m8OLa3OTV2k8SIlIKw5HjKaW8oII/EUdSokKFbM/7JDcpKOKaZYOXh/7Hi2BZ+b9eN1TQpi6i0rRjOPaCBpz6c5DMhZjk+c5wThsq+l6DI3rgMZs2J4ZbAL3BtU/wCBX9hJeJjgSlQlXI/YxjlCcDy0QCtnkPltJ X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR03MB3871.namprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(376002)(136003)(366004)(39860400002)(346002)(5660300002)(54906003)(2616005)(8936002)(34490700002)(1076003)(66476007)(66946007)(6666004)(956004)(4326008)(6512007)(6486002)(8676002)(75432002)(6506007)(26005)(6916009)(52116002)(2906002)(86362001)(186003)(16526019)(786003)(316002)(66556008)(478600001)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: QGOXdT5udOQWJCFG1UcAy3aijHr3Wf6QX4hzh5hY9tjw/ejgsDYwmURX6yGtmKOMxDcYWCSEGuIwlqViVPUdQUAI9ehEsjI2TETbihGBhwE/aVB/nAo80GX2WPBqIljQXqVYR9S489ak+N/NPk3qU+90UEms5vjEcdlonnwH1Jjr8WT/QT/rFuxizc4cplE/9MY0OrcZ6M5ZE1BE2AYHiBzb7dcQplsTAt1yAqpGN1ddENXLiqcG4wNzZCJgf2i/rd0UBYTdVOO/c1bR+M2NMluxcf7uZJZ1IlZNhq/7WV8Z5g9iy4c2yQgZ+t4BzZL6nz9gCTauzz4dLsBHmLreWG607pbD7x44w20Hq3ZVlZgl9ANJZu6uuyXax8+scVPl1OAW/YVRs9adAhv70xBp4aXHGtvygTIAnYkA1Q7ABuUwHYOd/MZsYuha7ze3jTKB2IXYO4UJQ2OewUb8KYvxqcwRlYdg9TJUsHxOapy7fb17gzPnm7eDfUxzsRst7l7LW93kZwQxs1isHNE7nGXjEi/kxil8PT12ue9TbFOZ5QLtTLg2daf3YC9HzkzzHhyexmdVxt9MrRgia0bg0zdogeiiVxWk5V6SdA0SEUjx317Fi1ffKCrqFjUnGQ3C8iJE8ft4QdzNgbueiqhr1vQ+Fw== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: f62925d3-7fb7-4a89-b332-08d8711018e5 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2020 13:42:02.8994 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pwx3B0tXPdx5ZgMxnS9rihcKmPNoGOdx5gU1XZ3ffmjrlNPI/DGD+sLtGQcIXdl8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR03MB5465 Received-SPF: pass client-ip=40.107.75.103; envelope-from=alxndr@bu.edu; helo=NAM02-BL2-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/15 09:42:14 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.998, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , Alexander Bulekov , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, dimastep@yandex-team.ru Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" libfuzzer supports a "custom crossover function". Libfuzzer often tries to blend two inputs to create a new interesting input. Sometimes, we have a better idea about how to blend inputs together. This change allows fuzzers to specify a custom function for blending two inputs together. Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny --- tests/qtest/fuzz/fuzz.c | 13 +++++++++++++ tests/qtest/fuzz/fuzz.h | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c index d926c490c5..00fa5fd52f 100644 --- a/tests/qtest/fuzz/fuzz.c +++ b/tests/qtest/fuzz/fuzz.c @@ -118,6 +118,19 @@ static FuzzTarget *fuzz_get_target(char* name) } +/* Sometimes called by libfuzzer to mutate two inputs into one */ +size_t LLVMFuzzerCustomCrossOver(const uint8_t *data1, size_t size1, + const uint8_t *data2, size_t size2, + uint8_t *out, size_t max_out_size, + unsigned int seed) +{ + if (fuzz_target->crossover) { + return fuzz_target->crossover(data1, size1, data2, size2, out, + max_out_size, seed); + } + return 0; +} + /* Executed for each fuzzing-input */ int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size) { diff --git a/tests/qtest/fuzz/fuzz.h b/tests/qtest/fuzz/fuzz.h index 8eb765edc8..ed9ce17154 100644 --- a/tests/qtest/fuzz/fuzz.h +++ b/tests/qtest/fuzz/fuzz.h @@ -77,6 +77,29 @@ typedef struct FuzzTarget { */ void(*fuzz)(QTestState *, const unsigned char *, size_t); + /* + * The fuzzer can specify a "Custom Crossover" function for combining two + * inputs from the corpus. This function is sometimes called by libfuzzer + * when mutating inputs. + * + * data1: location of first input + * size1: length of first input + * data1: location of second input + * size1: length of second input + * out: where to place the resulting, mutated input + * max_out_size: the maximum length of the input that can be placed in out + * seed: the seed that should be used to make mutations deterministic, when + * needed + * + * See libfuzzer's LLVMFuzzerCustomCrossOver API for more info. + * + * Can be NULL + */ + size_t(*crossover)(const uint8_t *data1, size_t size1, + const uint8_t *data2, size_t size2, + uint8_t *out, size_t max_out_size, + unsigned int seed); + } FuzzTarget; void flush_events(QTestState *); @@ -91,6 +114,10 @@ void fuzz_qtest_set_serialize(bool option); */ void fuzz_add_target(const FuzzTarget *target); +size_t LLVMFuzzerCustomCrossOver(const uint8_t *data1, size_t size1, + const uint8_t *data2, size_t size2, + uint8_t *out, size_t max_out_size, + unsigned int seed); int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size); int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp);