From patchwork Fri Nov 27 18:46:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Malcomson X-Patchwork-Id: 1407378 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=gdOz9gH7; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CjNry54jbz9s0b for ; Sat, 28 Nov 2020 05:46:57 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E35203972826; Fri, 27 Nov 2020 18:46:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E35203972826 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1606502814; bh=Bhqh63qaR56DpvJq0AeecQ0RKUcnp5C6vUI2+vs2ppM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=gdOz9gH7eO7dE8acwc+OWy4TyTAFoKI9oBg9YKutsfm0ga0p/aLwYIvd6RY43Yq0q Mv7u4Tt9wtfyrxpU6s0f8oQamJYqgAl7VgYLctrpqLyPeatCnxTkSQvGwclj9BSf90 OOTLABfYJ/dtKobSRxjIw41UtTVa/2qddBtk0LAI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00075.outbound.protection.outlook.com [40.107.0.75]) by sourceware.org (Postfix) with ESMTPS id 34813386188D for ; Fri, 27 Nov 2020 18:46:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 34813386188D Received: from AM9P191CA0009.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21c::14) by AM6PR08MB3574.eurprd08.prod.outlook.com (2603:10a6:20b:4e::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3564.28; Fri, 27 Nov 2020 18:46:48 +0000 Received: from AM5EUR03FT022.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:21c:cafe::3c) by AM9P191CA0009.outlook.office365.com (2603:10a6:20b:21c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Fri, 27 Nov 2020 18:46:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (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=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 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 AM5EUR03FT022.mail.protection.outlook.com (10.152.16.79) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.26 via Frontend Transport; Fri, 27 Nov 2020 18:46:48 +0000 Received: ("Tessian outbound fcd5bc555ddc:v71"); Fri, 27 Nov 2020 18:46:47 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 4f4e519cc3ad9e17 X-CR-MTA-TID: 64aa7808 Received: from fb5ef449b3f1.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 79A86D18-3F64-44AD-BC36-FE1B269A5361.1; Fri, 27 Nov 2020 18:46:31 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id fb5ef449b3f1.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 27 Nov 2020 18:46:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RORU37amostjt1iJpcbeRxzCKFlKKmBkJa1zlshgNG1eAHzR1vTKo5hSxLRGQ3naAUO3SUutHOifQ5WcBLZrmrE+NcllbAe9PMb3d/z3Eok7DEShDgBuH19zaM4PR7I/P61CVp3XfYHw/vqkRj8TuIW2Rf6Wa3ukXJ+7qJGOtErSLUUVME3EPo5PX7WNyWNsMf7Zh3NggpOjao9ndvnHrw2x+PQyC3hmfpdGOripS6HvTKyxW4rT2A2eeLq2RasFyyNHQtsKGSOBAXKCnZPl6OAixHTVqTzrIx/Gz8gv3ky8X1XXCp4+Z6ME+aTbbg2tuAHH37ZLWuR2iCv/lNyP7A== 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=Bhqh63qaR56DpvJq0AeecQ0RKUcnp5C6vUI2+vs2ppM=; b=g3lEC/1bBpieO9BtPLu4LRuE47aNEVRbH0bnQ60uaBvi2zVKjFWsquo4ezxdqqG8KuaEhKdl3MClOeFTWntM4VRDrT13lBueLfhDbzx+AhTqx4YKgWbGeENn/lARc0qteuqhefG2lOyqT6k5CUHYDPT2P2CdwxJjwvcewVPL9t+OxxjOSZRNKNfDWtFrusjM3K9KmBonJkVFi9YQBLB7DPhIELQqbGP/sfsKhfwaFoVS5w3IQ4cxMWD5YXbvEvy7ODD0YI+3j/jja+Ni4ZbFHVosg4NFjQRMjEHD9EHgsHNUoCfUVb3x/M9RAHH65hISSwqS02cFZXi++xeMfnELiA== 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 Authentication-Results-Original: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3157.eurprd08.prod.outlook.com (2603:10a6:209:48::24) by AM5PR0802MB2612.eurprd08.prod.outlook.com (2603:10a6:203:99::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.21; Fri, 27 Nov 2020 18:46:30 +0000 Received: from AM6PR08MB3157.eurprd08.prod.outlook.com ([fe80::93:8d42:2d3f:8400]) by AM6PR08MB3157.eurprd08.prod.outlook.com ([fe80::93:8d42:2d3f:8400%4]) with mapi id 15.20.3589.022; Fri, 27 Nov 2020 18:46:30 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH] testsuite: Correct check_effective_target_hwaddress_exec Date: Fri, 27 Nov 2020 18:46:28 +0000 X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: LNXP265CA0012.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5e::24) To AM6PR08MB3157.eurprd08.prod.outlook.com (2603:10a6:209:48::24) Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from e120487-lin.cambridge.arm.com (217.140.106.55) by LNXP265CA0012.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.23 via Frontend Transport; Fri, 27 Nov 2020 18:46:29 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 82f0ea05-6b4b-45db-228c-08d89304cbe2 X-MS-TrafficTypeDiagnostic: AM5PR0802MB2612:|AM6PR08MB3574: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: eWhJMMqWY//cqsLzQg2G5e7bn9FwAo012cWc8AO59muiMW2f5+rnpyeRAz4CYZGcN0VhEwJLNErt+fam4vXz8YPmH0BeEO/sFW3cSsD5YrjeSgx4Ke4RksKb7alpY37ACPHZYFwafT7Qn2hl0VSp9ZbYMiRQSrghQN0m/qFmc20aqY8R0mSwdmJl+zFu6YzvvpA7vuiUMGKg+ZyVNyFRaQbh0FVnOPYzBzDa2+0K2nY9YWacdvQfILYv03PVgBmI00Ln+qxKTuJU8soKwcQNcka3rIhTDX1xtbxXZXG5W8omWd3hR6cG8V3PGRbolPdz9qaJuaV52TxzAx9ncUVmHg== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3157.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(366004)(346002)(396003)(376002)(39860400002)(6512007)(9686003)(44832011)(6916009)(2906002)(52116002)(54906003)(6486002)(316002)(4326008)(478600001)(956004)(33964004)(5660300002)(83380400001)(33656002)(186003)(16526019)(26005)(86362001)(8676002)(66616009)(8936002)(66946007)(66556008)(66476007)(235185007)(52536014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: H4n/KK1LLBYpsuG18ujKFK8KWclQNS57jHDHdpoJ4UcbZUXsLnta4yYO5KZfkalweWJDwUNH3vu0etiww32rMMQsYfuLulQg7H6bR8Pk0TkFE7Vu7k+z7UBqr4Vw4WXlC3cEBkxpppjde62xxj8Plw6TAsExEA3P7f3Brnq3nJMyEIzzS7SsUosakfyZDzB5hZBmvzaV5ugZPT7lg3C4jW8zShFyMcQD2wuTPFxRELRRpCJeRJcpdmPxDoc69EQtXNvJ/hpqZNbElVX7MwaScJeeki8hgdH8GXq/hJ8yPvA/ZkCDzkMPc1BKpCxUIZ/nf4BJgEIQICgc2ZXZ61KxQvnginVkQzIJBUBD1QLtKIFmKVE5qfzJoeVpH0noawEWZyJ0A2zH9eyNhbGBlzFEKOzGQi6p4PKKbR3wbr6HaClrIAW+ucy7cO7mh2Hx/RQ7v4hnSN6QYecTg89mOYmYLfYr4i0P4d1BLSKbjjWBZjgRW6ddKx6gtmgc6Rqik1fnhoGSEAJvjG2sG3boiiuaD3P4bwMx4XJtmfXYfImvVcO2Byeg6ydfFh7a0e/IhoUewvnDem2el0GMH26MB2g3IJOz+YWWackd20wQdvHXj/tCy2vrWdgMttQbVjwBiJLWVm+4ZrFVNT0L1SwnvEnxfjNdm3nPbQrVjKrOZ+BQfi9Qhfgih/4Du0yH96ettRGe/8cEOK0BctTn8H+sM3jZgadeKp4exxK96+KonJrMJyyEqdtv42bJGK6wXQVEgPCPPwxEsDOndaagTSvZ1LyxTE6DUAMcZ2A11NbsayWbMTIu6vdKD3l73ssk7Q7oD13SACNn0PzakmnFu8005iBVrrLsj3KkbDqfr8aqxgwrzuhMY29gPZvppRMJi6bC9FUlFnUF4hoOn3YCHV2X1WTMo4B8NdUlH2haoaPRTc4nBJRA0ZG4ko4cjnma703FdHVYSNxGzS7sqnxcSJDP4MiNdnWWPIwYnUGCiBmnBcYq4Vat2nw/z+wrJ+SNrP68FyhZ X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2612 Original-Authentication-Results: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT022.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 8f2b0d34-79d8-434e-7410-08d89304c0db X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bjKj2AoE1avukDKzfk+3zr6lFHKKNl8vH8XI85r9aCP89XW3FJtfbzx0KLT3UjARGDGIfKLM6dKWj1QYDF5QAwgSRII+dP9NxN9YmGCh5dRjgK5omyxaNaUQiogYEYZWIFzgZ4RTECNga38Dn/P+UytpSVzK2XFvQ/k8DXTNUNolACF25H+zgmJIYaFjMy9w/KhNTsNINhLF4p13MM/bpQBIiQesz/lPqWMNF1vn10e7BFfzES2u2ypQ4x5DJU6GT6KkQbpicwk4G14OuULAa28uQDdd14GcygW3xMpNH7Z3nqbGrpN68bw6oatC+w1SYnpM51n+B6dkjObQ2pSegb25ImBgMMoDHlxfrj2V2e46jiHC1v9laZv4n0RHAmQ3yK66BUDY4xkhZXPuNosjKQ== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(376002)(346002)(136003)(396003)(39860400002)(46966005)(8936002)(36906005)(66616009)(6486002)(478600001)(8676002)(44832011)(47076004)(26005)(70586007)(186003)(54906003)(33964004)(356005)(4326008)(83380400001)(6512007)(2906002)(9686003)(6916009)(81166007)(70206006)(336012)(16526019)(82310400003)(316002)(86362001)(33656002)(82740400003)(52536014)(235185007)(956004)(5660300002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2020 18:46:48.2032 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 82f0ea05-6b4b-45db-228c-08d89304cbe2 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT022.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3574 X-Spam-Status: No, score=-15.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Matthew Malcomson via Gcc-patches From: Matthew Malcomson Reply-To: Matthew Malcomson Cc: Richard Sandiford Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hello, ----- This test should ensure that we can compile with hwasan, that such a compiled binary runs as expected, *and* that we're running on a kernel which implements the capability to ignore the top bytes of pointers in syscalls. It was expected that a basic test of `int main(void) { return 0; }` would check this, since there is a check called during `__hwasan_init` in libhwasan to ensure that the kernel we're running on provides a `prctl` to request the relaxed ABI. Unfortunately, the check in libhwasan has a bug in it, and does not correctly fail when the kernel feature is not around. This means that check is not automatically provided by the runtime. The sanitizer runtime will be fixed but would like to install this fix here in case fixing the library is not quick enough for the release (and so that people running the testsuite do not see spurious errors in the meantime). Tested by running testsuite on an AArch64 machine with and without the required kernel. Observed that the test does indeed fail when the kernel feature is unavailable and pass when the feature is available. Note that this test is directly targetting AArch64 by using `prctl` numbers specific to it. That's unfortunate, but once the runtime fix has gone in we will be able to remove that requirement. Ok for trunk? gcc/testsuite/ChangeLog: * lib/hwasan-dg.exp (check_effective_target_hwaddress_exec): Fix check for correct kernel version. ############### Attachment also inlined for ease of reply ############### diff --git a/gcc/testsuite/lib/hwasan-dg.exp b/gcc/testsuite/lib/hwasan-dg.exp index 892f2bab43325e830b5d9243377c70e074cdfe40..bd2a011947f9d3384ee32ffa9996a49429256af2 100644 --- a/gcc/testsuite/lib/hwasan-dg.exp +++ b/gcc/testsuite/lib/hwasan-dg.exp @@ -41,7 +41,24 @@ proc check_effective_target_fsanitize_hwaddress {} { proc check_effective_target_hwaddress_exec {} { if ![check_runtime hwaddress_exec { - int main (void) { return 0; } + #ifdef __cplusplus + extern "C" { + #endif + extern int prctl(int, unsigned long, unsigned long, unsigned long, unsigned long); + #ifdef __cplusplus + } + #endif + int main (void) { + #define PR_SET_TAGGED_ADDR_CTRL 55 + #define PR_GET_TAGGED_ADDR_CTRL 56 + #define PR_TAGGED_ADDR_ENABLE (1UL << 0) + if (prctl (PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0) == -1) + return 1; + if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == -1 + || !prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0)) + return 1; + return 0; + } }] { return 0; } diff --git a/gcc/testsuite/lib/hwasan-dg.exp b/gcc/testsuite/lib/hwasan-dg.exp index 892f2bab43325e830b5d9243377c70e074cdfe40..bd2a011947f9d3384ee32ffa9996a49429256af2 100644 --- a/gcc/testsuite/lib/hwasan-dg.exp +++ b/gcc/testsuite/lib/hwasan-dg.exp @@ -41,7 +41,24 @@ proc check_effective_target_fsanitize_hwaddress {} { proc check_effective_target_hwaddress_exec {} { if ![check_runtime hwaddress_exec { - int main (void) { return 0; } + #ifdef __cplusplus + extern "C" { + #endif + extern int prctl(int, unsigned long, unsigned long, unsigned long, unsigned long); + #ifdef __cplusplus + } + #endif + int main (void) { + #define PR_SET_TAGGED_ADDR_CTRL 55 + #define PR_GET_TAGGED_ADDR_CTRL 56 + #define PR_TAGGED_ADDR_ENABLE (1UL << 0) + if (prctl (PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0) == -1) + return 1; + if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == -1 + || !prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0)) + return 1; + return 0; + } }] { return 0; }