From patchwork Tue Nov 5 11:34:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Malcomson X-Patchwork-Id: 1189603 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-512437-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="b/XX2RWY"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="3ra9MOjF"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="3ra9MOjF"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 476nfq485kz9sPK for ; Tue, 5 Nov 2019 22:36:03 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:references:in-reply-to :content-type:mime-version; q=dns; s=default; b=vx8suIlzCSmpD6rL 0ilFZI4FQkaunu9lG7k4RTreuEUHL16iaEwxgOE2NIxxhoB+QbPL1LWkdkif7bC+ LNV3iixUuST8/sm6sl5PL6hY5kkWKcFwoXHwJNv7ZuK4/GGseXL5IKl2mYSf+uKR SZrMbVpWSsjeT9p0C7xhbjItb0E= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:references:in-reply-to :content-type:mime-version; s=default; bh=NH5d+5stHO5o//Yqtx5qBI 9VSA8=; b=b/XX2RWYNg/4UajTl7ccVOwbyWaFtvuSCiLWClxrOkS5nQp8MyePgX N9XIJmCGaoncvqDn56afybC+kcAjNStGncMQRve1+TOSokFiOA5YerejkgfXfOdq ZQzhI3SKDRL16efwsUEoJTTVcFJnpDKs4g1qohD4yStCYrRuingss= Received: (qmail 86023 invoked by alias); 5 Nov 2019 11:34:30 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 85941 invoked by uid 89); 5 Nov 2019 11:34:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: FRA01-PR2-obe.outbound.protection.outlook.com Received: from mail-eopbgr120053.outbound.protection.outlook.com (HELO FRA01-PR2-obe.outbound.protection.outlook.com) (40.107.12.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Nov 2019 11:34:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jOvbjjWLA2aMeiotD/bAmxYIIKStlAaxVbyLonXScxU=; b=3ra9MOjFaufaSqmTmO3eICG5gVdPCxWx4cBRuS7ta7Zs0OorDIJb3ougV8J4ZHaSsx33XEXDwrPhkeC2GKTL8d8+FEaH/VIct2UWNs2itYMtFZZks3mb03KWyaxCZGlLDZzQxrvBfA3S2XOKd4KBsOHP1r/s6QK44mQzNciLjhQ= Received: from AM6PR08CA0044.eurprd08.prod.outlook.com (2603:10a6:20b:c0::32) by PR2PR08MB4665.eurprd08.prod.outlook.com (2603:10a6:101:25::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2408.24; Tue, 5 Nov 2019 11:34:23 +0000 Received: from VE1EUR03FT021.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::207) by AM6PR08CA0044.outlook.office365.com (2603:10a6:20b:c0::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2408.24 via Frontend Transport; Tue, 5 Nov 2019 11:34:23 +0000 Authentication-Results: spf=fail (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; gcc.gnu.org; dmarc=none action=none header.from=arm.com; Received-SPF: Fail (protection.outlook.com: domain of arm.com does not designate 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT021.mail.protection.outlook.com (10.152.18.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2387.20 via Frontend Transport; Tue, 5 Nov 2019 11:34:23 +0000 Received: ("Tessian outbound 6481c7fa5a3c:v33"); Tue, 05 Nov 2019 11:34:23 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 48949c37cf76a959 X-CR-MTA-TID: 64aa7808 Received: from 0790675fd61d.2 (cr-mta-lb-1.cr-mta-net [104.47.14.51]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id 68879333-3D38-4DB4-85CB-17DFAD914BBD.1; Tue, 05 Nov 2019 11:34:17 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04lp2051.outbound.protection.outlook.com [104.47.14.51]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 0790675fd61d.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 05 Nov 2019 11:34:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PvuMp2BVgORIotcdHI5WwCdmWhP7LBUDj1y6A1DAz65PXgBTX7ADqhJZucwTqI56D7H7YhiPjXsjb4qGpAgxM+eENgcEE5FSc6rVsXp0WILzUo2l10WIMNeL686y5Lm2QgYcyALtt+z9UIil/ogDEym8zRE2+M++nh5NFemET/400iIK1Jy/LSkyIrefHpLwMRJAC2zESBOeR8edLk7BEFhlimVKAH+5YPuUgkR3x4SRrl9NGaRlAB0CfQENe4EGrM+4uC1FpSOlz9m+oQ6Fx6/Xe+NUHlqvx4p6FMXVFS2eFMIeoCN0tUESuQT3kXn6V+dq5jbiv5Ai8FArAkcWqg== 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=jOvbjjWLA2aMeiotD/bAmxYIIKStlAaxVbyLonXScxU=; b=Mn3txU2YfMQLP/0kSBaa2X3fzMB1NGddRrXHjlHBwcTIzay4VA5ATNDBWlMySLp2ZdXnPpvehbAbsCJizgXiDKpI1a5j1vgS0rKZmSkEeIimYjzuVGZ3kbg0llkD15bzrbC1uYtvuPlipkzqEBoOFhOPTemN2Qfr6Gshsf0krpZAkTUJj9GoQLCGDc6KnthccdErj9hkrrWlgIaJ51RU0WboMv+G/4VQSsbNnNNQnwtLMmsYgwj6x4hDfyNFGLR6t1AOlqqNbPpthf50YCmJ8B0LNmCH62OLTuTVs4cell3LGrQFQMuho4a57pWGBq3pLbQN1hD91fMgEv/a6V9Uuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jOvbjjWLA2aMeiotD/bAmxYIIKStlAaxVbyLonXScxU=; b=3ra9MOjFaufaSqmTmO3eICG5gVdPCxWx4cBRuS7ta7Zs0OorDIJb3ougV8J4ZHaSsx33XEXDwrPhkeC2GKTL8d8+FEaH/VIct2UWNs2itYMtFZZks3mb03KWyaxCZGlLDZzQxrvBfA3S2XOKd4KBsOHP1r/s6QK44mQzNciLjhQ= Received: from HE1PR0802MB2251.eurprd08.prod.outlook.com (10.172.131.21) by HE1PR0802MB2313.eurprd08.prod.outlook.com (10.172.127.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2408.24; Tue, 5 Nov 2019 11:34:15 +0000 Received: from HE1PR0802MB2251.eurprd08.prod.outlook.com ([fe80::e120:9a38:bcf4:6075]) by HE1PR0802MB2251.eurprd08.prod.outlook.com ([fe80::e120:9a38:bcf4:6075%5]) with mapi id 15.20.2408.024; Tue, 5 Nov 2019 11:34:15 +0000 From: Matthew Malcomson To: "gcc-patches@gcc.gnu.org" CC: nd , "kcc@google.com" , "dvyukov@google.com" , Martin Liska , Richard Earnshaw , Kyrylo Tkachov , "dodji@redhat.com" , "jakub@redhat.com" Subject: [PATCH 8/X] [libsanitizer] Expose __hwasan_tag_mismatch_stub Date: Tue, 5 Nov 2019 11:34:15 +0000 Message-ID: References: <157295142743.27946.1142544630216676787.scripted-patch-series@arm.com> In-Reply-To: <157295142743.27946.1142544630216676787.scripted-patch-series@arm.com> Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Matthew.Malcomson@arm.com; x-ms-exchange-transport-forked: True x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:6790;OLM:6790; X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(376002)(136003)(396003)(366004)(39860400002)(346002)(54534003)(189003)(199004)(11346002)(446003)(66616009)(5660300002)(26005)(102836004)(7696005)(2501003)(6506007)(7736002)(8676002)(81156014)(81166006)(33656002)(478600001)(74316002)(2906002)(76176011)(186003)(386003)(99936001)(8936002)(14454004)(2351001)(44832011)(486006)(476003)(66476007)(316002)(52116002)(71190400001)(6116002)(25786009)(3846002)(305945005)(54906003)(86362001)(66066001)(9686003)(6436002)(5024004)(5640700003)(4326008)(55016002)(99286004)(14444005)(66446008)(71200400001)(66556008)(52536014)(66946007)(64756008)(256004)(6916009); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0802MB2313; H:HE1PR0802MB2251.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: M5hexGwpjQUYHtOd3TKQwTkAxhWheK0GgXIYveH8y1G9r4G9Ys8cpjWSMWqCfzUztQerMCqJVAY3k+I39rdDtxd2l0Yy+fDrRj5vzXQUqF0hcLAUs6NVL0qhUmgJgIarl9P30oQWqW+xDoRJvNavYfnqLqPSra1eigISpvZWtE/qvwqpFQObuNKY3BeRrGVa5KVZx1CStegGZQY6xMo+uwswBMidUz3b/HxCR3VcU5GvOkrR6sxkGEFho86LUmmjm/BC94i+eW7t4blrXBtFW/f9TqfHDKREINe8KCunyagsvoNnCola3rQNpHJcnhtYS+xQRLZZ/Pse2VlFpmXCHxinE/pDfeW95V+OqROxeajvVLPRdcCL6mSGIzQfeADR42Z8EdudRrzivYisausVoQO2vHzKV0q8lyLtB9jndnK3DJxM0+9+usXLtirqc95U MIME-Version: 1.0 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Matthew.Malcomson@arm.com; X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT021.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: c36ce800-5014-4084-9a63-08d761e41658 X-IsSubscribed: yes Backport from llvm upstream (monorepo revision 612eadb). This allows us to report tag mismatches without threading it through the backend to generate assembly. libsanitizer/ChangeLog: 2019-11-05 Matthew Malcomson * hwasan/hwasan_interface_internal.h (__hwasan_tag_mismatch4): New exported symbol. * hwasan/hwasan_linux.cpp (__hwasan_tag_mismatch_stub): Rename to ... (__hwasan_tag_mismatch4): ... this. Also add "size" argument. * hwasan/hwasan_tag_mismatch_aarch64.S: Update function call to use new name. ############### Attachment also inlined for ease of reply ############### diff --git a/libsanitizer/hwasan/hwasan_interface_internal.h b/libsanitizer/hwasan/hwasan_interface_internal.h index ca57f0fe437bfdbc3d490c1978985fc3ab64d4c5..aedda317497b61349050511a3d244f480fae5ba2 100644 --- a/libsanitizer/hwasan/hwasan_interface_internal.h +++ b/libsanitizer/hwasan/hwasan_interface_internal.h @@ -112,6 +112,10 @@ SANITIZER_INTERFACE_ATTRIBUTE void __hwasan_tag_mismatch(uptr addr, u8 ts); SANITIZER_INTERFACE_ATTRIBUTE +void __hwasan_tag_mismatch4(uptr addr, uptr access_info, uptr *registers_frame, + size_t outsize); + +SANITIZER_INTERFACE_ATTRIBUTE u8 __hwasan_generate_tag(); // Returns the offset of the first tag mismatch or -1 if the whole range is diff --git a/libsanitizer/hwasan/hwasan_linux.cpp b/libsanitizer/hwasan/hwasan_linux.cpp index 948e40154fec9295a451a3bc4e6a6914f619d6e3..dfef11883a284dae0c96cfcc6a8fd1cc06c24d71 100644 --- a/libsanitizer/hwasan/hwasan_linux.cpp +++ b/libsanitizer/hwasan/hwasan_linux.cpp @@ -460,21 +460,6 @@ static bool HwasanOnSIGTRAP(int signo, siginfo_t *info, ucontext_t *uc) { return true; } -// Entry point stub for interoperability between __hwasan_tag_mismatch (ASM) and -// the rest of the mismatch handling code (C++). -extern "C" void __hwasan_tag_mismatch_stub(uptr addr, uptr access_info, - uptr *registers_frame) { - AccessInfo ai; - ai.is_store = access_info & 0x10; - ai.recover = false; - ai.addr = addr; - ai.size = 1 << (access_info & 0xf); - - HandleTagMismatch(ai, (uptr)__builtin_return_address(0), - (uptr)__builtin_frame_address(0), nullptr, registers_frame); - __builtin_unreachable(); -} - static void OnStackUnwind(const SignalContext &sig, const void *, BufferedStackTrace *stack) { stack->Unwind(StackTrace::GetNextInstructionPc(sig.pc), sig.bp, sig.context, @@ -493,4 +478,24 @@ void HwasanOnDeadlySignal(int signo, void *info, void *context) { } // namespace __hwasan +// Entry point for interoperability between __hwasan_tag_mismatch (ASM) and the +// rest of the mismatch handling code (C++). +void __hwasan_tag_mismatch4(uptr addr, uptr access_info, uptr *registers_frame, + size_t outsize) { + __hwasan::AccessInfo ai; + ai.is_store = access_info & 0x10; + ai.is_load = !ai.is_store; + ai.recover = access_info & 0x20; + ai.addr = addr; + if ((access_info & 0xf) == 0xf) + ai.size = outsize; + else + ai.size = 1 << (access_info & 0xf); + + __hwasan::HandleTagMismatch(ai, (uptr)__builtin_return_address(0), + (uptr)__builtin_frame_address(0), nullptr, + registers_frame); + __builtin_unreachable(); +} + #endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD diff --git a/libsanitizer/hwasan/hwasan_tag_mismatch_aarch64.S b/libsanitizer/hwasan/hwasan_tag_mismatch_aarch64.S index 92f62748048682f2e762a91050232fd3c65d538f..d1e0654cf715149d9ce6e3d8863ccd4f33745c95 100644 --- a/libsanitizer/hwasan/hwasan_tag_mismatch_aarch64.S +++ b/libsanitizer/hwasan/hwasan_tag_mismatch_aarch64.S @@ -89,12 +89,12 @@ __hwasan_tag_mismatch: stp x4, x5, [sp, #32] stp x2, x3, [sp, #16] - // Pass the address of the frame to __hwasan_tag_mismatch_stub, so that it can + // Pass the address of the frame to __hwasan_tag_mismatch4, so that it can // extract the saved registers from this frame without having to worry about // finding this frame. mov x2, sp - bl __hwasan_tag_mismatch_stub + bl __hwasan_tag_mismatch4 CFI_ENDPROC .Lfunc_end0: diff --git a/libsanitizer/hwasan/hwasan_interface_internal.h b/libsanitizer/hwasan/hwasan_interface_internal.h index ca57f0fe437bfdbc3d490c1978985fc3ab64d4c5..aedda317497b61349050511a3d244f480fae5ba2 100644 --- a/libsanitizer/hwasan/hwasan_interface_internal.h +++ b/libsanitizer/hwasan/hwasan_interface_internal.h @@ -112,6 +112,10 @@ SANITIZER_INTERFACE_ATTRIBUTE void __hwasan_tag_mismatch(uptr addr, u8 ts); SANITIZER_INTERFACE_ATTRIBUTE +void __hwasan_tag_mismatch4(uptr addr, uptr access_info, uptr *registers_frame, + size_t outsize); + +SANITIZER_INTERFACE_ATTRIBUTE u8 __hwasan_generate_tag(); // Returns the offset of the first tag mismatch or -1 if the whole range is diff --git a/libsanitizer/hwasan/hwasan_linux.cpp b/libsanitizer/hwasan/hwasan_linux.cpp index 948e40154fec9295a451a3bc4e6a6914f619d6e3..dfef11883a284dae0c96cfcc6a8fd1cc06c24d71 100644 --- a/libsanitizer/hwasan/hwasan_linux.cpp +++ b/libsanitizer/hwasan/hwasan_linux.cpp @@ -460,21 +460,6 @@ static bool HwasanOnSIGTRAP(int signo, siginfo_t *info, ucontext_t *uc) { return true; } -// Entry point stub for interoperability between __hwasan_tag_mismatch (ASM) and -// the rest of the mismatch handling code (C++). -extern "C" void __hwasan_tag_mismatch_stub(uptr addr, uptr access_info, - uptr *registers_frame) { - AccessInfo ai; - ai.is_store = access_info & 0x10; - ai.recover = false; - ai.addr = addr; - ai.size = 1 << (access_info & 0xf); - - HandleTagMismatch(ai, (uptr)__builtin_return_address(0), - (uptr)__builtin_frame_address(0), nullptr, registers_frame); - __builtin_unreachable(); -} - static void OnStackUnwind(const SignalContext &sig, const void *, BufferedStackTrace *stack) { stack->Unwind(StackTrace::GetNextInstructionPc(sig.pc), sig.bp, sig.context, @@ -493,4 +478,24 @@ void HwasanOnDeadlySignal(int signo, void *info, void *context) { } // namespace __hwasan +// Entry point for interoperability between __hwasan_tag_mismatch (ASM) and the +// rest of the mismatch handling code (C++). +void __hwasan_tag_mismatch4(uptr addr, uptr access_info, uptr *registers_frame, + size_t outsize) { + __hwasan::AccessInfo ai; + ai.is_store = access_info & 0x10; + ai.is_load = !ai.is_store; + ai.recover = access_info & 0x20; + ai.addr = addr; + if ((access_info & 0xf) == 0xf) + ai.size = outsize; + else + ai.size = 1 << (access_info & 0xf); + + __hwasan::HandleTagMismatch(ai, (uptr)__builtin_return_address(0), + (uptr)__builtin_frame_address(0), nullptr, + registers_frame); + __builtin_unreachable(); +} + #endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD diff --git a/libsanitizer/hwasan/hwasan_tag_mismatch_aarch64.S b/libsanitizer/hwasan/hwasan_tag_mismatch_aarch64.S index 92f62748048682f2e762a91050232fd3c65d538f..d1e0654cf715149d9ce6e3d8863ccd4f33745c95 100644 --- a/libsanitizer/hwasan/hwasan_tag_mismatch_aarch64.S +++ b/libsanitizer/hwasan/hwasan_tag_mismatch_aarch64.S @@ -89,12 +89,12 @@ __hwasan_tag_mismatch: stp x4, x5, [sp, #32] stp x2, x3, [sp, #16] - // Pass the address of the frame to __hwasan_tag_mismatch_stub, so that it can + // Pass the address of the frame to __hwasan_tag_mismatch4, so that it can // extract the saved registers from this frame without having to worry about // finding this frame. mov x2, sp - bl __hwasan_tag_mismatch_stub + bl __hwasan_tag_mismatch4 CFI_ENDPROC .Lfunc_end0: