public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/108777] New: Add support for --param asan-kernel-mem-intrinsic-prefix=1
@ 2023-02-13 16:43 jakub at gcc dot gnu.org
  2023-02-13 16:57 ` [Bug sanitizer/108777] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-13 16:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108777
           Summary: Add support for --param
                    asan-kernel-mem-intrinsic-prefix=1
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org
  Target Milestone: ---

As mentioned in the https://lkml.org/lkml/2023/2/9/1182 thread, Linux kernel
would like
to have --param asan-kernel-mem-intrinsic-prefix=1 support which would use
__asan_memcpy, __asan_memmove and __asan_memset with -fsanitize=kernel-address
and
__hwasan_memcpy, __hwasan_memmove and __hwasan_memset with
-fsanitize=kernel-hwaddress
instead of memcpy, memmove and memset calls in kasan instrumented functions,
such that
kernel memcpy/memmove/memset could remain uninstrumented for use in kernel
functions
with no_sanitize ("kernel-address").

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug sanitizer/108777] Add support for --param asan-kernel-mem-intrinsic-prefix=1
  2023-02-13 16:43 [Bug sanitizer/108777] New: Add support for --param asan-kernel-mem-intrinsic-prefix=1 jakub at gcc dot gnu.org
@ 2023-02-13 16:57 ` jakub at gcc dot gnu.org
  2023-02-13 16:59 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-13 16:57 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-02-13
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 54456
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54456&action=edit
gcc13-pr108777.patch

Untested implementation.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug sanitizer/108777] Add support for --param asan-kernel-mem-intrinsic-prefix=1
  2023-02-13 16:43 [Bug sanitizer/108777] New: Add support for --param asan-kernel-mem-intrinsic-prefix=1 jakub at gcc dot gnu.org
  2023-02-13 16:57 ` [Bug sanitizer/108777] " jakub at gcc dot gnu.org
@ 2023-02-13 16:59 ` jakub at gcc dot gnu.org
  2023-02-13 19:57 ` elver at google dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-13 16:59 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |elver at google dot com

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Marco, is this what you are looking for?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug sanitizer/108777] Add support for --param asan-kernel-mem-intrinsic-prefix=1
  2023-02-13 16:43 [Bug sanitizer/108777] New: Add support for --param asan-kernel-mem-intrinsic-prefix=1 jakub at gcc dot gnu.org
  2023-02-13 16:57 ` [Bug sanitizer/108777] " jakub at gcc dot gnu.org
  2023-02-13 16:59 ` jakub at gcc dot gnu.org
@ 2023-02-13 19:57 ` elver at google dot com
  2023-02-13 21:18 ` fw at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: elver at google dot com @ 2023-02-13 19:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Marco Elver <elver at google dot com> ---
(In reply to Jakub Jelinek from comment #2)
> Marco, is this what you are looking for?

Yes, looks good - the tests verify the behaviour I'd expect. Thanks!

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug sanitizer/108777] Add support for --param asan-kernel-mem-intrinsic-prefix=1
  2023-02-13 16:43 [Bug sanitizer/108777] New: Add support for --param asan-kernel-mem-intrinsic-prefix=1 jakub at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-02-13 19:57 ` elver at google dot com
@ 2023-02-13 21:18 ` fw at gcc dot gnu.org
  2023-02-13 21:32 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: fw at gcc dot gnu.org @ 2023-02-13 21:18 UTC (permalink / raw)
  To: gcc-bugs

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

Florian Weimer <fw at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fw at gcc dot gnu.org

--- Comment #4 from Florian Weimer <fw at gcc dot gnu.org> ---
Shouldn't this be an -f switch if it's an official compiler feature?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug sanitizer/108777] Add support for --param asan-kernel-mem-intrinsic-prefix=1
  2023-02-13 16:43 [Bug sanitizer/108777] New: Add support for --param asan-kernel-mem-intrinsic-prefix=1 jakub at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-02-13 21:18 ` fw at gcc dot gnu.org
@ 2023-02-13 21:32 ` jakub at gcc dot gnu.org
  2023-02-14 11:10 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-13 21:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
It is a similar tweak like many other asan tweaks which use params rather than
switches.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug sanitizer/108777] Add support for --param asan-kernel-mem-intrinsic-prefix=1
  2023-02-13 16:43 [Bug sanitizer/108777] New: Add support for --param asan-kernel-mem-intrinsic-prefix=1 jakub at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-02-13 21:32 ` jakub at gcc dot gnu.org
