public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH RFA] asan: poisoning promoted statics [PR113531]
Date: Wed, 31 Jan 2024 09:51:05 +0100	[thread overview]
Message-ID: <CAFiYyc2eJpsnEJOYoYSteE9jYN=Y6eWi6FhA+fU++Hx2TY25Ng@mail.gmail.com> (raw)
In-Reply-To: <20240131033759.2236614-1-jason@redhat.com>

On Wed, Jan 31, 2024 at 4:38 AM Jason Merrill <jason@redhat.com> wrote:
>
> Tested x86_64-pc-linux-gnu, OK for trunk?

It's a quite "late" fixup, I suppose you have tried to avoid marking it
during gimplification?  I see we do parts of this during BIND_EXPR
processing which is indeed a bit early but possibly difficult to rectify.

So, OK if you think fixing during gimplification is overly messy.

Richard.

> -- 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
>
> 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 <initializer_list>
> +
> +void f(int) { }
> +
> +void g()
> +{
> +  for (auto i : { 1, 2, 3 })
> +    f (i);
> +  f(42);
> +}
> +
> +int main()
> +{
> +  g();
> +  g();
> +}
>
> base-commit: 209fc1e5f6c67e55e579b69f617b0b678b1bfdf0
> --
> 2.39.3
>

  reply	other threads:[~2024-01-31  8:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-31  3:37 Jason Merrill
2024-01-31  8:51 ` Richard Biener [this message]
2024-01-31  9:07   ` Jakub Jelinek
2024-01-31 11:18     ` [PATCH] gimple-fold: Remove .ASAN_MARK calls on TREE_STATIC variables [PR113531] Jakub Jelinek
2024-01-31 12:04       ` Richard Biener
2024-01-31 15:20         ` [PATCH] gimple-low: " Jakub Jelinek
2024-01-31 17:57           ` Richard Biener
2024-01-31 13:45   ` [PATCH RFA] asan: poisoning promoted statics [PR113531] Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFiYyc2eJpsnEJOYoYSteE9jYN=Y6eWi6FhA+fU++Hx2TY25Ng@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).