From patchwork Wed Aug 19 06:10: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: 11722567 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D5981913 for ; Wed, 19 Aug 2020 06:12:34 +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 A14262063A for ; Wed, 19 Aug 2020 06:12:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="MrHVCy1f" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A14262063A 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:35848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HKr-0005LW-Lc for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:12:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HK3-0003mA-DB for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:43 -0400 Received: from mail-bn8nam11on2094.outbound.protection.outlook.com ([40.107.236.94]:24608 helo=NAM11-BN8-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 1k8HK1-0001Y3-8Q for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I9qVtKIr4f30K41YUr6wB/A89QepprACARFeseeSrXxz/DKQBVTCFn/YowSwp32mP0urkKOWtLTfX515szkL11s95o0SK25M0IP2gnp/zHgIo+Xln999uKCkm1l9YsjUOk5Tzqqs+cphBVu66wNwcZI3ijPyG0wZdgdTSeydRRkq09TZP55UnHB6LJfa7kuK4y+qA/ecUN4iMbP/n7Rq9ANg8SulNh8ksxrFOK0QXgOOw1sC5Dpus2LzdqqTY/n4fBqGV/Ti6f3zkdKqvh1fOAd+Z4uswP+N2uaJNGF9fKxd/QonkPBe/Mn6jWIIjpxsX+rXLRoXg+LefgQBztQA7A== 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=Iy876L3SaINJIQ4UizsMomYb3fp4iPmxSgYioPmr5Ns=; b=RklFadHLowQTnFxKTyrPDfBRxL9cBMwUxxdbEX4WzX6hMyZhDmiMpCW2nNpnOLRhqwwrpkxADwrG4l8A4nL4cakTDGRWPMWNGbZ0j/No4X8Zja40VL1On0qyaldiyAN+8U1k598NKJ40QPfJWGhrwtafRgCWTBmeJnMleGYds+W223+zjT2JPeD1OfQ3uRAemjNWdhDY8/nwk8uoXdxgzwlhZzlXNzaQZWcQ2cPwrEd/PMCsyILl4zRrandVRovIrrmH2vkM5IwRoHp7d0xs3XFUALPKdrAilYP6GAEELONythZfSU3vCh5cIHdi8L0fDwOf55/6JYfGDltcFrWznQ== 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=Iy876L3SaINJIQ4UizsMomYb3fp4iPmxSgYioPmr5Ns=; b=MrHVCy1f1Bjp7VAW4QhKYB7HXJzoU57aEb4v4ftRIbUSkv2wHmmekrHbMANGLayKbSkzIUmL5sEJKrEciDFHnNedt3JY2/KJJ98J5o3/GxSFW1NW56er10wpR9A1IxOhrgreWbkh5w/UOL3NSCQw7LcD5ex8+1rkoPG9UE9BkTw= 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 SN6PR03MB3934.namprd03.prod.outlook.com (2603:10b6:805:70::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24; Wed, 19 Aug 2020 06:11:32 +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.3283.028; Wed, 19 Aug 2020 06:11:32 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 01/15] fuzz: Change the way we write qtest log to stderr Date: Wed, 19 Aug 2020 02:10:56 -0400 Message-Id: <20200819061110.1320568-2-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11:31 +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: 44916f85-cd34-44ea-35bf-08d84406b7fb X-MS-TrafficTypeDiagnostic: SN6PR03MB3934: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:901; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: R9p/lLXI2MBJkKFPFA0d9v7CJytHFL/xUcqDb+sP+N2gLVC3hfOBEHuFpnVLe9s2QZGhGQq5lO/za/z8P0G+4297B5Qs5zKrRMU9mYlFxsqn9rcL0Okoj81K5as4zAfb7d9OwW0aAlN+1pEiexP9Atq6hvoNDVAajDIRPQMI06icxx0RjtZPDDeJ3kxvAEwbWtf3BmkwdWoIO8fqhpkExUZcEpPfhTg2rG0dI1DRdEouiSj31rStLwDcMYXJUTiu6rgdKltSFFupYl3f73h10HxdW7U0UzqOJpN4sdgl2iLFEXyV4AsAfKMH5/fXrH/A 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)(136003)(346002)(39860400002)(396003)(366004)(376002)(1076003)(8676002)(6666004)(2906002)(6512007)(8936002)(6916009)(83380400001)(6486002)(54906003)(956004)(6506007)(2616005)(36756003)(26005)(52116002)(86362001)(478600001)(786003)(66556008)(316002)(4326008)(75432002)(66946007)(5660300002)(66476007)(186003)(16526019); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: lMz0dTpocGTK9MUNw1erv68p+4BXu1yjJpw2pmK4EGgzsAWIl0PcUp140zAoM9CedCvMHHS02pdghCAE/cMvs9KDN3/truXNa70TJQHNqQ0yox3vqMAP5o+BZ5mtvdeTZQ2EKRHpWAcONyC1KkSOkWHvgAhsp/H+ENJhs0hvCwybHAqM5i/8x5GK0x5pI24DocIWXaX0Gt1KZZJFyjmarZ/bRXB9jxIt6PzyYR8IZkQeSGR+RwsrzzDS8zDxGvNrORt4QCNJza/U5rJs/ZtGilGTCc4J82I7FJUu8OzmEdZDVWandDR6sVj8c2mlpYWEFhyPJYweW3SVAAaEbtJAadPWXx9pvhG4v1cqkjQPQoCN3INPee/XUAyKG3Ux9V2QJJhscyIFOW/Nca5zPAFRmLJZ8HA1x+ytIBhxsicxmg+7UvCz68StyqM8ATIjSqpMc1gVdtYWWX4zwFLpoBIur6RGhNiQnLc8WzsIvSe8qp0rZXBFpuYMzr9lfKpWICeqA7T/301bRQKEYXlOoHG1HQk8uhiP+jnMmwTTp0mvP/2erjV+xY1OmDsVXBM07HIi4gBATnN7knV/ioeMn4IQrJbhfbTeEMkZ73jhxKXWJw6Ku151rLJ14MzGEsHL6LS3mUeI6BoNWAhSE/DigLHcIw== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 44916f85-cd34-44ea-35bf-08d84406b7fb X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:32.4609 (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: m6xwjuCHNBuhUquLn72HlJ5XvanJcAu0Q3oA4weATQy5LgZ9T5buEvvISlYrDfXu X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3934 Received-SPF: pass client-ip=40.107.236.94; envelope-from=alxndr@bu.edu; helo=NAM11-BN8-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:39 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , Alexander Bulekov , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Telling QTest to log to /dev/fd/2, essentially results in dup(2). This is fine, if other code isn't logging to stderr. Otherwise, the order of the logs is mixed due to buffering issues, since two file-descriptors are used to write to the same file. We can avoid this, since just specifying "-qtest" sets the log fd to stderr. If we want to disable qtest logs, we can just add -qtest-log none. Reviewed-by: Darren Kenny Signed-off-by: Alexander Bulekov --- tests/qtest/fuzz/fuzz.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c index 031594a686..8234b68754 100644 --- a/tests/qtest/fuzz/fuzz.c +++ b/tests/qtest/fuzz/fuzz.c @@ -202,9 +202,8 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp) /* Run QEMU's softmmu main with the fuzz-target dependent arguments */ GString *cmd_line = fuzz_target->get_init_cmdline(fuzz_target); - g_string_append_printf(cmd_line, - " -qtest /dev/null -qtest-log %s", - getenv("QTEST_LOG") ? "/dev/fd/2" : "/dev/null"); + g_string_append_printf(cmd_line, " %s -qtest /dev/null ", + getenv("QTEST_LOG") ? "" : "-qtest-log none"); /* Split the runcmd into an argv and argc */ wordexp_t result; From patchwork Wed Aug 19 06:10: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: 11722571 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 069F8913 for ; Wed, 19 Aug 2020 06:12:38 +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 C1A722063A for ; Wed, 19 Aug 2020 06:12:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="OmjkTAti" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C1A722063A 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HKv-0005Un-0v for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:12:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HK5-0003n4-SZ for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:45 -0400 Received: from mail-bn8nam11on2094.outbound.protection.outlook.com ([40.107.236.94]:24608 helo=NAM11-BN8-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 1k8HK3-0001Y3-HC for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hXQ2ELnqCy7Pqf8PEyQ8faptxks75gv9wEBKSYNDDhsMZAn4StbdDt4eYHmcIr5T4fHM3nczPbGS5MhMKFSvMOFaqT+zg6RMDxrnBrz3yOfALp/MKgQJjYyX5q3GHjKFI39wjgjylqo+7u2/OkULASvclAtFQ3Y4lSytffthrusl6clMOXDtwvC4RReyu57JRaChw4AaDqgioLkYdunqNlGsI9WFXTCdsHfYfnXANE2oRfR29Jx7DZjJRyEoKXOuWVZP4AHMDOZBQQgXM1jOsbSwqMuVckKUD6P4cODjU/4ro8GmC56+uR9h/D+luPDbUUL1nGd/j8JinOZj/ykHug== 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=SWEzcaWFdEVXODDUnm8nt4ca+HlarEt7G5Nj0Axorvo=; b=XT3IMe03N+1KGWNrfXJzarg6tWz+l8uTU2ReWqEEdJ+6qY6LE1mtnK/xQbB0RlFmM2LUSAG3bapds4fUaUFYq4RoFwn64XznytA50OvVLAgHvF+nKKwda175z3ULS0rigE+oVwNO5Sb79GgNMzmOI7LcYl6yaSqMUUiYtGZjnhQGC2FIXQSyn7wEYL/wNsz/GT6tetNkECRfaJtYYxUQ0OsgpnVkSNv4pfnMo2PCKSrKTfoWiyu9uGEXV/pJgfy25GsvcQHWJcGzz1YA+K6d8If2Rg35AE5EwRqxYwlof+NuzmHGMcqglD9llYBBc4bhCQW74yFG4CDrw+ux7GpTLQ== 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=SWEzcaWFdEVXODDUnm8nt4ca+HlarEt7G5Nj0Axorvo=; b=OmjkTAti+739bX668v43ZpvXmB2mh3Ln7bqcRYM5Hm3co5u+MDCKDueN6EYEv1oMLczAcvGritGg6DYMcIX4fmh190JhDl1PtmwJXhDEuHqqbOE7T6SiS1Xtercjwy5rKRBlyMsB9+eVjIn0X1Y0bHHy54PqtvAqiKlbW4CButs= 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 SN6PR03MB3934.namprd03.prod.outlook.com (2603:10b6:805:70::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24; Wed, 19 Aug 2020 06:11:34 +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.3283.028; Wed, 19 Aug 2020 06:11:33 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 02/15] fuzz: Add general virtual-device fuzzer Date: Wed, 19 Aug 2020 02:10:57 -0400 Message-Id: <20200819061110.1320568-3-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11: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: deaebf47-2418-458a-1a37-08d84406b8d0 X-MS-TrafficTypeDiagnostic: SN6PR03MB3934: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1079; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LbzIXGty96IWOxdmw5xinCR3BqWy174sn6oWSJiHjG555DQ8TWNNtite6981ogLEN28QVIe5dsgqWzS8Yjpe7I9JpmXRKMQM0wtJgpDqWZakw7gNPS1waLsuKkyiq55YgmNuh4lcB5kXbY6pxSHXHWmCxFlxrA2m62a9zzpmVo4xmHteAfMfh3PjIziC5uTwEUlYDV/z6A3v/kPfB+f+/qi6xvJwY70VooKas3hsoUZM1lzhV8qCDCYqho6XUfwhjy3cjqYQkV6huwlofw5pvh5ok02cKmkKxAk/S22U3VKdnTBj4HVkA9Oea/awGFJgJWxXgY/CIbTLFILJb/XpUOAmGp7RuQ6dl4L3IiHUOInApCGqlcMQoTwtlPV3NUu7bvuDB3pvvmTrc0zwM2bl4w== 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)(136003)(346002)(39860400002)(396003)(366004)(376002)(1076003)(8676002)(30864003)(6666004)(2906002)(6512007)(8936002)(6916009)(83380400001)(6486002)(54906003)(956004)(6506007)(2616005)(36756003)(26005)(52116002)(86362001)(478600001)(786003)(66556008)(966005)(316002)(4326008)(75432002)(66946007)(5660300002)(66476007)(186003)(16526019); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: Jo8Azom4jPt2D3SN7qQ6JfdTUdX2ai/mWKE2l97CegUeMb2YVlg+U1R2qlzm0IuPeXxK8gxHzEj0xzXP7RCvnIhJghyLMoJYtVch+Q/fk6Ma7lct9Y0zflQ/RQVdmHSeYaHglCjp5Zz39BX1mpgeGZH1YIvwRVrCGy7eQSpok5r7GpSjPVAxhoQnAgGpDEDaD1zqUn+GDwZ1JR2fH6QzOyg0oge/ryW16T5Wkj54OhQEPgKuEncv+l9za9VnfRttjqFLVf/tFGXV7hKx6gjjRQ8imRf2NK4yLuFcAC73IFAocMaR8Y4e5IcvOGV6bIzvGBC+2mfPwUmoi7l4L0sxo/N03sbkWzpMLSOF+/hJ5Oougfd8VCyzMtA2xtK+AePUrvBXeZfXyq9NLRetKi+v4exszx+1x6K5xOO8bav4x0coklBFr4lk5U4ju6Ns/Dit/rG6dQiPgK0lc5AZx7ARu/v72wQ1KBlP2iO+JpNFU0Gv9N58zUE8yV8wCt3PaVe2nF08eCVsiQU9ebbrjb3SwsM/AkMiQ4jxMS9Z9IuIh0SGRPuU8tBFhAYS83lDaGsNZWAL03sp0v6syBasMHcgv6Rh03/e+yE7IJvq5XU37uClw04JA3AIqKObngP3MxEn+Nl9CqA9nxk3lht9RQE3/A== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: deaebf47-2418-458a-1a37-08d84406b8d0 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:33.6532 (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: uzyqXn++HvQx/fZdOZOKdZ7W7MGUAWRiDlmq448yGd+gwTzQdBctCoN2I5hGtlGR X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3934 Received-SPF: pass client-ip=40.107.236.94; envelope-from=alxndr@bu.edu; helo=NAM11-BN8-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:39 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , Alexander Bulekov , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.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/Makefile.include | 1 + tests/qtest/fuzz/general_fuzz.c | 494 ++++++++++++++++++++++++++++++ 2 files changed, 495 insertions(+) create mode 100644 tests/qtest/fuzz/general_fuzz.c diff --git a/tests/qtest/fuzz/Makefile.include b/tests/qtest/fuzz/Makefile.include index 5bde793bf2..854322efb6 100644 --- a/tests/qtest/fuzz/Makefile.include +++ b/tests/qtest/fuzz/Makefile.include @@ -11,6 +11,7 @@ fuzz-obj-y += tests/qtest/fuzz/qtest_wrappers.o fuzz-obj-$(CONFIG_PCI_I440FX) += tests/qtest/fuzz/i440fx_fuzz.o fuzz-obj-$(CONFIG_VIRTIO_NET) += tests/qtest/fuzz/virtio_net_fuzz.o fuzz-obj-$(CONFIG_SCSI) += tests/qtest/fuzz/virtio_scsi_fuzz.o +fuzz-obj-y += tests/qtest/fuzz/general_fuzz.o FUZZ_CFLAGS += -I$(SRC_PATH)/tests -I$(SRC_PATH)/tests/qtest diff --git a/tests/qtest/fuzz/general_fuzz.c b/tests/qtest/fuzz/general_fuzz.c new file mode 100644 index 0000000000..01bcb029b1 --- /dev/null +++ b/tests/qtest/fuzz/general_fuzz.c @@ -0,0 +1,494 @@ +/* + * 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 "cpu.h" +#include "tests/qtest/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 { + size_t addr; + size_t len; /* The number of bytes until the end of the I/O region */ +} address_range; + +static useconds_t timeout = 100000; +/* + * List of memory regions that are children of QOM objects specified by the + * user for fuzzing. + */ +static GPtrArray *fuzzable_memoryregions; +/* + * 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, + MemoryRegion *io_space, + uint8_t index, + uint32_t offset) { + MemoryRegion *mr, *root; + index = index % fuzzable_memoryregions->len; + int candidate_regions = 0; + int i = 0; + int ind = index; + size_t abs_addr; + AddressSpace *as = (io_space == get_system_memory()) ? &address_space_memory : &address_space_io; + + while (ind >= 0 && fuzzable_memoryregions->len) { + *result = (address_range){0, 0}; + mr = g_ptr_array_index(fuzzable_memoryregions, i); + if (mr->enabled) { + abs_addr = mr->addr; + for (root = mr; root->container; ) { + root = root->container; + abs_addr += root->addr; + } + /* + * Only consider the region if it is rooted at the io_space we want + */ + if (root == io_space) { + hwaddr xlat, len; + if(address_space_translate(as, abs_addr, &xlat, &len, true, MEMTXATTRS_UNSPECIFIED) == mr){ + ind--; + candidate_regions++; + result->addr = abs_addr; + if(mr->size){ + result->addr += (offset % mr->size); + } + result->len = mr->size-(result->addr-abs_addr); + } + } + } + ++i; + /* Loop around */ + if (i == fuzzable_memoryregions->len) { + /* No enabled regions in our io_space? */ + if (candidate_regions == 0) { + break; + } + i = 0; + } + } + return candidate_regions != 0; +} +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 success = get_io_address(result, get_system_io(), index, offset); + return success && result->addr <= 0xFFFF; +} +static bool get_mmio_address(address_range *result, + uint8_t index, uint32_t offset) +{ + return get_io_address(result, get_system_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.len >= 2) { + qtest_inw(s, abs.addr); + } + break; + case Long: + if (abs.len >= 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.len >= 2) { + qtest_outw(s, abs.addr, a.value & 0xFFFF); + } + break; + case Long: + if (abs.len >= 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.len >= 2) { + qtest_readw(s, abs.addr); + } + break; + case Long: + if (abs.len >= 4) { + qtest_readl(s, abs.addr); + } + break; + case Quad: + if (abs.len >= 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.len >= 2) { + qtest_writew(s, abs.addr, a.value & 0xFFFF); + } + break; + case Long: + if (abs.len >= 4) { + qtest_writel(s, abs.addr, a.value & 0xFFFFFFFF); + } + break; + case Quad: + if (abs.len >= 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 (getenv("QTEST_LOG")) { + 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_ptr_array_remove_fast(fuzzable_memoryregions, mr); + g_ptr_array_add(fuzzable_memoryregions, mr); + } + } + 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_ptr_array_remove_fast(fuzzable_memoryregions, mr); + g_ptr_array_add(fuzzable_memoryregions, mr); + } + } + } + return 0; +} + +static void general_pre_fuzz(QTestState *s) +{ + if (!getenv("QEMU_FUZZ_OBJECTS")) { + usage(); + } + if (getenv("QEMU_FUZZ_TIMEOUT")) { + timeout = g_ascii_strtoll(getenv("QEMU_FUZZ_TIMEOUT"), NULL, 0); + } + + fuzzable_memoryregions = g_ptr_array_new(); + char **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"); + for (int i = 0; i < fuzzable_memoryregions->len; i++) { + MemoryRegion *mr; + mr = g_ptr_array_index(fuzzable_memoryregions, i); + printf(" * %s (size %lx)\n", + object_get_canonical_path_component(&(mr->parent_obj)), + mr->addr); + } + + if(!fuzzable_memoryregions->len){ + printf("No fuzzable memory regions found...\n"); + exit(0); + } + + 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); From patchwork Wed Aug 19 06:10: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: 11722579 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C007A913 for ; Wed, 19 Aug 2020 06:14: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 849E32063A for ; Wed, 19 Aug 2020 06:14:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="bO5+K+rB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 849E32063A 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HMI-0000Uq-NE for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:14:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HK7-0003q5-Qf for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:47 -0400 Received: from mail-bn8nam11on2094.outbound.protection.outlook.com ([40.107.236.94]:24608 helo=NAM11-BN8-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 1k8HK6-0001Y3-1Y for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ItT9rcVQM+atQFXmuKQAz++8UAefcV2W4yTddcdK6tMn/0mr4sUa8PeWek7s4JkvTJdEJ7U4+OmWqh9cmuQxNlkFpbjmYNhxagulOy5323tTsF6kNDZ1xPJzC7QIA8KLlnPLMPAbMz1A3tmZzSdexoUWwj2j6a+YURIAMFjJ5BDqlk4+4H7r9z2WAGDU/YKbvUYljqJDpkTCRpUcrqrRGhm3KqXZLDducE7GyUvIBL3kKeCQNJSi9O/4CFbcl7MSKCjvz6sjnTVZYbRcBszZ4uLdVSVtvWh/cpbOgiImTldHG5YDjCPWxTorU9puOiHrHvB8W41EHGX4rTuNeFtWpQ== 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=Nc+tX5jZ0Br6pPcYnH1iQaIY5uk/eODZWK2u5mJvG10=; b=g4j1R7RCNWlhr0WhChkGkqQpsOk6SVSP6BjhlhW3IJYSBx+ItlAxpjm9YE21KC+1XRppb40snlNU+ofdF+SyKomSbUMMhZuDjvOO2KdVbrdteTdKI1Ivz6A+oSxFxinrRM5mBo0U4URNSRxI+6T+l2zaD8ArtiX5qxaar9S7BZIQ2V1BXlzfrP/BCWIhBLkLSbBScEXvbKX0LhXQ11TTNKaJJgxMLSWrwpoZ+5tuUk6CEEr6NYrjQNEpXdTr6oXhUfI5qfWZtNN7AhR2po1mRM10IeIKEX6pI6uvKjzXagVdc9234lkDGZ8ehj9zgRSPVCvEyErzEX8geEF/zPLb1A== 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=Nc+tX5jZ0Br6pPcYnH1iQaIY5uk/eODZWK2u5mJvG10=; b=bO5+K+rBWsUukMe9vw44/OIwzY+WY1z+HQilGLP1XtlI3R723jSBF9ng/eU3GWr6hQxjsUal6jPVtPNAuZWAlD8JN/vQ6ThUy6EksFsXNouWHWF+qaRSkyaaQlOMZ9h3OQ5ZJuZQtbgQTELcQmntM0QZ3PL4irmu/Kyk5a0eNBo= 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 SN6PR03MB3934.namprd03.prod.outlook.com (2603:10b6:805:70::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24; Wed, 19 Aug 2020 06:11: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.3283.028; Wed, 19 Aug 2020 06:11:35 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 03/15] fuzz: Add PCI features to the general fuzzer Date: Wed, 19 Aug 2020 02:10:58 -0400 Message-Id: <20200819061110.1320568-4-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11: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: 519a2f93-474d-4811-5006-08d84406b9b5 X-MS-TrafficTypeDiagnostic: SN6PR03MB3934: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:302; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q8CjH3ImOWk3gmPWKGvGnmVT03q/U25d7oq1NX0Tsvyc2yYuCM96hZMLJNWv+1jUMblsqI3nIEEjYnQBSRlMhagyUb8+T9Nf2xgzgStTHddk2xRIb0ORswJ753jiBCs8Ke/FVSLdiPbezVBncmKg8y4L/16rpBSTY/QCxaeZlpsSzGqSPLuJM5+YP07pjEwvSdvVxcJ2Po8Za/WVsESGkKkgV+vPMdScccDqQ7D84FhuJmfeLtXFj9JPlZCd4xEmsmCHmJoQW1PL10VLN0yziQUBKBi40qK98K4Tehlurz/zPnLCvAWBfXRAbepKMz637zuJv/fYm763QGtroFv7ow== 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)(136003)(346002)(39860400002)(396003)(366004)(376002)(1076003)(8676002)(6666004)(2906002)(6512007)(8936002)(6916009)(83380400001)(6486002)(54906003)(956004)(6506007)(2616005)(36756003)(26005)(52116002)(86362001)(478600001)(786003)(66556008)(316002)(4326008)(75432002)(66946007)(5660300002)(66476007)(186003)(16526019); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: y+tk6c5+uMjQ5AOAu7NC7x2QQk9fhU8D/6wi9aeDTNqP0kyWgyZYkg9Sa9Fo6YeGqmDDwr0TBZpTpV6B3XHmEGjM+5H/FLyt6nxDNe5JkkLFj4HnHrQGlDp0dWMVGEPtlk/GzGjZ04Aj53fwBWKGXD4t6wo2LLCIqlHj+xvq7bRtMSyMGoZi7HxXsmNhXhamLcryKaxSjHzUHEy4uZuJZbatqwLwheOQ+pTsK9zHg/CDjxOkAJBs5ocdTx1i18g+yqVLEjmsBIf4Oc/jOkA4Idvm+Kq6lF2YnptcFpNhUsHit6UBG/7stKzw7v1dVdthi6N4Shv6oSdjp2ldr8VId9hrxari6a0xB08LuJGg+EPaypB+w2wmZrJWA0lj1s/uJsaPRfrt6en3lFsAAh6UxgoTNKpn4D2HqjazCxPeoWRJKXKgIzDXX9XkvCyvtUWvjMgqe3f3nTmClJT95arqcpllvarq/W8ot0RYn4JaFzl+tz1XpjZ3zkLp2uYlpMXswk1sCjOdeX/qmUdXsdeElPrImrSNX0tonyAZOvPzajoeiV7pJYA35TTIB78HlT882BrXzuuopG9vcCOIVyOKRIuXLDIXUxcILA1mvP7ymyjVV8ijYa8KVnPw0DwlrQ566itStquSnZht/pFUjsxRoQ== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 519a2f93-474d-4811-5006-08d84406b9b5 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:35.4472 (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: pVzgT6nH7Fr0MzZcx7Wwa8HOzOPog8AEh0PZ8xOg6V0BU6mXPXQkFoYkaoqep78H X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3934 Received-SPF: pass client-ip=40.107.236.94; envelope-from=alxndr@bu.edu; helo=NAM11-BN8-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:39 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , Alexander Bulekov , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.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 | 83 +++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tests/qtest/fuzz/general_fuzz.c b/tests/qtest/fuzz/general_fuzz.c index 01bcb029b1..17b572a439 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 { size_t addr; size_t len; /* The number of bytes until the end of the I/O region */ @@ -52,6 +58,8 @@ static useconds_t timeout = 100000; * user for fuzzing. */ static GPtrArray *fuzzable_memoryregions; +static GPtrArray *fuzzable_pci_devices; + /* * 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 @@ -283,6 +291,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); @@ -327,6 +394,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; @@ -418,6 +487,19 @@ static int locate_fuzz_objects(Object *child, void *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); + + /* + * 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))) { @@ -445,6 +527,7 @@ static void general_pre_fuzz(QTestState *s) } fuzzable_memoryregions = g_ptr_array_new(); + fuzzable_pci_devices = g_ptr_array_new(); char **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]); From patchwork Wed Aug 19 06:10: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: 11722573 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 886E1913 for ; Wed, 19 Aug 2020 06:12:41 +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 4E60A2063A for ; Wed, 19 Aug 2020 06:12: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="b/VJCvAz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E60A2063A 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HKy-0005cW-AE for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:12:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HKA-0003vA-15 for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:50 -0400 Received: from mail-bn8nam11on2094.outbound.protection.outlook.com ([40.107.236.94]:24608 helo=NAM11-BN8-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 1k8HK7-0001Y3-Vu for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ctWiDwctOI1DSsZqoA7vvOSu5Pc/LnKO3BWXu+vqfIutQcDf5/DQmWmPtcG3fslvPhkPhC29d+Yl1xkNTrWFPqpFarS9C2y1t/DNVqfna6lnEdEWSqLEcMP/Prb80VdGfJHvJWdP6Ynvr+Y+zEr4jdtdSlO78dxvSIz+8woJMJzstgsZx/Da6iXTEVFdGYLY/1Xq/6ZIhh1c4DVnIF3OzHJ7Rkz5F72QPKAW/XX1bwLKbu265+mC7pvyXdmDYdwvYnE73coT4/NZJB6n9kdfTMWyLp++C5YC4ARK5GpGC97ks6VFtGjd+v+a1uVvoKcRNwjne7RMaGJBPdRs6D6A3w== 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=hCggRrhPh/AAJe2zJp4UEjc0k4DnsBalDqzad0fhcMs=; b=EHyjv9jDThk9rMTOz5cWZUxw1avhVzhFOwENfpf+0bK3poLKwwXGIiW0r94h7JSGOLSy5GIrEaTMnLviPBDzuZH5/pCVGJKW6I04Z2rBELu1IwpuTXgzuNq5yL7BjJMm1EMObke0VRZG0pvNrgBoj1XHTNUkW+9Sjmb3mRHvj4iugQChDFLW8AZx1/YLR03N9kyfGnfeVRu95ejfQ0OvHRnG7YVbm97/4jZ87uHeD877830csnZrVk49zdNMYEIgIA86oY3af25J5ff3Za3KtNT7iQkD3UM4LYr6Oy7f9XT0Nj1gs8z6YGarubetLeYokHVpNNSos6E9n7II6OLAtA== 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=hCggRrhPh/AAJe2zJp4UEjc0k4DnsBalDqzad0fhcMs=; b=b/VJCvAzeztyqu0MfgKEH9sJwr/S3s8sv5E5p+R0Qr2cPNONg2QOO2wKhGaMRUXsO16HnPiu9AvC09/hPtTV4On4kMk8m4NKYaaMzEBgGt/MBetIqMjiKAVLVxHSHOwxeKfizEhyBuHFfxpiZGsD+3F2Z+51X85fiD+2qysoXWc= 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 SN6PR03MB3934.namprd03.prod.outlook.com (2603:10b6:805:70::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24; Wed, 19 Aug 2020 06:11: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.3283.028; Wed, 19 Aug 2020 06:11:37 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 04/15] fuzz: Add DMA support to the generic-fuzzer Date: Wed, 19 Aug 2020 02:10:59 -0400 Message-Id: <20200819061110.1320568-5-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11:35 +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: fc379912-4cd3-48c7-c7b5-08d84406ba8e X-MS-TrafficTypeDiagnostic: SN6PR03MB3934: 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: y/UfrigJxnsBELpJ1VRkc2wR5k6ksN2ZKRffmPvscow55fRoHgrl+0pXHpH91I5iXWWmBHgFJN5slyaV23Ze3G8YI2E0mefno0+QBID27WavJ1pGUGD0qnBKcJbQKMhUS2u2XM/u7qMo9OSaBXzerCniO13xR9NUTWSC3p9YLBlF2UfzGOy6aIe5D3Fy9iujXYVayYn+gcbhyCvYBTzRfWef62HrFtNSoSXwTyPI2wn+MH5vQk4tWtH7wLnaLKgMjD4+1dRy0HuV3LePK3E5adgOvKjYxIikdU/P+zk8IqlteFoyKkjYe5cl1l/i8FPlqfZC2mYYBgATOrAj/pp7fO3RE4qjeKA0cKXpwSXX/Br/XN2/VGImWzmjMJahvf4t 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)(136003)(346002)(39860400002)(396003)(366004)(376002)(1076003)(8676002)(6666004)(2906002)(6512007)(8936002)(6916009)(83380400001)(6486002)(54906003)(956004)(6506007)(2616005)(36756003)(26005)(52116002)(86362001)(478600001)(786003)(66556008)(316002)(4326008)(75432002)(66946007)(5660300002)(66476007)(186003)(16526019)(41533002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: +1Zk0ZODLb2XwGggO2nFcYhTLrCEUcb6sKp0L7Vbmsr1LtJ14CwDsumvDUGJNbbTK5jDrHosYEeJ0azMbu08ko/N2n++Tp/hZLJLID7NGEGEtsVjhnbbTnSED5guUYaIX92JZ9++/tdHj+s1b1LgX3WKB03B2rlWGNVXmheG/dcHHnZBWjv1dvfDSzi24IS7u/Se8MWWMgbNj+mnRMrlmKKyzUFU/KFlk3OS8RQI3WMT9a6/ZVE2fh/2OpaQHDirvBNMZz45iZdo0qRo/Oc/Im0SD8NoM/WFuXkK0sJdfEe10SPTqXW7wxiizObmDenf6rQD83fbpipWRmUBuJLCEC3OJ4Knu0u3jMEKPpf1xjk/UDKE1AwmE2n0TRM6bqzvCwvzSWoyxRmlzKmmQyxKFzFx035yPlLeNF+sNNQdn+UxFhkM3w2anGzYfboTXdsoqxNpXGoL09YdTRK1FlvxLsXBT6Rd8i61AP4KwctyKcH/dwT2d8Xw9NwPzvssiXBeoUbBEpVFpGoTGdjIuI5nKw0sU3n753/2ZtNN0Tzy5IGUH8lQ+ej1SqnDCGHn7fhLYB09zru6/P4a1ICHRhkg2qR+bQDbbtEuA9wN7FztmQlHLiXB7Jjzyn17OXKL6kg3F3jwotdOcA4llsLnxfYj2w== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: fc379912-4cd3-48c7-c7b5-08d84406ba8e X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:37.0862 (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: jX+32amdRqkVzkyPVXLec5qetESaqd+9GuB33KBR7NRCN32a9YcqeWaSp12wpVZs X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3934 Received-SPF: pass client-ip=40.107.236.94; envelope-from=alxndr@bu.edu; helo=NAM11-BN8-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:39 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , Alexander Bulekov , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.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 17b572a439..36d41acea0 100644 --- a/tests/qtest/fuzz/general_fuzz.c +++ b/tests/qtest/fuzz/general_fuzz.c @@ -25,6 +25,8 @@ #include "exec/address-spaces.h" #include "hw/qdev-core.h" #include "hw/pci/pci.h" +#include "hw/boards.h" +#include "exec/memory-internal.h" /* * SEPARATOR is used to separate "operations" in the fuzz input @@ -38,12 +40,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 @@ -53,6 +59,24 @@ typedef struct { } address_range; static useconds_t timeout = 100000; +/* + * 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 03 00 05 03 00 07 03 ... + */ +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. @@ -60,6 +84,116 @@ static useconds_t timeout = 100000; static GPtrArray *fuzzable_memoryregions; static GPtrArray *fuzzable_pci_devices; +/* + * 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 && !(mr->ops == &unassigned_mem_ops)) + || 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. + */ + for (int i = 0; i < dma_regions->len && avoid_double_fetches; ++i) { + address_range region = g_array_index(dma_regions, address_range, i); + if (addr < region.addr + region.len && 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.len) { + fuzz_dma_read_cb(region.addr + region.len, + addr + len - (region.addr + region.len), 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.len); + if (getenv("QTEST_LOG")) { + /* + * 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.len); + } 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.len); + } + 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 @@ -350,6 +484,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); @@ -396,6 +559,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; @@ -425,6 +590,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)); @@ -441,6 +608,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 { @@ -455,6 +623,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); @@ -522,9 +693,16 @@ static void general_pre_fuzz(QTestState *s) if (!getenv("QEMU_FUZZ_OBJECTS")) { usage(); } + 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_ptr_array_new(); fuzzable_pci_devices = g_ptr_array_new(); From patchwork Wed Aug 19 06:11: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: 11722577 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 86FC4913 for ; Wed, 19 Aug 2020 06:14:02 +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 5C10F2063A for ; Wed, 19 Aug 2020 06:14: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="Eqns08QU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C10F2063A 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HMH-0000Pf-Ih for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:14:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HKC-000411-9y for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:52 -0400 Received: from mail-bn8nam11on2094.outbound.protection.outlook.com ([40.107.236.94]:24608 helo=NAM11-BN8-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 1k8HKA-0001Y3-6q for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XBY73N0lLc97JvfpxawWZyc5TNNCsDq0ai42Hoh/QR1XdMPFzrnbJ30G2O8VIZ3EPpzJFB3hr9MYy324Y6EAi3aMh2mx/rJQLiREH1o45bSZYJWXuuOulKEfUhn3CiDzTBiuVROYegQDORKemeN2yLxgspi8odyr8BbQ5jfJxH/FsLrCdTqjLIt78JU9MvRMfCFFkm+4BQEQi4CvhYZLZx67GphWg44lpVcmYdAi+ZOwNyK8ER9GKjgh44OzWbJeb5sop8HilWTVgzAXwdIYARTIN6bbCgOa2xNRyAMeu6kmDe+BlLPb/gfgkc0f3Eg2bAhJ03ticnvhnHwWkvLwpQ== 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=Ref5m5sgPAF97HDguwHBZ7XY1CrXwWJNYyIB79SnAaM=; b=RWUN9sFqplWJL0PjzWIiQbanVG2oJ2WzyIiTkfg3H6if0OB4cNLY6hYUIO3ucq6YERr9r3Mw33w5YEzeXw0qQi3DfDNnLxNulKCbq7tHa63vnOAA3g7aWl9kQUDt2Zwg9ndBDAJy1NyU3mtqLFrSmSuYEmeooa+YgJsAEtV6J+enFyEcTdfpO3CrO7FPGqeAKyDWgaSeVtWCHQ1MdlSSJZcyNzdQaG8b91VR/fxSaCPVuYfDUzBJnFb6qxxzPkooUj29lQ6CUMFoJ/xG6311Ddg7QIVKb/4s74kqrQusHDxtTRfdBvASFdHIhzo4HXnhc2FeLP6kvDN820sX29jdRQ== 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=Ref5m5sgPAF97HDguwHBZ7XY1CrXwWJNYyIB79SnAaM=; b=Eqns08QUbF0FK3eDJ6k1EHENFzBHETX3y6zXhLcLMnsW8pPTNifkS7H5Ju3m9oPZqlHomM5BGNRluZw6C0h4ruCZFR43/Cv5QCzvDl+Xnf1KB1ccu/iNYE6ZQ/iR9h6/PMNVSQowCkCgSq5fhQedsVTbGxFs0mUHJaVif5papGg= 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 SN6PR03MB3934.namprd03.prod.outlook.com (2603:10b6:805:70::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24; Wed, 19 Aug 2020 06:11:38 +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.3283.028; Wed, 19 Aug 2020 06:11:38 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 05/15] fuzz: Declare DMA Read callback function Date: Wed, 19 Aug 2020 02:11:00 -0400 Message-Id: <20200819061110.1320568-6-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11: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: e0da4405-786b-4869-6013-08d84406bb85 X-MS-TrafficTypeDiagnostic: SN6PR03MB3934: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1091; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GaO4bSIVuJkf7AXXW8F1F6lGaLA/8IImWXWF9tzXg0H2a+Py+68r+lXbNBZoEolsCyizZeN5LrD4/HMr/TjLCTnoE+6IqcVAC2ryZpq3ePc6lSs3pH8noDBzuGBQZ2CYalG0ZfjrFvxWnyk5xBGNYszHNd6/pwpvfha/ip9J4NK5h9ThRCVuefDPgYXIo4hrf+WDl9bYO72BieyhDkZMbrSAd8L1f3iN97DgoxAl8bqgq6jJ+v65jF1fZW0X5OgkyxS9cYFr3sKsXJbdrYddfmlNqxo/v5clZnOyoTLumQkkzLS5Q8m2SaDjV1R3CiBOQtxVDmEJpwlt625Btpo+oA== 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)(136003)(346002)(39860400002)(396003)(366004)(376002)(1076003)(8676002)(6666004)(2906002)(6512007)(8936002)(6916009)(6486002)(54906003)(956004)(6506007)(2616005)(36756003)(26005)(52116002)(86362001)(478600001)(786003)(66556008)(316002)(4326008)(75432002)(66946007)(5660300002)(66476007)(186003)(16526019); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: QrIuYD1xYliePOWUt4RynnYB+m56N9ZlQzY72cfc1k1pCoHYrR21G+UeOrusJl1ONyFLDYtTbX1t5Li6j7tu01qmpMPOd1u84pwV6NZz5k/bsy0NdRexdPotOVqumiPRArq6Lm7G/iEOp4GJVIc6ItIcnLIq2lbv7ANWslXApJPqzPerFsgNBjEZfc/oERJOTlnY8TOcTSSMi0I2bCO1VUVR9k8qpUmS30jDslYtVcC/SNVXP1SP6UmAiEDvFcjKNlWbQPtCMYwnJ1otJTmFOhZhcSWpod+IZ7fnYo/RZONHLB2cTOGJR1ZHa0PBZLsbGkLNsFwAJ2SrveqZNy4jfjNpsWqGDYZ8o7jbuHCeS78P38ylSwy2+FM2KNeTeEfeEmkwaMpFNjuRHAVs9zqhr4+WlO8YYVe9vJNBWxrouGPa2V7UIC8x7NtsSfmmNc/MgsbcEy85kO/LyrVhS9GNVeAwcSy275NL3jmzlinkEs1++nKrSkVRZdOVYyMLnQFCl8zdgIUDV4Cmz9i2rc3CtgFIxtvhpcVSqUAn8aJlWhmNsmCHhYvgxZyVzUqODcaoCnyTfMV6hTqaubHeocuiXMnezKADNOq4x5c6TJE9rOYwHYpn2Zq0IpGaKsw1q6QmpDG0BQ0Xkfq3+vvw7QBGMQ== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: e0da4405-786b-4869-6013-08d84406bb85 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:38.3415 (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: +AQR+W+9qMDS/sPkP7aTh5xNigiH3adWqQa2TBkhoIypl/Ln0nACvbfsU8/CM4b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3934 Received-SPF: pass client-ip=40.107.236.94; envelope-from=alxndr@bu.edu; helo=NAM11-BN8-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:39 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, 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 , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.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 agains 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 307e527835..2ec3b597f1 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -47,6 +47,21 @@ OBJECT_GET_CLASS(IOMMUMemoryRegionClass, (obj), \ 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 af25987518..b0c2cf2535 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -3223,6 +3223,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 Wed Aug 19 06:11: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: 11722583 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 52824913 for ; Wed, 19 Aug 2020 06:15:38 +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 287FF20772 for ; Wed, 19 Aug 2020 06:15: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="IuV90DFM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 287FF20772 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:51844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HNp-0003Oh-Cz for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:15:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HKE-00046B-Co for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:54 -0400 Received: from mail-bn8nam11on2094.outbound.protection.outlook.com ([40.107.236.94]:24608 helo=NAM11-BN8-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 1k8HKC-0001Y3-Ex for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bGUD7Wlsra9TNtAWhAqxxgOXuX0aRdTVE03Zc8Y9hV0OGpSjOJ3WeM0Lf0lcAPI8vNd6tFHAjTB8OrtFixYVybNy+r0Jo4NgERlQkOb/IBb+0RcXLuq5LcjzFDgCX7ncqEj9uoFrrSSkXs7HGDoaZYWaH5EVtVOPw7kQ/XufffOLbjjg2PSDrKlS/PfMdxgER7C8JjED+ZFrmufSoN6d7aaZTlzlsMfErRJNPD5FcNxsbashAPiDk0ihXlhyQMW3GSzvVlku74B6uS8lo4qZCuJY35D7Cp4G6N0A2/N4PyaKxk5IIDwxyh2vz66/DpVjgCmMcnmjCrAqxP4e4zbY/g== 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=iXTbiJoPSKS3VxKPN9vb51pNXpSxynA+NscG/Jzs/8w=; b=ldOEGhYv0TgH/oeJxhcmp33EB+Dw+EAMbrjKisCs5tLu9WGokRKkhJ6tdFNNlp+rBlnLQqnOFIBrkGAQtsHe4VHcEu3+KZrXoGQ4YTcSuhhoBM2F5hT68v/a0zck1cUq6Brib4DLxie7MYL6US7+c5dQclNcPjRkLFRE13D0YrI4lZSKrQhjQRPTrX3R1+1Y92VKDSyAWrHxTwVZqygAH55f/WJIh1NQkhkay9/RzKbbsf+vDjnMv6jHTCjAjpBlFV+zYWaDqpJ4hNxdp1A84KzHFvMLs2c+YepItTq+MRfxGpkh5mUJBOzg2t2s9c7CMm2XBiQbqs9vIARv7FXrag== 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=iXTbiJoPSKS3VxKPN9vb51pNXpSxynA+NscG/Jzs/8w=; b=IuV90DFMJyUp6NEIU0Zjz6I1/VOWBGuNFl9hx+HWeUehcgAZtyk6VH40fYN3k2OBd7IY/fwb0mKF8UB4zbZ9tnG5dSM3FF92vxIPT4tPEin7h0GGQs9g4hhGCRf3YDjihXjhWlNBOJWoIDBfqvRrKK84ogqLpwcducNsMMooDIg= 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 SN6PR03MB3934.namprd03.prod.outlook.com (2603:10b6:805:70::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24; Wed, 19 Aug 2020 06:11: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.3283.028; Wed, 19 Aug 2020 06:11:40 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 06/15] fuzz: Add fuzzer callbacks to DMA-read functions Date: Wed, 19 Aug 2020 02:11:01 -0400 Message-Id: <20200819061110.1320568-7-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11:38 +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: fcb07eb8-d985-4372-f91f-08d84406bc72 X-MS-TrafficTypeDiagnostic: SN6PR03MB3934: 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: muPoSCTdVrrgcw2O8TzXWnTWOKvsnpNAAjbdYSmCWhxO9yL3tay0If01+5FnYYB8ug+NQm3Qe6aakhOjxaqz0PUJUwf22pNHGOMEPXGKB1yiIE9UYKCsorSjA0E9PdANyt7hXKERacPy+xavUSPihWE8rKo44V1BWitHgf2g2YAvV+FTANxncSqgo2aNvbE8+4E3Av7KtiNYbtafIkOw5GgXxTSwkRiWtk9cLV9CoBmp/Bq+n6bTfnoyVhktB4+b4K1sXef9H9vXX4Mn6ATHfcYCMZ5QcH3oZ9C8DAJnIcQ0OLX6fGmJ+erl1qTFH4Og 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)(136003)(346002)(39860400002)(396003)(366004)(376002)(1076003)(8676002)(6666004)(2906002)(6512007)(8936002)(6916009)(83380400001)(6486002)(54906003)(956004)(6506007)(2616005)(36756003)(26005)(52116002)(86362001)(478600001)(786003)(66556008)(316002)(4326008)(75432002)(66946007)(5660300002)(66476007)(186003)(16526019); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: i6Ngx9jtMJmyRFlaMohxcgKSNaOb0CWuMhUz+9WNqAN9Hi2OC9UyFPeiln/2NNp1UaTvOhyIh1jCGWwFnv7FwxE9hVxfeYB98NjScCzMm1ELU2xFlmKRapBUZ2vzDaIwkf3TWNSzGlKOv7rVgbRPeMMy4hhkqNgkGSoFLYb42vPP8Anzj+fnzqk6KUK1/3SbHjXXwIVvxFEEh4SsFErDFMm0JPOZvewIpbOBAZzPqcsih1yi6zSRwZl5PQICgoN7q6PqB4pFUAKhyLrlD7VK3xo7u05xWlO5tkfgEF7o2pLVzG1uH41loqkBytijnH7fldUUt3pHxCgYQYXQXHDeLjTZ+l3CFFfXh8417Hf4TqThE4jnMwolFiMkeA2NJ7NWiCKH+rz1JizmDMA512SMHvfa8XR6UAJpYsCzdEg/yMkeAmBQKj5Gfj5/yIg/zozFl9Z3gHyzmoBJRPnmFQRmuAjR46nKyfV9+z8exPzm6L1AFmGwvXOhPWSKqCu5Jug5oaMaRY/eyo5weXkTGdjjIbzvTSKCn/fQacNPfFEjwqcwsLkFaJAj7zGBQliHMVNGXYORoX2wT/cryE4A0Qjc0wFTgY3sToVsf7KWl4CfJWN7YcCACzawF6iPBKmsIijOehJLrISSR1PgRQ8cu+Rwfw== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: fcb07eb8-d985-4372-f91f-08d84406bc72 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:39.9506 (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: wY/6cw4WAPCSt8/vXvAMaM0qFt3Kmj+k5G7yejGnEhS89d1KQm1C6vgJl33OA8zC X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3934 Received-SPF: pass client-ip=40.107.236.94; envelope-from=alxndr@bu.edu; helo=NAM11-BN8-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:39 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, 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 , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.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.inc.h | 3 +++ memory_ldst.inc.c | 4 ++++ softmmu/memory.c | 1 + 5 files changed, 11 insertions(+) diff --git a/exec.c b/exec.c index 6f381f98e2..c81f41514d 100644 --- a/exec.c +++ b/exec.c @@ -3241,6 +3241,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); } @@ -3601,6 +3602,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 2ec3b597f1..f8b943521a 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.inc.h b/include/exec/memory_ldst_cached.inc.h index fd4bbb40e7..aff574039f 100644 --- a/include/exec/memory_ldst_cached.inc.h +++ b/include/exec/memory_ldst_cached.inc.h @@ -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.inc.c b/memory_ldst.inc.c index c54aee4a95..8d45d2eeff 100644 --- a/memory_ldst.inc.c +++ b/memory_ldst.inc.c @@ -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 b0c2cf2535..be87044641 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1405,6 +1405,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 Wed Aug 19 06:11: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: 11722585 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47E73618 for ; Wed, 19 Aug 2020 06:15: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 1EFF920738 for ; Wed, 19 Aug 2020 06:15:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="ayPxOVJ3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1EFF920738 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:52098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HNt-0003V9-CQ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:15:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HKG-0004BF-BS for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:56 -0400 Received: from mail-bn8nam11on2094.outbound.protection.outlook.com ([40.107.236.94]:24608 helo=NAM11-BN8-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 1k8HKE-0001Y3-G4 for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:55 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YqxVs/Xe8fC76nuK2olidT+UqwyukPUiIadPEjAruIZnoPFZNOMrDTmsvnEmF4GRoQ4LWD2j60XuoQ08w75c+fyXSnGZEajTk4w+cHs+7zpCrx5klSsuRCfWqyQr3xZQScsElYo4QyqkizEJzI5H4KvFTvogpB8DkjhMUzhKHtmBsbGUrC2v5T2cpQhwCZhfJhpfWtwdhQQItyHsShxGi02uXEHhWTxC+7TVjgxlqp9yGQ0sHLyKvMLaUeW2sszEpwtdQDNJ8Nt8Pu2wGjfRaBHL24kz1P64kXY49tf4mSKnyzjowwCoRLVG0ZzgiPGbsjQ/RLxvlwjJ5aUiW0S8rA== 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=IIe/dnR63JYB8Up+MAS928e1OIoQgKr9JYoMOnC4QsQ=; b=lgDfCj/cONlcBWdmqvl6XvF0sUWScqaW7dmOTrMGIB0n5mx0X61l7FsBOh+6GaGtL5MeQb3eomsZeud7dP1oravjasgQMCVBwwrf7L9UdU26X39YAMhETOSmOlB2fQ6QWIA1CyvK97KY7rp6/UMfF7SvFSYJOsRYGem+p+GLWVjxrMO1d54pBZnRORv6h0hFrOcjkjmsVU7F++XDONOYtacBJu0JHNgUUV/Z7Tro9FzOnxUG0eQDDSa/NtJfYOwvhXNcs7bVikF0F7Qt/1Ouu0OI+kNJJHbLbzdzPysV5ldlXiabHuB1CvRWah2bOiYg2ZDdMcKrCQtCZJE2VcOS9Q== 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=IIe/dnR63JYB8Up+MAS928e1OIoQgKr9JYoMOnC4QsQ=; b=ayPxOVJ3fMgf1IsKgAQWfValVB6jhwziw+v2zrGw40/7aQ7Cdjupkd/rR8vhXublUGV8X6loHi3adWfe8QHfrRtklrSaRD5N2Fc/XYG0cKb6MbJHpeq/QW3ARyS/pE17J5sd0nXQqzQahPVQD78moCw0MoKUn8Jag0OGIZ/7Am0= 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 SN6PR03MB3934.namprd03.prod.outlook.com (2603:10b6:805:70::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24; Wed, 19 Aug 2020 06:11: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.3283.028; Wed, 19 Aug 2020 06:11:41 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 07/15] fuzz: Add support for custom crossover functions Date: Wed, 19 Aug 2020 02:11:02 -0400 Message-Id: <20200819061110.1320568-8-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11: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: 25481880-6dc7-4cae-1e39-08d84406bd4e X-MS-TrafficTypeDiagnostic: SN6PR03MB3934: 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: CGQrUSzht4n2UlEwkpcBcbkzh23HNB51cSY+IVJKPW2c8ys67OVT490OG7mc3yYNktyLas12dgY/dUbBELI/D9aPLEwgYTybuVKdfRtbL9GNd5ZtDatc/JRRjhj11l05Vdss/Z5JhSsy+70hhGBh3+y1CEAEthrDzCbkj2KMN/j2839cW5l8OetBQfhQrLVUh9LpI7KE2YrO15kpPZ7Dfb/1em03bJgyyoEVP4uyob7UVp4slhPof/kPGY6gU1H4l39jkvFDwgDYgDqO4md9JrQcmR8zyGHGSguRdOuoaBiWwoT4RO9VmTwDhUXx38C8FQRmUejRuBx8MIGDDG/HEQ== 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)(136003)(346002)(39860400002)(396003)(366004)(376002)(1076003)(8676002)(6666004)(2906002)(6512007)(8936002)(6916009)(6486002)(54906003)(956004)(6506007)(2616005)(36756003)(26005)(52116002)(86362001)(478600001)(786003)(66556008)(316002)(4326008)(75432002)(66946007)(5660300002)(66476007)(186003)(16526019); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: P1S5rnLSXLtfwAB/A57giw0NKHWBzNfOFqMOzRTTar1SdtAWv1vVANtyp1UaGR+3T1UfCO3pOxibXNGljUtw2LYV4mP85PZVAjfRz+hgSRzBHLUAtCCwLpMgGkgFw07iTi3fasaC+17y88/PPy7Q4gB+y9pWJf0NaNVTiamd8p2s77l/zkZqfRtWJVMIWmgXisDd8uKRjA+cHAnsupBf0igN0vgl7sa1PuTbQp+HCrQ8LfZp7M2BNtieLb3KaVHX+fEKgDbsdaYgrzejTqNqrihKITsOHufnnORBOgsPzN7MoqjCilcWHxkpiBCdfIUZ6cXb9YWq7uYb1dQXHOmILy3dYIvMpbb5Siy3jLQZgbncB2uBKWtiDmy85F6qTSa7obJB20syDB2VEUCktBh20CGCRIOVasmc7xTyjmlASq8kvGdv9/qEG5kETbaaVTWvhnTKV9y6WGoMUifaWZ0q8f8T+Yaj7Bgp77SmiYyZct8knm/T5Fta3y1KGBtLk5tZXJ0poK1vKQN/4DDuHOzoEysC3pB86B5XzbzszuKB8TpUVTjsWb4k+ivig4NLptAnGuuAvphH5HHstJXgP3FSm5Pv3tMzE/jc9rlYjtbL73GCQFaEeeHY2RoJrJ1N4Nltun/+eYKVuwvmunZ3JVWauw== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 25481880-6dc7-4cae-1e39-08d84406bd4e X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:41.2059 (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: gA59hEwW3bITOD8XvK2yTwV+1UJG21SOAB2UgV5z72h/R6gGeCB5sejDP/BMl3ep X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3934 Received-SPF: pass client-ip=40.107.236.94; envelope-from=alxndr@bu.edu; helo=NAM11-BN8-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:39 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , Alexander Bulekov , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.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 | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c index 8234b68754..248fab5f37 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 9ca3d107c5..d36642b5ec 100644 --- a/tests/qtest/fuzz/fuzz.h +++ b/tests/qtest/fuzz/fuzz.h @@ -77,6 +77,28 @@ 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 +113,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 Wed Aug 19 06:11: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: 11722569 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A6DD1392 for ; Wed, 19 Aug 2020 06:12:38 +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 D43212080C for ; Wed, 19 Aug 2020 06:12:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="yATVM20c" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D43212080C 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HKv-0005UH-0h for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:12:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HK7-0003p1-9i for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:47 -0400 Received: from mail-dm6nam08on2119.outbound.protection.outlook.com ([40.107.102.119]:43040 helo=NAM04-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 1k8HK5-0001Ya-Du for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PAwrhRSMSN8gPQv9rsc1SYUr6gh4V71Grjlf04HjO5Qm54qfdlEUtOR/bjM4suEGThV3OvyyXHnLa9XyDh5jxjyJ4fYAkroQdp1Hp3EGAwUqyye1sUUPLUJeZElmZBzIPvHyS0VsjsQzqfdetckwNp1rhtafv3nqfmSC3BMN6ZZ5RriXhL/UDBL9GoRQ8OiPPafi1KyYTzecRNlpUkKSGm3O/sOt6QiWRUb42brJKoKRNafC3tqZs2MuExoHgQbeUWCB/nam5fDfzVtNnK1j5G7uP+3qKFGUSyqfgcM85zaqVOtnELCpJvh8Unlnm6W524Ok/IRZs+lmVtMyrUXl8w== 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=2jEEW4n2UfTBJrvMDdGccCjGVukwQQAPAZDCU6cSZao=; b=VbTIDG4uazim9f7LKrysKrQyscH2scAeig8Hb9T6tVNP4EQq4m5cG8fWY6Aad0lOWvBbo9KeImIZsEAFz7oZDa4f8p4tRBkrZ4t80le5rhjXO1o+d/dliogQi4l3A2N8QFMNhVdznnXMj18ey1F+y3wCumIR3+9NqW2jABcHp6C3tyu/9OHWH5YldRw5sHZrH6yO/qPfBmawn4FTd1hXjaMuZVQOJLPMEDQ//CbB0GHGMU67AqKG3cg9rOflEk388YKEy/MgANN+2Fsz0n35QhBXDvioVim0C6rNiodvSrsyFggb0LWqEMmwFJpS9uNxgscDFzrKRAWMzHexpYv6xA== 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=2jEEW4n2UfTBJrvMDdGccCjGVukwQQAPAZDCU6cSZao=; b=yATVM20c4PjH5wsqEnjvcXah2lcEH3ocqTMgp3voDhNuMvqTZX252gOttYdQAUhuYQFgQO2VBKcYmgcKsUjBqW7KVUT84/u8e2bZ9xWkWr8cYQTKnj8ClHOIexZ2eJPYC6CCDru9SUVs3iiLZkmegJdDWq8lOMdcesrrZDu2H94= 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 SN6PR03MB3486.namprd03.prod.outlook.com (2603:10b6:805:44::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.18; Wed, 19 Aug 2020 06:11:42 +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.3283.028; Wed, 19 Aug 2020 06:11:42 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 08/15] fuzz: add a DISABLE_PCI op to general-fuzzer Date: Wed, 19 Aug 2020 02:11:03 -0400 Message-Id: <20200819061110.1320568-9-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11: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: 17defa43-83d0-4012-8294-08d84406be04 X-MS-TrafficTypeDiagnostic: SN6PR03MB3486: 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: 0IqRJUjQVF0c62fikvroKARp/RBk2OsqIgH8HJ4G2J125iarRgyUSeNkkOdAp/otJnMfkk35J/FUl4qbIBoBrCnI/AL4Tun4odz+PT4xgERu5MS5MajhpzfXic/qYaMr+DSLQy2qYEjuZBpU+OOXKVLNLJDGA2memG5cL+PNkQWBVJ1yaKaEKI2ynyxnONM8aI8xTPFNJV2NmIJdwx6fjATG3fuRW/bjU8I4ijhAeGBnIqOm/mZVafJ6K+gSvnEYNCowD8eyMVlB+Nw5Vv3ewBMXOiuaRnccYK4yiW70bG1GGUiPln7qbOfu5eJwJVob9SFiNPxfOzulk3wUu3ZQMw== 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)(136003)(39860400002)(346002)(366004)(396003)(376002)(5660300002)(66946007)(1076003)(6666004)(66476007)(8676002)(66556008)(956004)(86362001)(83380400001)(786003)(54906003)(316002)(2616005)(26005)(75432002)(4326008)(6916009)(6512007)(6486002)(8936002)(36756003)(16526019)(186003)(2906002)(478600001)(52116002)(6506007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: klmv5zGCLlum6WCT5l7+UfnsERz6Dt8c99qkxJgS4V7DngU20ueVWHE9hnTt68Y3Z3yz0FLkhhSTaTRECLHCQqzUyGDGteWQI0RlJhqtv8wgwkFC3GX7wc6hY/ayV193maCqX/nKZNltcqdQ6BqCpiwoAh4LevLIUyXfsHxZsFdNEhkE4vKczgZmaGH2BgRerv43xIFfQNVZkY02EIg8EUylYmlOPL/DgEBUDgRLYrqZQ1D/g25q+lEdC/d1rUeunYF/6d4PW57XHoyjkUS8YCdfWW0CgTkEQrES8FW5/COxmgZez7HA4SsJ7nzzzHoCYqGlBQNhZhlein/d2F7Yqr6tmkRTQp3jTfed5qlPsWuaJbexYr3ps16b96CvRPTLFPp8FRpA51TKwcQHLH5FsfTFdcoXky+a5GVxuGy01nqkvjc4iLWaTxrdpsgQoAcMUtvlcsRYL6nLmxGjWehjddBh8P8Ie/+QZsdfSZ/qm4C3OESgMolSIKoDVXqEOocsSQ7ulAl+csv0GkufvAmJ0RMEUoGfTCoYAFn8JJ7dT4kBEPHy55TMNvEXM+ktHoHJIFY+QWMraiMrvFHdjVOmOrvCKNfnlyKSD6+TyPISWm47Fmrm19tKk9Q+U7kx5mB/3uM3LKQBXzVr4IzRYy9kHA== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 17defa43-83d0-4012-8294-08d84406be04 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:42.3263 (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: SbvM6orp3XYWdJOxIfQ0HLt+6pe5KBrqZne26PcSIY1qfCTv61m5/2C5hASCGsGy X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3486 Received-SPF: pass client-ip=40.107.102.119; envelope-from=alxndr@bu.edu; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:44 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , Alexander Bulekov , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.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 36d41acea0..26fcd69e45 100644 --- a/tests/qtest/fuzz/general_fuzz.c +++ b/tests/qtest/fuzz/general_fuzz.c @@ -40,6 +40,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, @@ -93,6 +94,7 @@ static GArray *dma_regions; static GArray *dma_patterns; static int dma_pattern_index; +static bool pci_disabled = false; void fuzz_dma_read_cb(size_t addr, size_t len, MemoryRegion *mr, bool is_write); @@ -433,7 +435,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)); @@ -463,7 +465,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)); @@ -518,6 +520,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 (getenv("QTEST_LOG")) { @@ -559,6 +566,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, @@ -591,6 +599,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 Wed Aug 19 06:11: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: 11722575 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A54CD1392 for ; Wed, 19 Aug 2020 06:13:58 +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 7A6DF2063A for ; Wed, 19 Aug 2020 06:13:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="aSaFU05X" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7A6DF2063A 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HMD-0000Fs-OM for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:13:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55296) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HK9-0003sx-3I for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:49 -0400 Received: from mail-dm6nam08on2119.outbound.protection.outlook.com ([40.107.102.119]:43040 helo=NAM04-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 1k8HK7-0001Ya-GG for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=STFLwxSCC7jU4N6SxMTfiONR5VCGlkF8/vimXVVnhZ8/KuP29tqNOgwoL0PQf5z7bl3ffHHxQMJFtzlUz1C84U2O9UaRekGqF8HbLlMduhCijxQs52OmuJJt7CiyseeuVAfobJoI7Wbbvr1a3T7KzCxX+IrCy82W5fD+HYEaUwcuqy9n+70bKvLi3VZynmwxF1BL/UCtB3vpS+R5ton5rj55y+UydqGhO8/KO/SnkleR0m5C7PsTHUJvERukjO/z5bh1mKGAIVHyQxMpbrLbgrJU1IUzMxogR+MP+tXxFuunyt5GBWZ2SBvDp5tIalllyE+yxppxsMIlPccgtYzkdA== 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=shbs9bBBvDEA9c2zzdAfxfgdSWSdqEYR0KGwIBv8/1I=; b=Vw9vBtw2n5yY8HBKdwRtREo/v8yRVmgDlles23wmuoywuMBxicbPXQoWgCG/8ZQwAGiPun1Zld905O9yR7g1zHDbIOPfdjL8Ap2Z+wfEPJvTV1/QKZjvuubgyDjM6F0QHj51fNSzAJuNpwsfmHWj6ZFgulCAYE54NhHkKEZIoWbK19r44Bk6XCOKNrJsdFcPhe5/PWYnmAsGqTfZYamXf07VjHgpM02sJf5bzJTy3O0apRDWsLm8xwtvtwh6rEKp0ToZQRJ8Dn73GH/c6MPlwNnilTnq3G/XyIGdbno/MOupSPZiKsuY6V+Gd86wZThsCsqO0LG360N1jlyd3LXoFg== 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=shbs9bBBvDEA9c2zzdAfxfgdSWSdqEYR0KGwIBv8/1I=; b=aSaFU05XxxpJxIfV+Jo1TauzI7cvenXM9j6lRsqlKk4ABug+AgFWzMKVtSda6jn258zRnK4i6tUy0dIw0zWEuD+J9v2wvdHM/Awxq21K/N3fzC9L0MwJ3alwy240MvgXT4be+hLs97xpcP8eAXEazgFccNCh4Z2AromQiNwUojM= 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 SN6PR03MB3486.namprd03.prod.outlook.com (2603:10b6:805:44::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.18; Wed, 19 Aug 2020 06:11:43 +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.3283.028; Wed, 19 Aug 2020 06:11:43 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 09/15] fuzz: add a crossover function to generic-fuzzer Date: Wed, 19 Aug 2020 02:11:04 -0400 Message-Id: <20200819061110.1320568-10-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11:42 +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: 61614652-3003-4ab9-5082-08d84406bea6 X-MS-TrafficTypeDiagnostic: SN6PR03MB3486: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5WqN0dvHh+9yktpTAtJEhAAZTAwZLG3RnWYxQZolYFz4P9iYMMPyIoUrxaHiDRgaBu/wSRTfA/WnjxaTMrCd7dxNlu2HKM2g0UzZEu7I5s/jTaGalgUFXxMAnrweQwQJq5Hv3Mh7gx3nZP2p0u6wNuRU6xhQ92Ga1W7MkeP+x5hce+vHIdErnNWOggudidp/Bmt7cgO7M5UGq+4DbS+CkYUek1f+6s70HUtx6Y8C+WFDLhFHsl/eRtG5L/a9VvThCLgB/DGmHQdnEWkqXH9DYS3gHP1xKu0EzWuuQ/nVU/ki8rc5HooUnyFXtjylrBEpL+y2C5Vpo6y4LbJ7oCMThllFJY1oYkt39omxCvtu0fbXHyfVtESbWi78tVXKRtFk 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)(136003)(39860400002)(346002)(366004)(396003)(376002)(5660300002)(66946007)(1076003)(6666004)(66476007)(8676002)(66556008)(956004)(86362001)(83380400001)(786003)(54906003)(316002)(2616005)(26005)(75432002)(4326008)(6916009)(6512007)(6486002)(8936002)(36756003)(16526019)(186003)(2906002)(478600001)(52116002)(6506007)(41533002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 1IVb0uYgtty0xFuD47daUM0ZVPxVbIt5R4c0BsXm94y9yZMgVCPxrZTYsKu6UfFBuoNiDyRJNlpVdqFvYMm0GYZ7BIZ6Z7TvY5MlKrCfbozAs1LTDx1XlLx6dCRhNi6rLJsrcwg8RPB4KVN9V6cS8ja2A6b/vqw2WHmzpk0Oj+/zOly+j73Wofqe/sbANMwumwtuDvMfkEA6RhUmkxRFtaz/o9pzBpDALSRT96fO4e2sS9UeV9jef8+7m3AcaHa9oLJIPhjOhXvInRgvUHW2hjdel9x6S+iwJXjEy7e0QtZ6x1bJ1YqVRqdI3Eo7SvPIyMQ919mDUHECVN+VCCQijhkyvOKtQlp/YsH2PbEL08YAYJSCAGYTietYZaXWoNBeLQjLMe46DQo7Tc3DzE8ils3iSSGM7VOM4aZQKjpa4x8UOlK0+LKiJMkC9s1jCgw+PaqSrSsgAmFX/nmB0IEXJcpPX2KAZ4+kZ//dubQ1Ex+O0uxWAtQeHNB8MZIUwlLiFGxho3d5D2l+xBTpAxwa1OwjQXbH37JRihw6iICMDlhxMHwRmfkG0BUdLhqHylSBe+Cn4zIdvNiilUJ5Gx3tzv9U09ucvVtV/0elkmwC3puPpWhUqACMHjClmFPzedHYGeb+6h3B4JVdwOpgQn9Ynw== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 61614652-3003-4ab9-5082-08d84406bea6 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:43.4117 (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: UJpppulYxO1hNxAmQvFSTYqkf0A/gKHxw2xrqZ5Lu3XDY3kA89vqk7nLHtdSQdQv X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3486 Received-SPF: pass client-ip=40.107.102.119; envelope-from=alxndr@bu.edu; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:44 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , Alexander Bulekov , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexander Bulekov --- tests/qtest/fuzz/general_fuzz.c | 81 ++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/tests/qtest/fuzz/general_fuzz.c b/tests/qtest/fuzz/general_fuzz.c index 26fcd69e45..2c3716f8cc 100644 --- a/tests/qtest/fuzz/general_fuzz.c +++ b/tests/qtest/fuzz/general_fuzz.c @@ -739,6 +739,83 @@ 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 = 0, size = 0; + + // Copy in the first input + copy = MIN(size1, max_out_size); + memcpy(out+size, data1, copy); + size+= copy; + max_out_size-= copy; + + // Append a separator + copy = MIN(strlen(SEPARATOR), max_out_size); + memcpy(out+size, SEPARATOR, copy); + size+= copy; + max_out_size-= copy; + + // Clear out the + copy = MIN(1, max_out_size); + if (copy) { + out[size] = OP_CLEAR_DMA_PATTERNS; + } + size+= copy; + max_out_size-= copy; + + copy = MIN(strlen(SEPARATOR), max_out_size); + memcpy(out+size, SEPARATOR, copy); + size+= copy; + max_out_size-= copy; + + copy = MIN(1, max_out_size); + if (copy) { + out[size] = OP_DISABLE_PCI; + } + size+= copy; + max_out_size-= copy; + + copy = MIN(strlen(SEPARATOR), max_out_size); + memcpy(out+size, SEPARATOR, copy); + size+= copy; + max_out_size-= copy; + + copy = MIN(size2, max_out_size); + memcpy(out+size, data2, copy); + size+= copy; + max_out_size-= copy; + + return size; +} + + static GString *general_fuzz_cmdline(FuzzTarget *t) { GString *cmd_line = g_string_new(TARGET_NAME); @@ -758,7 +835,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 Wed Aug 19 06:11: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: 11722587 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B63D913 for ; Wed, 19 Aug 2020 06:15:43 +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 3284720738 for ; Wed, 19 Aug 2020 06:15:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="J94n7b7G" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3284720738 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:52260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HNu-0003Zx-Em for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:15:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HKB-0003xc-1X for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:51 -0400 Received: from mail-dm6nam08on2119.outbound.protection.outlook.com ([40.107.102.119]:43040 helo=NAM04-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 1k8HK9-0001Ya-AD for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:50 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SS/k08ZyqNjppf9hBYHzRUdvMjvNeWEcL25vKQ1RwdApUidURJ+ds0OHLuEXUXv6B0YtLFlpL68Ypy4/ctYZJK292ZklTJdpcsFxgRJr1OfNVruwfRlv9G3WkMAJ271ZB6VoMovzT85Rh++UkZjW6QmAGCrjs+YyYA8OuOVp/cQKGUy2QnzVNnGWwJgAZF7eF2AS6e57fYlsEYYRLYMlUmzOUF6Rew4NLYFjFmVHqpKO2Zrit2bqIqeqUvpIXlKGHZiMnLtIMDbFKav3uMVhf9FWImZ3ovYxB1ArJojZPisHVgyvB17g7ZBZ0D3pWYftM5buTetyof6fBcpceqUgvA== 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=ktyxUGnYf+LmUVRdpxI0BGBhgpxPWQEYle6Jaz1ifws=; b=jiSK+ygIRl7raRxAtzPu6XE8oh/Tm1uYpUFW/nd5SN31m1PL1h69LvvGhVQOA6CuAuuDEE0Q6Q5vLICR5X4X4RR9vcI1624WMiczpITWm9OOZB9Voy1LdjC3v6ghPqZEnYLu9FQ8Fl04SOhHOZhgSCHCyuI3FGXM0VzZ4eg/FlKFzeaEzFpV/5OC7BfYTesCLeb+82LZconMuQ7fnLc6HeBOhPoBD8J/tA0Qqfipew4NLQIJH+q1vOHTnMGBU5gYNG+NiMVPCHEFLYrivKOT4vayMTanSMKZvau768Rht4bOy6iytqs7b/KsdSQXlbaLpi7aKu5TllxaLt75WjlHaw== 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=ktyxUGnYf+LmUVRdpxI0BGBhgpxPWQEYle6Jaz1ifws=; b=J94n7b7GHEDfO95LNXrGtcaXIhp6nlch9QUKxnBzi/9CGlId7O7sHdk5TIyacgI2NG7DKiNurhtyIjFW+0Bq7agCsACB20M2o9xxmXMctsNg3LKGmGBViXOAnHVeV4c1v0cJHpg6z1kSMOy5NY1gkXvMrk1QEneTYnlCe1UKXjM= 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 SN6PR03MB3486.namprd03.prod.outlook.com (2603:10b6:805:44::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.18; Wed, 19 Aug 2020 06:11: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.3283.028; Wed, 19 Aug 2020 06:11:44 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 10/15] scripts/oss-fuzz: Add wrapper program for generic fuzzer Date: Wed, 19 Aug 2020 02:11:05 -0400 Message-Id: <20200819061110.1320568-11-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11:43 +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: 844b34a6-8a2a-4217-094a-08d84406bf40 X-MS-TrafficTypeDiagnostic: SN6PR03MB3486: 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: 27kycPXM8crZb46y0My1PPbmaJiYcc3XIMU9+m40d1aqrI0NPD80XHZPz+9tDckQtjSCO2ydiEWL3VWz0TXCV8hiNvwGwoeyVZcDkCDU3N7sifB7M7p0Lk1hujxGdIDGLdUoZZftn9DSsmYbtXR+0SGpZtU57NAgBQads6mGnoqc2YZolwd3oQX/4xz9xyvhTvT8jycAXWmLCxp7dUY/DpZR+hx7JjWqvDLG9Xx2Ufnac/FOpYUSQHEEzWCwUz2aKEwxgKITyAKpSgg/Xj6MaZ8ecn92cJ9QFJ2A3EuJ2ignEES7EI4kTNV1h3tpkItOG46RU9r4cjghPzfF1fmtUxGy5DESFTt2VqR9lNhftHJ0YsnmPqrit194OXYufh2J 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)(136003)(39860400002)(346002)(366004)(396003)(376002)(5660300002)(66946007)(1076003)(6666004)(66476007)(8676002)(66556008)(956004)(86362001)(83380400001)(786003)(54906003)(316002)(2616005)(26005)(75432002)(4326008)(6916009)(6512007)(6486002)(8936002)(36756003)(16526019)(186003)(2906002)(478600001)(52116002)(6506007)(41533002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 36LV42fjSiIjwcGPQTUoXUnutpeNHmJAxjBa0t0ynsiF5OrPGIlQvbk0CXU+8oRgRN4QrsWFSAJTzNPyDKNAGxQVfi30+U8DQFSE4TqoHE+T2hD4AjURdDPAm0I4evwRzVwR/ZZoEvzoRN5fhXgVtm0Ff16zNwmrLW1VvP600XCOWMQiYKqAsLEFirloJ1I8gztARvTbvhORwUJh1vxsD6EB8Evpjf+9v49HV+hdKUL1IxtaWOu8cIsXGLIEaRwF9fhnqTq1419KWCZAeT5Y58TXCANRlVwpL/ovqmiqHLsPogJS2rhrLMVfhlnoJ1eeLMXOFYItZJcVPXBnvfBsVHrlRuE356B2Xhurvp6qU5OmLDO7/LgJW1vLh+QrBtrrAbUr1OjeSBUVbAAOuJn1j2YZh5y7kU2mvgG+ih21qK4kUdHyVi6m5jTIaNm6m+eV7GuUnfoX6G8VaJ8lZ489pwuM8exyu1i0JKYpMSvPs7Gv8H2j58A2C0Wpr2GjIJ7hjfRHg2c5LyjjQQUxi8ii79vhmzfckjteEfkBAdukVkH4ceogQFoB3cOAxdKTmg5vNKCvmIfxeyTnPfT5v3e+omz4L6rwEkwxoUIBkz/DMzRpa0Tm6mCf9r2F0UQgwMbILs2NlElvpD9npy1eqb6umg== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 844b34a6-8a2a-4217-094a-08d84406bf40 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:44.6110 (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: Dmba6IlgrQoERGfUXqsDn2+qRF7jEfZh40XzpvAGWxCBAkC1Nci72I8qz7hG64fc X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3486 Received-SPF: pass client-ip=40.107.102.119; envelope-from=alxndr@bu.edu; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:44 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=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 , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.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.c | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/oss-fuzz/target.c diff --git a/scripts/oss-fuzz/target.c b/scripts/oss-fuzz/target.c new file mode 100644 index 0000000000..4a7257412a --- /dev/null +++ b/scripts/oss-fuzz/target.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 Wed Aug 19 06:11: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: 11722591 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 25E2C618 for ; Wed, 19 Aug 2020 06:17:15 +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 EFEDB20772 for ; Wed, 19 Aug 2020 06:17:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="2CmpsNLc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EFEDB20772 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HPO-0006F2-3f for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:17:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55354) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HKD-00042s-1d for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:53 -0400 Received: from mail-dm6nam08on2119.outbound.protection.outlook.com ([40.107.102.119]:43040 helo=NAM04-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 1k8HKB-0001Ya-9S for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nBLScZlvdAqhg6rsJJtm6xQuYTfJ0nQPzhbK7sE7Xr2TJOrQdaFZKanxxvE3AzgTJ0IPAzH67uvGbJIWvXtPEemBJNgF4aZYYokXtn346TulWCsQw7e6RwQo0Tvp2nDSlZ+J0G3ZAv7QmPGsrzt3jPYIaRZ2I/AhBaD4V85/xtwybmLsUlvc3mJcg9BVBF1+Zej2h2gCN4VZe00AiUZTSwtUysKBIpv7d+AZ6ADO5D7isI+sqplyUwi09CJ+AKCFDjpDxhDWuLqP3f0OjEfL4fhM4Xi5QPz+MBP77dUsAYKUP0xKpLWYKmKkO5vKgLqXztzlHe44WW/o5dNkOFKs+g== 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=NpNZNsG6MAtW9gsCEmHuXJ48bi7crbRDQgLPRi4F5tU=; b=KntpVxqnhD0sR0tLMpUjKNfkL9qXTYV0OugvyQvsnvSYQktCLtRZ06GBK30lhDag0Mm7fB0vKKWMhxairIfjZl/hRACWo5IZKOawy7oRyim/l8PwmmdauvenFqGABCZEDQTMZLKackcZBi8iFXX3d3Xez7WKf8vASeGbGRc1x8j4nX69lRZiSckDhDK4Mjja8Jo2uxPr0QVCHVfC6Z75Y9T4GCtQex3UEVGTXEUb7C59BWlua0+fnoOc50qc8cyKrTaNHcX2yF/gdIDHX6WuBF6n+etjoeSlEgXWgfMQ6ZC6+0/crVzNJKsj3Np0lNDqIRIlYOcTrHIayoDzvLtFkQ== 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=NpNZNsG6MAtW9gsCEmHuXJ48bi7crbRDQgLPRi4F5tU=; b=2CmpsNLc9TW9PZ5pbdkh4GCD1EOCG0zNvS/dlDLYVphXw3IRESgwGDVTYCU9+wPOzY7BqhfacCkH+sxrmCBe9sGmDJmz09plAJIug9zx7cI+l1yl2dLtz3Pk1HbUc2dztBmD0WPDcgIk8qqAZEYxp31iJBctuwSIFQI7jH0PQW0= 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 SN6PR03MB3486.namprd03.prod.outlook.com (2603:10b6:805:44::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.18; Wed, 19 Aug 2020 06:11: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.3283.028; Wed, 19 Aug 2020 06:11:46 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 11/15] scripts/oss-fuzz: Add general-fuzzer build script Date: Wed, 19 Aug 2020 02:11:06 -0400 Message-Id: <20200819061110.1320568-12-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11: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: 83621cc0-2bc8-4d98-0a01-08d84406c034 X-MS-TrafficTypeDiagnostic: SN6PR03MB3486: 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: aci04U0TPCaLX08mOSAoLKNrV14PjDr8ePqEpMueuLdokkrcg6RRjAUQFdKB/pqBJuPI76Npgtp3GFqHQojXYBr14GeOQsnifFhHhuxyAbRx1vCvEzPLLQTOUUtgtL3J8BDLoDqSeBCRDJwQa9kI7u97U50ll0id6Lwfov5H3wsz68PSH5alC0hPSMDXhfusbTq+Dn22VRlXKOMtmRS+cytM/+uxjkriC0MEX3ilWzPPmlZGwn8wURrrBmXacyv9Lezp1EmiQu41ZbNEAaIuZWqizsJflVprZ8DMg5V730pgkbwmJtL0ktWqZ84cvWULMRzrUq8KW07+CV/5xXlQCw== 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)(136003)(39860400002)(346002)(366004)(396003)(376002)(5660300002)(66946007)(1076003)(6666004)(66476007)(8676002)(66556008)(956004)(86362001)(786003)(54906003)(316002)(2616005)(26005)(75432002)(4326008)(6916009)(6512007)(6486002)(8936002)(36756003)(16526019)(186003)(2906002)(478600001)(52116002)(6506007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: WPRDP4GhUOstmcv92wAlWaBtTZtZCK56PViEBY0rBXBJi0QU3QRucgpJbBxywJZd8VCZPJBiKGGQfQ82kqbOXfne6YfpgDmClrUhKCb0CBT5+p3kjuXvySluHW1A7D89sCPI0bv8Sd6U4MnNT6X8j3d3X6rma+WPkWLQ18W/20aNHljVUSO6uehBeV80++kxcFFX5k9JwTyYBhKzVAwTQw99Vvg0L/Bdcq08QEkEFQsqoHkCFZ+f2y2Bj2ZQ1wxKCMUfPU8rEFga8lcFkvo+Bih9QshTVQ88WWzfVecjjYhbIgU1N3/w+VwkkdzZBlrb7UTHJdelmT5DT2I6nRweCjZg2waMkGw47rC0+teIHIso9SdWAJyJ/VOVVLTsi6pm8XP8s74V3Oc8K2A1FlHGjsvUsogjr/BXFYCamp5w6p4WNPFAJN7jqYD83niPEv7kp/XxmqKxbashRiXoSFo+1SmQSMZGWfQnN2f974qQdZ1414wgy2XITfW/ZDd/fLkqIKQ7wqajTW14yJ0JHqrHxEA/7z6P3moYce4DeGOvbY6DggbgdMJBPY7WI/jqKjl/qOvY4xRt2J7t9wwoNyG5jcNcZU7KC9x8kGQYXSKdBqDksQ/PebVnDLJqJ6XMezXmrFNMlGwGqvWCm88EDqdCIA== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 83621cc0-2bc8-4d98-0a01-08d84406c034 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:46.1751 (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: rj6OxvHzaVYDf2wrwX3UGQ0iZ3kKzrTZpACHPoQSRe10cCHd3Y4eDusJlhMW4wkN X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3486 Received-SPF: pass client-ip=40.107.102.119; envelope-from=alxndr@bu.edu; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:44 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=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 , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.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 | 62 +++++++++++++++++++++++ 1 file changed, 62 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..79f4664117 --- /dev/null +++ b/scripts/oss-fuzz/build_general_fuzzers.py @@ -0,0 +1,62 @@ +#!/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 = "" + + +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="{}" -DQEMU_FUZZ_OBJECTS="{}" \ + {} -o {}'.format( + str_to_c_byte_array(cfg["args"].replace("\n", " ")), + str_to_c_byte_array(cfg["objects"].replace("\n", " ")), + TEMPLATE, path)) + + +def main(): + global CC + global TEMPLATE + + if len(sys.argv) != 3: + usage() + + cfg_path = sys.argv[1] + out_path = sys.argv[2] + + CC = os.getenv("CC") + TEMPLATE = os.path.join(os.path.dirname(__file__), "target.c") + + 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 Wed Aug 19 06:11:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11722581 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1FE1C913 for ; Wed, 19 Aug 2020 06:14:06 +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 EA9182063A for ; Wed, 19 Aug 2020 06:14:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="Fa1+gooT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EA9182063A 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:45012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HML-0000bG-5U for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:14:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HKF-00047v-04 for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:55 -0400 Received: from mail-dm6nam08on2119.outbound.protection.outlook.com ([40.107.102.119]:43040 helo=NAM04-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 1k8HKD-0001Ya-9b for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nS0wZ1vxXFwH09cMUPT6hfpFt9y4hrDMV0DQSqNO5E7rvbcyqpq1NoZyy05xHXsLRUoS49lDtXj8ZJ9MdBu/s6/hvVj374MeUivu5xTIB2Ztj22qFUTgzM2Rohxa8prqpHyabF3fp/KXpJUnXIbC7/dbhJzutsspOAVmJ/6pNdhEX3d5n9IkY/WN4Q1YZpDyUTACVLULkE4vs7W/soQdxnEdXSuNhmdpeXeI8iwkNZSSYFx1AkagVTdda8wCb33UPuwMU8ccB1gmVrBeJeXHDMMAkiQdUKJDEJ2dLzcQKY3jKj8BqdMa6IUKWRkL8ALiTl2Bm1VIpfn0+FissJP1tA== 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=vsvnYrqrAnVDB2Zr7IRC0dE3StgyMFquvqkkkQsDfAI=; b=MY5dGPDP+ZqCr/znFmT9Pslx+H8/Fo14+F4jysEGQThmt4o98bxI5embLpo4cwOhyo2oHFrubIr2Oid5rFf8uOnm+GcGGvPQCCM7pjV4voWQ3QtLGbvoZWEu6dyVOeZezFccRupdRnXqG+OCBife/MQOwhfxGijUdt6ip5Rf8P0tpEbG12++F23zc9zPtQqEeQaV9fYvP6NbCvpdBd9d5a018W8vSzrxDemKrBtqLaxUb3bRQSeJOI9lRYn60ln8EAFYtSOJs/v0STZI+hE5z09s5AW7ank2qi+G4vNThGYs7j0r/D/ecirk9+QlOMovpJLI5w2WM2b+LGRZajX/sg== 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=vsvnYrqrAnVDB2Zr7IRC0dE3StgyMFquvqkkkQsDfAI=; b=Fa1+gooTNcRb2xwKtNwehWBVULFfCdYDkxp2UwQ1jjS8cR+RyidxO6tJsFfOh8gjZJ1kB1w/HPF1j1KGDGOi7T4tK3opiPrjhmcSaGWFD6lqLdk0cKqPvY4RdBGbkyg7PKDfntIgttaEKubJr1ta/4lbk08Zlyi2EbUrXJb9zek= 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 SN6PR03MB3486.namprd03.prod.outlook.com (2603:10b6:805:44::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.18; Wed, 19 Aug 2020 06:11:48 +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.3283.028; Wed, 19 Aug 2020 06:11:48 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 12/15] scripts/oss-fuzz: Add general-fuzzer configs for oss-fuzz Date: Wed, 19 Aug 2020 02:11:07 -0400 Message-Id: <20200819061110.1320568-13-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11:47 +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: 7565a8dc-5ef7-437b-5e0f-08d84406c15a X-MS-TrafficTypeDiagnostic: SN6PR03MB3486: 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: zYMvHCtUvLYVUadrZA9IDaCWWi2XFy4ShZnUGJ9fPV3W/esOVUj+cyZ15/OT+zhbnMoWPBSv7NYHNdUMcvwgg8ewV1RisXBommJCvN88QGmZn9B8WCNDfH8eQBoIgAg7X9HnCNgFD3B9w1/VfJxid7bEYDtMWdD3f4uUrzyOdyQwgpvYbtVFwi8E5IIh5bXBd3P8eM1AvBjcVhgeGkZwFe7Rdoje2a15b/MnzLDK3AxgO82O0gBBqC8/ubqI9gb7FgIS828Zq+ozbWDCrXljhf2sUK9v0C+gJtnFLOvvH5yckI3UEzDysQQyzHupnX2r 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)(136003)(39860400002)(346002)(366004)(396003)(376002)(5660300002)(66946007)(1076003)(6666004)(66476007)(8676002)(66556008)(956004)(86362001)(786003)(54906003)(316002)(2616005)(26005)(75432002)(4326008)(6916009)(6512007)(6486002)(8936002)(36756003)(16526019)(186003)(2906002)(478600001)(52116002)(6506007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: C4hSQz4XsXda+HAM3hsB7asBg2XeovrNArEdXv7P1tfuIX3VhmGBsPR/iIitBEt9Lpdt2A1lZhge9aY3ZtKMJEP75b5pOfVq+VnyXke39338n/76XRkK6gdvVzL/QkhyoSVln/1LZ3S1cyyqZF76r3JLeZtmEUEEGgGqcG9QK0YiyOfEDhPkQ+itb3zCjXox2WTOUNfKmos2LUQ7yoPfOpaBKvUGAZML0l/nbSyCb9/5fYJ8dYdzz5IxuaTlpz9nSPA8SIlNDnKH1qgh2c7W+viat6kIyXyK9sjIR4rgjePdpv//xOqE/4Yqx00cBIi7Ah00eTj3ZoJQxx5jkSYx19ZYurNW8fZw/Ezm7J6SOekee2eORUz7br3mSFje1gV0hZ3vdVISMwg93xhPY5ovJO9I+Ss5qovjChPY8p6YlqLzJG0QgVqHEpi7Wly2/76VcldzGHMv9Tqr2w5iQQhPI6X65FOCge1ID3YJGrR5KiRUUA+2bTZ7sSYq3Z+U+eYrfTj44/u+7z6YX+btC7M4T5EFEGXFzCqtJEJqeaofPZWuKt8BOvlfSriHqfTX4WgjKjmOqCgt/sGIlru/3LVBO/y19RsTPkkhF/VQaDzOVuvK54YwfOMDZJSK3kLkFWh3QeKUEe2Yl2VpVPsRe63NZQ== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 7565a8dc-5ef7-437b-5e0f-08d84406c15a X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:48.0950 (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: Z4n7+Ou9j4UVJBJGWu6AzUGX2nx0rNO7OglZ0SPgyHVc4C/4PE2zB/2KMEiJ29BL X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3486 Received-SPF: pass client-ip=40.107.102.119; envelope-from=alxndr@bu.edu; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:44 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=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 , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.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 Wed Aug 19 06:11:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11722595 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FFA3913 for ; Wed, 19 Aug 2020 06:18:54 +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 7530E20738 for ; Wed, 19 Aug 2020 06:18:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="jSDaUWJY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7530E20738 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:35270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HQz-0008ES-Mm for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:18:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HKG-0004Cq-V3 for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:56 -0400 Received: from mail-dm6nam08on2119.outbound.protection.outlook.com ([40.107.102.119]:43040 helo=NAM04-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 1k8HKF-0001Ya-7O for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CTwU9fdSPmQYvnUliTtfl+a9bmER9lmsrXKWz3pXyXFJwUg6jHSxyHBWKWTQmd+aOJ0gR/tXk/QsTdFm5fdFyzyr4RHmWu/Qv2K7GIA9I+b4pIrY0pD61jRWOKZ6guNGa49+tYY0Wihlh8QkqCetxPCUJhaBDCxG179WoMejQmeXvCeyhNtueulQBX6QNtHxQPfc+jxKZthc+vcqi/UbZ2hCMAXa1A/LRM0NCrjQKPKMN1yM7BCAO8QmmYPWwIKoTfruDI04YGSBmm4xcEEiVZwpF4jQOUtOcFmLXyTSUZRaYmG7d+tTA5NUSKDe1Ur2AS8VQWlla37ABf4ibfyQ/w== 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=UlDkX144i9bzPIsAfGO0qjdctGzXJJqv2P+4rdPQcLA=; b=BRLCS3TK0DYFaPqI5WptNTxFfiYcBmzPf6zi3k9Sjv6Bmd2arutcv0Upsnur4ilABO08++Oab/eJo7UJOPSH7DzwupqoeqKheQZ7ai9cnSj8HayW4LcR+zh6nthcrBBJ101qSkX/2qCMfhDbuzLI5zMFZRcgxiCgmOgPahurUJ3n79ULDcg8FlvEORQEi8YRP6zgC/uhKCubp3Vr6lG+rCtPmnO3FI+9XP9OGcUffUUZp1wIcV+DPLiOjrEDwL9mv5PBXtF/JRjhgRGtq7w+ie7R7HFMdpDHcV+35OPRCxaMPK9f8YhJapwedW2mP3VAuB6lJDo5xeKuWf0gqOmMBA== 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=UlDkX144i9bzPIsAfGO0qjdctGzXJJqv2P+4rdPQcLA=; b=jSDaUWJYP0LJ59U+QLIt/gLVP4WL3BZ3qpuOaTtwnNzs5d0U4eD77amMTaZCLey5kPectM0DzSV/fbqLpwcFLZ3ohdcDaUfDV3ht2f3chQ7LBpR9GOHqICMGOzQKgHzd/qqsgo6iFyYEjxMLjYCS7BbmOiiQpLkCtwUhkDkYerk= 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 SN6PR03MB3486.namprd03.prod.outlook.com (2603:10b6:805:44::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.18; Wed, 19 Aug 2020 06:11: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.3283.028; Wed, 19 Aug 2020 06:11:50 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 13/15] scripts/oss-fuzz: build the general-fuzzer configs Date: Wed, 19 Aug 2020 02:11:08 -0400 Message-Id: <20200819061110.1320568-14-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11: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: 3e1ae9dd-2f79-4d9c-6953-08d84406c2b2 X-MS-TrafficTypeDiagnostic: SN6PR03MB3486: 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: okVvWj3OvQCHJlBdxEPtQTR6Kd4o8ZYrGSHCxaMNhztNdY3MWmq+ezvbtobQ+Ivl/2PXOfFPO0+WR8srnSFl5G+CKcnWXqO34zA7NtSvYf3ob11645fUH1LmSG7B3seOhsnXgnAIuuAc7AVQtFocZFbxgBjo7yM2g6DAUc7xhxkIHJQ6G3lym5mCmmM7kKDbkTzXCpSfu2iEONOIvGeXojem3Y2Yz2Hgkj3dprkAF0NQmyIxcgyQC9V5aENgz3R9gve7+eoyFSFqj2Oay7o1Yx8k3gaYzoc6TV6SGVdag1xUrxfNVM/fBBZ8jYlX1d4Z0MNheOFkYU9Yz/E5rp7Wmg== 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)(136003)(39860400002)(346002)(366004)(396003)(376002)(5660300002)(66946007)(1076003)(6666004)(66476007)(8676002)(66556008)(956004)(86362001)(83380400001)(786003)(54906003)(316002)(2616005)(26005)(75432002)(4326008)(6916009)(6512007)(6486002)(8936002)(36756003)(16526019)(186003)(2906002)(478600001)(52116002)(6506007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: XUWlpJaXfKIZ0bw95IWAc0cEn+PZXvTT5se/sZTNWs55nMK9D6uLI7lGy4ZQqld8vm3T8mXTN0FLwElhNzbQXDARLgWGlrOvbWdaXWNoY//QdtALCiiWHUa4hv8RTusiYSlB5YkzlA3E/6rIPWc5hXUBoM8mH3Uie8OwIFyVyuTvbUWrVFhRW/2R3s5GbL9/4v4Nep5DBdVWNMcFLZgfyWNwup1o9VNEY+Hn9ynNIQOjgP54sIz3fpWBoADPyGSQxBnmAcU8J002Fyr/g8gyCtQXcgCiXfhXvT7gpvI5RiKEDtK8zKUSNDT0/kaSs3w1JcHN2Pr3qNCG240bp6fL94K4pNoa6my+Cj1MNh+aRmMaxOq0E6Ko+cKiZruRDglmOpIb9XTCQHm6cWuFGRgLUvOwcSYdnOK2q61P4RijGHua92Yu1nX1BWZIqS0wcMzzAqvblIXhumXmo4umjc8bYr7NhrOyOMULmmXyeSVPTwCIoRndR1eZ+ffcEwzL/J1JIbra54hf51kU6AJyVR6Zy5AtGcIa1PZUW2gr5vJoljGqdf/90YxsD9yLVyeQ6oFXSlwKeW/hvQGy8Ee8u2JW1abDhsYcnaOjkXIbT6V+FsziPQu6dY2E8XIwwLPthhG9SAI0L4xn2Yqar/PQ9/JRMw== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 3e1ae9dd-2f79-4d9c-6953-08d84406c2b2 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:50.2498 (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: gpJPoROapvDoi9HdHC+RBfVZfqltSgOph0uFIm4RockByqngisIigS+n6j2Lgzey X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3486 Received-SPF: pass client-ip=40.107.102.119; envelope-from=alxndr@bu.edu; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:44 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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 , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.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 | 8 +++++++- scripts/oss-fuzz/general_fuzzer_configs.yml | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/oss-fuzz/build.sh b/scripts/oss-fuzz/build.sh index a07b3022e8..2071e77ac2 100755 --- a/scripts/oss-fuzz/build.sh +++ b/scripts/oss-fuzz/build.sh @@ -38,7 +38,7 @@ OSS_FUZZ_BUILD_DIR="./build-oss-fuzz/" # remove it, resulting in an unresolved reference to qemu_build_not_reached # Undefine the __OPTIMIZE__ macro which compiler.h relies on to choose whether # to " #define qemu_build_not_reached() g_assert_not_reached() " -EXTRA_CFLAGS="$CFLAGS -U __OPTIMIZE__" +EXTRA_CFLAGS="$CFLAGS -U __OPTIMIZE__ -DCONFIG_FUZZ=y" if ! { [ -e "./COPYING" ] && [ -e "./MAINTAINERS" ] && @@ -101,5 +101,11 @@ do cp ./i386-softmmu/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 diff --git a/scripts/oss-fuzz/general_fuzzer_configs.yml b/scripts/oss-fuzz/general_fuzzer_configs.yml index 010e92a2a5..f70bacb243 100644 --- a/scripts/oss-fuzz/general_fuzzer_configs.yml +++ b/scripts/oss-fuzz/general_fuzzer_configs.yml @@ -92,7 +92,7 @@ configs: -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*" + objects: "*usb* *xhci*" - name: pc-i440fx args: -machine pc From patchwork Wed Aug 19 06:11:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11722593 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 507C0913 for ; Wed, 19 Aug 2020 06:17: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 26DC620738 for ; Wed, 19 Aug 2020 06:17: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="qUa3wlSF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 26DC620738 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HQ4-0006x7-Ep for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:17:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HKJ-0004IC-1r for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:59 -0400 Received: from mail-dm6nam08on2119.outbound.protection.outlook.com ([40.107.102.119]:43040 helo=NAM04-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 1k8HKH-0001Ya-5O for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:11:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J6Yx/XrmB3PrpKpKD4zfnIRXjuu2p+/1lh8s81N3jDwcc7HqEI4HkDQ7k5ZLoNkwyQBx85ABoj3qxSEsp9WUGiYx0lGufcQtCXuSybUwFEf5LrphVmt+h5QeS4frSUu9WU91SDFifzhl53gUbsg/T5w6Ek1UjmIDjAx6z7IO+rGdrQ/iXSbLgfau5wY++L1G4tcssgFkggCZDSLu9xQlYSn0/EE/2+1VkHEjDnMKN1+sCmwAtXOxQ3gqNQ4BYZsey/vasd9VFiNWa1+cADgd1aM1zxsn+iCNw/37OfL84eOTA5GU4JCG1RrvB+2H/TBMOXufDFOy0noxbqpTF1L/sg== 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=+KM79cPkTvUzrM+zvLY1mMAUOTr71w0mWHKq6fqwQWw=; b=JJqzjwK2t+79Bo8d7WB4XFGjo7oVQBACwrI+ddwTQVx3zEvNJLoUVqCEKpD7EC0qYuNhXtb0wsL40VCwIcjy3PxRKNq8Yokn7x6avu3n5G1s3IbZSMj0jMEvpJw/MqJyv+0PrmS79JwyEDZE9txhhforK2mMCXYQwef5gssYvdj7bpVQbqTZjj0kp7jyWbzTuGbpUWgGyx9FWio+0qI46gE6iazXEFTaJkQ4DsfctpphYUx/GeuYOn67m4/P7Sj+SW09czwCYKHksDpE2eSiyo7DjxfH2EMbXsY0JpJiWLYhjwgPIjHkLx+sulHxxBhKHr55L2zUlDYA99xjUaElIQ== 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=+KM79cPkTvUzrM+zvLY1mMAUOTr71w0mWHKq6fqwQWw=; b=qUa3wlSFnwbCMSIa0i7WdkwTwBAcWDWaK7QfSkv+fY84+w7PZtQk60xDwHMAACIDomrHQEEGmxqPATQrQtIYlf/BARkzL4+1U9OoS3wPIRBxKGzUFMdKFLaRiRBfOo8UyOuoBxKhYZfMFzGhKP7pRVcKWH8OY1X4yTWimFInJDQ= 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 SN6PR03MB3486.namprd03.prod.outlook.com (2603:10b6:805:44::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.18; Wed, 19 Aug 2020 06:11:51 +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.3283.028; Wed, 19 Aug 2020 06:11:51 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 14/15] scripts/oss-fuzz: Add script to reorder a general-fuzzer trace Date: Wed, 19 Aug 2020 02:11:09 -0400 Message-Id: <20200819061110.1320568-15-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11:50 +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: d0c63674-3735-4ccc-4c69-08d84406c35c X-MS-TrafficTypeDiagnostic: SN6PR03MB3486: 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: 2xQVtJOj+gNJ782IzijDZRkydV9CdWJrb+40nPmXoSqODv4d8xUlpsRe0BtBC3BxVN0LPy3exdOkcj8ohGrke+n98MDAXDvDLjv6GUoexP/x479WYh3qtfstAMRyHZDlWcntE0B09VL2OfMN169TH5ZROrHipJ+FXtPQ23mI6Z7m0WN19F6ahHAl+19HY1tfLOKRrkQUWcBNjh/5L+Q/RMC0D5w3LvQQUK/5HW+s6ZDQv3QTZwufxF6etUkpfuJdETEr8BDZHavL40Ol0TixrYVa/VJ78BS15OWrTwKxgz99lkLmdtO7bBgQE/8seDPS/UjCVEiTEdrAKZiPuSMLKQ== 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)(136003)(39860400002)(346002)(366004)(396003)(376002)(5660300002)(66946007)(1076003)(6666004)(66476007)(8676002)(66556008)(956004)(86362001)(83380400001)(786003)(54906003)(316002)(2616005)(26005)(75432002)(4326008)(6916009)(6512007)(6486002)(8936002)(36756003)(16526019)(186003)(2906002)(478600001)(52116002)(6506007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: RY1qzlb4O7BNvljhlAtqc+MPWPaUses6oRI7/2tXT/cH5krkA4O0Hp14j45p+WmHW+Adv/mT84YGsLD/Pf0VCHrmPC3MdJqwqjdFWJ9ehxK5sjqitlukmUttVNzgOQU94T0yKc+hsLsiqVBXBsct8S6mqCLlJjaoJ2Sk4d7YWmAzbhRmmKQiKIRnxlKuIWkEIU3sARvTemxceY4B3x8sLjJPdFwsMEIlfmEqB3q4z3aI3LLtkgyEi19isIJdn6cZV2btI9/siSfYFmQhn5RTqVd+uBLYRokuX/MzPRuKaMFukMqDVaE3Vl6mfuz2zLiDWA5NhmJp26UlpqFShjWBTm0ZPNeoJbGOFbz/PUMS2E9ffkzXacH2MV2mRma+797p1ZJlYTXj79ZL+NvKAAqG5utf9bua07ml/iPw7W3Ib3Jhtq1nG/Jex5At/ssb8UvZRcfsjGhKIoizk3ku0W/9BhlttB+7HFYKhzVgCg782QgKirDR1NeeN9OiQgNdtsCkN2LYG9Hn7SSDQT3nX/aPaazTPc6avgI3ogwIZ7QmlzxvF/frTgMcS3r/S7grsFZ8jt8o7hSyd4GBh3U7GmczyFOdsElunQ1CrgxVJZjdOQBc9ECUIljaHzfO5fIjMJ6IWE/kwxrKAQb/AIqZXBUf8w== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: d0c63674-3735-4ccc-4c69-08d84406c35c X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:51.5361 (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: dS/WMfl2u+xLsTeZlZji/0S9nBoENYaothUZt0ZBf59FQ9xJ5KJCttnILDSbPLGl X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3486 Received-SPF: pass client-ip=40.107.102.119; envelope-from=alxndr@bu.edu; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:44 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=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 , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.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 Wed Aug 19 06:11:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11722589 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C360618 for ; Wed, 19 Aug 2020 06:17:10 +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 01EB120738 for ; Wed, 19 Aug 2020 06:17:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="DEAkSWcB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 01EB120738 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k8HPJ-00068g-99 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Aug 2020 02:17:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k8HKK-0004L3-S4 for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:12:00 -0400 Received: from mail-dm6nam08on2119.outbound.protection.outlook.com ([40.107.102.119]:43040 helo=NAM04-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 1k8HKJ-0001Ya-9A for qemu-devel@nongnu.org; Wed, 19 Aug 2020 02:12:00 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tj6PEN0GYT9389zSedJcJ5CTOuZzeV1GqBQ2bfjfc16jIgOmCHaltA9wtBhVlD81H2mL+OCfZlswpIozuy+qMSHaBaFImOU00Eg7WSDi8hZMHNypnu9n2IaMZYdj4UjlusguN3F3RFhGOonRNKBQjkIHSCeUVKVIZ6IsUSPa/P6zPaSpdPv75jlbQymXP8c7dQdwSQQGs2GQTZpY/HsrSSy0YbT8UKAsuucazkpCcnGxXae9kYLU7hfh3Dcswq7boSy7DfvHvTwUMILghnFumE3GXT7744WeeeDKTRPMJCZvej7tjXoJ/XF+RRUKOYFYcFVisF5ADEZxgXIG+m9SoQ== 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=lRhs2novFQWQnQokVQCeusPDfBEBhfeP1bRZh7zsdmE=; b=SQNLTrYXTAdmzxAL7UKvAKKTR83RkS1RR++GFQwHX56Gc2DLZqmmrb4FLoZG1A8jkBuC1MqTBr+rwKuKZ0Rg5eCPU+DN1/h+lUchIQi03Cu09tRO5HE4st8WJq5P/7kX/g7HUOrVJb9VeH9MWxNxa02f7UTouTvYTJkmCILAN5DQASNskriLEyD68MxJcHhEtbmzEZT8a42gFQMti7Lmb1Lq1b3B3KZFCHNe3Ts/15MgPfNTCpLsWQwFRfDjSBJrA/DOeNUfPup6vl787zVP3LkWisUEWs/3Uz1HU8H1z3eiGg0UGUXTDqouSkBtldQSTeFmRyLD9TEZ4Tsn/hO6eA== 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=lRhs2novFQWQnQokVQCeusPDfBEBhfeP1bRZh7zsdmE=; b=DEAkSWcBWXTkNFMVjIcttA60QcFwGs9HsJw9SGGvGRD1mZTfWsRbtpGrqQ/Ww2jZfOxnknlY2+JLxnzx3mxZSkWhvDMtAws4NQr2LTsAfiwYGLSljYlFPePoQayGpXiBGW3d5V5AOHEcH3W7kwCXmFJ+PDXuzcYTlfLyRCm5IDU= 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 SN6PR03MB3486.namprd03.prod.outlook.com (2603:10b6:805:44::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.18; Wed, 19 Aug 2020 06:11:53 +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.3283.028; Wed, 19 Aug 2020 06:11:53 +0000 From: Alexander Bulekov To: qemu-devel@nongnu.org Subject: [PATCH v2 15/15] scripts/oss-fuzz: Add crash trace minimization script Date: Wed, 19 Aug 2020 02:11:10 -0400 Message-Id: <20200819061110.1320568-16-alxndr@bu.edu> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819061110.1320568-1-alxndr@bu.edu> References: <20200819061110.1320568-1-alxndr@bu.edu> X-ClientProxiedBy: BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) 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 BL0PR1501CA0012.namprd15.prod.outlook.com (2603:10b6:207:17::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Wed, 19 Aug 2020 06:11:51 +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: 4b20200f-80cc-4a75-c0d2-08d84406c425 X-MS-TrafficTypeDiagnostic: SN6PR03MB3486: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1728; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ENXJwSSVD8Jk+0x0taAUEQlrMIZVmmOK1OxH9K13/usXuQW+yy0m5WxtBaD5hgBJarYQMDsF+zVHFq8/lfbMUb/0LEnSyz6DT8UdTx4aQy72lXQKyUjmCRR6rngSWWKfR6blBEHJ9qrQAZBogkmymICzbly/CY6k+6j0/dNuQZcR/nliXKHwPkOjMBIoxSwpzyUDT1qsNZhXRCkhJOTop60UUcyX93zoX6L+wkUdK8ttWqJ5t2vYnZq+fZkEGj7obYWPFR7zegdiJ+lNO7XCWAQttNrvEuZzfbig5C88YejU/Bp/sWSDYLJi03w+awou82JXcUAwpG7AVcEU1/cdnw== 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)(136003)(39860400002)(346002)(366004)(396003)(376002)(5660300002)(66946007)(1076003)(6666004)(66476007)(8676002)(66556008)(956004)(86362001)(786003)(54906003)(316002)(2616005)(26005)(75432002)(4326008)(6916009)(6512007)(6486002)(8936002)(36756003)(16526019)(186003)(2906002)(478600001)(52116002)(6506007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: rkTgH9bnjKP0GAzOC98/o5tlpAz5PAmUmk67EuzTyla7SRDBhv+19GMJHmxtLiGSusqzoXoBp31Im0sH0dedsyw3V0fxc9nRvGtXDJiz+NcyF9FPLz0P5SDv8lWClPDv2pUCnnF7jL0eMdc8sMGbdvrcKVHDXEj2zTRe5V9fWQDJQRh0PyasC/5tQWTyRbQ93TrnUwiMse+MLez7ZIScxM9HJIaI9cbA5t7ZuituskZkY8XGZJvAzSs/Ca3MPup7JF9Pz/Pds3hYk2quS4d4VzNx7H5mcWnFO1Tur7hMnDVKxoRtSrBqNMo7zcptBDASLZAH2MNBsfcINvG0/t4BylNJmE2ibIpoS93FqQ9J+9d4MOHPCW20AatCt5RqnNg7yeRLk8BlBJagrl9w/eB6N1ievt3g2IMfLC98/9f5/G/FbDuj2LuW5XWeHULk3UJbF6Wl55Tmd5hsrCfdz14WwtInlzbDLcry264MKg1Fo/IuATXhjJqYJW8joRkyaRJeBB20aTdUhRNjnnrZ7TJKkMVJxDNoxDDzuS71KgIoBcuq94vIr4F/g7wf3rlsjJJlG7Rzvc3YJerQE5WikA4ACaUg7n3FKhf2fEVX4V4WUEYFxlIPdQPR+DPEUzORGMflqKl0DoDRl0PseOzq5qTqzw== X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 4b20200f-80cc-4a75-c0d2-08d84406c425 X-MS-Exchange-CrossTenant-AuthSource: SN6PR03MB3871.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2020 06:11:52.9313 (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: VR7ibrM/2pl+B3zj++UPRUwk6EFtokFQYK3sPAcnFJVEo5+4Pin8cCqVjjNwqYYx X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB3486 Received-SPF: pass client-ip=40.107.102.119; envelope-from=alxndr@bu.edu; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/19 02:11:44 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=1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=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 , f4bug@amsat.org, darren.kenny@oracle.com, bsd@redhat.com, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.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 | 118 +++++++++++++++++++++++ 1 file changed, 118 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..2f1f4f368e --- /dev/null +++ b/scripts/oss-fuzz/minimize_qtest_trace.py @@ -0,0 +1,118 @@ +#!/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 + +QEMU_ARGS = None +QEMU_PATH = None +TIMEOUT = 5 +CRASH_TOKEN = None + + +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 {}s {} {} 2>&1 < {}".format(TIMEOUT, + QEMU_PATH, QEMU_ARGS, 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[:] + while i < len(newtrace): + 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 + # Try to split up writes into multiple commands, each of which can be + # removed. + 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])