@ 2023-02-14 11:10 ` cvs-commit at gcc dot gnu.org
  2023-02-14 11:11 ` jakub at gcc dot gnu.org
  2023-02-14 11:12 ` elver at google dot com
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-14 11:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:91b36d1c85ae3ad667d11c1ceeffc698126ab804

commit r13-5982-g91b36d1c85ae3ad667d11c1ceeffc698126ab804
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Feb 14 12:10:09 2023 +0100

    asan: Add --param=asan-kernel-mem-intrinsic-prefix= [PR108777]

    While in the -fsanitize=address case libasan overloads memcpy, memset,
    memmove and many other builtins, such that they are always instrumented,
    Linux kernel for -fsanitize=kernel-address recently changed or is changing,
    such that memcpy, memset and memmove actually aren't instrumented because
    they are often used also from no_sanitize ("kernel-address") functions
    and wants __{,hw,}asaN_{memcpy,memset,memmove} to be used instead
    for the instrumented calls.  See e.g. the
https://lkml.org/lkml/2023/2/9/1182
    thread.  Without appropriate support on the compiler side, that will mean
    any time a kernel-address instrumented function (most of them) calls
    memcpy/memset/memmove, they will not be instrumented and thus won't catch
    kernel bugs.  Apparently clang 15 has a param for this.

    The following patch implements the same (except it is a usual GCC --param,
    not -mllvm argument) on the GCC side.  I know this isn't a regression
    bugfix, but given that -fsanitize=kernel-address has a single project that
    uses it which badly wants this I think it would be worthwhile to make an
    exception and get this into GCC 13 rather than waiting another year, it
    won't affect non-kernel code, nor even the kernel unless the new parameter
    is used.

    2023-02-14  Jakub Jelinek  <jakub@redhat.com>

            PR sanitizer/108777
            * params.opt (-param=asan-kernel-mem-intrinsic-prefix=): New param.
            * asan.h (asan_memfn_rtl): Declare.
            * asan.cc (asan_memfn_rtls): New variable.
            (asan_memfn_rtl): New function.
            * builtins.cc (expand_builtin): If
            param_asan_kernel_mem_intrinsic_prefix and function is
            kernel-{,hw}address sanitized, emit calls to
            __{,hw}asan_{memcpy,memmove,memset} rather than
            {memcpy,memmove,memset}.  Use sanitize_flags_p (SANITIZE_ADDRESS)
            instead of flag_sanitize & SANITIZE_ADDRESS to check if
            asan_intercepted_p functions shouldn't be expanded inline.

            * gcc.dg/asan/pr108777-1.c: New test.
            * gcc.dg/asan/pr108777-2.c: New test.
            * gcc.dg/asan/pr108777-3.c: New test.
            * gcc.dg/asan/pr108777-4.c: New test.
            * gcc.dg/asan/pr108777-5.c: New test.
            * gcc.dg/asan/pr108777-6.c: New test.
            * gcc.dg/completion-3.c: Adjust expected multiline output.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug sanitizer/108777] Add support for --param asan-kernel-mem-intrinsic-prefix=1
  2023-02-13 16:43 [Bug sanitizer/108777] New: Add support for --param asan-kernel-mem-intrinsic-prefix=1 jakub at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-02-14 11:10 ` cvs-commit at gcc dot gnu.org
@ 2023-02-14 11:11 ` jakub at gcc dot gnu.org
  2023-02-14 11:12 ` elver at google dot com
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-14 11:11 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Implemented for GCC 13.1 (to be released in April/May this year).

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug sanitizer/108777] Add support for --param asan-kernel-mem-intrinsic-prefix=1
  2023-02-13 16:43 [Bug sanitizer/108777] New: Add support for --param asan-kernel-mem-intrinsic-prefix=1 jakub at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-02-14 11:11 ` jakub at gcc dot gnu.org
@ 2023-02-14 11:12 ` elver at google dot com
  7 siblings, 0 replies; 9+ messages in thread
From: elver at google dot com @ 2023-02-14 11:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Marco Elver <elver at google dot com> ---
Thanks for the quick turnaround!

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-02-14 11:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-13 16:43 [Bug sanitizer/108777] New: Add support for --param asan-kernel-mem-intrinsic-prefix=1 jakub at gcc dot gnu.org
2023-02-13 16:57 ` [Bug sanitizer/108777] " jakub at gcc dot gnu.org
2023-02-13 16:59 ` jakub at gcc dot gnu.org
2023-02-13 19:57 ` elver at google dot com
2023-02-13 21:18 ` fw at gcc dot gnu.org
2023-02-13 21:32 ` jakub at gcc dot gnu.org
2023-02-14 11:10 ` cvs-commit at gcc dot gnu.org
2023-02-14 11:11 ` jakub at gcc dot gnu.org
2023-02-14 11:12 ` elver at google dot com

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).