From patchwork Tue Jul 4 07:47:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 783775 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3x1x1k2nTDz9s65 for ; Tue, 4 Jul 2017 17:47:54 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IQAUUMj4"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=p4iZlvHfX9bWM0J49 +2C6mIp6DocOphQcrq9JSB3k5b3HwKWbxGsrl6srJ/JqnFlKYd5V8U8Sza0Mt/kc g9VXPcQDUH4Xs6e/zyrbMITcVSAbj5eMEWYkk24fO8k6hpkc62a4GS60SXQwyANl lfqXpPmzBhOcrdZPsAgcPSsEW4= 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 :subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=W16Xk3SuuaQmL3SbrOc0bIV 4zo0=; b=IQAUUMj4GsAAcGDD0Rll9XNwyy5NXij1MCRHDHyHgDW7frFvun+dnJo 6bJhEUbIfZNLrRX+Zo+EYKc+Xq8raL0HaIPEAtyJFHVEA3LwjImec6yLYjEjuXGX Q1PBMMYLTRoEzJci+a4LvF6lkXP8t5OJRrpGPNkPkcgbUERiXOMg= Received: (qmail 80510 invoked by alias); 4 Jul 2017 07:47:42 -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 80413 invoked by uid 89); 4 Jul 2017 07:47:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Jul 2017 07:47:31 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id CD88FAD78; Tue, 4 Jul 2017 07:47:29 +0000 (UTC) Subject: [PATCH] Enable addressable params sanitization with --param asan-stack=1. To: Jakub Jelinek Cc: GCC Patches References: <20170619141340.GP2123@tucnak> <20170620093204.GF2123@tucnak> <20170629111737.GB2123@tucnak> <53a86396-fb7f-40c0-bd6a-334c377febf5@suse.cz> <20170630093059.GG2123@tucnak> From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Message-ID: <136220ee-a743-dc68-019a-7ae8abce8d12@suse.cz> Date: Tue, 4 Jul 2017 09:47:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20170630093059.GG2123@tucnak> X-IsSubscribed: yes Hello. As mentioned in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81040#c15, the sanitization is done only when one uses use-after-scope. That's caused by fact that I decorated the newly created auto variables with DECL_ARTIFICIAL = 1. Because of that static inline bool asan_protect_stack_decl (tree decl) { return DECL_P (decl) && (!DECL_ARTIFICIAL (decl) || (asan_sanitize_use_after_scope () && TREE_ADDRESSABLE (decl))); } returns false. I hope not marking the variable as DECL_ARTIFICIAL will work fine? Or am I missing something? Thanks, Martin From b79133e3c9ad41b44f0a12c574fc1d0b8348ad89 Mon Sep 17 00:00:00 2001 From: marxin Date: Tue, 4 Jul 2017 09:22:23 +0200 Subject: [PATCH] Enable addressable params sanitization with --param asan-stack=1. gcc/ChangeLog: 2017-07-04 Martin Liska PR sanitizer/81040 * sanopt.c (sanitize_rewrite_addressable_params): Do not decorate variable as DECL_ARTIFICIAL in order to sanitize it. gcc/testsuite/ChangeLog: 2017-07-04 Martin Liska PR sanitizer/81040 * g++.dg/asan/function-argument-1.C: Run the test-case w/o use-after-scope sanitization. --- gcc/sanopt.c | 1 - gcc/testsuite/g++.dg/asan/function-argument-1.C | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/sanopt.c b/gcc/sanopt.c index 7692f6a9db7..8c80ff37d4d 100644 --- a/gcc/sanopt.c +++ b/gcc/sanopt.c @@ -905,7 +905,6 @@ sanitize_rewrite_addressable_params (function *fun) tree var = build_decl (DECL_SOURCE_LOCATION (arg), VAR_DECL, DECL_NAME (arg), type); TREE_ADDRESSABLE (var) = 1; - DECL_ARTIFICIAL (var) = 1; gimple_add_tmp_var (var); diff --git a/gcc/testsuite/g++.dg/asan/function-argument-1.C b/gcc/testsuite/g++.dg/asan/function-argument-1.C index 148c4628316..bdbb37a44a4 100644 --- a/gcc/testsuite/g++.dg/asan/function-argument-1.C +++ b/gcc/testsuite/g++.dg/asan/function-argument-1.C @@ -1,5 +1,6 @@ // { dg-do run } // { dg-shouldfail "asan" } +// { dg-options "-fsanitize=address -fno-sanitize-address-use-after-scope" } struct A { -- 2.13.2