From 8b6731e674c76cb48a417f2eef74ced92a17f469 Mon Sep 17 00:00:00 2001 From: Martin Liska 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 PR sanitizer/94910 * asan.c (asan_emit_stack_protection): Emit also **SavedFlagPtr(FakeStack, class_id) = 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 c9872f1..e015fa3 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, class_id) = 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 = gen_rtx_MEM (ptr_mode, base); + mem = adjust_address (mem, ptr_mode, offset); + rtx addr = gen_reg_rtx (ptr_mode); + emit_move_insn (addr, mem); + mem = gen_rtx_MEM (QImode, addr); + emit_move_insn (mem, const0_rtx); + } else if (use_after_return_class >= 5 || !set_storage_via_setmem (shadow_mem, GEN_INT (sz), -- 2.7.4