Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8940644ybi; Tue, 23 Jul 2019 18:31:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzRjje7RIv6AZJxg+byXKl+hkwkDWNbmzLtbWShVL6Yu3p/LrZ+Mw9PBz3idHgQgnnkR/uy X-Received: by 2002:a17:902:4b:: with SMTP id 69mr82638172pla.89.1563931882573; Tue, 23 Jul 2019 18:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563931882; cv=none; d=google.com; s=arc-20160816; b=zYlwgfotqhTsOvSdmXTQhmXj4O1Sk2z2rc07o6L07EFAmCW+7TvCLgZH4g8J/Jk9PP p63GjOXGTnCDmJBN0UGBxTSRNhVgy3CxrO+BG0w/C2snVbzh+R7nBjFrnpf+A3kulZby RaSiA9IdWOKYHjPj4xauPyMopFStEqxssp4+JpKcUePiHubJC0NtlWCdUNanTx8/B2Bz l6ccftWhRtxLvvAtG6ayxqSbyb+iNgg/1lJhzTgWPY1y/YYaeX2RtbgZXi6I0aExvjl1 SSejOu7E0AiZ+ej6U0vrJiFV3ZdfdQ+wPbkk8EGTI6XwJULA7DO8JAppNf/A7E1PYkww TK2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=MMJBYXKZKq/K0xhBsKvlfCTzpFlBz/mgOHrf5z8HQi0=; b=mllODZHSVX1q0cDIZqQYMamThiHr2lJRZ/88VDmsl93UrdRG1J5slJmrphQ/BEVpJa +Tao+FApCd0iYbc86LX2GTLdPa5o1Z6iglWGS+tSVC3F/BzzVdvHVqoeXE2dG7VxpEvu ZqGu39Cwo3rUgUCUI/BoYyXYrWzpZDksESqtzle03DbVDQygmdrCoTQRtj4kJQ39pyIM c1fjoJ9WOX7ydZBgpHAXH1dPvVcG8hbrZwfVjvpZBzvkVRGHZ57C3RLDqXPcKuWUJHUb jmcAAq2LHLg9uxKrXpKCwTk4JxQAc1qmUovqiy8aQ3+hNu417fiQr4YTh9JXJzjebPuO yqxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h11si39981995pjb.98.2019.07.23.18.31.06; Tue, 23 Jul 2019 18:31:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732683AbfGWQYL (ORCPT + 99 others); Tue, 23 Jul 2019 12:24:11 -0400 Received: from foss.arm.com ([217.140.110.172]:57322 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729829AbfGWQYL (ORCPT ); Tue, 23 Jul 2019 12:24:11 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 25DE3337; Tue, 23 Jul 2019 09:24:10 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 736473F71A; Tue, 23 Jul 2019 09:24:08 -0700 (PDT) Date: Tue, 23 Jul 2019 17:24:03 +0100 From: Mark Rutland To: Marco Elver Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Andrey Konovalov , Peter Zijlstra , x86@kernel.org, kasan-dev@googlegroups.com Subject: Re: [PATCH 2/2] lib/test_kasan: Add stack overflow test Message-ID: <20190723162403.GA56959@lakrids.cambridge.arm.com> References: <20190719132818.40258-1-elver@google.com> <20190719132818.40258-2-elver@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190719132818.40258-2-elver@google.com> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 19, 2019 at 03:28:18PM +0200, Marco Elver wrote: > Adds a simple stack overflow test, to check the error being reported on > an overflow. Without CONFIG_STACK_GUARD_PAGE, the result is typically > some seemingly unrelated KASAN error message due to accessing random > other memory. Can't we use the LKDTM_EXHAUST_STACK case to check this? I was also under the impression that the other KASAN self-tests weren't fatal, and IIUC this will kill the kernel. Given that, and given this is testing non-KASAN functionality, I'm not sure it makes sense to bundle this with the KASAN tests. Thanks, Mark. > > Signed-off-by: Marco Elver > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: "H. Peter Anvin" > Cc: Andrey Ryabinin > Cc: Alexander Potapenko > Cc: Dmitry Vyukov > Cc: Andrey Konovalov > Cc: Mark Rutland > Cc: Peter Zijlstra > Cc: x86@kernel.org > Cc: linux-kernel@vger.kernel.org > Cc: kasan-dev@googlegroups.com > --- > lib/test_kasan.c | 36 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 36 insertions(+) > > diff --git a/lib/test_kasan.c b/lib/test_kasan.c > index b63b367a94e8..3092ec01189d 100644 > --- a/lib/test_kasan.c > +++ b/lib/test_kasan.c > @@ -15,6 +15,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -709,6 +710,32 @@ static noinline void __init kmalloc_double_kzfree(void) > kzfree(ptr); > } > > +#ifdef CONFIG_STACK_GUARD_PAGE > +static noinline void __init stack_overflow_via_recursion(void) > +{ > + volatile int n = 512; > + > + BUILD_BUG_ON(IS_ENABLED(CONFIG_STACK_GROWSUP)); > + > + /* About to overflow: overflow via alloca'd array and try to write. */ > + if (!object_is_on_stack((void *)&n - n)) { > + volatile char overflow[n]; > + > + overflow[0] = overflow[0]; > + return; > + } > + > + stack_overflow_via_recursion(); > +} > + > +static noinline void __init kasan_stack_overflow(void) > +{ > + pr_info("stack overflow begin\n"); > + stack_overflow_via_recursion(); > + pr_info("stack overflow end\n"); > +} > +#endif > + > static int __init kmalloc_tests_init(void) > { > /* > @@ -753,6 +780,15 @@ static int __init kmalloc_tests_init(void) > kasan_bitops(); > kmalloc_double_kzfree(); > > +#ifdef CONFIG_STACK_GUARD_PAGE > + /* > + * Only test with CONFIG_STACK_GUARD_PAGE, as without we get other > + * random KASAN violations, due to accessing other random memory (we > + * want to avoid actually corrupting memory in these tests). > + */ > + kasan_stack_overflow(); > +#endif > + > kasan_restore_multi_shot(multishot); > > return -EAGAIN; > -- > 2.22.0.657.g960e92d24f-goog >