From patchwork Wed Jan 31 03:37:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1893203 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fjHI4ptQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TPnnL2vRcz23g7 for ; Wed, 31 Jan 2024 14:38:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 37F963858281 for ; Wed, 31 Jan 2024 03:38:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 464DA3858D1E for ; Wed, 31 Jan 2024 03:38:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 464DA3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 464DA3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706672289; cv=none; b=dQNGBaScz9i8ZcwUiFltxO+alYGKcm7Np0YpiprCCSYSxcqEJ1norAL/hdeNTHpCqDZF2v+k1UCgiBTg9RGobFyNdn+QRB6ayFJqgM0pUdObOwwT6i1kMW7ZFWjlOBX5oi8ufWNt4+g7ZTFsvp0DA9K9Z5jQW/qzDVXzuadl6bg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706672289; c=relaxed/simple; bh=TRiensm6KEOzEGjk0c76ts2MdVmx2ZdR2vkBynMCmoQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=B56H7E4et7G7RpWDVZ3TLF5dnpsIaMKVzPqTuDappjzsxN0mJ0XSLeNNE6yyTDVKnnc47jLhsZaiMGE8ZIKz28Lk0AsKWUP2O82pf1HVAeR6ziW7DxXXZmmaGBx6Fs6UuTs1iGowHKoiCjkJafbHfLtStn6fdVUdsDdRk1ls3es= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706672287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8QwVqCroVVpzHekINVFxucqygBRAkl6d435o22lm3O0=; b=fjHI4ptQfeqQHu86GQMTwE5Fu4BoUXFys3ExaRGVjaIcCIJi6Y5UsKAcx+ce2zh4T+b9ri zkeGSd87Xw8WHkkLMRPVFaiwrfZlBuhKgufQ8reHi4pJZlH5JuHbq2YxT+UvRQcSUeBc4m hZoMSLnj7+H5i3Bs5LYoOBbZuSRG2us= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-253-Lquu8V9HNV-tn50qykOZXA-1; Tue, 30 Jan 2024 22:38:03 -0500 X-MC-Unique: Lquu8V9HNV-tn50qykOZXA-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7853c364e60so17397685a.2 for ; Tue, 30 Jan 2024 19:38:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706672283; x=1707277083; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8QwVqCroVVpzHekINVFxucqygBRAkl6d435o22lm3O0=; b=SAjCStKM+9cJPhqF4Eqm7KjQ2teQ2sYqjPZQHITyWw/pR2FlJ9ZuewuLaGKUC7CsKa /o7Qm+37sltrL7xz66b6wjANWneUYtQfHHuAKWEDc3HBdy5HDsCn8IYvhgabYalUR6Cb lit3dBxk7VshcQwgI4i1Iu981g9B0Bf1wL7NVfk3jyXNdDBI/ZADc4vXADokHJG6zUsO XwRNsaBtjit/bNnxCHM+/e2Keolg5mBoL4JAAv/bW+tNd1JDIc943chWUQN2gI81/Lgi eCHyVoxmFG2i2lkY5H+/LQbO4F08GaOu0LCBfyrBf8XXipR+CWO8xdjHl/uVZrDyfI6U RvpA== X-Gm-Message-State: AOJu0YxW1GQo24ZgTIEUw86cEQ98QIliSPCbZILwHFHWTH4QmqYPypXf nzlVATJDeIew8pwvIAjIqhAGGdaN5YANRfhPrOOADZ1dpZce873DbMCg9XOEPrmwbhmTP3i6Ov0 /Xd0GgK75cgG2jPNcbXoBevd9KEsv3G5fs3Gnq7xe8roszKbDqJSlBdrtJj/K+5wXQ5/+l99KxW wLDWLcSAUyx3+qA5IFSOopwoXjLxjcb/Z4VMg= X-Received: by 2002:a05:620a:558c:b0:783:fbc1:9c2a with SMTP id vq12-20020a05620a558c00b00783fbc19c2amr362129qkn.29.1706672282657; Tue, 30 Jan 2024 19:38:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQolCM3yYvARSfwiIHZSVEyMgpWfz5b1/s/jN8W6XBTRqHx+teIbq/Z9tI+lrXNdbVgRZJuw== X-Received: by 2002:a05:620a:558c:b0:783:fbc1:9c2a with SMTP id vq12-20020a05620a558c00b00783fbc19c2amr362107qkn.29.1706672282065; Tue, 30 Jan 2024 19:38:02 -0800 (PST) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id g25-20020a37e219000000b007836647671fsm2870353qki.89.2024.01.30.19.38.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 19:38:01 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [PATCH RFA] asan: poisoning promoted statics [PR113531] Date: Tue, 30 Jan 2024 22:37:59 -0500 Message-Id: <20240131033759.2236614-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, OK for trunk? -- 8< -- Since my r14-1500-g4d935f52b0d5c0 we promote an initializer_list backing array to static storage where appropriate, but this happens after we decided to add it to asan_poisoned_variables. As a result we add unpoison/poison for it to the gimple. But then sanopt removes the unpoison. So the second time we call the function and want to load from the array asan still considers it poisoned. A simple fix seems to be to not expand unpoison/poison for such a variable, since by that time we know it's static. PR c++/113531 gcc/ChangeLog: * asan.cc (asan_expand_mark_ifn): Check TREE_STATIC. gcc/testsuite/ChangeLog: * g++.dg/asan/initlist1.C: New test. --- gcc/asan.cc | 8 ++++++++ gcc/testsuite/g++.dg/asan/initlist1.C | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 gcc/testsuite/g++.dg/asan/initlist1.C base-commit: 209fc1e5f6c67e55e579b69f617b0b678b1bfdf0 diff --git a/gcc/asan.cc b/gcc/asan.cc index 0fd7dd1f3ed..efecac2ea2b 100644 --- a/gcc/asan.cc +++ b/gcc/asan.cc @@ -3762,6 +3762,14 @@ asan_expand_mark_ifn (gimple_stmt_iterator *iter) gcc_checking_assert (TREE_CODE (decl) == VAR_DECL); + if (TREE_STATIC (decl)) + { + /* Don't poison a variable with static storage; it might have gotten + marked before gimplify_init_constructor promoted it to static. */ + gsi_remove (iter, true); + return false; + } + if (hwasan_sanitize_p ()) { gcc_assert (param_hwasan_instrument_stack); diff --git a/gcc/testsuite/g++.dg/asan/initlist1.C b/gcc/testsuite/g++.dg/asan/initlist1.C new file mode 100644 index 00000000000..6cd5b7d3aba --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/initlist1.C @@ -0,0 +1,20 @@ +// PR c++/113531 +// { dg-do run { target c++11 } } +// { dg-additional-options "-fsanitize=address" } + +#include + +void f(int) { } + +void g() +{ + for (auto i : { 1, 2, 3 }) + f (i); + f(42); +} + +int main() +{ + g(); + g(); +}