public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ubizjak at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/111736] Address sanitizer is not compatible with named address spaces
Date: Thu, 21 Mar 2024 09:18:26 +0000	[thread overview]
Message-ID: <bug-111736-4-MqMo8UcNEk@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-111736-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111736

--- Comment #19 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Uroš Bizjak from comment #16)
> (In reply to Richard Biener from comment #13)
> > The original testcase is fixed, appearantly slapping 'extern' on the int
> > makes it not effective.
> > 
> > Possibly better amend the
> > 
> >   if (VAR_P (inner) && DECL_HARD_REGISTER (inner))
> >     return;
> > 
> > check though.  As indicated my fix fixed only VAR_DECL cases, there's
> > still pointer-based accesses (MEM_REF) to consider.  So possibly even
> > the following is necessary
> 
> I must admit that to create the patch from Comment #11 I just mindlessly
> searched for DECL_THREAD_LOCAL_P in asan.cc and amended the location with
> ADDR_SPACE_GENERIC_P check.
> 
> However, ASAN should back off from annotating *any* gs: prefixed address. 
> 
> I'll test your patch from Comment #13 ASAP.

Weee, it works!

Decompressing Linux... Parsing ELF... Performing relocations... done.
Booting the kernel (entry_offset: 0x0000000000000000).
[    0.000000] Linux version 6.8.0-11485-ge1826833c3a9 (uros@localhost) (xgcc
(GCC) 14.0.1 20240321 (experimental) [master r14-9588-g415091f0909], GNU ld
version 2.40-14.fc39) #1 SMP PREEMPT_DYNAMIC Thu Mar 21 09:44:30 CET 2024
...

I have used slightly different patch:

--cut here--
diff --git a/gcc/asan.cc b/gcc/asan.cc
index cfe83106460..026d079a4a1 100644
--- a/gcc/asan.cc
+++ b/gcc/asan.cc
@@ -2755,6 +2755,9 @@ instrument_derefs (gimple_stmt_iterator *iter, tree t,
   if (VAR_P (inner) && DECL_HARD_REGISTER (inner))
     return;

+  if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (inner))))
+    return;
+
   poly_int64 decl_size;
   if ((VAR_P (inner)
        || (TREE_CODE (inner) == RESULT_DECL
--cut here--

Hard registers and named address spaces really have nothing in common.

IMO, the fixes here should be applied to all release branches. Running KASAN
sanitized kernel with the named AS is the ultimate test for this PR.

  parent reply	other threads:[~2024-03-21  9:18 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-09 11:53 [Bug sanitizer/111736] New: " ubizjak at gmail dot com
2023-10-09 12:31 ` [Bug sanitizer/111736] " rguenth at gcc dot gnu.org
2023-10-09 13:27 ` amonakov at gcc dot gnu.org
2023-10-09 16:27 ` amonakov at gcc dot gnu.org
2023-12-05 13:05 ` rguenth at gcc dot gnu.org
2023-12-05 14:11 ` cvs-commit at gcc dot gnu.org
2023-12-05 14:12 ` rguenth at gcc dot gnu.org
2023-12-19  9:29 ` ubizjak at gmail dot com
2023-12-19 10:06 ` rguenth at gcc dot gnu.org
2023-12-19 11:04 ` cvs-commit at gcc dot gnu.org
2023-12-29  9:42 ` ubizjak at gmail dot com
2024-03-20 20:04 ` ubizjak at gmail dot com
2024-03-20 21:45 ` ubizjak at gmail dot com
2024-03-21  6:44 ` ubizjak at gmail dot com
2024-03-21  7:24 ` rguenth at gcc dot gnu.org
2024-03-21  7:26 ` rguenth at gcc dot gnu.org
2024-03-21  7:45 ` rguenth at gcc dot gnu.org
2024-03-21  8:04 ` ubizjak at gmail dot com
2024-03-21  8:35 ` rguenther at suse dot de
2024-03-21  8:46 ` jakub at gcc dot gnu.org
2024-03-21  9:18 ` ubizjak at gmail dot com [this message]
2024-03-21  9:26 ` jakub at gcc dot gnu.org
2024-03-21  9:41 ` jakub at gcc dot gnu.org
2024-03-21  9:49 ` cvs-commit at gcc dot gnu.org
2024-03-21 11:49 ` cvs-commit at gcc dot gnu.org
2024-03-21 12:56 ` jakub at gcc dot gnu.org
2024-03-22  8:25 ` cvs-commit at gcc dot gnu.org
2024-03-25  9:13 ` ubizjak at gmail dot com
2024-03-25  9:31 ` jakub at gcc dot gnu.org
2024-03-25  9:45 ` jakub at gcc dot gnu.org
2024-03-25 10:20 ` ubizjak at gmail dot com
2024-03-26 10:13 ` cvs-commit at gcc dot gnu.org
2024-03-30  3:55 ` cvs-commit at gcc dot gnu.org
2024-03-30  3:55 ` cvs-commit at gcc dot gnu.org
2024-04-23 17:09 ` cvs-commit at gcc dot gnu.org
2024-04-23 17:09 ` cvs-commit at gcc dot gnu.org
2024-04-23 17:09 ` cvs-commit at gcc dot gnu.org
2024-04-23 17:09 ` cvs-commit at gcc dot gnu.org
2024-04-24 14:39 ` cvs-commit at gcc dot gnu.org
2024-04-24 14:39 ` cvs-commit at gcc dot gnu.org
2024-04-24 14:39 ` cvs-commit at gcc dot gnu.org
2024-04-24 14:40 ` cvs-commit at gcc dot gnu.org
2024-04-24 14:41 ` ubizjak at gmail dot com
2024-05-20 19:53 ` pchelkin at ispras dot ru
2024-05-20 19:56 ` pchelkin at ispras dot ru
2024-05-20 19:57 ` pchelkin at ispras dot ru
2024-05-21  8:19 ` ubizjak at gmail dot com
2024-05-21  9:01 ` ubizjak at gmail dot com
2024-05-21  9:03 ` ubizjak at gmail dot com
2024-05-21  9:18 ` rguenth at gcc dot gnu.org
2024-05-21  9:20 ` ubizjak at gmail dot com
2024-05-21  9:55 ` ubizjak at gmail dot com

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=bug-111736-4-MqMo8UcNEk@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).