From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.5 required=3.0 tests=DKIM_ADSP_ALL,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F0B2C31E46 for ; Wed, 12 Jun 2019 15:36:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6340D21721 for ; Wed, 12 Jun 2019 15:36:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.de header.i=@amazon.de header.b="ipmiOu/3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437553AbfFLPgb (ORCPT ); Wed, 12 Jun 2019 11:36:31 -0400 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:63119 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437543AbfFLPgb (ORCPT ); Wed, 12 Jun 2019 11:36:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1560353790; x=1591889790; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=YD1Fi0GvdNAKUu8A+dqXH3sOUetAnqKZZEfujw59KzM=; b=ipmiOu/3ZJoQzP0NCQw2D2tIqIubIXK1aJ9JIAd2ArtpCWH/6wmlEAwR 4dIgwcsbumT1PSnwq9duknlEzaHWjYuxiciFx5n5nmIscQl9BLwrl2GiW qEjeteP5YfoscJ60ckU8hF+8im11X0fJ1DJzaZpqASrv8IyN3RDaNFXHo c=; X-IronPort-AV: E=Sophos;i="5.62,366,1554768000"; d="scan'208";a="679536197" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2a-53356bf6.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 12 Jun 2019 15:36:28 +0000 Received: from EX13MTAUEB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-2a-53356bf6.us-west-2.amazon.com (Postfix) with ESMTPS id 5360CA2413; Wed, 12 Jun 2019 15:36:27 +0000 (UTC) Received: from EX13D08UEB001.ant.amazon.com (10.43.60.245) by EX13MTAUEB001.ant.amazon.com (10.43.60.129) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 12 Jun 2019 15:36:27 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D08UEB001.ant.amazon.com (10.43.60.245) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 12 Jun 2019 15:36:26 +0000 Received: from u6cf1b7119fa15b.ant.amazon.com (10.28.85.98) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 12 Jun 2019 15:36:24 +0000 From: Sam Caccavale CC: , , , , , , , , , , , , , , , , , , , , Sam Caccavale Subject: [v2, 3/4] Demonstrating unit testing via simple-harness Date: Wed, 12 Jun 2019 17:35:59 +0200 Message-ID: <20190612153600.13073-4-samcacc@amazon.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190612153600.13073-1-samcacc@amazon.de> References: <20190612153600.13073-1-samcacc@amazon.de> MIME-Version: 1.0 Content-Type: text/plain To: unlisted-recipients:; (no To-header on input) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Simple-harness.c uses inline asm support to generate asm and then has the emulator emulate this code. This may be useful as a form of testing for the emulator. CR: https://code.amazon.com/reviews/CR-8591638 --- tools/fuzz/x86ie/Makefile | 7 ++++-- tools/fuzz/x86ie/simple-harness.c | 42 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 tools/fuzz/x86ie/simple-harness.c diff --git a/tools/fuzz/x86ie/Makefile b/tools/fuzz/x86ie/Makefile index d45fe6d266b9..e79d275e1040 100644 --- a/tools/fuzz/x86ie/Makefile +++ b/tools/fuzz/x86ie/Makefile @@ -44,8 +44,11 @@ LOCAL_OBJS := emulator_ops.o stubs.o afl-harness: afl-harness.o $(LOCAL_OBJS) $(KERNEL_OBJS) @$(CC) -v $(KBUILD_CFLAGS) $(LOCAL_OBJS) $(KERNEL_OBJS) $< $(INCLUDES) -Istubs.h -o $@ -no-pie -all: afl-harness +simple-harness: simple-harness.o $(LOCAL_OBJS) $(KERNEL_OBJS) + @$(CC) -v $(KBUILD_CFLAGS) $(LOCAL_OBJS) $(KERNEL_OBJS) $< $(INCLUDES) -Istubs.h -o $@ -no-pie + +all: afl-harness simple-harness .PHONY: clean clean: - $(RM) -r *.o afl-harness + $(RM) -r *.o afl-harness simple-harness diff --git a/tools/fuzz/x86ie/simple-harness.c b/tools/fuzz/x86ie/simple-harness.c new file mode 100644 index 000000000000..f21fdafe1dd1 --- /dev/null +++ b/tools/fuzz/x86ie/simple-harness.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include "emulator_ops.h" +#include + +extern void foo(void) +{ + asm volatile("__start:" + ".byte 0x32, 0x05, 0x00, 0x00, 0x00, 0x00;" // xor eax,DWORD PTR [rip+0x0] + ".byte 0x90;" + //".byte 0x0f, 0x7f, 0xde;" // movq mm6,mm3 + ".byte 0x0f, 0x6f, 0xde;" // same instruction... + ".byte 0x90;" + "__end:"); +} + +int main(int argc, char **argv) +{ + extern unsigned char __start; + extern unsigned char __end; + struct state *state = create_emulator(); + int rc; + + /* Ensures the emulator is in a valid state. */ + initialize_emulator(state); + + /* Provide the emulator with instructions to emulate. */ + state->data = &__start; + state->data_available = &__end - &__start; + + /* rip addressed instruction */ + rc = emulate_until_complete(state); + + /* Free the emulator. */ + free_emulator(state); + + return 0; +} -- 2.17.1 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879