From patchwork Wed Feb 19 15:04:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 1240741 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-519794-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=hotmail.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=qGZYhxLK; 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 48N1H06S45z9sRf for ; Thu, 20 Feb 2020 02:04:58 +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:subject:date:message-id:content-type:mime-version; q=dns; s= default; b=c6unhd8GS9mTtkX8dI3iZ+rAFS/Ivi87Pk5yP2GhwWl8IV99GAYLG v8YsHBYOHRxJ3+EIRtIbet6hNKc/dY/vfjn6mM09MIHvlwdurXg4DuT8enq5gTvl e+9VXxM1uQILei27Y7Fh8rmm31hY60sbfh/C187gMeVt4KrGCioALQ= 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:subject:date:message-id:content-type:mime-version; s= default; bh=H4gLh5exgDHeEhReHOGjkZmUbQk=; b=qGZYhxLKX5yDg6OFzh5r 8tV4nFVIzwfZpeJnTHb1IsA9x+74qc60U5NdUM1ib/fOv5pDQah03PICOzccwfU1 MRn2RKfe+26Mkcfos2MGz2gFBO2yqbZzNbT+bT1GX+kA58Cv0Z/uN5VlQCA0Ov/n K1WdYdMSfVYlxPb//i1Kclo= Received: (qmail 82247 invoked by alias); 19 Feb 2020 15:04:48 -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 82239 invoked by uid 89); 19 Feb 2020 15:04:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, 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=HTo:U*rguenther, HX-Languages-Length:1820, H*c:HHH X-HELO: EUR05-AM6-obe.outbound.protection.outlook.com Received: from mail-am6eur05olkn2101.outbound.protection.outlook.com (HELO EUR05-AM6-obe.outbound.protection.outlook.com) (40.92.91.101) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Feb 2020 15:04:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f0nvI4oNInw84HyqJJ0jQgzo5G0YbK2KgRdVjwphhnMKFE95vXiMMIonRWoeWH6tLLOuqwUDI/v6qapr7ZYrtLCTeYVGThkb9egYCosAPwPhcScHWnKxpUzheS7y2BBxLLFCI+DQdZ+4Wb9dvMOWQ+bPvPVt0Mc5ApKmeYXxeH0rW4iDSZAbEbk3r7mYMvbKIkl1D2LI2kaSNmxDPG64eumhEQXiiLfqKdLqkNMsW3Fbfej7/8Afe5shXPl5vk6bXCdge30SSnBFPwilIGpNj0i6IHBR3QKHS8qWepaolBnmnKLb1hx0Z//pEn6k9lfp61bRutm0Lo/TbIqshqxfhg== 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=CN1ASK4ZsVF/S29Z62sseDkZiDLVGqADamlgJoABWHM=; b=jlja1sa9CaTNJQCj6+zQ58lTMn9GQJYR4Ddzf7VlN5PMNuYnC/J+PwdCb7cu7cczN6Nn6k4QzuqRm02SExPp34ab5RDZIGcf2vyWOe2VvL0eQBb95cnucvfo46I9QbpCGw/Hla/5N+S3WvEESYqcp5mYKr1oZDNsIWXGmEfp62Mb0CD6vQNsAwDXNOEgOw6dx5rmEL/CsrycCbPRdDVKHBz4C48/VYH4lLgkr99ZXpB4qaHR0Wel7y0vkqt/EJ7fFWElX5y0N526sCzDv1t7MBf1x48tEVgqjn9UZ3PgQT2dvVrNBX9+igTbnxRJ8y5crliPLx8uHAs7uqYrq6LyHw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from VI1EUR05FT068.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc12::35) by VI1EUR05HT183.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc12::135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.22; Wed, 19 Feb 2020 15:04:43 +0000 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com (10.233.242.53) by VI1EUR05FT068.mail.protection.outlook.com (10.233.242.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.22 via Frontend Transport; Wed, 19 Feb 2020 15:04:43 +0000 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::1956:d274:cab3:b4dd]) by AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::1956:d274:cab3:b4dd%6]) with mapi id 15.20.2729.032; Wed, 19 Feb 2020 15:04:43 +0000 Received: from [192.168.1.101] (92.77.140.102) by ZRAP278CA0013.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:10::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.17 via Frontend Transport; Wed, 19 Feb 2020 15:04:42 +0000 From: Bernd Edlinger To: "gcc-patches@gcc.gnu.org" , Richard Biener , Jakub Jelinek Subject: [PATCH] Avoid collect2 calling signal unsafe functions and/or unlink, with uninitialized memory (for gcc-8 branch) Date: Wed, 19 Feb 2020 15:04:43 +0000 Message-ID: x-microsoft-original-message-id: <9c2a3b9d-2752-fb09-cace-dc3a1e0c524f@hotmail.de> x-ms-exchange-antispam-messagedata: tsrAhMUeP7UwTAbHj+vrAL2AwS4vHyySwPnecxSFI0Donmq7i3X+E8mYyoD1J0KCkLYfd+Y1t0dgmNfwOW/tI6qnvIjl/n1ycFKGMZSyPjYgfm5tTR3iG7PGrOsZzDGN/QHg0CGInTJ5tbdCQG8eWQ== x-ms-exchange-transport-forked: True MIME-Version: 1.0 Hi, this fixes the signal handler calling signal unsafe vfprintf and/or passing uninitialized memory to unlink in signal handler. This is the patch for the gcc-8 branch. Bootstrapped and reg-tested with x86_64-pc-linux-gnu. Is it OK for the gcc-8 branch? Thanks Bernd. From dd98fe7c45c5096dfab9425dce6e0f88f5ccdcbe Mon Sep 17 00:00:00 2001 From: Bernd Edlinger Date: Mon, 17 Feb 2020 17:40:07 +0100 Subject: [PATCH] Avoid collect2 calling signal unsafe functions and/or unlink with uninitialized memory 2020-02-19 Bernd Edlinger * collect2.c (tool_cleanup): Avoid calling not signal-safe functions. (maybe_run_lto_and_relink): Avoid possible signal handler access to unintialzed memory (lto_o_files). --- gcc/collect2.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gcc/collect2.c b/gcc/collect2.c index a96af13..11e3a39 100644 --- a/gcc/collect2.c +++ b/gcc/collect2.c @@ -382,6 +382,10 @@ static void scan_prog_file (const char *, scanpass, scanfilter); void tool_cleanup (bool from_signal) { + /* maybe_unlink may call notice, which is not signal safe. */ + if (from_signal) + debug = false; + if (c_file != 0 && c_file[0]) maybe_unlink (c_file); @@ -741,7 +745,10 @@ maybe_run_lto_and_relink (char **lto_ld_argv, char **object_lst, ++num_files; } - lto_o_files = XNEWVEC (char *, num_files + 1); + /* signal handler may access uninitialized memory + and delete whatever it points to, if lto_o_files + is not allocatted with calloc. */ + lto_o_files = XCNEWVEC (char *, num_files + 1); lto_o_files[num_files] = NULL; start = XOBFINISH (&temporary_obstack, char *); for (i = 0; i < num_files; ++i) -- 1.9.1