Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751485AbcLEORK (ORCPT ); Mon, 5 Dec 2016 09:17:10 -0500 Received: from mx2.suse.de ([195.135.220.15]:38569 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750841AbcLEORJ (ORCPT ); Mon, 5 Dec 2016 09:17:09 -0500 From: Jiri Slaby To: akpm@linux-foundation.org Cc: dvyukov@google.com, linux-kernel@vger.kernel.org, marxin , Jiri Slaby Subject: [PATCH] kasan: add test for -fsanitize-address-use-after-scope Date: Mon, 5 Dec 2016 15:16:15 +0100 Message-Id: <20161205141615.8199-1-jslaby@suse.cz> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: marxin In commit 828347f8f9a5 ("kasan: support use-after-scope detection") we added support for use-after-scope. Let's add a check if it actually works. Signed-off-by: Martin Liska Signed-off-by: Jiri Slaby --- lib/test_kasan.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/test_kasan.c b/lib/test_kasan.c index fbdf87920093..32f31b8d306e 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -352,6 +352,19 @@ static noinline void __init kasan_stack_oob(void) *(volatile char *)p; } +static noinline void __init kasan_stack_use_after_scope(void) +{ + char *ptr = NULL; + { + char a; + + ptr = &a; + } + + pr_info("use-after-scope on stack\n"); + *(volatile char *)ptr; +} + static noinline void __init ksize_unpoisons_memory(void) { char *ptr; @@ -461,6 +474,7 @@ static int __init kmalloc_tests_init(void) kmalloc_uaf2(); kmem_cache_oob(); kasan_stack_oob(); + kasan_stack_use_after_scope(); kasan_global_oob(); ksize_unpoisons_memory(); copy_user_test(); -- 2.11.0