On 5/20/20 1:03 PM, Franz Sirl wrote:
Am 2020-05-19 um 21:05 schrieb Martin Liška:
Hi.
We make direct emission for asan_emit_stack_protection for smaller stacks.
That's fine but we're missing the piece that marks the stack as released
and we run out of pre-allocated stacks. I also included some stack-related
constants that were used in asan.c.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
gcc/ChangeLog:
2020-05-19 Martin Liska <mli...@suse.cz>
PR sanitizer/94910
* asan.c (asan_emit_stack_protection): Emit
also **SavedFlagPtr(FakeStack) = 0 in order to release
a stack frame.
* asan.h (ASAN_MIN_STACK_FRAME_SIZE_LOG): New.
(ASAN_MAX_STACK_FRAME_SIZE_LOG): Likewise.
(ASAN_MIN_STACK_FRAME_SIZE): Likewise.
(ASAN_MAX_STACK_FRAME_SIZE): Likewise.
---
gcc/asan.c | 26 ++++++++++++++++++++++----
gcc/asan.h | 8 ++++++++
2 files changed, 30 insertions(+), 4 deletions(-)
>- if (asan_frame_size > 32 && asan_frame_size <= 65536 && pbase
>+ if (asan_frame_size >= ASAN_MIN_STACK_FRAME_SIZE
Hi,
is the change from > to >= and from 32 to 64 for ASAN_MIN_STACK_FRAME_SIZE
intentional? Just asking because it doesn't look obvious from Changelog or patch.
Also a few lines below the "5" in
use_after_return_class = floor_log2 (asan_frame_size - 1) - 5;
looks like it may be related to ASAN_MIN_STACK_FRAME_SIZE_LOG.
Hello.
Thank you very much for the useful feedback. I really made the refactoring
in a wrong way.
I'm suggesting to only change the emission of asan_emit_stack_protection.
Tested locally with asan.exp file.
Ready for master?
Thanks,
Martin
regards,
Franz
>From 5d0c64b2f4028af3ed575934ecc0c3378cca3de1 Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@suse.cz>
Date: Tue, 19 May 2020 16:57:56 +0200
Subject: [PATCH] Add missing store in emission of asan_stack_free.
gcc/ChangeLog:
2020-05-19 Martin Liska <mli...@suse.cz>
PR sanitizer/94910
* asan.c (asan_emit_stack_protection): Emit
also **SavedFlagPtr(FakeStack) = 0 in order to release
a stack frame.
---
gcc/asan.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/gcc/asan.c b/gcc/asan.c
index c9872f1b007..e8d2a25ff79 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -1598,8 +1598,24 @@ asan_emit_stack_protection (rtx base, rtx pbase, unsigned int alignb,
if (use_after_return_class < 5
&& can_store_by_pieces (sz, builtin_memset_read_str, &c,
BITS_PER_UNIT, true))
- store_by_pieces (shadow_mem, sz, builtin_memset_read_str, &c,
- BITS_PER_UNIT, true, RETURN_BEGIN);
+ {
+ /* Emit:
+ memset(ShadowBase, kAsanStackAfterReturnMagic, ShadowSize);
+ **SavedFlagPtr(FakeStack) = 0
+ */
+ store_by_pieces (shadow_mem, sz, builtin_memset_read_str, &c,
+ BITS_PER_UNIT, true, RETURN_BEGIN);
+
+ unsigned HOST_WIDE_INT offset
+ = (1 << (use_after_return_class + 6));
+ offset -= GET_MODE_SIZE (ptr_mode);
+ mem = adjust_address (mem, Pmode, offset);
+ mem = gen_rtx_MEM (ptr_mode, mem);
+ rtx tmp_reg = gen_reg_rtx (Pmode);
+ emit_move_insn (tmp_reg, mem);
+ mem = adjust_address (mem, QImode, 0);
+ emit_move_insn (mem, const0_rtx);
+ }
else if (use_after_return_class >= 5
|| !set_storage_via_setmem (shadow_mem,
GEN_INT (sz),
--
2.26.2