From patchwork Mon Sep 21 02:24:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 304891 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=-12.7 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, 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 02F42C43465 for ; Mon, 21 Sep 2020 02:27:36 +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 6F8E42078E for ; Mon, 21 Sep 2020 02:27:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="nJTF+/aC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F8E42078E 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]:40160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBYE-0004rn-DA for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:27:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWL-00036l-A1 for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:37 -0400 Received: from mail-dm6nam10on2102.outbound.protection.outlook.com ([40.107.93.102]:19201 helo=NAM10-DM6-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 1kKBWI-0000aa-Uz for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:36 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R1FsDraple05J2T5o0B1b6nyoWCu96jra3t4vx9xnGWoMt9zc/bdbtTY9hIr6F1oE9SXYBVhBHBw6rQGjyHODkimIKdEadh6QOiw+bYt8T3kGErFxBiqhk255Z1ruWqhYoF4OXkP8DezKd24j/lCnOv/zeU2Mp4Cu3bgxJKl74fWbHudASr32/g8LryP0Jz8bqc5RRHSZ9wnK53mNv5/oLk3cLJGgfCzkD0CeDIe31/FOGS4tVdP6tDeHqh1EHklMaQXDJj2nNdXuXp8Md3RFBOqL4s715FjevZVOO7OB1aF+/FnGSB3ke3Ule2EP5bJTkjmoDYoHbJeNZZgV1Kq4g== 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=zXkCKaQY/ufWCpE8/SM6P3+jQtV8gI8PiTB1OsVzgVU=; b=TUioZ1hz3qpevoTZPf9TuTyOQ57UU8JU+zEJFedB1hyJB+9FOqKFc6ieBTHG2AHENNP4aQQPLEXXT/bD0C3KvsYWf5Aj3j2nrtAfVkzvc5HtNHahQRBGA656BR9KFW3Ccx/MTfSj9vMqBLTZ3XZIpBBp5ONfJKAFgZc8dbwSK8dXaNo6aUHlFcb33xTrFnEAlmiZPuD+fjdENtkXN9NbXok6AV2NfPL39J6NyhdX+0KdGYggrYO48EIMMZxrUvq1pLKcNlRT8qL6lTfvZ4oTquyxzDDasAaJkF2RkpWzt5LpMvo8m1fdK+nJd/0xEMCTyyNLHnMAHeibt/vYBqdTOw== 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=zXkCKaQY/ufWCpE8/SM6P3+jQtV8gI8PiTB1OsVzgVU=; b=nJTF+/aCDQ8PI5Tz+/nvAhk42d0A9xNV9ZZMO+n4n1UxR72/lO0lj9mArR1kfxEiwvwNkZLQbqs+NBBSJO9XJSy94Hmw9c1edipIOqCbeNNOdmBBUKrBb/46ocaSW7eb2oMgojVQfJVstqMrPFnD604D6gMt014Nw98nTEFw1bo= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:20 +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.3391.024; Mon, 21 Sep 2020 02:25:20 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 01/16] memory: Add FlatView foreach function Date: Sun, 20 Sep 2020 22:24:51 -0400 Message-Id: <20200921022506.873303-2-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:19 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2a9b9828-a1ca-4484-22f1-08d85dd595fa X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2657; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TSyF2pAPDz3E7c3t9Wbb11kMGdGBtjzfot+j9MHHgpgLErnDyse7yuRc1pq5FmynMGCUwb5w5M4NaZpAW+qvMPZKkgXfaq/pMP/qCmwiZY92ovWc6+9wDy+kbDRZdNcoAXxJSke4Q6QLCVq7yqy1qYAYrdeDvvd41cvMrdZ0nfj8UcgixvzEMldDgJ6nSI40Fq6PGA/gAOD6lG2pt0kLFelJ/zckFG1zVlZCbjtCQv15CrRS7PGLfOPQKdbLyRmbqNJDadf/qjegk1ZSs8Qa1x4PkLdLzn0MjVR3g/QX/qoJTNLcYdKKAgS8iu5b6MlesRs8EAKDGZNAQW3COUHjb/Sxl0yJz1KNOe54PxG564ZDdZoXz5QrbdS96WGt1X1G 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: UihiY8Q3taAKZsg6r8DzUf22MwelYJ7xGvCRr6I17/dDqhmU1BHmkBWWQrpPjabmfKCPiFxfng8hYsAqW5Zwn5XJ1jn3mujTquu7E8xs5lhYWjf6ulbo1RPF3QBOMzMXwCOFL8mSczYEyjpJGpq4Net6NHdnO8fAQjM0whucvcuuArfQMeMjxYYplbwdUO4W34svBhqL2UqSY6N8FHt2OCotGh823A9JV0a7+EVuzTYjntoIcRUmUGJVKNBi+A/QevsQpR3lSWUoflIaii3GYkPVYB2kvEu3LH42aKP6AQaYKl1C2AUkPOaXNSF62FbsLV+c5LVeQMSf5uToQae5rstCs4uAcf64OAhuF8XYnoNLwCc6hTW+aO8jtgKfffkqizOMChbxmcgOd6ffQuzVtaUjVeD4IyiH8WeIXoddzgIW+k+JXuqX3BOr4Tp6G6Supfqes+mx2f3ZQVu05laRE/jb5xR+xCSt2L30nswoBJQFK9Lnp/aQijDj82RVEsPysOLzoRMBrbuyLA9Vsd+L4J0cR8/27QMD4EvvkFVdTkQfgIXUxaappNfZwNr2I1lhZbUUAxBBu7dHzIRT7rP6oMS1ym/1EPHDOHhGsTjm++3m5ksQ6MlE8M7/7R942PdhFnUjaaVDsf3tzqSMgbaFDw== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 2a9b9828-a1ca-4484-22f1-08d85dd595fa X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:20.1259 (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: V5ID/VB6FRRiwfpHt1eKOCugNMSk4UrPu5Bz1eM7N5WU268+bqBNYjXNQLB8FR9h X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.93.102; envelope-from=alxndr@bu.edu; helo=NAM10-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:33 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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: Alexander Bulekov , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexander Bulekov Acked-by: Paolo Bonzini --- include/exec/memory.h | 5 +++++ softmmu/memory.c | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index f1bb2a7df5..975a90c871 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -688,6 +688,11 @@ static inline FlatView *address_space_to_flatview(AddressSpace *as) return atomic_rcu_read(&as->current_map); } +typedef int (*flatview_cb)(ram_addr_t start, + ram_addr_t len, + const MemoryRegion*, void*); + +void flatview_for_each_range(FlatView *fv, flatview_cb cb , void *opaque); /** * MemoryRegionSection: describes a fragment of a #MemoryRegion diff --git a/softmmu/memory.c b/softmmu/memory.c index d030eb6f7c..9db5fbe43a 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -655,6 +655,15 @@ static void render_memory_region(FlatView *view, } } +void flatview_for_each_range(FlatView *fv, flatview_cb cb , void *opaque) +{ + FlatRange *fr; + FOR_EACH_FLAT_RANGE(fr, fv) { + if (cb(fr->addr.start, fr->addr.size, fr->mr, opaque)) + break; + } +} + static MemoryRegion *memory_region_get_flatview_root(MemoryRegion *mr) { while (mr->enabled) { From patchwork Mon Sep 21 02:24:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 273219 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=-17.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, HK_RANDOM_FROM, INCLUDES_PATCH, MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, 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 A5454C43466 for ; Mon, 21 Sep 2020 02:27:39 +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 364732078E for ; Mon, 21 Sep 2020 02:27:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="Mpa4LUUY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 364732078E 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]:40522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBYI-00050p-58 for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:27:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41448) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWR-000380-U9 for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:43 -0400 Received: from mail-dm6nam10on2102.outbound.protection.outlook.com ([40.107.93.102]:19201 helo=NAM10-DM6-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 1kKBWP-0000aa-GP for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e89B4jW2Kg8PP3Rme4saI2AEJYjwKz6kzzBwcoPPYwejBxlArbKjR7viH6LZknM2bovu+XPKvaHSjspsaZKM7A22l1BqwpgaGBQ+kAd9Byp0oaqKrmH5dcGBmso8noHEQX6vlR5Smpe/sCPOV9XIQ4EJbsbioFzXuBXE+edU8U3sKip06C08mAYSyuibmOM7R4+OegruG0Jptjg/WOFj3Mn0wNJFWZtl8cpuiEvEGlFIzCq5NRB/CAXmArdI3ahZ9vdqdRkxwb36rQgvKXG9CaHmk1C86L39fHlB9s5uxuJC6At1rNiUKCLWg0ohdOtW08J9ufkf6zZu2NvDZae/zA== 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=6FhtfdJO4D9jlL2lnHUenV9S3dZN3wvSNiOT4tZknA8=; b=KseNHkXsF95ozpJ9PzktszlMK8zPUl8gLwA6x6DEXbpr+DztaftExJRKp+uER+otHh2qWVmI7Q4tDUcE6FBv59ENXS6ZU0zazA6FE3Q7vC8/EJjWPI3X3zVQKia8c3+h/iM9UpoftQhLDl1sBhu5QQSU/begqrGJOYEzdESThRY1uh/ReUczOhe7uMxguYYgWKbibk6E8xOiiYHmd1PrIEO6OjnIfrwSmIPDsoU6HqXkoIaHTdlHX3M0kfUwp73tIJebWKZMrEq6iBKt5jU9vf4LYLjzE90ABBkBxK0Y1AypyJh0Vrf5dFPcb2tUozTFDZwIjk01UtZKvR///SwK5A== 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=6FhtfdJO4D9jlL2lnHUenV9S3dZN3wvSNiOT4tZknA8=; b=Mpa4LUUYHBis2WpqL94E4xItW6Mc6IqlLrupGIcyZTJY0rE+kSiL4OSDhnCf1TUkXg+wa219twnRC+dp1A5xFxryKFUl+OIdY7IxAViVVF2fy7Lakx14mkXi9wh6jBda+C4iKtPW0XXCGAhZTRsl/x3z442ePvEQvwyXtt4YRE0= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:23 +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.3391.024; Mon, 21 Sep 2020 02:25:22 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 02/16] fuzz: Add general virtual-device fuzzer Date: Sun, 20 Sep 2020 22:24:52 -0400 Message-Id: <20200921022506.873303-3-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:20 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8bb5964f-6fde-4d59-f36e-08d85dd596b4 X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:849; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 17GJm4m0dmJJhq8wtzoZTQsQMcZowdUz8L/h1ItjbDljaANUOrNRDBsf1ksvAbL/RLiPu8viDyKwZ0H/XnYIb3S3zLweUqd85Gn+Y3nJogNOxQNdyNh3ZL/bxgV8/5YBp0ZVcdfMg5RXeYglKg6UvjJbFNmW5V2bEdWIKk1ZVISruF8YKdrZpdvXMe/eOW1X3YXbokGgw85tYXdsxf5jM1yR1y/wXEWeHjraqE/Aio2nBX8fvCbLR2vtAz+MAz6ZGhRCIEHcAPeVF7F7XeEc2yxgBEijJfXVW/EPltIKELQMm9I+nCQW4DYTyf6SvkKh/XdO7t379IspXyy7iaP+BFHOPHiBr8R0csCdvUjwKEadMyo4JXEjG0b1I9+yFWTSEu+4AsPKjtUuwCN//ruDnxP1dZT6qdi9C81M8Fs1K4P9LdSmNuginskXwSdY+TiydMZOXjxlEZoCMZJOXi7aJQ== 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(83380400001)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(966005)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(30864003)(66556008)(52116002)(786003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: pv6WNUCbHY/DWHlE9z+/FhOaRxHJ8zx8aZwJ92vvlys87hUcPYubguD27o1udbFRc4IBMZWIxZvwSnDOij/DNmLdnHidJ5fSceHfeSuAbsHZCf+IsrNeJzxmDaRThYWNjMXukxuMjksy7BK/4MsQcENHv4Tc0JPtmXeSt56iDyi2VDN1ywQb3tWfP4j/r0ATgKQKD7SWpfQSxhT46Tj2z2mWXmf4pRCuYit2YAMb9QV2kWiam6ZzurOFp/X0knljtAQZRUGR+ZnB/hDtkJcgpXOT/0rQmlS/cXMtuOxlIf/rnBmzODQquo2ufLh+d+KkiRKMf345FeUlLzLrOhtB8vRN9FeeuTKTzX73+N6xVB75n3gwQGkXZMnbMmUXHuS2ElN52iuTZzOGQlFPPMCAcS5Muw4NL2dD1su+kmAMoSiM4A2Ap2HR72Bvr3vS2cJnNTcqvLceeO9nZkTb3AB1KCD21dL7WPtY8TclOj1lvOboLY1Dke1xXlEu15ayruy7eukb0iRWH9fVl0RTQXdbvYj6OL5pv/Kj2w/FQ1purQox5w0IkAH3lYiv2VVDbtEcAsDNA+KUNTeX8js4i3KxhDMInW+NPKK5cMINp0rP95ADebqYtWkiVz/axTMGXS0TkrJnYGgvfCp35y9d8PFfeg== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 8bb5964f-6fde-4d59-f36e-08d85dd596b4 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:22.1177 (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: 0cm2IDjdKu1c1mPpCPadSx19DMwAw+Eglcd6QoOfKLAetzF1Z8e5HBJdDA/Rrg4x X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.93.102; envelope-from=alxndr@bu.edu; helo=NAM10-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:33 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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 , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This is a generic fuzzer designed to fuzz a virtual device's MemoryRegions, as long as they exist within the Memory or Port IO (if it exists) AddressSpaces. The fuzzer's input is interpreted into a sequence of qtest commands (outb, readw, etc). The interpreted commands are separated by a magic seaparator, which should be easy for the fuzzer to guess. Without ASan, the separator can be specified as a "dictionary value" using the -dict argument (see libFuzzer documentation). Signed-off-by: Alexander Bulekov --- tests/qtest/fuzz/general_fuzz.c | 498 ++++++++++++++++++++++++++++++++ tests/qtest/fuzz/meson.build | 1 + 2 files changed, 499 insertions(+) create mode 100644 tests/qtest/fuzz/general_fuzz.c diff --git a/tests/qtest/fuzz/general_fuzz.c b/tests/qtest/fuzz/general_fuzz.c new file mode 100644 index 0000000000..bf75b215ca --- /dev/null +++ b/tests/qtest/fuzz/general_fuzz.c @@ -0,0 +1,498 @@ +/* + * General Virtual-Device Fuzzing Target + * + * Copyright Red Hat Inc., 2020 + * + * Authors: + * Alexander Bulekov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include + +#include "hw/core/cpu.h" +#include "tests/qtest/libqos/libqtest.h" +#include "fuzz.h" +#include "fork_fuzz.h" +#include "exec/address-spaces.h" +#include "string.h" +#include "exec/memory.h" +#include "exec/ramblock.h" +#include "exec/address-spaces.h" +#include "hw/qdev-core.h" + +/* + * SEPARATOR is used to separate "operations" in the fuzz input + */ +#define SEPARATOR "FUZZ" + +enum cmds { + OP_IN, + OP_OUT, + OP_READ, + OP_WRITE, + OP_CLOCK_STEP, +}; + +#define DEFAULT_TIMEOUT_US 100000 +#define USEC_IN_SEC 100000000 + +typedef struct { + ram_addr_t addr; + ram_addr_t size; /* The number of bytes until the end of the I/O region */ +} address_range; + +static useconds_t timeout = 100000; + +static bool qtest_log_enabled; + +/* + * List of memory regions that are children of QOM objects specified by the + * user for fuzzing. + */ +static GHashTable *fuzzable_memoryregions; + +struct get_io_cb_info { + int index; + int found; + address_range result; +}; + +static int get_io_address_cb(ram_addr_t start, ram_addr_t size, + const MemoryRegion *mr, void *opaque) { + struct get_io_cb_info *info = opaque; + if (g_hash_table_lookup(fuzzable_memoryregions, mr)) { + if (info->index == 0) { + info->result.addr = start; + info->result.size = size; + info->found = 1; + return 1; + } + info->index--; + } + return 0; +} + +/* + * Here we want to convert a fuzzer-provided [io-region-index, offset] to + * a physical address. To do this, we iterate over all of the matched + * MemoryRegions. Check whether each region exists within the particular io + * space. Return the absolute address of the offset within the index'th region + * that is a subregion of the io_space and the distance until the end of the + * memory region. + */ +static bool get_io_address(address_range *result, AddressSpace *as, + uint8_t index, + uint32_t offset) { + FlatView *view; + view = as->current_map; + g_assert(view); + struct get_io_cb_info cb_info = {}; + + cb_info.index = index; + + /* + * Loop around the FlatView until we match "index" number of + * fuzzable_memoryregions, or until we know that there are no matching + * memory_regions. + */ + do { + flatview_for_each_range(view, get_io_address_cb , &cb_info); + } while (cb_info.index != index && !cb_info.found); + + *result = cb_info.result; + return cb_info.found; +} +static bool get_pio_address(address_range *result, + uint8_t index, uint16_t offset) +{ + /* + * PIO BARs can be set past the maximum port address (0xFFFF). Thus, result + * can contain an addr that extends past the PIO space. When we pass this + * address to qtest_in/qtest_out, it is cast to a uint16_t, so we might end + * up fuzzing a completely different MemoryRegion/Device. Therefore, check + * that the address here is within the PIO space limits. + */ + bool found = get_io_address(result, &address_space_io, index, offset); + return result->addr <= 0xFFFF ? found : false; +} +static bool get_mmio_address(address_range *result, + uint8_t index, uint32_t offset) +{ + return get_io_address(result, &address_space_memory, index, offset); +} + +static void op_in(QTestState *s, const unsigned char * data, size_t len) +{ + enum Sizes {Byte, Word, Long, end_sizes}; + struct { + uint8_t size; + uint8_t base; + uint16_t offset; + } a; + address_range abs; + + if (len < sizeof(a)) { + return; + } + memcpy(&a, data, sizeof(a)); + if (get_pio_address(&abs, a.base, a.offset) == 0) { + return; + } + + switch (a.size %= end_sizes) { + case Byte: + qtest_inb(s, abs.addr); + break; + case Word: + if (abs.size >= 2) { + qtest_inw(s, abs.addr); + } + break; + case Long: + if (abs.size >= 4) { + qtest_inl(s, abs.addr); + } + break; + } +} + +static void op_out(QTestState *s, const unsigned char * data, size_t len) +{ + enum Sizes {Byte, Word, Long, end_sizes}; + struct { + uint8_t size; + uint8_t base; + uint16_t offset; + uint32_t value; + } a; + address_range abs; + + if (len < sizeof(a)) { + return; + } + memcpy(&a, data, sizeof(a)); + + if (get_pio_address(&abs, a.base, a.offset) == 0) { + return; + } + + switch (a.size %= end_sizes) { + case Byte: + qtest_outb(s, abs.addr, a.value & 0xFF); + break; + case Word: + if (abs.size >= 2) { + qtest_outw(s, abs.addr, a.value & 0xFFFF); + } + break; + case Long: + if (abs.size >= 4) { + qtest_outl(s, abs.addr, a.value); + } + break; + } +} + +static void op_read(QTestState *s, const unsigned char * data, size_t len) +{ + enum Sizes {Byte, Word, Long, Quad, end_sizes}; + struct { + uint8_t size; + uint8_t base; + uint32_t offset; + } a; + address_range abs; + + if (len < sizeof(a)) { + return; + } + memcpy(&a, data, sizeof(a)); + + if (get_mmio_address(&abs, a.base, a.offset) == 0) { + return; + } + + switch (a.size %= end_sizes) { + case Byte: + qtest_readb(s, abs.addr); + break; + case Word: + if (abs.size >= 2) { + qtest_readw(s, abs.addr); + } + break; + case Long: + if (abs.size >= 4) { + qtest_readl(s, abs.addr); + } + break; + case Quad: + if (abs.size >= 8) { + qtest_readq(s, abs.addr); + } + break; + } +} + +static void op_write(QTestState *s, const unsigned char * data, size_t len) +{ + enum Sizes {Byte, Word, Long, Quad, end_sizes}; + struct { + uint8_t size; + uint8_t base; + uint32_t offset; + uint64_t value; + } a; + address_range abs; + + if (len < sizeof(a)) { + return; + } + memcpy(&a, data, sizeof(a)); + + if (get_mmio_address(&abs, a.base, a.offset) == 0) { + return; + } + + switch (a.size %= end_sizes) { + case Byte: + qtest_writeb(s, abs.addr, a.value & 0xFF); + break; + case Word: + if (abs.size >= 2) { + qtest_writew(s, abs.addr, a.value & 0xFFFF); + } + break; + case Long: + if (abs.size >= 4) { + qtest_writel(s, abs.addr, a.value & 0xFFFFFFFF); + } + break; + case Quad: + if (abs.size >= 8) { + qtest_writeq(s, abs.addr, a.value); + } + break; + } +} +static void op_clock_step(QTestState *s, const unsigned char *data, size_t len) +{ + qtest_clock_step_next(s); +} + +static void handle_timeout(int sig) +{ + if (qtest_log_enabled) { + fprintf(stderr, "[Timeout]\n"); + fflush(stderr); + } + _Exit(0); +} + +/* + * Here, we interpret random bytes from the fuzzer, as a sequence of commands. + * Our commands are variable-width, so we use a separator, SEPARATOR, to specify + * the boundaries between commands. This is just a random 32-bit value, which + * is easily identified by libfuzzer+AddressSanitizer, as long as we use + * memmem. It can also be included in the fuzzer's dictionary. More details + * here: + * https://github.com/google/fuzzing/blob/master/docs/split-inputs.md + * + * As a result, the stream of bytes is converted into a sequence of commands. + * In a simplified example where SEPARATOR is 0xFF: + * 00 01 02 FF 03 04 05 06 FF 01 FF ... + * becomes this sequence of commands: + * 00 01 02 -> op00 (0102) -> in (0102, 2) + * 03 04 05 06 -> op03 (040506) -> write (040506, 3) + * 01 -> op01 (-,0) -> out (-,0) + * ... + * + * Note here that it is the job of the individual opcode functions to check + * that enough data was provided. I.e. in the last command out (,0), out needs + * to check that there is not enough data provided to select an address/value + * for the operation. + */ +static void general_fuzz(QTestState *s, const unsigned char *Data, size_t Size) +{ + void (*ops[]) (QTestState *s, const unsigned char* , size_t) = { + [OP_IN] = op_in, + [OP_OUT] = op_out, + [OP_READ] = op_read, + [OP_WRITE] = op_write, + [OP_CLOCK_STEP] = op_clock_step, + }; + const unsigned char *cmd = Data; + const unsigned char *nextcmd; + size_t cmd_len; + uint8_t op; + + if (fork() == 0) { + /* + * Sometimes the fuzzer will find inputs that take quite a long time to + * process. Often times, these inputs do not result in new coverage. + * Even if these inputs might be interesting, they can slow down the + * fuzzer, overall. Set a timeout to avoid hurting performance, too much + */ + if (timeout) { + struct sigaction sact; + struct itimerval timer; + + sigemptyset(&sact.sa_mask); + sact.sa_flags = SA_NODEFER; + sact.sa_handler = handle_timeout; + sigaction(SIGALRM, &sact, NULL); + + memset(&timer, 0, sizeof(timer)); + timer.it_value.tv_sec = timeout / USEC_IN_SEC; + timer.it_value.tv_usec = timeout % USEC_IN_SEC; + setitimer(ITIMER_VIRTUAL, &timer, NULL); + } + + while (cmd && Size) { + /* Get the length until the next command or end of input */ + nextcmd = memmem(cmd, Size, SEPARATOR, strlen(SEPARATOR)); + cmd_len = nextcmd ? nextcmd - cmd : Size; + + if (cmd_len > 0) { + /* Interpret the first byte of the command as an opcode */ + op = *cmd % (sizeof(ops) / sizeof((ops)[0])); + ops[op](s, cmd + 1, cmd_len - 1); + + /* Run the main loop */ + flush_events(s); + } + /* Advance to the next command */ + cmd = nextcmd ? nextcmd + sizeof(SEPARATOR) - 1 : nextcmd; + Size = Size - (cmd_len + sizeof(SEPARATOR) - 1); + } + _Exit(0); + } else { + flush_events(s); + wait(0); + } +} + +static void usage(void) +{ + printf("Please specify the following environment variables:\n"); + printf("QEMU_FUZZ_ARGS= the command line arguments passed to qemu\n"); + printf("QEMU_FUZZ_OBJECTS= " + "a space separated list of QOM type names for objects to fuzz\n"); + printf("Optionally: QEMU_FUZZ_TIMEOUT= Specify a custom timeout (us). " + "0 to disable. %d by default\n", timeout); + exit(0); +} + +static int locate_fuzz_memory_regions(Object *child, void *opaque) +{ + const char *name; + MemoryRegion *mr; + if (object_dynamic_cast(child, TYPE_MEMORY_REGION)) { + mr = MEMORY_REGION(child); + if ((memory_region_is_ram(mr) || + memory_region_is_ram_device(mr) || + memory_region_is_rom(mr) || + memory_region_is_romd(mr)) == false) { + name = object_get_canonical_path_component(child); + /* + * We don't want duplicate pointers to the same MemoryRegion, so + * try to remove copies of the pointer, before adding it. + */ + g_hash_table_insert(fuzzable_memoryregions, mr, (gpointer)true); + } + } + return 0; +} +static int locate_fuzz_objects(Object *child, void *opaque) +{ + char *pattern = opaque; + if (g_pattern_match_simple(pattern, object_get_typename(child))) { + /* Find and save ptrs to any child MemoryRegions */ + object_child_foreach_recursive(child, locate_fuzz_memory_regions, NULL); + + } else if (object_dynamic_cast(OBJECT(child), TYPE_MEMORY_REGION)) { + if (g_pattern_match_simple(pattern, + object_get_canonical_path_component(child))) { + MemoryRegion *mr; + mr = MEMORY_REGION(child); + if ((memory_region_is_ram(mr) || + memory_region_is_ram_device(mr) || + memory_region_is_rom(mr) || + memory_region_is_romd(mr)) == false) { + g_hash_table_insert(fuzzable_memoryregions, mr, (gpointer)true); + } + } + } + return 0; +} + +static void general_pre_fuzz(QTestState *s) +{ + GHashTableIter iter; + MemoryRegion *mr; + char **result; + + if (!getenv("QEMU_FUZZ_OBJECTS")) { + usage(); + } + if (getenv("QTEST_LOG")) { + qtest_log_enabled = 1; + } + if (getenv("QEMU_FUZZ_TIMEOUT")) { + timeout = g_ascii_strtoll(getenv("QEMU_FUZZ_TIMEOUT"), NULL, 0); + } + + fuzzable_memoryregions = g_hash_table_new(NULL, NULL); + + result = g_strsplit(getenv("QEMU_FUZZ_OBJECTS"), " ", -1); + for (int i = 0; result[i] != NULL; i++) { + printf("Matching objects by name %s\n", result[i]); + object_child_foreach_recursive(qdev_get_machine(), + locate_fuzz_objects, + result[i]); + } + g_strfreev(result); + printf("This process will try to fuzz the following MemoryRegions:\n"); + + g_hash_table_iter_init(&iter, fuzzable_memoryregions); + while (g_hash_table_iter_next(&iter, (gpointer)&mr, NULL)) { + printf(" * %s (size %lx)\n", + object_get_canonical_path_component(&(mr->parent_obj)), + mr->addr); + } + + if (!g_hash_table_size(fuzzable_memoryregions)) { + printf("No fuzzable memory regions found...\n"); + exit(1); + } + + counter_shm_init(); +} +static GString *general_fuzz_cmdline(FuzzTarget *t) +{ + GString *cmd_line = g_string_new(TARGET_NAME); + if (!getenv("QEMU_FUZZ_ARGS")) { + usage(); + } + g_string_append_printf(cmd_line, " -display none \ + -machine accel=qtest, \ + -m 64 %s ", getenv("QEMU_FUZZ_ARGS")); + return cmd_line; +} + +static void register_general_fuzz_targets(void) +{ + fuzz_add_target(&(FuzzTarget){ + .name = "general-fuzz", + .description = "Fuzz based on any qemu command-line args. ", + .get_init_cmdline = general_fuzz_cmdline, + .pre_fuzz = general_pre_fuzz, + .fuzz = general_fuzz}); +} + +fuzz_target_init(register_general_fuzz_targets); diff --git a/tests/qtest/fuzz/meson.build b/tests/qtest/fuzz/meson.build index b31ace7d5a..a59de6aa8c 100644 --- a/tests/qtest/fuzz/meson.build +++ b/tests/qtest/fuzz/meson.build @@ -5,6 +5,7 @@ specific_fuzz_ss.add(files('fuzz.c', 'fork_fuzz.c', 'qos_fuzz.c', specific_fuzz_ss.add(when: 'CONFIG_I440FX', if_true: files('i440fx_fuzz.c')) specific_fuzz_ss.add(when: 'CONFIG_VIRTIO_NET', if_true: files('virtio_net_fuzz.c')) specific_fuzz_ss.add(when: 'CONFIG_VIRTIO_SCSI', if_true: files('virtio_scsi_fuzz.c')) +specific_fuzz_ss.add(files('general_fuzz.c')) fork_fuzz = declare_dependency( link_args: config_host['FUZZ_EXE_LDFLAGS'].split() + From patchwork Mon Sep 21 02:24:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 273217 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=-12.7 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 55A1EC43463 for ; Mon, 21 Sep 2020 02:30:50 +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 A8EE92067D for ; Mon, 21 Sep 2020 02:30:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="iJtA1tka" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A8EE92067D 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]:48986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBbM-0008VQ-Gb for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:30:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41470) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWT-000399-VQ for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:45 -0400 Received: from mail-dm6nam12on2117.outbound.protection.outlook.com ([40.107.243.117]:28256 helo=NAM12-DM6-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 1kKBWS-0000b7-2t for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gh2WO/lK7kMR8v+8iXRkfeIJUsuuTHS0mBvRHkXqyx22jE8enrciuiZRW77bQqbcQ/r7dLytYGVy0dBJbg4D5hOxDPCd3YdHFUdH/RABJTUatCF9YGvS7eMdgTUqSQzlzurPOP7n+bLGb3dvb8P/f4GrLV+IWy5XFIkIetYEVv7l4hiRdKMUmJ4biXqYObDtoKwypT/QL9ALQGa3FUD+mf+ES0KMPpO7UyJ1nMm0DmOt2XW1qTg0I669D8SgeNh/IcNqCIkRzMRvp9XREAt+hRdpdEHjrl9ROWiWi4AUyXixjxFQwgyzuElnVvikMdQGxSmQq1P/tNluPyWUsy96uA== 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=sETfKWrK2/FdFUo0x/a5ED2AtHMkmhB2OCwpeRseRyo=; b=AwMLzjc/rCa8PIT1W0L+y8OaHlhx/03XcC8MVyv/FoE9mt6bsZZokf3CsT/v5FxrFVccnlAlGjbOJVCY/B1gX1YZMhOJNkFcvcMsq/X3+kcxFR+kSMdFbXTh3v++KFA3koakn23I2M3h+wWP/SI2XzFrQ9C+GHkw+7nRuJM395u9GhXZ75TBcJNeLDi52auZT60yweQMZccvtRmC/AMfwP59i5/DsqiLRMKsFn4AF+U3Oh23DN3ekk82KUThbTc2LDhSHJh7Nt/v0j4K1DTqr4J2q62lW5i4ndVstVdwx+zAqTgEnEaT0cwk3vBb4HQO+w/sOXh9eYQtbzJma7vx9g== 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=sETfKWrK2/FdFUo0x/a5ED2AtHMkmhB2OCwpeRseRyo=; b=iJtA1tkaLi0DC+sI7hI2vPwhir8hCe/aoAX8fUXE1b+vE0kvEu3tIwIFh12ffWfuujqYLrTQdG2rjVr4Jmd+lUXQd6JtkjQqFcAa4S8N6SFX3v3wIqyNKDbIiuZG0xbx8G6l2LcL1fvyxqwq5TNTY8GQWexh/WRhekOX7dnh8vc= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:24 +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.3391.024; Mon, 21 Sep 2020 02:25:24 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 03/16] fuzz: Add PCI features to the general fuzzer Date: Sun, 20 Sep 2020 22:24:53 -0400 Message-Id: <20200921022506.873303-4-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:23 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f3552ee0-5f4a-426c-966f-08d85dd5984c X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:268; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: v5kNdLJqKpfQ9QXzQvemwKOIhCJBlzHZH7DP30oy0wAJ25ZAs9HRneJFOxzHWSqgbBfW4GkW+ZHqAs7g+biKI65Rh0WbT9aDFYn+X8nOS/axWlohT4AaJar5j9wVIL1QcUw3mY+fNNOpX+Q4RuyjHrxw06vcvlkQjccXPRJ8WraSaLpOj8jpnk7BIDeCNmwZFBOssKB3b7aCOKqOOlkNVVOde7DnfG9vOvEHc92QtER7FOjIrBBWU0HnCFF8x4Zm36Vddp/iWbB4cJUdUP8UA0IPkJze10+lgLeadqNqAueBY1a/b9M2ovptIjAMS52wkgp5C8d83PDrqymrRszYcjkiOcscM6NQ7nmh6syKok0D/oeJM85EnHExNofD4Gmm 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(83380400001)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: x1sVVQuaodCgKwkCvdX39ialyFNt2LAgwcHmCTdFfgY8+KzjTSRCj4PvP/Dzzyx5DZu6YTLsVtsH7JPvt0G0BTbtNty81ZJQuOo98FaY67wD3KEncmPm2lkoe3msW8/7n8I9MkfyQqHtJghgMyFW3yQjOyEagjtRQWvaG2+XlJQhlPTkjx1rS1MGBV1c69UUaR0VMMIpCg3xmU7RnfM87CgQ7S8tjK3wNhIiea9VBnkma2KYvnCPp6PFgykDikAFoJ8HPxu5coQPdlDxpVaTxkfW99V16sxG+5FdcsPgLfZbDhoCtZAYqhD7D99VrxmlfYHHAXwg+RZ16Jjaga0Un0T+2hp/3Y3nBL8rJsyASpmqtCtWLdn4tSaoczhCw0nlBknZQfOsmTEcMOoDOvEgOnDLMVqzD1pbUHl3lhsWOwNAowSZOWNvVQdfcmNTMQwYfPQKbPaE3PUACmBn8uMaj2mYgHG0YdeIBFBvPA9k9UwCVyuGhB64VsN5frF4MRL4BOYeb65JY84+GfDm6dAW1fqe97hwU6Tmy3VIbXr7IU2KRQvjbEo9U5fkvyT58OpNKBMFIop9wPwtwwrUb9MFgaUlWKzZc0GqCPWBuuGX1aO54rASqJ3PEOf2njvwuL8RegiQ+L/ZWKOdtGdpM0s3Kg== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: f3552ee0-5f4a-426c-966f-08d85dd5984c X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:24.2605 (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: 4ZvhtWVdMLeqC94sxiCDePKRt45ByXM6Z0hmJX83Os86kwHsk908cw0Mw7qskuVo X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.243.117; envelope-from=alxndr@bu.edu; helo=NAM12-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:42 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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 , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This patch compares TYPE_PCI_DEVICE objects against the user-provided matching pattern. If there is a match, we use some hacks and leverage QOS to map each possible BAR for that device. Now fuzzed inputs might be converted to pci_read/write commands which target specific. This means that we can fuzz a particular device's PCI configuration space, Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny --- tests/qtest/fuzz/general_fuzz.c | 81 +++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/tests/qtest/fuzz/general_fuzz.c b/tests/qtest/fuzz/general_fuzz.c index bf75b215ca..7c4c1398a7 100644 --- a/tests/qtest/fuzz/general_fuzz.c +++ b/tests/qtest/fuzz/general_fuzz.c @@ -24,6 +24,7 @@ #include "exec/ramblock.h" #include "exec/address-spaces.h" #include "hw/qdev-core.h" +#include "hw/pci/pci.h" /* * SEPARATOR is used to separate "operations" in the fuzz input @@ -35,12 +36,17 @@ enum cmds { OP_OUT, OP_READ, OP_WRITE, + OP_PCI_READ, + OP_PCI_WRITE, OP_CLOCK_STEP, }; #define DEFAULT_TIMEOUT_US 100000 #define USEC_IN_SEC 100000000 +#define PCI_HOST_BRIDGE_CFG 0xcf8 +#define PCI_HOST_BRIDGE_DATA 0xcfc + typedef struct { ram_addr_t addr; ram_addr_t size; /* The number of bytes until the end of the I/O region */ @@ -55,6 +61,7 @@ static bool qtest_log_enabled; * user for fuzzing. */ static GHashTable *fuzzable_memoryregions; +static GPtrArray *fuzzable_pci_devices; struct get_io_cb_info { int index; @@ -280,6 +287,65 @@ static void op_write(QTestState *s, const unsigned char * data, size_t len) break; } } +static void op_pci_read(QTestState *s, const unsigned char * data, size_t len) +{ + enum Sizes {Byte, Word, Long, end_sizes}; + struct { + uint8_t size; + uint8_t base; + uint8_t offset; + } a; + if (len < sizeof(a) || fuzzable_pci_devices->len == 0) { + return; + } + memcpy(&a, data, sizeof(a)); + PCIDevice *dev = g_ptr_array_index(fuzzable_pci_devices, + a.base % fuzzable_pci_devices->len); + int devfn = dev->devfn; + qtest_outl(s, PCI_HOST_BRIDGE_CFG, (1U << 31) | (devfn << 8) | a.offset); + switch (a.size %= end_sizes) { + case Byte: + qtest_inb(s, PCI_HOST_BRIDGE_DATA); + break; + case Word: + qtest_inw(s, PCI_HOST_BRIDGE_DATA); + break; + case Long: + qtest_inl(s, PCI_HOST_BRIDGE_DATA); + break; + } +} + +static void op_pci_write(QTestState *s, const unsigned char * data, size_t len) +{ + enum Sizes {Byte, Word, Long, end_sizes}; + struct { + uint8_t size; + uint8_t base; + uint8_t offset; + uint32_t value; + } a; + if (len < sizeof(a) || fuzzable_pci_devices->len == 0) { + return; + } + memcpy(&a, data, sizeof(a)); + PCIDevice *dev = g_ptr_array_index(fuzzable_pci_devices, + a.base % fuzzable_pci_devices->len); + int devfn = dev->devfn; + qtest_outl(s, PCI_HOST_BRIDGE_CFG, (1U << 31) | (devfn << 8) | a.offset); + switch (a.size %= end_sizes) { + case Byte: + qtest_outb(s, PCI_HOST_BRIDGE_DATA, a.value & 0xFF); + break; + case Word: + qtest_outw(s, PCI_HOST_BRIDGE_DATA, a.value & 0xFFFF); + break; + case Long: + qtest_outl(s, PCI_HOST_BRIDGE_DATA, a.value & 0xFFFFFFFF); + break; + } +} + static void op_clock_step(QTestState *s, const unsigned char *data, size_t len) { qtest_clock_step_next(s); @@ -324,6 +390,8 @@ static void general_fuzz(QTestState *s, const unsigned char *Data, size_t Size) [OP_OUT] = op_out, [OP_READ] = op_read, [OP_WRITE] = op_write, + [OP_PCI_READ] = op_pci_read, + [OP_PCI_WRITE] = op_pci_write, [OP_CLOCK_STEP] = op_clock_step, }; const unsigned char *cmd = Data; @@ -415,6 +483,18 @@ static int locate_fuzz_objects(Object *child, void *opaque) /* Find and save ptrs to any child MemoryRegions */ object_child_foreach_recursive(child, locate_fuzz_memory_regions, NULL); + /* + * We matched an object. If its a PCI device, store a pointer to it so + * we can map BARs and fuzz its config space. + */ + if (object_dynamic_cast(OBJECT(child), TYPE_PCI_DEVICE)) { + /* + * Don't want duplicate pointers to the same PCIDevice, so remove + * copies of the pointer, before adding it. + */ + g_ptr_array_remove_fast(fuzzable_pci_devices, PCI_DEVICE(child)); + g_ptr_array_add(fuzzable_pci_devices, PCI_DEVICE(child)); + } } else if (object_dynamic_cast(OBJECT(child), TYPE_MEMORY_REGION)) { if (g_pattern_match_simple(pattern, object_get_canonical_path_component(child))) { @@ -448,6 +528,7 @@ static void general_pre_fuzz(QTestState *s) } fuzzable_memoryregions = g_hash_table_new(NULL, NULL); + fuzzable_pci_devices = g_ptr_array_new(); result = g_strsplit(getenv("QEMU_FUZZ_OBJECTS"), " ", -1); for (int i = 0; result[i] != NULL; i++) { From patchwork Mon Sep 21 02:24:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 304890 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=-12.7 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 2FB0BC43465 for ; Mon, 21 Sep 2020 02:27:42 +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 9B35C2078E for ; Mon, 21 Sep 2020 02:27:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="Wa7/x5E6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9B35C2078E 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]:40610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBYK-000532-Ge for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:27:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWU-00039P-71 for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:46 -0400 Received: from mail-dm6nam10on2102.outbound.protection.outlook.com ([40.107.93.102]:19201 helo=NAM10-DM6-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 1kKBWS-0000aa-3c for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hS/lQIHohVd4qF4WUykCZdR2kSqq08+4tM1COIwpXhuk93KpkP/ixn3t01Lerh3pRfISHCQJRvu89prJlcmGwu9Idu1txTHvcAAxSJbYy7PQ24ZvoMWGnDvVWQgmXMXgPtP5yMoma2ry+tGKXPWQxlzad5UUvpbm+APKV2/EjseVFTkSaxBdA8YJxYsg7QbdkEVvZCnoTBgNa0N0x0/GH2dCR+bNI68UCetnW/ciESfghKgeqCa17QcIoVqb1Hk4RvEt2WH2Ct3zLPOxAzmSqY3C3BuPAW2Bm7mlN4tOJXGEbJ0q7jVMmcKzcegLRmO4bAfnZAE7lgLUWKijt4Zsmg== 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=2CI5T1yx+mOXY4V4y2IXPoMd/ij1V2jlSmbIJC+q3xA=; b=VTnDhp/OJv3onTeOseBlMxFefmIfskgFKqLOapjN5+jSxXjfedcdP5lYWBPm1+rZD+ifi/K1uL0+hdl02wQB0pvp9Y2cc3QPnsDdDnxt/XY6dHAyRqSi9hJYYKk5tH6CEtJ0QziiHW4qiY5VPSj0a2Rc5QCy2idC4DiZD8lXTLfrVqIfRpcD70pg2yVt4odSdhwAJ/a4+JcG5G8voF1uxTzorw0n5qymdEpnxRXz5OLJ8MtDd47o0IiiuXCrRbzlbK3HFgnlMvk8j/j3FBJNtlvlUEB6dcdKrFXNTkxi1iM4uqGqvF37Nn66GTVpqKnlPqSqt28mg44mxTqNyZAowA== 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=2CI5T1yx+mOXY4V4y2IXPoMd/ij1V2jlSmbIJC+q3xA=; b=Wa7/x5E6yAOnnKwb/IxRQjTeNXeX85Sbdqru//3Q7JTdp+a1JIDOZBZQZuUYB9f/A3/4VfRR+R8haXRHDKbhqoP//PwezEZThniqnKCaYXcg1MwAvvjmLux6sgaz+OMkaJzFAjI4a4yGY0Ili+eX2YAC2vH3PKCA1s0fiRVdPhg= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:26 +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.3391.024; Mon, 21 Sep 2020 02:25:26 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 04/16] fuzz: Add DMA support to the generic-fuzzer Date: Sun, 20 Sep 2020 22:24:54 -0400 Message-Id: <20200921022506.873303-5-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:24 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3d9417e2-470f-41c1-d003-08d85dd59938 X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:67; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WwV4Trz7A5m0It+5nhOY7PbYeKN8QVBQZbu4TjAPDgrSfnSiKFvPoO+QGy1On/OTTn2ZnbXOZLMu5ditnm6ai1oum/OkhgH9EDEaWW5bQSWyVyZHIDemYWsSuuyg+8SZ4weYc7bJ5tZ/DdYOIpSnHTFI/58+QaAChugh9hjFM6RkZN5zLsu6xes4rFlf7dLfZYvQVsxsQqIGVxIqQVDcRttPls+yfh4N/tc68Bmm7VPAtb6eM8Pr8xFGy7ALIGFkKjPGDupMbY+4VmMQu2CVB1jbTjdDGkzf/1P/cRaTMYfbV7jJ3iTvkIsSKKg7Z5gM9eA5/4AZ0G6XE98HVOKxYIKPacuHOu+sLk7TbIvueSGiDvXH/pvKMmSyOYY6F7oUNrRdeKMgkqoafRDR6cODjc042MXTM69ayZ676aDWBP0= 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(83380400001)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003)(41533002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: we541XiQNjdNv0pK9DUK6yrcJH8i6yFVuoSkVDieHKBqSeOaTGKzQW23ecEfjgkOo9papIumlpoW+HiuUOCu81/PicI98NmLX6ubU/azsoNsQAdKxW6Ueg5m+WyOpkJ+vvgDHIizyoNx+056EqvzWzibJSpagnuLmPYyZjaCEbcac9q2YN+PdkOLsaBSskZhQ/Pqcj0Fqx2gcdK8rgwX9gyfCKMGNCEQ9QUwGew7bpPjZ1NZ9coVExyiFYKJNrN7Z2GZhF7lu0TK1bAYftSJ57XDqFoTnCnRKJvtoIfQBOymwAGD/pHdazfwLQK4k21cJgc6gSmFe6fO47Wmmay+5+oR3Xsc3p7JJlVtABqSEhrrbD5ESZGDlFn7F0YF2WPAVeYkPrja5YGkOB1zS9JyeBfU8zurEJk5sgXP521HXcmRDnsGRi8QHlBHIDvTWO1hjDJwQbNQI5DbrmI3e67t52UP/2RNt4ryre6nN0JFca/TM1dZQLaaGNsTUMBWj6NiWVPPVc8LHkRtkx0yT6EpgdErz/t9gbyv955XtBODNwlCpFjz+F8AaqIJqBgcJZWuIAy7Me/XOOX5ZMhI5gm0WMu37Gjsv0rQFXYbIiIdkVz/Z1PiAq9iW+9bcKNBDKIAkYxWJIurXPDP6zf7+Vt+Nw== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 3d9417e2-470f-41c1-d003-08d85dd59938 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:25.7357 (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: s6/dQm6B8yZwTgXa2shdQMYoIi6uudwnRS+oQtHhz1eQgOiCfgPPhO+rts7n9aTn X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.93.102; envelope-from=alxndr@bu.edu; helo=NAM10-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:33 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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 , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" When a virtual-device tries to access some buffer in memory over DMA, we add call-backs into the fuzzer(next commit). The fuzzer checks verifies that the DMA request maps to a physical RAM address and fills the memory with fuzzer-provided data. The patterns that we use to fill this memory are specified using add_dma_pattern and clear_dma_patterns operations. Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny --- tests/qtest/fuzz/general_fuzz.c | 178 ++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) diff --git a/tests/qtest/fuzz/general_fuzz.c b/tests/qtest/fuzz/general_fuzz.c index 7c4c1398a7..5e42504821 100644 --- a/tests/qtest/fuzz/general_fuzz.c +++ b/tests/qtest/fuzz/general_fuzz.c @@ -25,6 +25,7 @@ #include "exec/address-spaces.h" #include "hw/qdev-core.h" #include "hw/pci/pci.h" +#include "hw/boards.h" /* * SEPARATOR is used to separate "operations" in the fuzz input @@ -38,12 +39,16 @@ enum cmds { OP_WRITE, OP_PCI_READ, OP_PCI_WRITE, + OP_ADD_DMA_PATTERN, + OP_CLEAR_DMA_PATTERNS, OP_CLOCK_STEP, }; #define DEFAULT_TIMEOUT_US 100000 #define USEC_IN_SEC 100000000 +#define MAX_DMA_FILL_SIZE 0x10000 + #define PCI_HOST_BRIDGE_CFG 0xcf8 #define PCI_HOST_BRIDGE_DATA 0xcfc @@ -56,6 +61,24 @@ static useconds_t timeout = 100000; static bool qtest_log_enabled; +/* + * A pattern used to populate a DMA region or perform a memwrite. This is + * useful for e.g. populating tables of unique addresses. + * Example {.index = 1; .stride = 2; .len = 3; .data = "\x00\x01\x02"} + * Renders as: 00 01 02 00 03 02 00 05 02 00 07 02 ... + */ +typedef struct { + uint8_t index; /* Index of a byte to increment by stride */ + uint8_t stride; /* Increment each index'th byte by this amount */ + size_t len; + const uint8_t *data; +} pattern; + +/* Avoid filling the same DMA region between MMIO/PIO commands ? */ +static bool avoid_double_fetches; + +static QTestState *qts_global; /* Need a global for the DMA callback */ + /* * List of memory regions that are children of QOM objects specified by the * user for fuzzing. @@ -84,6 +107,117 @@ static int get_io_address_cb(ram_addr_t start, ram_addr_t size, return 0; } +/* + * List of dma regions populated since the last fuzzing command. Used to ensure + * that we only write to each DMA address once, to avoid race conditions when + * building reproducers. + */ +static GArray *dma_regions; + +static GArray *dma_patterns; +static int dma_pattern_index; + +void fuzz_dma_read_cb(size_t addr, size_t len, MemoryRegion *mr, bool is_write); + +/* + * Allocate a block of memory and populate it with a pattern. + */ +static void *pattern_alloc(pattern p, size_t len) +{ + int i; + uint8_t *buf = g_malloc(len); + uint8_t sum = 0; + + for (i = 0; i < len; ++i) { + buf[i] = p.data[i % p.len]; + if ((i % p.len) == p.index) { + buf[i] += sum; + sum += p.stride; + } + } + return buf; +} + +/* + * Call-back for functions that perform DMA reads from guest memory. Confirm + * that the region has not already been populated since the last loop in + * general_fuzz(), avoiding potential race-conditions, which we don't have + * a good way for reproducing right now. + */ +void fuzz_dma_read_cb(size_t addr, size_t len, MemoryRegion *mr, bool is_write) +{ + /* Are we in the general-fuzzer or are we using another fuzz-target? */ + if (!qts_global) { + return; + } + + /* + * Return immediately if: + * - We have no DMA patterns defined + * - The length of the DMA read request is zero + * - The DMA read is hitting an MR other than the machine's main RAM + * - The DMA request is not a read (what happens for a address_space_map + * with is_write=True? Can the device use the same pointer to do reads?) + * - The DMA request hits past the bounds of our RAM + */ + if (dma_patterns->len == 0 + || len == 0 + || mr != MACHINE(qdev_get_machine())->ram + || is_write + || addr > current_machine->ram_size) { + return; + } + + /* + * If we overlap with any existing dma_regions, split the range and only + * populate the non-overlapping parts. + */ + address_range region; + for (int i = 0; i < dma_regions->len && avoid_double_fetches; ++i) { + region = g_array_index(dma_regions, address_range, i); + if (addr < region.addr + region.size && addr + len > region.addr) { + if (addr < region.addr) { + fuzz_dma_read_cb(addr, region.addr - addr, mr, is_write); + } + if (addr + len > region.addr + region.size) { + fuzz_dma_read_cb(region.addr + region.size, + addr + len - (region.addr + region.size), mr, is_write); + } + return; + } + } + + /* Cap the length of the DMA access to something reasonable */ + len = MIN(len, MAX_DMA_FILL_SIZE); + + address_range ar = {addr, len}; + g_array_append_val(dma_regions, ar); + pattern p = g_array_index(dma_patterns, pattern, dma_pattern_index); + void *buf = pattern_alloc(p, ar.size); + if (qtest_log_enabled) { + /* + * With QTEST_LOG, use a normal, slow QTest memwrite. Prefix the log + * that will be written by qtest.c with a DMA tag, so we can reorder + * the resulting QTest trace so the DMA fills precede the last PIO/MMIO + * command. + */ + fprintf(stderr, "[DMA] "); + fflush(stderr); + qtest_memwrite(qts_global, ar.addr, buf, ar.size); + } else { + /* + * Populate the region using address_space_write_rom to avoid writing to + * any IO MemoryRegions + */ + address_space_write_rom(first_cpu->as, ar.addr, MEMTXATTRS_UNSPECIFIED, + buf, ar.size); + } + g_free(buf); + + /* Increment the index of the pattern for the next DMA access */ + dma_pattern_index = (dma_pattern_index + 1) % dma_patterns->len; +} + /* * Here we want to convert a fuzzer-provided [io-region-index, offset] to * a physical address. To do this, we iterate over all of the matched @@ -346,6 +480,35 @@ static void op_pci_write(QTestState *s, const unsigned char * data, size_t len) } } +static void op_add_dma_pattern(QTestState *s, + const unsigned char *data, size_t len) +{ + struct { + /* + * index and stride can be used to increment the index-th byte of the + * pattern by the value stride, for each loop of the pattern. + */ + uint8_t index; + uint8_t stride; + } a; + + if (len < sizeof(a) + 1) { + return; + } + memcpy(&a, data, sizeof(a)); + pattern p = {a.index, a.stride, len - sizeof(a), data + sizeof(a)}; + p.index = a.index % p.len; + g_array_append_val(dma_patterns, p); + return; +} + +static void op_clear_dma_patterns(QTestState *s, + const unsigned char *data, size_t len) +{ + g_array_set_size(dma_patterns, 0); + dma_pattern_index = 0; +} + static void op_clock_step(QTestState *s, const unsigned char *data, size_t len) { qtest_clock_step_next(s); @@ -392,6 +555,8 @@ static void general_fuzz(QTestState *s, const unsigned char *Data, size_t Size) [OP_WRITE] = op_write, [OP_PCI_READ] = op_pci_read, [OP_PCI_WRITE] = op_pci_write, + [OP_ADD_DMA_PATTERN] = op_add_dma_pattern, + [OP_CLEAR_DMA_PATTERNS] = op_clear_dma_patterns, [OP_CLOCK_STEP] = op_clock_step, }; const unsigned char *cmd = Data; @@ -421,6 +586,8 @@ static void general_fuzz(QTestState *s, const unsigned char *Data, size_t Size) setitimer(ITIMER_VIRTUAL, &timer, NULL); } + op_clear_dma_patterns(s, NULL, 0); + while (cmd && Size) { /* Get the length until the next command or end of input */ nextcmd = memmem(cmd, Size, SEPARATOR, strlen(SEPARATOR)); @@ -437,6 +604,7 @@ static void general_fuzz(QTestState *s, const unsigned char *Data, size_t Size) /* Advance to the next command */ cmd = nextcmd ? nextcmd + sizeof(SEPARATOR) - 1 : nextcmd; Size = Size - (cmd_len + sizeof(SEPARATOR) - 1); + g_array_set_size(dma_regions, 0); } _Exit(0); } else { @@ -451,6 +619,9 @@ static void usage(void) printf("QEMU_FUZZ_ARGS= the command line arguments passed to qemu\n"); printf("QEMU_FUZZ_OBJECTS= " "a space separated list of QOM type names for objects to fuzz\n"); + printf("Optionally: QEMU_AVOID_DOUBLE_FETCH= " + "Try to avoid racy DMA double fetch bugs? %d by default\n", + avoid_double_fetches); printf("Optionally: QEMU_FUZZ_TIMEOUT= Specify a custom timeout (us). " "0 to disable. %d by default\n", timeout); exit(0); @@ -523,9 +694,16 @@ static void general_pre_fuzz(QTestState *s) if (getenv("QTEST_LOG")) { qtest_log_enabled = 1; } + if (getenv("QEMU_AVOID_DOUBLE_FETCH")) { + avoid_double_fetches = 1; + } if (getenv("QEMU_FUZZ_TIMEOUT")) { timeout = g_ascii_strtoll(getenv("QEMU_FUZZ_TIMEOUT"), NULL, 0); } + qts_global = s; + + dma_regions = g_array_new(false, false, sizeof(address_range)); + dma_patterns = g_array_new(false, false, sizeof(pattern)); fuzzable_memoryregions = g_hash_table_new(NULL, NULL); fuzzable_pci_devices = g_ptr_array_new(); From patchwork Mon Sep 21 02:24:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 273215 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=-12.7 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 C98D6C43463 for ; Mon, 21 Sep 2020 02:32:36 +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 5736B2078E for ; Mon, 21 Sep 2020 02:32:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="4Fbg1oiK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5736B2078E 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]:57530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBd5-0003kM-DF for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:32:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWW-0003BX-8o for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:48 -0400 Received: from mail-dm6nam12on2117.outbound.protection.outlook.com ([40.107.243.117]:28256 helo=NAM12-DM6-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 1kKBWU-0000b7-5B for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FA7Foc+S48w1lnh9WPhKNGHDvpJpgicLBbF//5Vse41xPpibYTfaZ/KJBOR0tweaxSdKIE7K79PyGIoJgGWxEgx/3wfvzOR2PWAuRFyrw0+jjpNjvLABhDF6MvyMob/CxJHVhVtNpFtZ3wkXQKwdGYDX0ZGH30Xpivl9O4XvM+HFtculGyrZlsIpD2+oiqzEqW0cBF1QW1NEBXnNZ9SE+kwqWU1x8Ikim6/EHAGMOOU2ArflkeGyHdqLJZbHH88yjMIJV5xf6zfGz8qLM28ctJVnPjI8QQaOISYvalPpGUegCeA+Aa2GgWjJfXBpqA3Qkzu2yZg8XT3DSMsBmg2NOw== 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=P7ascJrHgiZuqYmVrSZhWk6zqYLMFU6jGYbOISteTtk=; b=BBPZTdSwzEgPcs3gR/7NV/mgNthA23ag1sRp07mNOAyrMDx09wVUmyXj3+UUPLTya45Qd955JpBw49EsGMcQX1YLGF2479BTEsGV+21toUS4xyNHIvDGGBVFdNlY70Wp91I/ElXKbo9zDY8goOSBSIdHkJ52OEjn1ByqAkzG3t6ehITgYwfyx022En4M0rIxUvUZI0bZTK9PkW46mMA3oPkltvRaYKL/OgnommjFu8VQstPfgHaBybHLR84xio9iZB5aV7FlJr2l4c3JGC+mI1R13WU96nWszR9/9ilHaI0SRkADaOfWTZuFNyw9kNksiK1SMYljBNDe3aTSx/fjQw== 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=P7ascJrHgiZuqYmVrSZhWk6zqYLMFU6jGYbOISteTtk=; b=4Fbg1oiKIrD0T8L4mj+buNKoRtDK4l+XBxx7irtQYiHV0W+FtUaP6shzAc4Br8LUXAfDJDYSgil424/s4uBCy3hMzHA9RzADQv3nSNPBxndw8eMwETnUb58oERoUwjNPCit+tZl5vKNxwWEX5WZX94eEd7DG0QszfhPWhBkEPwE= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:29 +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.3391.024; Mon, 21 Sep 2020 02:25:29 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 05/16] fuzz: Declare DMA Read callback function Date: Sun, 20 Sep 2020 22:24:55 -0400 Message-Id: <20200921022506.873303-6-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:27 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8d30576a-3a58-486a-2aab-08d85dd59abc X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2512; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NEQcMl6gAUkCxexlr/imay7xNXE4rRVvfOAef3DMZq4j+sDIX78iC839LnnVcP9P3jS7F1dBt3ZKHAWznupPF9rVCdncFTptUsmzuXIwDnYv3zyBiA6euA3Oex/YiYHu2AyxBTrXBc27oxlY5f8INgaTG+DBbdV5JvjqjNjO4dhqdXYt9lkYU7cNowZo4IX6wySc5l0SNoIOI2StHkSfPEABfMzD0pJQmO601GO9+aMKoZ0kmSokM60YncttNoJ+GHCXTRlmF/9QDs2knchA0I0VLxFj3d0BWYnasX6Tqdye49/oidP/iIWUSQl7N33gcCYzf+W9EG/7Ehtz6dMwH1AxROUZfvlma1syZ2VZEfuRAHdyRBgd7FiRZCGNyYBA 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: ywtz921CfNzyiQmCiuy04z0kohhXQOyPKrM5b7qTovrciwr40SuY/5tlFjglXmcySV2cBDqsaoe8m3ahVTFF6vca8G7dq3qYr549PFSrwitVmvDhzN+9GzXjrzCTNExW6V/9/+nIsjdsDJAaj8FuSzDTWvAAQjgTEpjNFmIZwZmuY893MFhGwOpFZSQPhMjBmuPwnoaAMk8rwAC1RVrdkay9sGoRDqZDLIMGxYVo7PPgxqVEKJljMZe+wYqFEOPs0tU6wFMG5aY9NizP8HQ+iwTpk8QVnlAKqe//ewnaLjkxYGztO14R+qm4qj4mt9hR9jmggqqwdI6w/S3XiCQVp1PytzWNWN7BKgMrXRsQGTAYhmZ9uhOK3FCV2kXnU7CmUnp9eiAgOquZBmW5rMw/WCCeb17By0bxWcxraHUHyLudqM3AEJaeE5ppGbm0UStKJZ4dZEBAPYgIdgZQAaL2rkVZitt2gpLYo6ONXqkLlp7FwZX+Pmd99HeekRs+d/jHjbla5a13YvF5Ulwm41zUVtyTOd/gh7+Cz9wFvH0iD39ht3iJJGhDP09CLUxt8+/G07MfH2D8SFSU2qnWYZsdQNofJYrmllAY7TaCU5rFBlvzv9XCL+MZ8lWRHyDDziFmUopkpXmpYBQXf2vLGFda6g== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 8d30576a-3a58-486a-2aab-08d85dd59abc X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:28.8719 (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: f6UA2K/WFEZIEGQxw7xz/j6kplF7GjOtcR7PtIQIUz7PZWxtcADjyV9gJKaDFr5x X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.243.117; envelope-from=alxndr@bu.edu; helo=NAM12-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:42 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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: Alexander Bulekov , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This patch declares the fuzz_dma_read_cb function and uses the preprocessor and linker(weak symbols) to handle these cases: When we build softmmu/all with --enable-fuzzing, there should be no strong symbol defined for fuzz_dma_read_cb, and we link against a weak stub function. When we build softmmu/fuzz with --enable-fuzzing, we link against the strong symbol in general_fuzz.c When we build softmmu/all without --enable-fuzzing, fuzz_dma_read_cb is an empty, inlined function. As long as we don't call any other functions when building the arguments, there should be no overhead. Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny --- include/exec/memory.h | 15 +++++++++++++++ softmmu/memory.c | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 975a90c871..d5511c7222 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -42,6 +42,21 @@ typedef struct IOMMUMemoryRegionClass IOMMUMemoryRegionClass; DECLARE_OBJ_CHECKERS(IOMMUMemoryRegion, IOMMUMemoryRegionClass, IOMMU_MEMORY_REGION, TYPE_IOMMU_MEMORY_REGION) +#ifdef CONFIG_FUZZ +void fuzz_dma_read_cb(size_t addr, + size_t len, + MemoryRegion *mr, + bool is_write); +#else +static inline void fuzz_dma_read_cb(size_t addr, + size_t len, + MemoryRegion *mr, + bool is_write) +{ + /* Do Nothing */ +} +#endif + extern bool global_dirty_log; typedef struct MemoryRegionOps MemoryRegionOps; diff --git a/softmmu/memory.c b/softmmu/memory.c index 9db5fbe43a..24e59593ca 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -3232,6 +3232,19 @@ void memory_region_init_rom_device(MemoryRegion *mr, vmstate_register_ram(mr, owner_dev); } +/* + * Support softmmu builds with CONFIG_FUZZ using a weak symbol and a stub for + * the fuzz_dma_read_cb callback + */ +#ifdef CONFIG_FUZZ +void __attribute__((weak)) fuzz_dma_read_cb(size_t addr, + size_t len, + MemoryRegion *mr, + bool is_write) +{ +} +#endif + static const TypeInfo memory_region_info = { .parent = TYPE_OBJECT, .name = TYPE_MEMORY_REGION, From patchwork Mon Sep 21 02:24:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 273218 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=-12.7 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 B4176C43463 for ; Mon, 21 Sep 2020 02:30:19 +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 0BB0B2078E for ; Mon, 21 Sep 2020 02:30:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="pUyDt6pb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0BB0B2078E 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]:48266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBar-0008CD-Rm for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:30:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWW-0003BQ-8M for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:48 -0400 Received: from mail-dm6nam10on2102.outbound.protection.outlook.com ([40.107.93.102]:19201 helo=NAM10-DM6-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 1kKBWU-0000aa-Eo for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bLnaaMTz+z8c0ITHHZLVuKac4tlscjKYAetommiIPRnWmrnoD6WSBs1rfGpk8FABNvuBgtKyq+Ld74Ds9GW4H3mf22AmqPC7huGGxJSJIvZ5wWEPDuBD7MdNq0vp+boSxth7jGS31qVF2IRsOV5FBDPslpLqSTUtAKTsNlRz88iXbwsTFXClu1YkEiNSR5l16PERX5YQ+Anxw8xps/N0eXss3rWYK/RoyJuYPHz6hnoVQSJ92otdLgtIbBisI7lz01UU9eXz3m6R7iRw/fsy8Ej5lSabtzmVFetQya9jSwTTBtKNpPaSAY3gUrUbMV/pCyfeiRD18H3g2uEnVPWm3g== 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=gfrylThJTtmuehPo+e7uWHAccet6AAc461eseC9qVek=; b=ObVxnE6yoaCrWJqZWJDr7wW/IIfOnvtIk1sTLlnv684ZlwI0KcAuVgvQ2QmsDMymPMKDahOACGb7z4NnHrK6Ace2kn7+YMpFKxsxWUQVheYpVr7wzIOjKmUQgTDGqwBaxfxLkSwgnKRF0TfAomVaHKwu/ZKTobMEDxl7q/RFojyI99QYOd/5wwbWfPHwdxdd5ewc3pu+A1wrXqfYru6es0r7yCjWvOA0a8z7U1IPUhnTbUBXJ7wuYn91n6NjIyv3T2jHQPLporEOC7xG38pfPwmJuwIGrxe7guM5NaPdta98rA995MZaJNqRZSN6mruIBqV7/LAUlKEU8BqI06WI0Q== 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=gfrylThJTtmuehPo+e7uWHAccet6AAc461eseC9qVek=; b=pUyDt6pbKr8OH01Z3KQHSq3jDAsIHbP+Ivm65FEu3bP9WRNgwI/q8DLyOKHqGLRnBVSoWp4v3AkQfGprP8J2zD0lIX97HFSMzj4lAZ/nPJiMJZ3BvI7ce4nT5FEG3kihTX0EJCGQHUOykMTO9uKXj0uKmINEZVF6W3+SQ7OOiNY= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:30 +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.3391.024; Mon, 21 Sep 2020 02:25:30 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 06/16] fuzz: Add fuzzer callbacks to DMA-read functions Date: Sun, 20 Sep 2020 22:24:56 -0400 Message-Id: <20200921022506.873303-7-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:30 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0fe3a0a8-d231-4fac-67f9-08d85dd59c6f X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:308; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: thJmUY3DEfo/V8d2zJlQNGxBF8K7/CEu8hlg0hbFvxFcrPI5+0vjnPLoQiwwnzIltXLgEpT4FiY033gIEOLLjt6u5FC5+g0xWi+Tvt3obuYeuL3519e12GY/IzpfIVwXxzjdRr2+3f/Tk3p3rSivdCLCY07TNwgcIPmHPcYsAabGYLtgl45GyTxWDFFVX4eNjqfBn795Zg9o7LBZXzTj1fg7SePLxrJ9vy4T6H4UUNMoiqEGstP+FXpSHdq6IAOAuNWNH3WsU5hDZcpOXVvzlndnYTh43CcTHJJ90Lyd3rW5MBm7xkw1KRXblHMtZCw08V0/tMRs6dJVCAjZ2XCllEsUR4mRfdYpBYpy0g+dYgP7PJLSzAdZMcE5V5InnE3X 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(83380400001)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: IrPFgnain0XVZZawOF13UDr+ieY8DMCNA+1gyHU43IMknwodC9Y/XGWd9tKDG+bDZ0rohs6I6goUdRM+xLIwWYoubGNqAE3ofAEN2pV6JRwiKb+yKYijHQx+I7eVjED2VlgLhIueuwVGptBeDw6gLZnOBPAd9o/BR05wgDPTQJe70QMtVmsdL9WPlz5zvRPxuZyZks8sSB5E//QCjYWsGX3N74hDDAeAjrFAoJH1hR53Ju7ryZQcFDPSH9PpI1FUltMBhi0Np7urVUTSk5Z6HXhII/xFxlcvw4VocRqMhlsjjFQ0mXMVjUiFac9zgRT4L3nlp8Tczld6w57w3/+KCPfGcoSBIrNYkoa1zJf6W1NNHpTlNB4E/OqeKoA+WwSABzympid+YZaYyoYPqPupXdyOrxEyOZ0ZR2XfoE//N+9PhLNWpKztVk96rYD+B4Td1cMD+UaIg4N7e8j56gsTXWXct4anIbR/VRAeDXoaDedHM3nLQvfxwbMiN6cdtk2zx+KxM5keXhARHQkAaV43pOzC0+GGKPNTr5+cH5ktyVtP3kiRS+wNvbCfVixhsqPRYCDbAItakGZarH0rGSR+88B+1KpoO96ervPOIqQ2C3ZeV5v9ESmvFX3sZGuNW/fzs2Ra9Y4B5DyTZosiDhaB3g== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 0fe3a0a8-d231-4fac-67f9-08d85dd59c6f X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:30.8718 (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: n5MvHK4bws795yLuz/bem++TrsRCd3izk3ZW405B8cHcXq/5KobeOy1U7dKkG5f+ X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.93.102; envelope-from=alxndr@bu.edu; helo=NAM10-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:33 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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: Alexander Bulekov , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com, Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We should be careful to not call any functions besides fuzz_dma_read_cb. Without --enable-fuzzing, fuzz_dma_read_cb is an empty inlined function. Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny --- exec.c | 2 ++ include/exec/memory.h | 1 + include/exec/memory_ldst_cached.h.inc | 3 +++ memory_ldst.c.inc | 4 ++++ softmmu/memory.c | 1 + 5 files changed, 11 insertions(+) diff --git a/exec.c b/exec.c index e34b602bdf..5803e16be2 100644 --- a/exec.c +++ b/exec.c @@ -3242,6 +3242,7 @@ MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr, stn_he_p(buf, l, val); } else { /* RAM case */ + fuzz_dma_read_cb(addr, len, mr, false); ram_ptr = qemu_ram_ptr_length(mr->ram_block, addr1, &l, false); memcpy(buf, ram_ptr, l); } @@ -3602,6 +3603,7 @@ void *address_space_map(AddressSpace *as, memory_region_ref(mr); *plen = flatview_extend_translation(fv, addr, len, mr, xlat, l, is_write, attrs); + fuzz_dma_read_cb(addr, *plen, mr, is_write); ptr = qemu_ram_ptr_length(mr->ram_block, xlat, plen, true); return ptr; diff --git a/include/exec/memory.h b/include/exec/memory.h index d5511c7222..988c2866cd 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2444,6 +2444,7 @@ address_space_read_cached(MemoryRegionCache *cache, hwaddr addr, void *buf, hwaddr len) { assert(addr < cache->len && len <= cache->len - addr); + fuzz_dma_read_cb(cache->xlat + addr, len, cache->mrs.mr, false); if (likely(cache->ptr)) { memcpy(buf, cache->ptr + addr, len); return MEMTX_OK; diff --git a/include/exec/memory_ldst_cached.h.inc b/include/exec/memory_ldst_cached.h.inc index fd4bbb40e7..aff574039f 100644 --- a/include/exec/memory_ldst_cached.h.inc +++ b/include/exec/memory_ldst_cached.h.inc @@ -28,6 +28,7 @@ static inline uint32_t ADDRESS_SPACE_LD_CACHED(l)(MemoryRegionCache *cache, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { assert(addr < cache->len && 4 <= cache->len - addr); + fuzz_dma_read_cb(cache->xlat + addr, 4, cache->mrs.mr, false); if (likely(cache->ptr)) { return LD_P(l)(cache->ptr + addr); } else { @@ -39,6 +40,7 @@ static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { assert(addr < cache->len && 8 <= cache->len - addr); + fuzz_dma_read_cb(cache->xlat + addr, 8, cache->mrs.mr, false); if (likely(cache->ptr)) { return LD_P(q)(cache->ptr + addr); } else { @@ -50,6 +52,7 @@ static inline uint32_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { assert(addr < cache->len && 2 <= cache->len - addr); + fuzz_dma_read_cb(cache->xlat + addr, 2, cache->mrs.mr, false); if (likely(cache->ptr)) { return LD_P(uw)(cache->ptr + addr); } else { diff --git a/memory_ldst.c.inc b/memory_ldst.c.inc index c54aee4a95..8d45d2eeff 100644 --- a/memory_ldst.c.inc +++ b/memory_ldst.c.inc @@ -42,6 +42,7 @@ static inline uint32_t glue(address_space_ldl_internal, SUFFIX)(ARG1_DECL, MO_32 | devend_memop(endian), attrs); } else { /* RAM case */ + fuzz_dma_read_cb(addr, 4, mr, false); ptr = qemu_map_ram_ptr(mr->ram_block, addr1); switch (endian) { case DEVICE_LITTLE_ENDIAN: @@ -110,6 +111,7 @@ static inline uint64_t glue(address_space_ldq_internal, SUFFIX)(ARG1_DECL, MO_64 | devend_memop(endian), attrs); } else { /* RAM case */ + fuzz_dma_read_cb(addr, 8, mr, false); ptr = qemu_map_ram_ptr(mr->ram_block, addr1); switch (endian) { case DEVICE_LITTLE_ENDIAN: @@ -175,6 +177,7 @@ uint32_t glue(address_space_ldub, SUFFIX)(ARG1_DECL, r = memory_region_dispatch_read(mr, addr1, &val, MO_8, attrs); } else { /* RAM case */ + fuzz_dma_read_cb(addr, 1, mr, false); ptr = qemu_map_ram_ptr(mr->ram_block, addr1); val = ldub_p(ptr); r = MEMTX_OK; @@ -212,6 +215,7 @@ static inline uint32_t glue(address_space_lduw_internal, SUFFIX)(ARG1_DECL, MO_16 | devend_memop(endian), attrs); } else { /* RAM case */ + fuzz_dma_read_cb(addr, 2, mr, false); ptr = qemu_map_ram_ptr(mr->ram_block, addr1); switch (endian) { case DEVICE_LITTLE_ENDIAN: diff --git a/softmmu/memory.c b/softmmu/memory.c index 24e59593ca..1adce47836 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1414,6 +1414,7 @@ MemTxResult memory_region_dispatch_read(MemoryRegion *mr, unsigned size = memop_size(op); MemTxResult r; + fuzz_dma_read_cb(addr, size, mr, false); if (!memory_region_access_valid(mr, addr, size, false, attrs)) { *pval = unassigned_mem_read(mr, addr, size); return MEMTX_DECODE_ERROR; From patchwork Mon Sep 21 02:24:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 304885 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=-12.7 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 82DB9C43463 for ; Mon, 21 Sep 2020 02:34: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 24E3E2078E for ; Mon, 21 Sep 2020 02:34:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="fQNz25ae" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 24E3E2078E 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]:36474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBep-0006gI-7n for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:34:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41528) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWY-0003Dv-4N for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:52 -0400 Received: from mail-dm6nam12on2117.outbound.protection.outlook.com ([40.107.243.117]:28256 helo=NAM12-DM6-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 1kKBWW-0000b7-FF for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZaXw3FHAMIiLBVsHd9XcPfBilkuzAFngDHsSJ7tbeRDhMth4oWaNDZ3I7X5XjLqNrl2Bcqk2t9Y7GDPlaR1GaXCfxcaqPN/WCXEW0utUA+33RizOQZJFIJjjGhOaoM3SmfvCOsZPpw9hog7hy9P5XyT4vwUABlu7M4cgCNdtkd16WDcVoWHP8ghmp4+Q2uTUS9Cvtx/OrbDpJdqToQsagdykFATfn/z2SYhi/U8Ai9AbspY9Cy73pMx3zOAVqn9R4dDFj+oZM6HeqlxkobObPEpo4mCR0tHEafVRgPul0lQWD1dYXr9h4Gd9BhGEdKxHFuNXoq9zAALAvIVQwqy33w== 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=PdbSPAuFvXRPyMkLVUBpMuOypvkPeOU9Oeq5sCNBAbk=; b=deQhs1knGwJbGBd/5sb/+WX9ncMU0/TFBr0fnRTMeLufmhdivivOLxQsxt9zYPqlyrvWYblfuSMp6b0SIPz5gb/Wppxelovbm7owK2V/2xeJPYpZG6wae0ImirNnRZj3E/kjm5prncVCUVo8ffkBwbC1lIc6DG3PoDopY1iu5ZW6FZ1XhXOMICLqfjP3COWSQ++qX16mYVZpwccnCQMxjjJKfjpXKSxCkf9QcJezLw7LhI85zgU/e6UVHK4Pb+y2sM9+ItgDcUN6MmTH/7Cs9u0dhtPUgZJF2koC956QF56u/Se4NE5aamLOvByBthernjvLCnbBRFewqxuXEFlZmw== 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=PdbSPAuFvXRPyMkLVUBpMuOypvkPeOU9Oeq5sCNBAbk=; b=fQNz25ae0P54GHpZyYVnICm0iXj2ZOe4n+CuXGkJnVMRxcfDLof/MZ9hOGPVA06TNWhX/h3Rjv+3pVLSn80mZAtWkFrfylgQYgZWB8yynygtIyANR23ok2y/qoPwetkq8IPv3xxGiCtC9fAESFgDVWkPEnxAaKTZx7CJBGP3hYs= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:33 +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.3391.024; Mon, 21 Sep 2020 02:25:33 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 07/16] fuzz: Add support for custom crossover functions Date: Sun, 20 Sep 2020 22:24:57 -0400 Message-Id: <20200921022506.873303-8-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:32 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fb05b5b6-6720-4f55-b1bd-08d85dd59dab X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: 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: u8udvrnZXdrVnIbBcDrU9PLE8ouxdnXqKjrx4puMmCcuYB3Tefg4ti/RYxi6egtEGDPDo/zB1Ush2YbxaxBum9x49UrU8Ebrnr20Txik4jmIGrrvE1NWr2xY+1j8hSZN1V4gc+WrXTuoTwmevo/IC/NL9IH9xzxS0KOmrY/Zfuzo5fK6QqoT/rp9/52ePsgj8Tw/MOwGvnRb6P/98sRW0k5xWCaXxHgLsLWkFIxzzFSjpIg52/K/PSelzGcPTE+4BltFz9HRqGabJMD3EfU823H8bP2YVfOU3eY/AGMPqxgklpUCkW1nKljpXzilWEEAZI68QR9vaj8O2tTlYJE0X/DjbFjWw0rAF666yJaF/8OEclFSOTMqwiZyG3MTlHEC 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 67FAfmIlhjHiuCz9DqpabfoONeNpIPd0dydqmQ/oD/Ww3zLlKxBqLnKTUIkyV7GpGG1KlkeAyqxpcrMxOD7WdieGV0qTytgmEub8E3w+1aLSHaLGg5VtoRyo/OLVZPiQDW5n+FsPSJs9e8GOfkVjK5vjT9ClkzuXq+6rWS66tMV99jDucZ8xLbhupQ2aJu0Ag2f1HQrYAN8rDnKF26qa0L1ecEqDlcphnb5xF/e9qPquqmjQ9KqMSqVTssDVL/KWSVXpb9UEif1J0qRET/C5pBabwgQ9zKGa3gASox4Op7qI4fb5S6jXBXoo+bicPiHyGZeVDkxHl7324iPda3WEXFtADW1qIgMLrGeU2l4EMRn7hWF5GcbLCU6e+ZUzAzLvESSx8sgi+VH2LawAvOYlCKjMI1lZ52orJX6dlrYqzVjGypI68j+osKriI2bM+i2+2LIlNNqqgt95GKIRsCiPBl3ImJYIyhWqIK4IjxrbsLZzfYyV3CwGuTYEOfA4SgIp5aBg/Qs65aILWlWPpU2nwmQx8ISyAXrcBT0c7xtOyRtswudy9HygUH1CwgI49rkNNmL53rojQ9zsNUUY1pdJe6hTTvS03+/oTMy0f12z2HSKQSWERXbQOY76ZQAv8A8/I8NEMD3Lz47IUYG0Wp+Juw== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: fb05b5b6-6720-4f55-b1bd-08d85dd59dab X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:32.9926 (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: 6HdJbDxcRqTY94zPQalDmGtIVQ2qMf01nfbm0eW981pATPGGFDP5B+MHanuLau/I X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.243.117; envelope-from=alxndr@bu.edu; helo=NAM12-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:42 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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 , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com 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 7f266ffc63..87a1b88f9b 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); From patchwork Mon Sep 21 02:24:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 304889 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=-12.7 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 18834C43465 for ; Mon, 21 Sep 2020 02:30:39 +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 87D012067D for ; Mon, 21 Sep 2020 02:30:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="hrG1+P6S" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 87D012067D 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]:48524 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBbA-0008K6-0l for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:30:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWY-0003Du-0r for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:52 -0400 Received: from mail-dm6nam10on2102.outbound.protection.outlook.com ([40.107.93.102]:19201 helo=NAM10-DM6-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 1kKBWW-0000aa-Fe for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fzeFbyi4AT7fn8UlOIODxbGG5rhBuN5UrcqvIXwRiz8HsGuOIMychrpdb3dHztSmPiS5u6jLUVYqvCy7U3e87YqGOLiCBO0T2fwLLbwSKQ0jDzuK00ZwEDn2jKntkY3Kg7ZgEN45Yl5L75KVGyormAYCDduZXpmjUqw++CSbuxecE4TERY4SpF2+Q58KKrGVpFs4A8gt5IkVNRzw0Q+JyLeyKy9oyJBij5ViP70vbdhQuhFG04/etYG8osYLzwHVMU8UhR/I/lhSDGosd+FTYWy0hY5qAbeltbfklnz29a0Og/jA/Lx0hAJvnj6YGmwcEzjmnrqwtjltSeNBboo2nw== 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=oM2SGcB6sbksJB4Rq/VsjMWKr5tR72Q/RHTWJfHdqfk=; b=ZuvJYrUc27YTPmuE7cmSgHonI7Alzz6mehdwinkEb283RJteGXR1DDDvwrILHTQ/nD56CCa9YDB68g2dk2nUjnogFXqgy3E9UXKMmcQRdr19r5MCHHONBOC978yCgh9UUgGmGzqiETTbqZwufIrLu6se7P1gE895MAfc6lCouh03ZeBZlm2zhsHLCdVDyMdF6ArASka8s0fCCEwd/HplM4JyvNrLZgGrggKkOvCN8MzRiQFXPT8pxAcPpYgKFzc6gjsUeiaPqYN80ZwDeyWKPpU4tFhEClqt5qJYCzxgow+/EIjI4eK+T8ICoomAuaZVNljq7p77IXZAEIw2AaWzdw== 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=oM2SGcB6sbksJB4Rq/VsjMWKr5tR72Q/RHTWJfHdqfk=; b=hrG1+P6SGMQNyLwDrEM4BeePkxRxgERBu48Um3rL2usOZxGsbF5Vf6UftfI7PbDnAPXK0vu4S5012x/sgHi56NEey2xMiXIMnnEmOF6q6ZWdE9a+tjkg2AEP+n3Ng5/lsJYQ7SwmiDzBROZ94yhHTXjOPRlnmmwR85kQWmadL6Y= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:35 +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.3391.024; Mon, 21 Sep 2020 02:25:35 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 08/16] fuzz: add a DISABLE_PCI op to general-fuzzer Date: Sun, 20 Sep 2020 22:24:58 -0400 Message-Id: <20200921022506.873303-9-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:34 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e5c33e85-1c1b-4362-21f3-08d85dd59ef1 X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:49; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kub0vZBBtz7GlNYxoKA9UGjr9ZGvSZh8vSbuCctb5aYJtPmqC3u5b4ZjBxJ/CGSq6RQat48zPivDH7iWtCA5bTwQYDJX9Uq62f93BcFks5GxHvwFpNW/iSPpVJYICW9EPWabpjktqZfHrLozjgiK/04mkSgTObK1PxGUd0GvB41jSYL2JMqlnYr9bqm6mn/8teiwEpPsPCxCNqia3F7kvuwhiIce04m3ZH+Dt1qkeck94rUU3cfPwmuV4APPucTqQIjdcD80+OxTM1ltOqSSmejl+4JyR2YwjzZuuOI9FbNbey83dDmLf0Kr84ujn6TgoJq3mbYy5F8KbGgg1jNcWpHdzmrgS2pBB8Rc5jRbw+AwooNB9zM8lL1P6bcpjAYE 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(83380400001)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 3Bq7cRsRSHgOMnksUiCsSFNBLnPEfZuURDS/EgOGo1Ttq7kVqkAreNkJPprypdBl7WGc89xH48v4/gwIwt3wjZyyjnM35EYC/cJrefDTz8pYBCTzvtnrnE++gqc3GemtTR5eYR4ImirKBnOekAYWY1SJU2kIcYKvMYMtyjUJZNQbrB/V8/4FE+S1qiiqk0Zo0DthPeqM/49E1jnokqRLc+wehMSWWfLYGISB9xZJoDIo5rfHSY1gggU3lrb9OJFxvGzrpHGhWnFUsb2Rn+e09OGWt0uYJgKBF1nWUjFp3bDbrRCxzfBf8SKelGte6+FDk1rsLo5Bv/kWc8HP6C+Z1wFH2lmS8XPOP91KgxqIgvNoqIJTv551bD1woZOZq+bNytB3k/DU7YtZajjaYpt6A4RGPB6kle7buomQyGpG1v2BY10c+7wBxodTb7omSdX5F/iBWLK/SDJodbsXHU+AhAvJvqpiCm5buum1niSC9YE/MtQWHbB2yHGo7C5QA+tfe30aS8XEF5yg4tCLu6jk7daPLcz3/WgJ35Lq8t6kgU5X2FhT2tCAsNOCAPxEGGupvyRB+iwh+RtI7KgskuGW1Uc0WGQGRv9uwIAT8zx2QJrPWRF77avNIsNGmWVuAUX0Hz4qFqR41VCRBvoPoHmX/A== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: e5c33e85-1c1b-4362-21f3-08d85dd59ef1 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:35.1993 (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: +F0bCZSG8KCzuPV8EtL/IyIF8j9CgLTD3f/cxX963ijfsdGR7UI5EDgYH6hOriOW X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.93.102; envelope-from=alxndr@bu.edu; helo=NAM10-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:33 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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 , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This new operation is used in the next commit, which concatenates two fuzzer-generated inputs. With this operation, we can prevent the second input from clobbering the PCI configuration performed by the first. Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny --- tests/qtest/fuzz/general_fuzz.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/qtest/fuzz/general_fuzz.c b/tests/qtest/fuzz/general_fuzz.c index 5e42504821..656ec7fd55 100644 --- a/tests/qtest/fuzz/general_fuzz.c +++ b/tests/qtest/fuzz/general_fuzz.c @@ -39,6 +39,7 @@ enum cmds { OP_WRITE, OP_PCI_READ, OP_PCI_WRITE, + OP_DISABLE_PCI, OP_ADD_DMA_PATTERN, OP_CLEAR_DMA_PATTERNS, OP_CLOCK_STEP, @@ -116,6 +117,7 @@ static GArray *dma_regions; static GArray *dma_patterns; static int dma_pattern_index; +static bool pci_disabled; void fuzz_dma_read_cb(size_t addr, size_t len, MemoryRegion *mr, bool is_write); @@ -429,7 +431,7 @@ static void op_pci_read(QTestState *s, const unsigned char * data, size_t len) uint8_t base; uint8_t offset; } a; - if (len < sizeof(a) || fuzzable_pci_devices->len == 0) { + if (len < sizeof(a) || fuzzable_pci_devices->len == 0 || pci_disabled) { return; } memcpy(&a, data, sizeof(a)); @@ -459,7 +461,7 @@ static void op_pci_write(QTestState *s, const unsigned char * data, size_t len) uint8_t offset; uint32_t value; } a; - if (len < sizeof(a) || fuzzable_pci_devices->len == 0) { + if (len < sizeof(a) || fuzzable_pci_devices->len == 0 || pci_disabled) { return; } memcpy(&a, data, sizeof(a)); @@ -514,6 +516,11 @@ static void op_clock_step(QTestState *s, const unsigned char *data, size_t len) qtest_clock_step_next(s); } +static void op_disable_pci(QTestState *s, const unsigned char *data, size_t len) +{ + pci_disabled = true; +} + static void handle_timeout(int sig) { if (qtest_log_enabled) { @@ -555,6 +562,7 @@ static void general_fuzz(QTestState *s, const unsigned char *Data, size_t Size) [OP_WRITE] = op_write, [OP_PCI_READ] = op_pci_read, [OP_PCI_WRITE] = op_pci_write, + [OP_DISABLE_PCI] = op_disable_pci, [OP_ADD_DMA_PATTERN] = op_add_dma_pattern, [OP_CLEAR_DMA_PATTERNS] = op_clear_dma_patterns, [OP_CLOCK_STEP] = op_clock_step, @@ -587,6 +595,7 @@ static void general_fuzz(QTestState *s, const unsigned char *Data, size_t Size) } op_clear_dma_patterns(s, NULL, 0); + pci_disabled = false; while (cmd && Size) { /* Get the length until the next command or end of input */ From patchwork Mon Sep 21 02:24:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 304888 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=-12.7 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 A5C37C43463 for ; Mon, 21 Sep 2020 02:31:23 +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 29C952067D for ; Mon, 21 Sep 2020 02:31: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="QfUeK4ma" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 29C952067D 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]:51942 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBbu-0001Qv-2p for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:31:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWc-0003J3-M5 for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:55 -0400 Received: from mail-dm6nam10on2102.outbound.protection.outlook.com ([40.107.93.102]:19201 helo=NAM10-DM6-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 1kKBWa-0000aa-UB for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NXfcZH8mFhDHXUla/WZTD4N86HE5by/uVuGiNqonTVFKIdgC+RbclyYPFmzrMtWo+icI35wZHclAcYFd6WzIV+q9Y9pfzNn/aUXkDuJTUxhhfyi5dB3kytJg7XfU45/FVK50fAtirDsMJmJYuUJUivcwzX+gjdn1djCCzltJUKx4E0USvSRo1BBwNijN2pHxdFeHpjYKiYlXeKJ8uLAGLlU8oD+ylUPZz08o2TeKTId/nVEjDpC5q+0UFyQI0Yka2vJb7F4XwBRsLnTs77QinEk2BGmBvrh/Cs9E3AZjzX1HfC1EDFq2m/1+97WYwHQTjUoplvVh/nqhFDAPwdpjiw== 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=Zt9C8PEHB/8DeEt2kjCOdyqp+2g+cWj62na1L4iBthQ=; b=HpGP1E7vF99hN2QxtOqHY6Coi6SRBFC5fNZUSkO15iZYjchr7zto0+7Q9t9h3YZx1j0ZNRecAB73hqEoDuSx8Ct1zo/d7Nq8IndaJExrajlpPOWFlE73K3R7gC4m8/4TU99JIEO1X+c7RU4C7e1DQh4GeTNx+JkToN6Qf8xmTZajHO22BVJjpy6pTKrBYNncPALsyxpesSdcmwiP1pjIlWVXSKFpKqXRW4GZnmVWiHxhTD3Lz7qlyBUJZYT69E5ldrjSGSgHrAbhSr0SZCt8f3ewGVypR+1fbIOfIurRTUUISUnUihRVBqEc9BVaAN0cmbih9k4CncK7qahngT9yHw== 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=Zt9C8PEHB/8DeEt2kjCOdyqp+2g+cWj62na1L4iBthQ=; b=QfUeK4ma/ix+L+6DdXMB08F/nmqwwFjNfgESBkElccpA/9J4X3EkBzR4KjPaVVaiTYCQZwhKUxaFgfFkhPrbkhwgCDt28utlR7NktfWULBitgo+z7D3/usEQBzR+uZb1D/GydZwltA1TgVLB1pgF7pw8ShHu/O+J+RyYKnbhcpw= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:37 +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.3391.024; Mon, 21 Sep 2020 02:25:37 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 09/16] fuzz: add a crossover function to generic-fuzzer Date: Sun, 20 Sep 2020 22:24:59 -0400 Message-Id: <20200921022506.873303-10-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:36 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 96b129b1-8eb4-4515-3039-08d85dd5a01c X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: 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: RMplwE1zZnS8Ab+u0HcuWHb2SZKf8jFatycyHPmcIgzyGXziE4wWKhk5B6rLOTx3VJyRuWUeCJF9+3B4F+eAZeMZbcxw5Y35Vnfy14O5JlrTz1S0/JTFDCamdcRcdcGCN8P9kwrfOqrBFUbIuhBk1gzDqc+JLtTQdnDAAXJO7/UyLXIPudcZCkOPtEJBND4v+0pVYYyf0bXd7cH/c8q1hz3IsMuu05iz5lBQap6wTXthLnFS6fEcTHWs8Shh81Z7z0Q/hVRj48v/Z+cPi9sgm+4U0ErqTKRehNDFQLXI6PN0ah0dqUSlK13fBb6AC1+ZEIopwRDgCa0zYYYBEWc36b6FiyseG2eGV0ovsJCasbkInmsntZu/sEIQ31tfOW9Kasv+I6Ezx3u7ErxJfdHBgs1lXfBCBl6FrGOGTMwebGY= 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(83380400001)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003)(41533002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: RmU6RggU3T3opnZ0c04CFMGyVMQvp7mW5glNbVGKLhpKKnmIerl677AEOY/p32gy3QFB54bE+W1OHETsNYgkHXTixxhOynrG0Cngi4hjkKrXDE1bUS2QqAKhsJe3oisGQID7adhk1Ga28P9UTBtFyptiZbWRybZpi8XG8we/S8bWe9eiisEH4m3GuW6TAyfiebS0j9ZI+Fo/ZPXSB/bt2jgr8fVCK/7eSJ92UeWvjViQiMXFqb93ogmnMSbQdA5WWIyVunTrExRptEGG7k9wgKC4tI3hyWIoSijGjxu/S+Quz4ff94ylqoo/LyAdpcePg7CJhoQMc8ZiSNr04d6wsRUCik4Sgf9t89bki+BZsf93mNo2MLH3MCXV0TYlmJGIcQEPELhnkg/Ah570tJNaTgeg7lQRtkJu7sofFGJfrrnIdLkkfBUWiaEwGOUJx5W55oz0KVhaF2gCNrG2088cWS6k/3Ya9Qo5F1/CPymHahVpAwfAjNrpRruhpoKt7Z6D8DTIvlQt2+BVzkj82wg+YMtFX1xkOq//LsKwpl31HZ10VWZ1F+f1auRerlCccDitiUwls9g3qZE5wY/NgM95O0EqR4gpo5ZKU/KZkS5ZJgBn832OoRIiEwLij23R1TLLeX7pywe6zpfh7yBBgykXjg== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 96b129b1-8eb4-4515-3039-08d85dd5a01c X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:37.0583 (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: QugGZkojhe/QCf1j+ji8TNw8ME5h9AD1ypc06Ai3s0U2a7XMh2a679g1D9eyxSCx X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.93.102; envelope-from=alxndr@bu.edu; helo=NAM10-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:33 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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 , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny --- tests/qtest/fuzz/general_fuzz.c | 90 ++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/tests/qtest/fuzz/general_fuzz.c b/tests/qtest/fuzz/general_fuzz.c index 656ec7fd55..3833b505c8 100644 --- a/tests/qtest/fuzz/general_fuzz.c +++ b/tests/qtest/fuzz/general_fuzz.c @@ -741,6 +741,92 @@ static void general_pre_fuzz(QTestState *s) counter_shm_init(); } + +/* + * When libfuzzer gives us two inputs to combine, return a new input with the + * following structure: + * + * Input 1 (data1) + * SEPARATOR + * Clear out the DMA Patterns + * SEPARATOR + * Disable the pci_read/write instructions + * SEPARATOR + * Input 2 (data2) + * + * The idea is to collate the core behaviors of the two inputs. + * For example: + * Input 1: maps a device's BARs, sets up three DMA patterns, and triggers + * device functionality A + * Input 2: maps a device's BARs, sets up one DMA pattern, and triggers device + * functionality B + * + * This function attempts to produce an input that: + * Ouptut: maps a device's BARs, set up three DMA patterns, triggers + * functionality A device, replaces the DMA patterns with a single + * patten, and triggers device functionality B. + */ +static size_t general_fuzz_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) +{ + size_t copy_len = 0, size = 0; + + /* Check that we have enough space for data1 and at least part of data2 */ + if (max_out_size <= size + strlen(SEPARATOR) * 3 + 2) { + return 0; + } + + /* Copy_Len in the first input */ + copy_len = size1; + memcpy(out + size, data1, copy_len); + size += copy_len; + max_out_size -= copy_len; + + /* Append a separator */ + copy_len = strlen(SEPARATOR); + memcpy(out + size, SEPARATOR, copy_len); + size += copy_len; + max_out_size -= copy_len; + + /* Clear out the DMA Patterns */ + copy_len = 1; + if (copy_len) { + out[size] = OP_CLEAR_DMA_PATTERNS; + } + size += copy_len; + max_out_size -= copy_len; + + /* Append a separator */ + copy_len = strlen(SEPARATOR); + memcpy(out + size, SEPARATOR, copy_len); + size += copy_len; + max_out_size -= copy_len; + + /* Disable PCI ops. Assume data1 took care of setting up PCI */ + copy_len = 1; + if (copy_len) { + out[size] = OP_DISABLE_PCI; + } + size += copy_len; + max_out_size -= copy_len; + + /* Append a separator */ + copy_len = strlen(SEPARATOR); + memcpy(out + size, SEPARATOR, copy_len); + size += copy_len; + max_out_size -= copy_len; + + /* Copy_Len over the second input */ + copy_len = MIN(size2, max_out_size); + memcpy(out + size, data2, copy_len); + size += copy_len; + max_out_size -= copy_len; + + return size; +} + + static GString *general_fuzz_cmdline(FuzzTarget *t) { GString *cmd_line = g_string_new(TARGET_NAME); @@ -760,7 +846,9 @@ static void register_general_fuzz_targets(void) .description = "Fuzz based on any qemu command-line args. ", .get_init_cmdline = general_fuzz_cmdline, .pre_fuzz = general_pre_fuzz, - .fuzz = general_fuzz}); + .fuzz = general_fuzz, + .crossover = general_fuzz_crossover + }); } fuzz_target_init(register_general_fuzz_targets); From patchwork Mon Sep 21 02:25:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 304886 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=-12.7 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 498EDC43465 for ; Mon, 21 Sep 2020 02:33:03 +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 DF0D22078E for ; Mon, 21 Sep 2020 02:33:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="HyblB8zW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF0D22078E 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]:60252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBdW-0004ru-2a for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:33:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWc-0003Iz-LS for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:55 -0400 Received: from mail-dm6nam12on2117.outbound.protection.outlook.com ([40.107.243.117]:28256 helo=NAM12-DM6-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 1kKBWb-0000b7-0H for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SshB1Gh3JnulgRRj6KYHLX5raYJYhJWnMZqf5XO0Ypt3uITaF6WrKFl8bGrJl6p/SHYbUvIXeUyWYvZajonBeEHrHnAQ3k6iEwhnD0pgPxiso7JSPrS9poHRfLUt9iNoibSR7D68wmrnGMAiv9UF02sROfnIlvfLPAIG9ldF04p/P5jMHwrA5wscrKbniYg40lDMYwoYx/OoSiOlfJOm51IkwQRZ7U5/rpCTyXQOs5o/lTemEY4hP6DGkt3jYWBK+aw1YJlDxW3kRZ4YzaqyH3NLUTTW9hFli0Csv+n0WdBhNOHKS7HBt2SZ9HfT1X217wNq3Ew+eF0UcV4Y1UFQMg== 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=d6hz67y/zGvT+mQzDe+EH2DgKtQ5SUMdPMnvak35Rkc=; b=df2J1JZI6dznFYfzicEa+N8vrE0+MSNHafmCJWtKUcw7SX51Pl/95ALguScwEXHI6tc2d/Opo3arK0E5Hrrg8uijG1f9D169+rI4DEpRyliiNms4D6cfZInKE/NZ3WWAgJ+FliT+VotKoy39L4VYlGC9vvCFOZ9M6APBl5PJNgKJJb+VTeEU0PAFHty9+7Jj7YyZMvJBDLYEprJwiHXrbNgdaqaCe6GaQShadhuWg7/ZJc4snzz5f/wYpYGOgGagHfcCcNXAvziY6ZDru5xuY30X2bqzWBfK5mG6B0PCBXmhei+Usg/4lIBkq2zqPzRVDx3WFrjR1B78W947UjtrXg== 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=d6hz67y/zGvT+mQzDe+EH2DgKtQ5SUMdPMnvak35Rkc=; b=HyblB8zW4IOl4IDTiYZrcaqeOHx8Dh+p807Wnjei2msKMu0xY0H0jhsUwmrJNo3vm59XVF687zzDjQALceMZTI1n7aT3ZoP+f0anKoYQraFRdRea5J+bjVchkZgYkd2wHpCgrjzPYFOYkSLSxiYQ2mKNVVOGIU38i3cS3MNelTo= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:39 +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.3391.024; Mon, 21 Sep 2020 02:25:38 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 10/16] scripts/oss-fuzz: Add wrapper program for generic fuzzer Date: Sun, 20 Sep 2020 22:25:00 -0400 Message-Id: <20200921022506.873303-11-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:37 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6ebfb7d2-62d1-40fa-5d6d-08d85dd5a0bf X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:849; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jx6qKRkBTies0M1OXUnnfkvAj/iiApTzE2KqBW2nzi2WDeYVmW2ISYEDg5zoww1IYVpUL58R5syfhbINVSnD7CvmqjBGC2/spz7OyosjiJ1gXtmVZ8Tykdl+QA97872ecxAUTBnYGpi7hXgIVZnbIKxNhLHEWiB3BH3tGqX63gzvtT/D4Vd3k3DraK/FGQwNuALZh6V3rTBUnK0l3RQARnb+iS/3SUeR4/ZL6s91gNqwnNV6/If12yWsKiVUETuOH/r+lCcYSJokulH1NSHkwsgxkN++LM888Eh6Ilnc6iR5jFXIVt/LvHru7J0HCmnpQ6Z87nnXCby1pn8anFLTJuS5SVnUr4Uwwzbd9WvP2BmjuThdLxAvl7lWovNoYX5gctFqHoj3x68l1vBqrxs1RyScZvgNofYJ8kepMXBHg7k= 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(83380400001)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003)(41533002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: OYpnsNke/4MwtzZn9HeRXlN8rxyCD7Q50WavKu69jbjONDPTCENEFDBL9kFcMGsLmRJb+paUaKc26B9cXHJvqPzwMB7mwdmHsyafrIy9GiZMjpgGf6MjTaIFna/4VslerzgErkgm7MkcnaS+ni9B4J9F9PIvoVPSfywHcbzWK/z8KK1Jv/MPPogcJ9/973ojY6NVNtfVjRqghIZKnIf3XkaBSFJYH3+7MBFv87/0Y4WBFtsROApTMFoZNJK4NYjvAGn9Kb8syccwnHkwiiFDhOuP99kRv2xcw+S08ci4bN6mKaiLJwJ2shkDrTSddzkR14QlzCRb1WQe79XUBBVHwB4Pq2Zzrve/5KXoH/wMuWI537Tfl9/eJRxtE0WuwpigCccACbElTs0FML7BED4yRGFNNRzFqoy4unKTmA/DN8Ja9YnH29vDPZ5ANaz4fnl9KRmuXLmE5yT5a+puKQ9SrZRqFuCfSwFNEr5ZDg0XiZrTrGhHOIPICHCci4/WZ1rjNYsUQ2YJcKCoH9Lbtnz7h4g8ql5t8kVZZFNnsjGQ5qJsmOQMNHaco6X+AOOrNjzngqcZMqjT8OpMYOSl+1jAZKBjNkRCvEDBT1WdZV4P1naCSINEOj6rKOvCSqZxMOehexflM2Mr/rMwn2W5S6lg6g== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 6ebfb7d2-62d1-40fa-5d6d-08d85dd5a0bf X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:38.3805 (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: qbMFSNibQ6Je20c0UYhdUoxlHdLkiU8UZM3Mnuty5jFuNHgz7K4CKE5yn5Ua1w5w X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.243.117; envelope-from=alxndr@bu.edu; helo=NAM12-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:42 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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: Thomas Huth , Alexander Bulekov , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On oss-fuzz we need some sort of wrapper to specify command-line arguments or environment variables. When we had a similar problem with other targets that I fixed with 05509c8e6d ("fuzz: select fuzz target using executable name") by selecting the fuzz target based on the executable's name. In the future should probably commit to one approach (wrapper binary or argv0-based target selection). Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny --- scripts/oss-fuzz/target_template.c | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/oss-fuzz/target_template.c diff --git a/scripts/oss-fuzz/target_template.c b/scripts/oss-fuzz/target_template.c new file mode 100644 index 0000000000..4a7257412a --- /dev/null +++ b/scripts/oss-fuzz/target_template.c @@ -0,0 +1,40 @@ +/* + * Copyright Red Hat Inc., 2020 + * + * Authors: + * Alexander Bulekov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include +#include +#include +#include +#include +#include + + +/* Required for oss-fuzz to consider the binary a target. */ +static const char *magic __attribute__((used)) = "LLVMFuzzerTestOneInput"; +static const char args[] = {QEMU_FUZZ_ARGS, 0x00}; +static const char objects[] = {QEMU_FUZZ_OBJECTS, 0x00}; + +int main(int argc, char *argv[]) +{ + char path[PATH_MAX] = {0}; + char *dir = dirname(argv[0]); + strncpy(path, dir, PATH_MAX); + strcat(path, "/deps/qemu-fuzz-i386-target-general-fuzz"); + + setenv("QEMU_FUZZ_ARGS", args, 0); + setenv("QEMU_FUZZ_OBJECTS", objects, 0); + + argv[0] = path; + int ret = execvp(path, argv); + if (ret) { + perror("execv"); + } + return ret; +} From patchwork Mon Sep 21 02:25:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 273213 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=-12.7 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 CDF41C43463 for ; Mon, 21 Sep 2020 02:34:57 +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 5CB3E2078E for ; Mon, 21 Sep 2020 02:34:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="Q322wDJ0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5CB3E2078E 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]:38512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBfM-0007VS-HX for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:34:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWe-0003Lv-Ld for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:56 -0400 Received: from mail-dm6nam12on2117.outbound.protection.outlook.com ([40.107.243.117]:28256 helo=NAM12-DM6-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 1kKBWc-0000b7-U8 for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=giscUlcdGilV4/eXV2ke0SzANvsSd5JkFvlaF9++i1hNOcOBOaruOzBasR83L6PSg43fZX5nUnddtvRcQnC62KjN8+E3LBoWUUoKeyU21z3G4fXwTT61/ooDA1moIxbgdKgIQ0o3okfIdbX1EaOQBE28/n/ur6YtY22qvdMOMGrGfYqKlugSCZn1wwgexw9PnZnVtf7U3DzFluZd4q+CspRSrn8kiOmYP+iNDZZ7MTcP3ZGVU9zujrsngFSzI0oal8vbKmJ9oR79fybkFse2jNHssaYZtDDcesEUL0Hc3lYPcPg2Qp3m1NCVR9ALoSZbZhQ/O5kbnBKlv5vnaM9IYw== 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=92Pi8V0q/CvMNhMCwNiYCwCGdchrZHzjQakpHWWY51Y=; b=UXbvOPKUXY20fiFNHr+PdTwNf+SQKXLbb21uRjiztjEW0n1Ygc7d2auBwwxGybLdf++Yc3RryGqJnDKOFF0JdCbWsU+P+sfN+7+CObvPwXO+dc2pPKk+mT8qCHM+AFwd0vdLuH4rJIxiQX11z8OV1Y8JXLe/kcZUuk0CtR93mcTH8pci1xvVoo9wk4GXFNLsDNNHtiue5c2fdGRpdKicaK0EF4etcyH9+TGdMZ33lpQJHZa7LmvGF2fO7cX5TuT0Tv73wwOm/rPgKB4rkOUdVpMeDCd7wAaR2NdzcgEh5qFzMYi8DMUmZEFnisectN00JaXHdXUttWyOeS8Y7dmeGQ== 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=92Pi8V0q/CvMNhMCwNiYCwCGdchrZHzjQakpHWWY51Y=; b=Q322wDJ0P2DyrDyFW1hObTzvJM/XWpvJ9EcZvuV025HVvR7l2T+0XjTS5+J6RuNMbEkb01ghPssEntLWw9c9y3XtPslFcqK3JQM6+zBqJXYyaxcwDA4mhk1hEQA5dfO34bmzenVp0SuLfLsBPuk3DbpuFX6ZhAEuLzu78DiR+5o= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:40 +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.3391.024; Mon, 21 Sep 2020 02:25:40 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 11/16] scripts/oss-fuzz: Add general-fuzzer build script Date: Sun, 20 Sep 2020 22:25:01 -0400 Message-Id: <20200921022506.873303-12-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:39 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eb742b7a-fa79-4ff6-f694-08d85dd5a1e9 X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:972; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Sndoy3h70Qh0ocEFJ/ft11zMAFUBjqXZidM0azWKaWn4a0nowQalkkPDGuv1cR8i2c/P1ru2of8c7f/iCudJzZwUybcGKp7CAHgrfH2LH3WPnOtGdnNiRI1tXY35C3JA9We5zk1POwng6vCjmuaWJJ/tVE2/LBkeeEzd+mgbByeNC1Qj8XVvUbATTtcVZVo5mNKteT+ILyU2k0C6Gya1NIlJN9dhlNGaEplGD86YZlX43R/xB81Tq0i5D+XlSh8flWm+26rcPO3g4JTk5N53eOMVyzUnpnldP3H8KMz4D5kOEuTsqElx4TEK6wS5ZWOZ+xsFpItf7O9lSHGcKvsVl124U7J6a2AkRV7yxyxzDl7vAAiHpdWBT38/zeXTC3ja 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 5YsHwUdBFNC6PNHxdlTMfAMSwQnDxLqFcaQcZJQjVjPGMSA3tZWPgtuRov8FnwqlqxBrfeMvnIcZxlZo41tP0r7Ejw5d4x/NcJjxrYdwrcaDYdzFSNrDN3681J9slNCfHJkdV225EUTbUUTwPQqcra+h9m3FBPAFFWr4Gkr1Yp2px9Jad+Tih1tvJ9CxW25kQMIxXyDDRwevd1AXTaIwb+ou1lqrtt3ioj1oqU+Lmj9u2Je3+oVBYj1Fl8Y8awxYequGMwAsBjANNmMihE/EaH9XxvhFHPpbo7Q+yNmej+l/fJVarQ09iUvS3VNFSncGiI5RNocWjqewoLi0/HlVlh5/m6Lh4KDLBSdc8O/c4yExTW0HhLpRtnZrMI0RSVJCTTGtiw1ev39KPnldLiapqz6ITIuWKCtxckrgKcofK0CHoIVbKqJzurakIz482vtWN242INSeUuLLaXqcCxVWC3XoIgE6Kzlmjimm+DLua2pEamUG9sgvhhlq+P+yqQWluDl5ly1CCbFWy7xhXSLIp20zcqUQnLL/4i8t+hoTC2JPMOz2OHprytp8BBfkTl3rKXUmWCkf8ZPQ8RjJx62x4y0ZTcJVfn7Cv8HvShTFtINMmpro34+6aNv+7EP0pD7Wj6P4+i2aoEh4DB6tbwlEsA== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: eb742b7a-fa79-4ff6-f694-08d85dd5a1e9 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:40.1125 (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: U8/SuRFsmU4C/N6e2U8iYSE5V0Tf/lnrzL1lai5bKGpqwVH36sM3cvh4SO00aun/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.243.117; envelope-from=alxndr@bu.edu; helo=NAM12-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:42 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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: Thomas Huth , Alexander Bulekov , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This parses a yaml file containing general-fuzzer configs and builds a separate oss-fuzz wrapper binary for each one, changing some preprocessor macros for each configuration. To avoid dealing with escaping and stringifying, convert each string into a byte-array representation Signed-off-by: Alexander Bulekov --- scripts/oss-fuzz/build_general_fuzzers.py | 69 +++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 scripts/oss-fuzz/build_general_fuzzers.py diff --git a/scripts/oss-fuzz/build_general_fuzzers.py b/scripts/oss-fuzz/build_general_fuzzers.py new file mode 100755 index 0000000000..918f1143a5 --- /dev/null +++ b/scripts/oss-fuzz/build_general_fuzzers.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +This script creates wrapper binaries that invoke the general-device-fuzzer with +configurations specified in a yaml config file. +""" +import sys +import os +import yaml +import tempfile + +CC = "" +TEMPLATE_FILENAME = "target_template.c" +TEMPLATE_PATH = "" + + +def usage(): + print("Usage: CC=COMPILER {} CONFIG_PATH \ +OUTPUT_PATH_PREFIX".format(sys.argv[0])) + sys.exit(0) + + +def str_to_c_byte_array(s): + """ + Convert strings to byte-arrays so we don't worry about formatting + strings to play nicely with cc -DQEMU_FUZZARGS etc + """ + return ','.join('0x{:02x}'.format(ord(x)) for x in s) + + +def compile_wrapper(cfg, path): + os.system('$CC -DQEMU_FUZZ_ARGS="{fuzz_args}" \ + -DQEMU_FUZZ_OBJECTS="{fuzz_objs}" \ + {wrapper_template} -o {output_bin}'.format( + fuzz_args=str_to_c_byte_array(cfg["args"].replace("\n", " ")), + fuzz_objs=str_to_c_byte_array(cfg["objects"].replace("\n", " ")), + wrapper_template=TEMPLATE_PATH, + output_bin=path)) + + +def main(): + global CC + global TEMPLATE_PATH + global OUTPUT_BIN_NAME + + if len(sys.argv) != 3: + usage() + + cfg_path = sys.argv[1] + out_path = sys.argv[2] + + CC = os.getenv("CC", default="cc") + TEMPLATE_PATH = os.path.join(os.path.dirname(__file__), TEMPLATE_FILENAME) + if not os.path.exists(TEMPLATE_PATH): + print("Error {} doesn't exist".format(TEMPLATE_PATH)) + sys.exit(1) + + with open(cfg_path, "r") as f: + configs = yaml.load(f)["configs"] + for cfg in configs: + assert "name" in cfg + assert "args" in cfg + assert "objects" in cfg + compile_wrapper(cfg, out_path + cfg["name"]) + + +if __name__ == '__main__': + main() From patchwork Mon Sep 21 02:25:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 304884 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=-12.7 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 EA94FC43463 for ; Mon, 21 Sep 2020 02:36:55 +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 69E2320795 for ; Mon, 21 Sep 2020 02:36:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="Co6bpaDV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 69E2320795 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]:43026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBhG-00013s-Fh for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:36:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWe-0003MA-Sl for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:56 -0400 Received: from mail-dm6nam10on2102.outbound.protection.outlook.com ([40.107.93.102]:19201 helo=NAM10-DM6-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 1kKBWc-0000aa-UN for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dxAYLMlJMSdN+zqUdtW4vCQWWbt5oAgmEOIahq4hwNkTbBo/AmDDAQaXS6/SCi5i021lbCPplU9/K+KJy4DpOze5oN8S3Cj1CT25qDbkhA6COB/HwZcJk6yzuVbD5vitWq26or+YFZSOh7Nsn8cATnauPlpU4ybfentbvYr6Ozge+3/sqVjZeKvUTeeGvk8RxSRYyZDKbcJh2J+wXIjoTY2HJVV5chvUv42LKzhU1mPjksiG6zQ8nVrRfBCLICQZLaMP7OkCPKKBYJy3sunhoFJ3Hla5ZI4HH/kT5Y44e0Rpg6X4raL5jdV2pRZaAXOVEPHhJVneGAaW7pyxsfqkpA== 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=HTVG0JaNcRK1O8YcQ/w2miabgaspKeTz12GX27XViEU=; b=DqhCu6H1ZfIHttz5sdvni5yaG6iGwClUb/IJxfG5vmcbmcegKruzPWDI02kd4RzFZs9k1aAm5aXl7Jx/ZQ3IdVcJvjtwOcdnQST5eB5EetvN2VhKfWYFWGlmYw2uS3c7yn/aBKSmfTcWEfQvLa4v5jGP8DT+v1J1PhQ37hDQ6hcF5v2k6Cfwg0jmgFinutfEn0oGPlcyptgSwWMyyxb12ySOpLURwxRTBKbkJvuws1z0ISfOIriE7zdBoFx1v1pqJdOFxnRNMIXcnYEVcAX6iwd6F4mulVVOzZEsVhbzUw/YdmHGwfJl8Mq28uL3nexvngnYFvgG0APBFFMpeYf9Pw== 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=HTVG0JaNcRK1O8YcQ/w2miabgaspKeTz12GX27XViEU=; b=Co6bpaDVFddCnX4p9aXO6dFvNW1qCn+q14BYe+CB+KK2dO2EGRLgElM0F+i7UkqF4qLj3wDqukxEPy3st5ONQnl7e38ippUTT6gffxm6e68G1BcXGQprCRfHGBAjDOcsP8Ft1NbOZYZlQpwjwJxmp+DIQtVSC5hftvQSLi2dosI= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:41 +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.3391.024; Mon, 21 Sep 2020 02:25:41 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 12/16] scripts/oss-fuzz: Add general-fuzzer configs for oss-fuzz Date: Sun, 20 Sep 2020 22:25:02 -0400 Message-Id: <20200921022506.873303-13-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:40 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fb7163f5-48d0-4918-16fb-08d85dd5a28a X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2582; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HF981iGDQqXThi082EAKq+XC1yzL57cTkDaaeCu+2oBagIktg3vRuM0936GI1vV8e2JlcRozikQYvkXiQiRZKXS2W7Xl1d7h3uTjJi6jjLHB9duYqklXiiEuatU057ysjcZO/nGUYtHKqJVOo3mv/AcW3zG64zE9pzVZnfSz9K39xrq0sVlNIz71OZGEJ0dTcq9OozsVIQqFxRE43sUgfEGAI6nrBCD+dt9mg56lfbPQ5JJji8mlKama0VN/ZSB0txdslTfkIjDr5AjunEbSWsIJfh2sM7HrRG6ICimnz00L1IfcvgB9zOmBmBIB3xXkajBY+SXGYyUGuuxvYP0gAmiCMNFts9+sfhL9gRSQShK0WYtzz3Wly/xPbaxRKBeW 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: A+gQSva0kg9HirgeQ5BEmSgyTwtC45xpUT8ToKRHJmLYel7BZ57MqDGh7m6txMfuforTwBbX1FCNn/ePh3KhhQqg7tSlV1iNeLksGH0+mTymCXzUUJ1Yb3adrK3fUi5P9CFdcUU5uiUmyUU4V4U1PCL5STQnWOMLRDxvicQxmLDcUvAM8MSkdO/APJ8Y2c42rOf3G4eI7E12y/TxuuMhk8YB1hjw7JCD0FajyOQHBKWIRy1rqsia7PZKpiTuv8rMjhpszTmulbDmrOVyjWENlJfda7Om7l7gRJ+MvUN899zdjHiNxRxFTXXGDzh8s/caWqvroWIQGjAjyCmOD0AO0CkNrWFxZxKG1MWu/uUdy93zzYJKNi/D00W/+wCO4oUncWEKQhC1dsnuVm/X8lQhHPFjydmwWyMPvvEz+b2QEKPa286KTZ7Q6b+Ya08YkvHVSZLWN1cHoHcrGQIzKZ3ZLPDTMw/ziMuXdhFonXzgyBv3OXSEofD8LeCTHuXxg3BnCdkHejGwawoAjCVvZTLahg7bIfDC741/hWvbXWaN9ph/C0fAoU4PA5xbNU5bIlRb9cBVlhkAOvaWKA25Zeh60IhVDqYImyDRToEYS47QmOqOyRKjRMm7xxAkp5yBxYfcmq8OEJ3D9WKqIJT0B6DXpg== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: fb7163f5-48d0-4918-16fb-08d85dd5a28a X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:41.4778 (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: lKkU24ds91gZTVRJ9VFiFWFAcUMX3aMcyQMsw26UC5Hx0Ut1Mwgi0NN6so7qbwpx X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.93.102; envelope-from=alxndr@bu.edu; helo=NAM10-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:33 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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: Thomas Huth , Alexander Bulekov , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Each of these entries is built into a wrapper binary that sets the needed environment variables and executes the general virtual-device fuzzer. In the future, we will need additional fields, such as arch=arm, timeout_per_testcase=0, reset=reboot, etc... Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny --- scripts/oss-fuzz/general_fuzzer_configs.yml | 103 ++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 scripts/oss-fuzz/general_fuzzer_configs.yml diff --git a/scripts/oss-fuzz/general_fuzzer_configs.yml b/scripts/oss-fuzz/general_fuzzer_configs.yml new file mode 100644 index 0000000000..010e92a2a5 --- /dev/null +++ b/scripts/oss-fuzz/general_fuzzer_configs.yml @@ -0,0 +1,103 @@ +configs: + - name: virtio-net-pci-slirp + args: > + -M q35 -nodefaults + -device virtio-net,netdev=net0 -netdev user,id=net0 + objects: virtio* + + - name: virtio-blk + args: > + -machine q35 -device virtio-blk,drive=disk0 + -drive file=null-co://,id=disk0,if=none,format=raw + objects: virtio* + + - name: virtio-scsi + args: > + -machine q35 -device virtio-scsi,num_queues=8 + -device scsi-hd,drive=disk0 + -drive file=null-co://,id=disk0,if=none,format=raw + objects: scsi* virtio* + + - name: virtio-gpu + args: -machine q35 -nodefaults -device virtio-gpu + objects: virtio* + + - name: virtio-vga + args: -machine q35 -nodefaults -device virtio-vga + objects: virtio* + + - name: virtio-rng + args: -machine q35 -nodefaults -device virtio-rng + objects: virtio* + + - name: virtio-balloon + args: -machine q35 -nodefaults -device virtio-balloon + objects: virtio* + + - name: virtio-serial + args: -machine q35 -nodefaults -device virtio-serial + objects: virtio* + + - name: virtio-mouse + args: -machine q35 -nodefaults -device virtio-mouse + objects: virtio* + + - name: e1000 + args: > + -M q35 -nodefaults + -device e1000,netdev=net0 -netdev user,id=net0 + objects: e1000 + + - name: e1000e + args: > + -M q35 -nodefaults + -device e1000e,netdev=net0 -netdev user,id=net0 + objects: e1000e + + - name: cirrus-vga + args: -machine q35 -nodefaults -device cirrus-vga + objects: cirrus* + + - name: bochs-display + args: -machine q35 -nodefaults -device bochs-display + objects: bochs* + + - name: intel-hda + args: > + -machine q35 -nodefaults -device intel-hda,id=hda0 + -device hda-output,bus=hda0.0 -device hda-micro,bus=hda0.0 + -device hda-duplex,bus=hda0.0 + objects: intel-hda + + - name: ide-hd + args: > + -machine q35 -nodefaults + -drive file=null-co://,if=none,format=raw,id=disk0 + -device ide-hd,drive=disk0 + objects: ahci* + + - name: floppy + args: > + -machine pc -nodefaults -device floppy,id=floppy0 + -drive id=disk0,file=null-co://,file.read-zeroes=on,if=none + -device floppy,drive=disk0,drive-type=288 + objects: fd* floppy* + + - name: xhci + args: > + -machine q35 -nodefaults + -drive file=null-co://,if=none,format=raw,id=disk0 + -device qemu-xhci,id=xhci -device usb-tablet,bus=xhci.0 -device usb-bot + -device usb-storage,drive=disk0 -chardev null,id=cd0 -chardev null,id=cd1 + -device usb-braille,chardev=cd0 -device usb-ccid -device usb-ccid + -device usb-kbd -device usb-mouse -device usb-serial,chardev=cd1 + -device usb-tablet -device usb-wacom-tablet -device usb-audio + objects: "*usb* *uhci* *xhci*" + + - name: pc-i440fx + args: -machine pc + objects: "*" + + - name: pc-q35 + args: -machine q35 + objects: "*" From patchwork Mon Sep 21 02:25:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 304887 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=-12.7 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 AB163C43463 for ; Mon, 21 Sep 2020 02:32:30 +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 38D742078E for ; Mon, 21 Sep 2020 02:32:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="qmZl5XoI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 38D742078E 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]:56892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBcz-0003Sp-7O for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:32:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWg-0003Rm-IU for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:58 -0400 Received: from mail-dm6nam12on2117.outbound.protection.outlook.com ([40.107.243.117]:28256 helo=NAM12-DM6-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 1kKBWe-0000b7-Rx for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fpdjvad1UUoxuflKjkrnKnq6NsmgPeTTjJjkdU99K6esE1HnFyHcT8kJB6jtHf+gHRaRb2MQnIC666nNLQ1aFBdsiZ68cXC8brI1TGdFdWG9cptKd7uwFQhUUVYBmI+pynz3Johxr2Ueb3UaIJ9vqLzhdW9xpEvnrY52E39JolsPc9843zaF+EdGZW94V8S6d4h14yBu6oWR28Zy7hP8yyAB3zJrapUgw0/5muSvmz+18Ow2cxMVo6jcnPazVk950gq2oolIlmHIRH5Bm1WQsqerXhWnrszIvm7xDts46yuxDQJdFljx0uy8X6F6eqLSoSOxQKb2BfW597DpYULjdw== 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=DTmTlyBJh6n8z64s22Lli8J7bcfVKAeNDxwX97zyLpk=; b=RPiHyDNO8eWHe9ke7oG3mmUlcXUi4GN+I06q7supTWRvj+lXMEc1p1L8LlRDH7/7i3nVlf8L++n86m5It5oZwcNI3mAI0CfuQFzVYsYnVxwtDZXRviHbU+c9J8Lym5xXD/jV4V9qs+SyduVg+K93dVcFr48ACsZzvLr6E148/shKGaCHGjpmckvNv2IKhx7X4biZNfXw2SyYLYEQHLoJA56espYouyBt3JVEx+IVMfEY+G6ne5Xye45KZlbUrCmzMRk6drgP1Da7+qugCifHtqYX7LhcBM/Pt3rh4C2JvCcEGPxLMQ8+POrbkpokqsju1KrU/eIjgh/U+vytVzZyFA== 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=DTmTlyBJh6n8z64s22Lli8J7bcfVKAeNDxwX97zyLpk=; b=qmZl5XoIp2qrcphGSU/Sn5l0VHdr5DYUsouFgZrHOTsmQDdvBj43rlp2Hm9lnutzkq9bmmGs3aDUB98dvTn3TanqC0EmIhbFW6+2juSpcaMkRmWqy5SboaSQAqM20bBcwn8ffIrDIeCPRPyV1HVNjO7qYj2HVefWcfMuuh1vMwA= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:44 +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.3391.024; Mon, 21 Sep 2020 02:25:44 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 13/16] scripts/oss-fuzz: build the general-fuzzer configs Date: Sun, 20 Sep 2020 22:25:03 -0400 Message-Id: <20200921022506.873303-14-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:41 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d355978b-56b4-4ec9-ffe0-08d85dd5a35c X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KySy3n6jYGpTu9UJx71MOjhmrFWO7BQcpd+nUI7nX/jO9vZwdrVL1WlyrSWiPnrt7lZRofq0mfUPKS1dV7ROm261e+IRBHfXowVuERuDVc/tmi1uK6zOyIBBhjs3svvwrjmj6e/eYv/L0O3e40b2JoUnkoMaverB2/W2rjBzpgGMxle7tXjIh29N/9veiMkst7fLN3A87xwCmXLoMwN4Cktb0TzCGDc5fDaZpXz5wVfmDNjy8CRadX22ouvbqIcQYvRR0Jib9mBGHAKEo4uk950f2DBkC2a33flemyZAp8NNON9npfzh0aBgGuOo2n7A6QfmOUzTOe/sDYpNkaQ+0ziCQnHbf0LoQlAYfmDW+hdyL1Wb8hafbpJhaTZLqCDs 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: UBWjtGmchTgF9HvduivUeIfp411fzRGqyJqmJYI4NsYY5nNwtEwUsekVsfuNRw0fzh80nJk3tcxEcqs7gRiltojIVfZjODhkAzqR7eaYNYt+GdOVoqxzH+zhQeIakZkWu0dU/Ep4LkX9vh48l81BER9WM7nnipVUiBxQ/eryWWe3zBnn3LGg8kPeusLOzmJzSwnZDQKrMAYYBDyOqj+cVkkM2oXPh5WgLLO/RQD16iFtToWYfrauDMaPqZcEAFeev6VSl/Prs0lbTpMawEKIpSaTBl0WtBl8wV4jap+l1zT63//M5ImFJPiH48XUZusNMWsir93xfPfDDisPN0xqnOILISb05ujXV994Jlsfc/zkI+sHNZIjsiMB/3Eq9Pki3JNkTnawAiPCGHR6LUssQBsd550H0WLuvTRwYNL9dmdabQUNEOOzbyIKNczaKXz848GsWXQ9l6XCabRCz5fXYEX16oItXyo3u08Tei1aFsGemIDIF+8bBf3spXE0A+fPPkTrsZGaKyi57xqQSBr6J6sda8sx/kA8KjsUSkGzTG1a9DGnWDFkVVd3dj6+fGwACxvQng+OCJUUhc6Wf87eUlkyp266KUVhuudIoTmN/fvlu/D+JsC9/9c1mviT3Y3vWp+rOCFV40Uo360Hb5A1Uw== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: d355978b-56b4-4ec9-ffe0-08d85dd5a35c X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:43.7745 (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: CBWbgpiQMiaOD3lRLTj3Rtz/hvvxtdw5X6bWJX/UhxvmHzC/mQADplAWxoFGLB/a X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.243.117; envelope-from=alxndr@bu.edu; helo=NAM12-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:42 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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: Thomas Huth , Alexander Bulekov , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Build general-fuzzer wrappers for each configuration defined in general_fuzzer_configs.yml and move the actual general-fuzzer to a subdirectory, so oss-fuzz doesn't treat it as a standalone fuzzer. Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny --- scripts/oss-fuzz/build.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/oss-fuzz/build.sh b/scripts/oss-fuzz/build.sh index d16207eb67..16b9f39d07 100755 --- a/scripts/oss-fuzz/build.sh +++ b/scripts/oss-fuzz/build.sh @@ -87,6 +87,7 @@ make "-j$(nproc)" qemu-fuzz-i386 V=1 # Copy over the datadir cp -r ../pc-bios/ "$DEST_DIR/pc-bios" +cp -r ../pc-bios/ "$DEST_DIR/deps/pc-bios" # Run the fuzzer with no arguments, to print the help-string and get the list # of available fuzz-targets. Copy over the qemu-fuzz-i386, naming it according @@ -97,5 +98,11 @@ do cp qemu-fuzz-i386 "$DEST_DIR/qemu-fuzz-i386-target-$target" done +mkdir -p "$DEST_DIR/deps" +mv "$DEST_DIR/qemu-fuzz-i386-target-general-fuzz" "$DEST_DIR/deps/" + +./scripts/oss-fuzz/build_general_fuzzers.py \ + "./scripts/oss-fuzz/general_fuzzer_configs.yml" "$DEST_DIR/general-fuzz-" + echo "Done. The fuzzers are located in $DEST_DIR" exit 0 From patchwork Mon Sep 21 02:25:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 304883 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=-12.7 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 C7ACFC43463 for ; Mon, 21 Sep 2020 02:38: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 1B9E82078E for ; Mon, 21 Sep 2020 02:38:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="IcwuSii6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B9E82078E 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]:46452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBih-0002V6-9L for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:38:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWg-0003So-Vi for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:59 -0400 Received: from mail-dm6nam10on2102.outbound.protection.outlook.com ([40.107.93.102]:19201 helo=NAM10-DM6-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 1kKBWe-0000aa-VS for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:25:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dkgZ6xnRCI2FcDsrDyU00LG5U5+Mcc4FT9fv1NXk5u0IXzlh7FJdBFaLqyuYB+CDuy23lUWjuPDTJhQgyAZc85r41bBj5vUJHiEfFg1jW/AkH4B2CiYsBtQeHoX6HnrzGs6Lsj65jG9eOrLUijAiB78K53PP9lcTdxbdu8TXZJrRXk8keXrEeMGM56+ZHXwno7Z73Q4mjr8TIm3AhzCyxHzEDCTBFsx1BGLuQ3pqZU65EwDmdLiSNDRCQD2A0DLZo+zRS2JgRP8o06WnzWOCsJu8DqYJpl8lUiyYe5uI7XYj33JTm+vLCgnBGIw0JZkkOpr6B+WJaUWU2KghEpihTA== 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=S7biyK8EuRC5wbDe8xPAiZCZtZWrpN0dJY9gbT8HveA=; b=H7YfMFa0hTGMeenTiASvDs4w+MmxTSV31/n7qEm+DpCZ4Dt80lsxN+cSDBdktA9gnbeUfMuDl8UJ//hG27L7n7yz1dk5lA/OBub7Fx0lz+apWMPTGZpl9GCr+T5WOoiUD1D2iuvuWHIlygWiB8xm/z5npvHRg76CTyo1LVJT359xSGQEXRuwwlAd7H+NPOgO3rQqzTvnseyVBPx5iA6Xnd5ahN4VCz423LPtzWCj45k3s6PFL9VPb+Z5Y3kQTOuvRSfINBkPG8FlHa5XLP9WY+ui8qTgZsnMlwaV4AJlelP6H2sAefsNSnaY/XOaDqgcD7PRguDTxKhgSdH5/iJPIA== 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=S7biyK8EuRC5wbDe8xPAiZCZtZWrpN0dJY9gbT8HveA=; b=IcwuSii6YEQ3W6AjRp9pn5lnUVc2N8QW/1xJew3COuO844pMIDrTQJ4Hi3OJwaycfdwuPxcgsItyeKBFOvWwiGI1QjfQMpAN/t1ZQrSxPqYxEo7oEw1gK053H1hj2J7ctdGf06XKVPn7C1aplV0wKQ8GhDokL1EK3xNVjfDOdUQ= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:46 +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.3391.024; Mon, 21 Sep 2020 02:25:46 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 14/16] scripts/oss-fuzz: Add script to reorder a general-fuzzer trace Date: Sun, 20 Sep 2020 22:25:04 -0400 Message-Id: <20200921022506.873303-15-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:45 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4b772435-3b87-46b0-129c-08d85dd5a583 X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5pQeylsPHwULbFkkkcMgdw/kq2L86R8MnBvCKnVN2+7ljLGV2R3Eb6ssWsR5QBjnv+8mBM26kbLskva1H/JFScB4ZpI79y6OpJ+q5CdTDpa41N3JyN7lp0XpzGP5WpgEekCWoU+PvxnKfj7ABRxmhVkDUtmlW90rkWKMOVBvj5yAvfBlgNfPmSG1Vr2U8Ju53ENKBUCJKfZ/7Y6Cb6XPYs0dHaL8KqF5Q9WIgkwo6DS99ACqW+WK7RfFORh4ZMlfUAza2T4dNeOeWohWB3HzhDJuulUT10FlIWpSsZayT3uwKkDPLKkpoOQQ+BENpBV+/QQ391UqTdQOOcCdvu/kx5ad1qkCJIxgFBPBGL7wJmDdLXvan1QWblC66eMoPGPH 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(83380400001)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 3nWeC3ZacuQta+VCPqpChCkF9a6/Ftu8FoN2UuCfNtnoPc1PYoXnZ8c5JHQImpepMs8SIt8YJehAN7zfKqK90TI2bC53EB67Zdr6qfsUyhlyEVa1A5yGHy3Pm3qcGOvup24PgonK9ArmDmzby3+UToiu+vkyxDRicwT16u9AGI8ZBeiKx76Jp+EJNZV7mXQRjhYw20qfze6qO6ijNAU+Zw3V93cKo/lvANuTCLdIsOvP9mTeD/XEudimRpwOo19By+PYqYbMDbkMsSQwTtXsYLoUgQLZqb/WrY8uX2PEyFLzZuFo5jkayVeP8zP/4wfDax5YvRZdI6vWue6dgLAqeaKpn8VLMzCrmjJb8M96+eaC0h+Le40+0k5gHIX13l+dnJkR/Rkpnh1SkXVrAIN6IXWreyu6tMaqQmMwHd2p3X4JamUmMxsT79WlSmoC2VLHvQV3YMGwk8QnXpK6W4u2TesHyzDepjIZP7rTD7LKXo1YszfIPbRppUOB0rn3oYZPS4hvFZZjEjxRO5s2boPHPSIhipppUwDn3UrP4TmZJMu6VZnHCDss5RqXHRirnLvXJ8BE0RVsutvIk/6WizlnccIVhlsPgNulc/Uk6hfxf7b4aVXHF1IUZ3TAdVZ8YmH+v1Ujcl1G4x9utAm8iXNISw== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 4b772435-3b87-46b0-129c-08d85dd5a583 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:46.7838 (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: N45RZTt0SKZ27WnM2fER9KQfDpE+PeOmA+T1oKJEGwbOt254ZG0e6hkx+v7ysP46 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.93.102; envelope-from=alxndr@bu.edu; helo=NAM10-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:33 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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: Thomas Huth , Alexander Bulekov , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The general-fuzzer uses hooks to fulfill DMA requests just-in-time. This means that if we try to use QTEST_LOG=1 to build a reproducer, the DMA writes will be logged _after_ the in/out/read/write that triggered the DMA read. To work work around this, the general-fuzzer annotates these just-in time DMA fulfilments with a tag that we can use to discern them. This script simply iterates over a raw qtest trace (including log messages, errors, timestamps etc), filters it and re-orders it so that DMA fulfillments are placed directly _before_ the qtest command that will cause the DMA access. Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny --- .../oss-fuzz/reorder_fuzzer_qtest_trace.py | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100755 scripts/oss-fuzz/reorder_fuzzer_qtest_trace.py diff --git a/scripts/oss-fuzz/reorder_fuzzer_qtest_trace.py b/scripts/oss-fuzz/reorder_fuzzer_qtest_trace.py new file mode 100755 index 0000000000..9fb7edb6ee --- /dev/null +++ b/scripts/oss-fuzz/reorder_fuzzer_qtest_trace.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +Use this to convert qtest log info from a generic fuzzer input into a qtest +trace that you can feed into a standard qemu-system process. Example usage: + +QEMU_FUZZ_ARGS="-machine q35,accel=qtest" QEMU_FUZZ_OBJECTS="*" \ + ./i386-softmmu/qemu-fuzz-i386 --fuzz-target=general-pci-fuzz +# .. Finds some crash +QTEST_LOG=1 FUZZ_SERIALIZE_QTEST=1 \ +QEMU_FUZZ_ARGS="-machine q35,accel=qtest" QEMU_FUZZ_OBJECTS="*" \ + ./i386-softmmu/qemu-fuzz-i386 --fuzz-target=general-pci-fuzz + /path/to/crash 2> qtest_log_output +scripts/oss-fuzz/reorder_fuzzer_qtest_trace.py qtest_log_output > qtest_trace +./i386-softmmu/qemu-fuzz-i386 -machine q35,accel=qtest \ + -qtest stdin < qtest_trace + +### Details ### + +Some fuzzer make use of hooks that allow us to populate some memory range, just +before a DMA read from that range. This means that the fuzzer can produce +activity that looks like: + [start] read from mmio addr + [end] read from mmio addr + [start] write to pio addr + [start] fill a DMA buffer just in time + [end] fill a DMA buffer just in time + [start] fill a DMA buffer just in time + [end] fill a DMA buffer just in time + [end] write to pio addr + [start] read from mmio addr + [end] read from mmio addr + +We annotate these "nested" DMA writes, so with QTEST_LOG=1 the QTest trace +might look something like: +[R +0.028431] readw 0x10000 +[R +0.028434] outl 0xc000 0xbeef # Triggers a DMA read from 0xbeef and 0xbf00 +[DMA][R +0.034639] write 0xbeef 0x2 0xAAAA +[DMA][R +0.034639] write 0xbf00 0x2 0xBBBB +[R +0.028431] readw 0xfc000 + +This script would reorder the above trace so it becomes: +readw 0x10000 +write 0xbeef 0x2 0xAAAA +write 0xbf00 0x2 0xBBBB +outl 0xc000 0xbeef +readw 0xfc000 + +I.e. by the time, 0xc000 tries to read from DMA, those DMA buffers have already +been set up, removing the need for the DMA hooks. We can simply provide this +reordered trace via -qtest stdio to reproduce the input + +Note: this won't work for traces where the device tries to read from the same +DMA region twice in between MMIO/PIO commands. E.g: + [R +0.028434] outl 0xc000 0xbeef + [DMA][R +0.034639] write 0xbeef 0x2 0xAAAA + [DMA][R +0.034639] write 0xbeef 0x2 0xBBBB +""" + +import sys + +__author__ = "Alexander Bulekov " +__copyright__ = "Copyright (C) 2020, Red Hat, Inc." +__license__ = "GPL version 2 or (at your option) any later version" + +__maintainer__ = "Alexander Bulekov" +__email__ = "alxndr@bu.edu" + + +def usage(): + sys.exit("Usage: {} /path/to/qtest_log_output".format((sys.argv[0]))) + + +def main(filename): + with open(filename, "r") as f: + trace = f.readlines() + + # Leave only lines that look like logged qtest commands + trace[:] = [x.strip() for x in trace if "[R +" in x + or "[S +" in x and "CLOSED" not in x] + + for i in range(len(trace)): + if i+1 < len(trace): + if "[DMA]" in trace[i+1]: + trace[i], trace[i+1] = trace[i+1], trace[i] + for line in trace: + print(line.split("]")[-1].strip()) + + +if __name__ == '__main__': + if len(sys.argv) == 1: + usage() + main(sys.argv[1]) From patchwork Mon Sep 21 02:25:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 273216 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=-12.7 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 61248C43465 for ; Mon, 21 Sep 2020 02:32:29 +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 D9D7F2078E for ; Mon, 21 Sep 2020 02:32:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="8NpT0laH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9D7F2078E 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]:56784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBcx-0003QI-Oz for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:32:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWi-0003Xb-Lk for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:26:00 -0400 Received: from mail-dm6nam12on2117.outbound.protection.outlook.com ([40.107.243.117]:28256 helo=NAM12-DM6-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 1kKBWg-0000b7-Od for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:26:00 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SQcCCo/0fn7hm6PViHOsr/X3dflpzN4d/TTMsQBOd6V3QA5CrIwFpFBg6gqOoq9ZtNSdrMt/9cOdSCdo65uKzR9yHb3Yn+YLyoOM1ToQBdO2mh+xKy9UL31VhhMEpNV2C56ZT5wq6wFcZEWVJYIauRn+XeYidFH5xhw3GDWrepx74lVm2m2+0iv/FAxRsblYhmZ5v7mriTERwDTmTpXPOp7u5EYl4kYIv1FkiSbDF+gzsiWGDbeswr/akLKKqIM5ktDg0UjT6BOpRPFQraaUUUA4hTmTRvjmt60y+Cve6MURObKIVY8oZpdU/AgPKyI0qpICn1KloDllPb6Su+XU9A== 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=0L41r48jbdQFt8ebZgEjrCNHjMkZsCBEX+y/w5PK8Fs=; b=jcj2THz7fDXx6iEYus2VFTVsrzZ3XjinTzu3qu0IC2CRVsg9pCAyBsoYvO4MOgfwMRi27PQqGaQZTLYGnngEfIa/81Hrsl8GjFooHbRlkDfIcAiKfZYDLCo5q89lFyoKhuxOnouqd+tQRG2eC5KqUXy0u8zKHLEIANdWnqvJfiiVQF+jFhCMWZ273Jk/JhS64zdMimx3pxEuoZnkZSHPaSperIFmSAt84L2Xq9dG8J9tMRWnh0dTSDdXskts/4vaeJKEwcaILmUMu19aNLVg5iYt/0wzTpQAkkdHu5xkrD9KedUuuIfWcA38627oTvTpKH9gRwy6PY4SpH0nvkbSMg== 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=0L41r48jbdQFt8ebZgEjrCNHjMkZsCBEX+y/w5PK8Fs=; b=8NpT0laHl/1u/4KB2XNN6HD3AxOkfP6lr4PS4Q/oDq95wnjzQ8pOzS0Jruq9o45kRRCTyZ3qFRJHPVWzkZrrxiUNGdQH0vb+BWBiJYlaUByE1PBAdorOPShlZsbWs0Vdo6TL2E1Meype/m34SXMGL1nkt9L6yiqzI7fdq9mw9tc= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:49 +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.3391.024; Mon, 21 Sep 2020 02:25:49 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 15/16] scripts/oss-fuzz: Add crash trace minimization script Date: Sun, 20 Sep 2020 22:25:05 -0400 Message-Id: <20200921022506.873303-16-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:48 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 24670455-4b32-47de-7d59-08d85dd5a719 X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1923; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DN7l+B9VK9ADUu+qAHOmh1O5g8EmQST7Hn2fDmyzrxDXYsQxosdnPi3F75Ar2NwrNJEEbmNet/bkqTfNj4ppGJb4tKyQXv8UhUe+AQwbryFJxl6zV3IFHPfj1/bBRI6nCXNq1YC0AaQ0qVlaZhTL4nAkLZBI/427ld21KE+vtsNOA9yHlts0boLH19ZHlgqDm6edN+qf4slIUiNYgGcO2As6qbXjJFsc/+PTQ9eZF3JCwvaf1ECrDdhsjgA6lL7v6vvUqHAp3Di5YJIgKica8rP7ABHeuop1lW0yUjUCKCJuJs5JFGWLyFik8eGdOAs+Z8cUg0/FDSEIHvZgdibftBXsCeLbSkEaBiyyjSfSFUW8+DPuxfeAAHkRCTX+qeyu 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(83380400001)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 0E2W45FJk8IcHLGlQbI8QLH52jBICrQbAbCJl5t6Fu9Qe19rwr9CAFQMSa8p6H/34YlQngoY/k1q2CHF8MQYr94UTLC6GIuRznNWcLWhDnrLfuOnQt8w2sSVXtEiast8ktm6Fs3qbw/KTypdjyR5td/g47OLu7wphT84X0sNtMKrG8VGakKb50JGbCOHvGTTLuEwjqLOv/WUVz+MojJptgqPmaToImbk73ZcTCE0azIxv9m/j9n6DBJ38t8xvODU92wjrTgwc5uhRuyaQ3lAQWPeWzNNpf9tU9DJ5amGn9uyhMXDQkBXVLgoir++tMzk4UvTKOCFrHnvwOYLhXtksqdPuWIiSmLaJwpJzbf36BvTnc9FMVTg6dnJHaS+/9gFe0D9pm2Ubu9MIQtYEJjhP2MFWG4yaKCiCr/bKhOfaElPnQO7ukAFjkc2UEFpSbD6sfG/r0lbdfd/s+ENJZF1VZR8oYoUgrSRhd1m42Fhat3fksyqDqCtfmG0O7dVHEiJjjXuUWv5tG9+4zLaIgYH4GCx0tfpz1iByD/bisp5cRNByCCVYFWL0f/2K1IEonMeQh1wOQwN444eDFYPpogh/FF/2HfVElnpnLeDqKnkzWZNgssm451eL8W8bDMa39Pnep4tuI4g8Z5CWvCCLT2xoA== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 24670455-4b32-47de-7d59-08d85dd5a719 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:48.9675 (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: PO+nr0MYdC5P6CDDeVb8oVRxvcJNghTxPpt3a0hZXJra8JC4oXEwKJS80N4PNRvU X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.243.117; envelope-from=alxndr@bu.edu; helo=NAM12-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:42 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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: Thomas Huth , Alexander Bulekov , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Once we find a crash, we can convert it into a QTest trace. Usually this trace will contain many operations that are unneeded to reproduce the crash. This script tries to minimize the crashing trace, by removing operations and trimming QTest bufwrite(write addr len data...) commands. Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny --- scripts/oss-fuzz/minimize_qtest_trace.py | 157 +++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100755 scripts/oss-fuzz/minimize_qtest_trace.py diff --git a/scripts/oss-fuzz/minimize_qtest_trace.py b/scripts/oss-fuzz/minimize_qtest_trace.py new file mode 100755 index 0000000000..05596d6f9c --- /dev/null +++ b/scripts/oss-fuzz/minimize_qtest_trace.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +This takes a crashing qtest trace and tries to remove superflous operations +""" + +import sys +import os +import subprocess +import time +import struct + +QEMU_ARGS = None +QEMU_PATH = None +TIMEOUT = 5 +CRASH_TOKEN = None + +write_suffix_lookup = {"b": (1, "B"), + "w": (2, "H"), + "l": (4, "L"), + "q": (8, "Q")} + +def usage(): + sys.exit("""\ +Usage: QEMU_PATH="/path/to/qemu" QEMU_ARGS="args" {} input_trace output_trace +By default, will try to use the second-to-last line in the output to identify +whether the crash occred. Optionally, manually set a string that idenitifes the +crash by setting CRASH_TOKEN= +""".format((sys.argv[0]))) + +def check_if_trace_crashes(trace, path): + global CRASH_TOKEN + with open(path, "w") as tracefile: + tracefile.write("".join(trace)) + + rc = subprocess.Popen("timeout -s 9 {timeout}s {qemu_path} {qemu_args} 2>&1\ + < {trace_path}".format(timeout=TIMEOUT, + qemu_path=QEMU_PATH, + qemu_args=QEMU_ARGS, + trace_path=path), + shell=True, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE) + stdo = rc.communicate()[0] + output = stdo.decode('unicode_escape') + if rc.returncode == 137: # Timed Out + return False + if len(output.splitlines()) < 2: + return False + + if CRASH_TOKEN is None: + CRASH_TOKEN = output.splitlines()[-2] + + return CRASH_TOKEN in output + + +def minimize_trace(inpath, outpath): + global TIMEOUT + with open(inpath) as f: + trace = f.readlines() + start = time.time() + if not check_if_trace_crashes(trace, outpath): + sys.exit("The input qtest trace didn't cause a crash...") + end = time.time() + print("Crashed in {} seconds".format(end-start)) + TIMEOUT = (end-start)*5 + print("Setting the timeout for {} seconds".format(TIMEOUT)) + print("Identifying Crashes by this string: {}".format(CRASH_TOKEN)) + + i = 0 + newtrace = trace[:] + # For each line + while i < len(newtrace): + # 1.) Try to remove it completely and reproduce the crash. If it works, + # we're done. + prior = newtrace[i] + print("Trying to remove {}".format(newtrace[i])) + # Try to remove the line completely + newtrace[i] = "" + if check_if_trace_crashes(newtrace, outpath): + i += 1 + continue + newtrace[i] = prior + + # 2.) Try to replace write{bwlq} commands with a write addr, len + # command. Since this can require swapping endianness, try both LE and + # BE options. We do this, so we can "trim" the writes in (3) + if (newtrace[i].startswith("write") and not + newtrace[i].startswith("write ")): + suffix = newtrace[i].split()[0][-1] + assert(suffix in write_suffix_lookup) + addr = int(newtrace[i].split()[1], 16) + value = int(newtrace[i].split()[2], 16) + for endianness in ['<', '>']: + data = struct.pack("{end}{size}".format(end=endianness, + size=write_suffix_lookup[suffix][1]), + value) + newtrace[i] = "write {addr} {size} 0x{data}\n".format( + addr=hex(addr), + size=hex(write_suffix_lookup[suffix][0]), + data=data.hex()) + if(check_if_trace_crashes(newtrace, outpath)): + break + else: + newtrace[i] = prior + + # 3.) If it is a qtest write command: write addr len data, try to split + # it into two separate write commands. If splitting the write down the + # middle does not work, try to move the pivot "left" and retry, until + # there is no space left. The idea is to prune unneccessary bytes from + # long writes, while accommodating arbitrary MemoryRegion access sizes + # and alignments. + if newtrace[i].startswith("write "): + addr = int(newtrace[i].split()[1], 16) + length = int(newtrace[i].split()[2], 16) + data = newtrace[i].split()[3][2:] + if length > 1: + leftlength = int(length/2) + rightlength = length - leftlength + newtrace.insert(i+1, "") + while leftlength > 0: + newtrace[i] = "write {} {} 0x{}\n".format( + hex(addr), + hex(leftlength), + data[:leftlength*2]) + newtrace[i+1] = "write {} {} 0x{}\n".format( + hex(addr+leftlength), + hex(rightlength), + data[leftlength*2:]) + if check_if_trace_crashes(newtrace, outpath): + break + else: + leftlength -= 1 + rightlength += 1 + if check_if_trace_crashes(newtrace, outpath): + i -= 1 + else: + newtrace[i] = prior + del newtrace[i+1] + i += 1 + check_if_trace_crashes(newtrace, outpath) + + +if __name__ == '__main__': + if len(sys.argv) < 3: + usage() + + QEMU_PATH = os.getenv("QEMU_PATH") + QEMU_ARGS = os.getenv("QEMU_ARGS") + if QEMU_PATH is None or QEMU_ARGS is None: + usage() + # if "accel" not in QEMU_ARGS: + # QEMU_ARGS += " -accel qtest" + CRASH_TOKEN = os.getenv("CRASH_TOKEN") + QEMU_ARGS += " -qtest stdio -monitor none -serial none " + minimize_trace(sys.argv[1], sys.argv[2]) From patchwork Mon Sep 21 02:25:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 273214 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=-12.7 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 DE555C43465 for ; Mon, 21 Sep 2020 02:34:18 +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 87E1D2078E for ; Mon, 21 Sep 2020 02:34:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="KGC9SMDc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 87E1D2078E 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]:36014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKBej-0006Ud-N1 for qemu-devel@archiver.kernel.org; Sun, 20 Sep 2020 22:34:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKBWi-0003Xy-RS for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:26:00 -0400 Received: from mail-dm6nam10on2102.outbound.protection.outlook.com ([40.107.93.102]:19201 helo=NAM10-DM6-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 1kKBWh-0000aa-4m for qemu-devel@nongnu.org; Sun, 20 Sep 2020 22:26:00 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AKy+uXd3TrvV2GYIqTXcJAeK1Zmnfk+yqUkFChcUpqxJg3NnMOq+qlwESjvChLMIK10TURMXt4hqyNWsXFgA2AlsTwUnYg+Pfzwuy3OonJiZdDxlzyoLDQ0S5y0cailrQzhItjIysVBwzPFhnDzWlD/dSBkEWAsclKGL8nZsC3V9yNVKYcero7kpOJU618/gfYSxQpk3FZvUQcAwnjnpYnnVXXyXGLsrx59OFHHcamS5etFBJVitPBgI8tVYlGPP8s+0jJ9aBGNQz1aUhFTl+0ID+0/Ab4O1rCeTIH6KSYvMehe0Q8mJN9AmrL40FEKGl6bW56GrQv0wHg2w4/AqNA== 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=KJCe5oqAIP3HXw+8Z68yrHbiF2LvbPR7sPrF0eRbeeA=; b=jZuvaAA5Q2psn3L9vYkWvM0EncBsMCxLcdNEoWRVsmpo4blT3zyN8qxQtlheEALluSYlG6kppo7VoaMrG8muzkEII/eZzmo4ewH3QBbYK+VVnJlxe/ZxS6BxiGHz/011wPOImzcI2yNIIRwJBgZqbvRNVZPBxJUc1GmtBZcw/EFNLe+i/Hq6p/YBTxsiAtpECvT6lMq4Dsjq64xKCLgFPjahbodXpI5Qh7cWdwac1ed/zhp2WuoLypswI3vYA+Yd9/qoV13YZzFQdYYz5cOgv13YpIDrmOF14KQ8lucK5VDTLJ/1RdGcyo01gIdTPJlW30QSeuSXzOPEPqDbwCtfaA== 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=KJCe5oqAIP3HXw+8Z68yrHbiF2LvbPR7sPrF0eRbeeA=; b=KGC9SMDcMuF2E09OesykARUbvTmg3BSzeQyHpt4X0cxx0/xCzA67+6juBQ4MHcavGwaaMc8awKdu6WxIgdyu3im1Y8ZHMWtMqKTlHvXDRSNQwiVvwHv6eI52hpPLWlHj9ooAF/lzIwDibmXBr6zcXjPNio0UysqIeMi85CFAgXc= 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 SN2PR03MB2237.namprd03.prod.outlook.com (2603:10b6:804:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.11; Mon, 21 Sep 2020 02:25:50 +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.3391.024; Mon, 21 Sep 2020 02:25:50 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v3 16/16] fuzz: Add instructions for using general-fuzz Date: Sun, 20 Sep 2020 22:25:06 -0400 Message-Id: <20200921022506.873303-17-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921022506.873303-1-alxndr@bu.edu> References: <20200921022506.873303-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) 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 BL0PR1501CA0034.namprd15.prod.outlook.com (2603:10b6:207:17::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.14 via Frontend Transport; Mon, 21 Sep 2020 02:25:49 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [72.93.72.163] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b0c6f634-cee5-4dfa-944e-08d85dd5a803 X-MS-TrafficTypeDiagnostic: SN2PR03MB2237: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8W09fBUsKPFJm/XO0bNuOVp6fBtP+BJCWzRXuOI9osXC7zqL+Z1QCcxBGr+Y/n2/ymGL4mogZw8U9ubiwCGNiNob4MFCINXi3PF8FMi9wC8lU+6+2thKt2Dp90RWqpHE3E0RH/SYz7dQmdYHAntPW7AHWT1B8HP74PekDoT/TDLoEMh2bMM5yFgICbeEtX85aOd209TNjCS/rjBmlXaLqYI81tQCEEJdRcC8KQSGOmYR1C/r6f2nbSn8pWybgCZPLbQ8XvJFO//FXrJ5wn6CaB5PS5yAbEnkz8FY/ayFK89b2jahAON65786JHskZPgav4QO8Y1xrR//2pgo0Kxbd2DuDMoPAVvIyDRpxNYTTYnF19UpM1P5xuqx4LBWP8Kq 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)(366004)(376002)(136003)(346002)(39860400002)(2616005)(956004)(4326008)(54906003)(83380400001)(26005)(478600001)(16526019)(6666004)(8936002)(316002)(6486002)(66476007)(1076003)(6512007)(186003)(6916009)(86362001)(66946007)(5660300002)(36756003)(75432002)(2906002)(6506007)(8676002)(66556008)(52116002)(786003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: VbaGiGVEPBBRKO1V/JaYN0i4QY8sXJJnX7R3aw4lwHDkW+Dc7wFTJvQsJuh4JKPCtouv6ElAlooIXFDXAa5q0DcrpSKJDx9d12wpUtwmb5Cv9giEOEfh8SAvu7hjSXXyeMMJ/qcZdtQ11/eswOAiWCo7iANdmapY5qk1Xw24J13bbJEt04Z5P8mHv4aPxQSmk+RM0CmDLnrlvqYa9YcMbSMrmNGH6CY8/r6KXZJQaGidM5rHakp7fyUef84xUhAFsieg6lw2+uhREESg0awU9qJX0v+3uoUocBPPFsbMQ5wF7jQEhxbuiewsfBlH/Q6sMAy3vPJIauNLa+TZSSPvgwWEmcxscYZ85WW/1F/Ei35m9eaX1ucMg0gRmIf1tHEOYvF0lqy192E2H1pMPuYD6ijonz/ZaMnifizHRQTTS2smYRHxKTvWQlK1IJ0RZ/n/9dEfFm8KdUalVp0anuJwd5xPo7SnhVgl8ue+lydjecg/bqPqRZqiJTYn9JI1gQgjcBOxZ+hUCP20Num0WeIpFm1Dg1yBcakKHJJBmbs75LPf7LiqpcNfjFT4wC8amSxEbqsxfBnkMeqhm3cIFk+N9Jwtf+ztYN+/+B59sspUkXWWJ+nr6AnOxiym3KBNAIccej0I348UucJPl+wYyQ2duA== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: b0c6f634-cee5-4dfa-944e-08d85dd5a803 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2020 02:25:50.4007 (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: Lb92QPyfLQJSdT6By+SFC5NQQRU31ndWDMhWYhoXREpHKR37vDoHSwosgu+/LDym X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2237 Received-SPF: pass client-ip=40.107.93.102; envelope-from=alxndr@bu.edu; helo=NAM10-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 22:25:33 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.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.001, 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: Thomas Huth , Alexander Bulekov , darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny --- docs/devel/fuzzing.txt | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/docs/devel/fuzzing.txt b/docs/devel/fuzzing.txt index 96d71c94d7..208b0c8360 100644 --- a/docs/devel/fuzzing.txt +++ b/docs/devel/fuzzing.txt @@ -125,6 +125,44 @@ provided by libfuzzer. Libfuzzer passes a byte array and length. Commonly the fuzzer loops over the byte-array interpreting it as a list of qtest commands, addresses, or values. +== The General Fuzzer == +Writing a fuzz target can be a lot of effort (especially if a device driver has +not be built-out within libqos). Many devices can be fuzzed to some degree, +without any device-specific code, using the general-fuzz target. + +The general-fuzz target is capable of fuzzing devices over their PIO, MMIO, +and DMA input-spaces. To apply the general-fuzz to a device, we need to define +two env-variables, at minimum: + +QEMU_FUZZ_ARGS= is the set of QEMU arguments used to configure a machine, with +the device attached. For example, if we want to fuzz the virtio-net device +attached to a pc-i440fx machine, we can specify: +QEMU_FUZZ_ARGS="-M pc -nodefaults -netdev user,id=user0 \ + -device virtio-net,netdev=user0" + +QEMU_FUZZ_OBJECTS= is a set of space-delimited strings used to identify the +MemoryRegions that will be fuzzed. These strings are compared against +MemoryRegion names and MemoryRegion owner names, to decide whether each +MemoryRegion should be fuzzed. These strings support globbing. For the +virtio-net example, we could use +QEMU_FUZZ_OBJECTS='virtio-net' +QEMU_FUZZ_OBJECTS='virtio*' +QEMU_FUZZ_OBJECTS='virtio* pcspk' # Fuzz the virtio-net device and the PC speaker... +QEMU_FUZZ_OBJECTS='*' # Fuzz the whole machine + +The "info mtree" and "info qom-tree" monitor commands can be especially useful +for identifying the MemoryRegion and Object names used for matching. + +As a general rule-of-thumb, the more MemoryRegions/Devices we match, the greater +the input-space, and the smaller the probability of finding crashing inputs for +individual devices. As such, it is usually a good idea to limit the fuzzer to +only a few MemoryRegions. + +To ensure that these env variables have been configured correctly, we can use: +./qemu-fuzz-i386 --fuzz-target=general-fuzz -runs=0 + +The output should contain a complete list of matched MemoryRegions. + = Implementation Details = == The Fuzzer's Lifecycle ==