From patchwork Tue Nov 5 11:33:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Malcomson X-Patchwork-Id: 1189598 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-512431-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="Kv7H8osv"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="6/C+Z/cQ"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="6/C+Z/cQ"; 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 476nd03fGHz9sNT for ; Tue, 5 Nov 2019 22:34:28 +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=iCQIsa/mEXenB+o9 Y3MdFXXh0/34LeRkJGgAnwbiY37Gu1S1UZ/Nm37dQwILIibmj5PwwGBAGegjNkm+ 08jEuV0Z7fDn9UkAhwSHMob1ssjIbdCwmoltO5A4KNyAa5CdG/IpBE58w5YC0qXA dE4VFLP8kMcnxV1I4bhk4h+yIig= 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=ESTxSBvt6RROk09l9ghCjM SyT+s=; b=Kv7H8osvXLft8NyYB+otmPVeanv8u4jeUfrMbFVmuzaP4t2H99R0uD 8YoLY9VUTL5Hz0kyACxher1TBINWhwWzpuzL5AzWL6gpTBv+04gfbqVGjH1bxhWZ PpUQaJKgUKFdkl8aaE3I2I3gBHNlrWSC3Pg1SJMHZFLzJqkh8Nl3Q= Received: (qmail 82926 invoked by alias); 5 Nov 2019 11:34:07 -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 82844 invoked by uid 89); 5 Nov 2019 11:34:07 -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, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: EUR01-HE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr130070.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) (40.107.13.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Nov 2019 11:34:04 +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=OSXfjZlsqQKAOPa14O+l8SNnVzv8C89cUHud/i9Dam8=; b=6/C+Z/cQHoDoA9ueNZyvLg6Dn3UBaX89sRERv+8TKm7cAH8gl1SwawpyIlYYUvenB3XaL02IQnOdbRx8LHm98+JeeGQ8lImoWB6UmE+GSyCJ8xqjSnMp02H+2tqnwkdCpEhWXRFm/dKNaBm3Id4LnoPtMsVqgAx+TyZ5yBvGVA0= Received: from DB6PR0801CA0051.eurprd08.prod.outlook.com (2603:10a6:4:2b::19) by DB8PR08MB5243.eurprd08.prod.outlook.com (2603:10a6:10:bf::32) 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:01 +0000 Received: from DB5EUR03FT009.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::205) by DB6PR0801CA0051.outlook.office365.com (2603:10a6:4:2b::19) 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:01 +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 DB5EUR03FT009.mail.protection.outlook.com (10.152.20.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:01 +0000 Received: ("Tessian outbound 851a1162fca7:v33"); Tue, 05 Nov 2019 11:34:01 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c8a87d086aaad5b7 X-CR-MTA-TID: 64aa7808 Received: from 498950ac46c9.2 (cr-mta-lb-1.cr-mta-net [104.47.14.52]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id 0459E6DB-48F3-4CF1-8B29-9E3AF38AAF85.1; Tue, 05 Nov 2019 11:33:55 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04lp2052.outbound.protection.outlook.com [104.47.14.52]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 498950ac46c9.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 05 Nov 2019 11:33:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EAZIzxYlbBcW6W9VTc8Z3fFIeLDKeCY+vWOrFLhoAJF3ULTArK0l/okveSRuxqVdQgxOW7YVRs4tbv2/FAtdxE3B33tppZ2+iqGt6vRR5l8mX4tqJHXqgR0txr+9OBUzyEhFBdgU629UEnxU5azlD6nPALGV8TPAkFuqDgmLDdqtXLC5Kc5Nf/pCO2gLfGXGlqIt8jVdv3rLDpIX2RbpxVskXGnhigo9Jmn6YzgtMTPjnQs0JWpiSOG0TDn7cyG9FXCWBtqX4HLwLPIvkzIuZzXHvN9KH5ztHgi9DgnVqzuf3UniJnYwqiD/M+9z9DeRepbD6j2BouFMjnZZ+qi3Tw== 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=OSXfjZlsqQKAOPa14O+l8SNnVzv8C89cUHud/i9Dam8=; b=LFlH74Ssh4lnFJuO9g08XLr4euiumoH69WYgFm++UEPxzZhFoE/tOEkgmw1pniGXvwLlNmF6F91xhOdAu7DNbRKIBqv4xAIn6CtrEEYGCFE2GOqNxeUpdcYOVTBeWx2c04DMyGRupXy8VYGVT1D+x0kGAWnwg5FJn8wCRMcfv0yKXxJgSwzvn0WWPP9lNaKKiavNFddxnkpnrsFKGx7GSwUYyr9a1Di22CcJtpcRwmjOjdodMD0YgUG5grvPSVGq8E7lvCWfn+8IJM1hYJ4Vqv0l31EwKJFBloiw6WHvYn4fjDNe6l12XKFA13CToicgmy3QcmMvyJbmLDDkCavFnw== 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=OSXfjZlsqQKAOPa14O+l8SNnVzv8C89cUHud/i9Dam8=; b=6/C+Z/cQHoDoA9ueNZyvLg6Dn3UBaX89sRERv+8TKm7cAH8gl1SwawpyIlYYUvenB3XaL02IQnOdbRx8LHm98+JeeGQ8lImoWB6UmE+GSyCJ8xqjSnMp02H+2tqnwkdCpEhWXRFm/dKNaBm3Id4LnoPtMsVqgAx+TyZ5yBvGVA0= 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:33:54 +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:33:53 +0000 From: Matthew Malcomson To: "gcc-patches@gcc.gnu.org" CC: nd , "rguenther@suse.de" , James Greenhalgh , Martin Liska , Richard Earnshaw , Kyrylo Tkachov , Marcus Shawcroft Subject: [aarch64] Allocate enough space for err_str in aarch64_handle_attr_branch_protection Date: Tue, 5 Nov 2019 11:33:53 +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:5516;OLM:5516; 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)(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: RDleM0hIq7EY4Zb2yjSNqV4UpD3Iu0Nkok0izVUuCC8PTjD9bPDTUGtUFcHLFDmGk5pdsTVSpV+NVPKhOjdcFm99RegqY7YzPj7cYg04xgFHpeIWVjK/ymoz0uSRfS2ghaYd0xPdt4JbB+McNjweYaMOlVMig4ezsl6b/fkE1IwGj+oANXt2GVuU9b3wX1pCk5ZSt71xbsQcUtHqofcxcc1G2RF3hJRxUh9XwAGJQR7KCaTjjBKrIZ+yXpyhAcyQC1LqHxUZHXQhV2uI0uEs2oY4RNodBVICZaLo4SrjXC2nMDvJu7kO1ic0ODO3hI9HPE1TO2UTWN+7ussWTlemigVpAymtHkasZYQTmEQ4hZZp1UGJxM+OGVlvFkiKwavW/XiZlv0gqIa3igfy6zK1cYiz2CynPDKH5xwRVidHcj1cDP+yPdyCKvKaL2KUEsSp MIME-Version: 1.0 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Matthew.Malcomson@arm.com; X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: c302e874-4770-4986-e9f8-08d761e40985 X-IsSubscribed: yes -fsanitize=hwaddress found a one-byte overwrite when running the testsuite here. aarch64_handle_attr_branch_protection allocates `strlen(str)` bytes for an error string, which is populated by `strcpy(..., str)` in the case where the branch protection string is completely invalid. Tested on aarch64 with hwasan (though not a full bootstrap since it's obvious). gcc/ChangeLog: 2019-11-05 Matthew Malcomson * config/aarch64/aarch64.c (aarch64_handle_attr_cpu): Allocate enough bytes for the NULL character. ############### Attachment also inlined for ease of reply ############### diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 232317d4a5a4a16529f573eef5a8d7a068068207..fc03faa8f8d459a84024d4394fff375b72d31264 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -13298,7 +13298,7 @@ aarch64_handle_attr_cpu (const char *str) static bool aarch64_handle_attr_branch_protection (const char* str) { - char *err_str = (char *) xmalloc (strlen (str)); + char *err_str = (char *) xmalloc (strlen (str) + 1); enum aarch64_parse_opt_result res = aarch64_parse_branch_protection (str, &err_str); bool success = false; diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 232317d4a5a4a16529f573eef5a8d7a068068207..fc03faa8f8d459a84024d4394fff375b72d31264 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -13298,7 +13298,7 @@ aarch64_handle_attr_cpu (const char *str) static bool aarch64_handle_attr_branch_protection (const char* str) { - char *err_str = (char *) xmalloc (strlen (str)); + char *err_str = (char *) xmalloc (strlen (str) + 1); enum aarch64_parse_opt_result res = aarch64_parse_branch_protection (str, &err_str); bool success = false;