From: Alexander Popov <alex.popov@linux.com>
To: Kees Cook <keescook@chromium.org>
Cc: kernel-hardening@lists.openwall.com,
Catalin Marinas <catalin.marinas@arm.com>,
Masahiro Yamada <yamada.masahiro@socionext.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Will Deacon <will@kernel.org>,
Naohiro Aota <naohiro.aota@wdc.com>,
Sven Schnelle <svens@stackframe.org>,
Masahiro Yamada <masahiroy@kernel.org>,
x86@kernel.org, Emese Revfy <re.emese@gmail.com>,
Iurii Zaikin <yzaikin@google.com>,
PaX Team <pageexec@freemail.hu>,
Laura Abbott <labbott@redhat.com>,
Mathias Krause <minipli@googlemail.com>,
linux-kbuild@vger.kernel.org,
Alexander Monakov <amonakov@ispras.ru>,
Michal Marek <michal.lkml@markovi.net>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Collingbourne <pcc@google.com>,
linux-arm-kernel@lists.infradead.org, notify@kernel.org,
Florian Weimer <fweimer@redhat.com>,
gcc@gcc.gnu.org, Brad Spengler <spender@grsecurity.net>,
linux-kernel@vger.kernel.org,
Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>,
Luis Chamberlain <mcgrof@kernel.org>,
Jessica Yu <jeyu@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Thiago Jung Bauermann <bauerman@linux.ibm.com>
Subject: Re: [PATCH 2/5] gcc-plugins/stackleak: Use asm instrumentation to avoid useless register saving
Date: Wed, 10 Jun 2020 18:47:14 +0300 [thread overview]
Message-ID: <757cbafb-1e13-8989-e30d-33c557d33cc4@linux.com> (raw)
In-Reply-To: <202006091143.AD1A662@keescook>
On 09.06.2020 21:46, Kees Cook wrote:
> On Thu, Jun 04, 2020 at 04:49:54PM +0300, Alexander Popov wrote:
>> Let's improve the instrumentation to avoid this:
>>
>> 1. Make stackleak_track_stack() save all register that it works with.
>> Use no_caller_saved_registers attribute for that function. This attribute
>> is available for x86_64 and i386 starting from gcc-7.
>>
>> 2. Insert calling stackleak_track_stack() in asm:
>> asm volatile("call stackleak_track_stack" :: "r" (current_stack_pointer))
>> Here we use ASM_CALL_CONSTRAINT trick from arch/x86/include/asm/asm.h.
>> The input constraint is taken into account during gcc shrink-wrapping
>> optimization. It is needed to be sure that stackleak_track_stack() call is
>> inserted after the prologue of the containing function, when the stack
>> frame is prepared.
>
> Very cool; nice work!
>
>> +static void add_stack_tracking(gimple_stmt_iterator *gsi)
>> +{
>> + /*
>> + * The 'no_caller_saved_registers' attribute is used for
>> + * stackleak_track_stack(). If the compiler supports this attribute for
>> + * the target arch, we can add calling stackleak_track_stack() in asm.
>> + * That improves performance: we avoid useless operations with the
>> + * caller-saved registers in the functions from which we will remove
>> + * stackleak_track_stack() call during the stackleak_cleanup pass.
>> + */
>> + if (lookup_attribute_spec(get_identifier("no_caller_saved_registers")))
>> + add_stack_tracking_gasm(gsi);
>> + else
>> + add_stack_tracking_gcall(gsi);
>> +}
>
> The build_for_x86 flag is only ever used as an assert() test against
> no_caller_saved_registers, but we're able to test for that separately.
> Why does the architecture need to be tested? (i.e. when this flag
> becomes supported o other architectures, why must it still be x86-only?)
The inline asm statement that is used for instrumentation is arch-specific.
Trying to add
asm volatile("call stackleak_track_stack")
in gcc plugin on aarch64 makes gcc break spectacularly.
I pass the target arch name to the plugin and check it explicitly to avoid that.
Moreover, I'm going to create a gcc enhancement request for supporting
no_caller_saved_registers attribute on aarch64.
Best regards,
Alexander
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-06-10 15:47 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-04 13:49 [PATCH 0/5] Improvements of the stackleak gcc plugin Alexander Popov
2020-06-04 13:49 ` [PATCH 1/5] gcc-plugins/stackleak: Exclude alloca() from the instrumentation logic Alexander Popov
2020-06-04 14:01 ` Jann Horn
2020-06-04 15:23 ` Alexander Popov
2020-06-09 18:39 ` Kees Cook
2020-06-10 15:24 ` Alexander Popov
2020-06-04 13:49 ` [PATCH 2/5] gcc-plugins/stackleak: Use asm instrumentation to avoid useless register saving Alexander Popov
2020-06-04 15:05 ` Miguel Ojeda
2020-06-09 18:46 ` Kees Cook
2020-06-10 15:47 ` Alexander Popov [this message]
2020-06-10 20:03 ` Kees Cook
2020-06-11 23:45 ` Alexander Popov
2020-06-04 13:49 ` [PATCH 3/5] gcc-plugins/stackleak: Add 'verbose' plugin parameter Alexander Popov
2020-06-09 18:47 ` Kees Cook
2020-06-10 15:52 ` Alexander Popov
2020-06-10 20:04 ` Kees Cook
2020-06-04 13:49 ` [PATCH 4/5] gcc-plugins/stackleak: Don't instrument itself Alexander Popov
2020-06-09 18:48 ` Kees Cook
2020-06-04 13:49 ` [PATCH 5/5] gcc-plugins/stackleak: Don't instrument vgettimeofday.c in arm64 VDSO Alexander Popov
2020-06-04 13:58 ` Will Deacon
2020-06-04 14:14 ` Jann Horn
2020-06-04 14:20 ` Alexander Popov
2020-06-04 14:25 ` Jann Horn
2020-06-04 14:44 ` Alexander Popov
2020-06-09 19:09 ` Kees Cook
2020-06-10 7:30 ` Will Deacon
2020-06-10 15:18 ` Alexander Popov
2020-06-04 21:39 ` [PATCH 0/5] Improvements of the stackleak gcc plugin Kees Cook
2020-06-09 19:15 ` Kees Cook
2020-06-10 15:14 ` Alexander Popov
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=757cbafb-1e13-8989-e30d-33c557d33cc4@linux.com \
--to=alex.popov@linux.com \
--cc=akpm@linux-foundation.org \
--cc=amonakov@ispras.ru \
--cc=bauerman@linux.ibm.com \
--cc=catalin.marinas@arm.com \
--cc=fweimer@redhat.com \
--cc=gcc@gcc.gnu.org \
--cc=jeyu@kernel.org \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=labbott@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=mcgrof@kernel.org \
--cc=michal.lkml@markovi.net \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=minipli@googlemail.com \
--cc=naohiro.aota@wdc.com \
--cc=notify@kernel.org \
--cc=pageexec@freemail.hu \
--cc=pcc@google.com \
--cc=re.emese@gmail.com \
--cc=spender@grsecurity.net \
--cc=svens@stackframe.org \
--cc=tglx@linutronix.de \
--cc=vincenzo.frascino@arm.com \
--cc=will@kernel.org \
--cc=x86@kernel.org \
--cc=yamada.masahiro@socionext.com \
--cc=yzaikin@google.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 NNTP newsgroup(s).