Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2997069pxb; Mon, 16 Nov 2020 03:03:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJztZ1EnMl83SzwZjyvAaux3QEDgDPUkGbDpPbo4GXKhT5kU+JhGeeFE28YJgCfIok2DOhXx X-Received: by 2002:a17:906:3c55:: with SMTP id i21mr1545682ejg.347.1605524632012; Mon, 16 Nov 2020 03:03:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605524632; cv=none; d=google.com; s=arc-20160816; b=VKheQ1wgkEHJ2OQO7Du9U0+QAw9v9O7g+2nXQkx3HOWDaTl2fGvzqGShvvoFeeLyJr 8ccwyYttqeo7wRaXRPQeih1xu1gOejblq2kygQ2Rt/KzvlS8Eu14stYcHgn87UGUV+wH GpEUbKbk/gfjJFruND82TANNZeHJjMbNLvXTf4in9NdQPD4RBmXuRbgRPJMcmjCv9al9 8zKmOy1xlN+a0X5fCkUpCR5IU3VXbu5UEwa1gKvzfTLAuVrr5UrbMQID4URJp/G+/2Dy ebqMOHstJuTXDeJFnlagEEPmJnZW0ZISEeWSPWGlmVKFf1Z4IlVhzwjft2Uy+5LvbzEo 5TEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=FX8GD+b8oMZGG7RMfkMYcB2Sb5EDK5FE7PKEweB+0bg=; b=0HnXpxkf9z/LmBdLZdGl3oHA76KJWUeb8KMnwtKUd0vJrUE2eEC3o35gJtQeeuArff n0e0T1ne52HSBy+a2cVzOptm6bF4H/z3qJOpAUOKccqCWYkxEJiwvcaeGkmpYO6S7tJ3 JrwwWO61x0D0EyQ0XmAZxPQ2pmANYr5QbE5O/g4/o36vuNqTlRVIBbVTA1mOA0pV+Q8e aaszE45fgxRue5NJI5Cz6cTvIE/Gk7+Vy8QHIusPe6aQRarHsn3e1ky0phE9yAOXALJ+ S4RifHrFa+uXAcAH2AbvldKDZdV3VF9lI8gmj5tmz2SBgMnqpTcd2oXlq2Z7yvP5DELK rc+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ojt003Ul; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u10si10617800edy.1.2020.11.16.03.03.28; Mon, 16 Nov 2020 03:03:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ojt003Ul; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729269AbgKPLAo (ORCPT + 99 others); Mon, 16 Nov 2020 06:00:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726710AbgKPLAo (ORCPT ); Mon, 16 Nov 2020 06:00:44 -0500 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB6B3C0613CF for ; Mon, 16 Nov 2020 03:00:42 -0800 (PST) Received: by mail-qt1-x843.google.com with SMTP id t5so12525479qtp.2 for ; Mon, 16 Nov 2020 03:00:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FX8GD+b8oMZGG7RMfkMYcB2Sb5EDK5FE7PKEweB+0bg=; b=Ojt003UlpmkrS+sQ1TQUN2zeBxWoQgiHTyQyOraAFHTpOpuEz7EnHTOYMGbWE0fs0B EF5O7dcxHUGo2tlteywoPZTgAuyQztFbOPomED6EGVvuLowGkFCbPXHs1Ol/fyjQjsc1 pn5cgVfOrt0iblSESh5xPqcL/mU+ZJGrHPnCpJ1Z7Niof6IVup10P22Vvq/VTHS4+hzJ gZFYUvHtfjzo7Y5R2twqZFQpH2tDdd6CzWtxSiW8TOmesIyG02+2lpspMTvhNDl7Sb8J 71eG1H27trjJb4xeC8LjH8QhWd7TEQ6pQmRQrvmQs26Q3mfUqqhqkqFkwcJUHOA11Fsm IsWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FX8GD+b8oMZGG7RMfkMYcB2Sb5EDK5FE7PKEweB+0bg=; b=C0ONknAR7q+R4HMtm1oJLHubJp3cl7ezBP1zAvYa8XkEKy/GmNC4jPIs9VxYBEbATg +HR7SgDdpptKjVsh3qqOt/nQTi0vKMVsE9K6FthkyPGJ9e9DUrwVCsBlKDdhxtFTrPZB FF3uf4W5iMpgRY/EiJYWErcyzWDAYHqDOVjQmM/p9tX32zIdM34u2T/oYFPBknbmvkuq BTAnnryZmPHZIrizEjgaMZZwgN6ksLRXUwlxxL4zecIbbTKmabuaB/EGYvIHVj07Iqt6 IcrXWXPxwl0MpX0A6BujjNqM/JCzg/spZBzfjbFt7LixFy/oXGiaWEAnYpa0wj0UJL4a 7xNg== X-Gm-Message-State: AOAM53225RcmN/L6f8vzlKGvFORYumxr0vtko/O6Ut7FXDZioZSTCwl0 D4IqP5ix1EHTWwyHoxogBaVKf1msnHoWVLiQeSKbOQ== X-Received: by 2002:aed:2b47:: with SMTP id p65mr13025705qtd.337.1605524441642; Mon, 16 Nov 2020 03:00:41 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Dmitry Vyukov Date: Mon, 16 Nov 2020 12:00:30 +0100 Message-ID: Subject: Re: [PATCH mm v3 04/19] kasan, arm64: unpoison stack only with CONFIG_KASAN_STACK To: Andrey Konovalov Cc: Andrew Morton , Catalin Marinas , Will Deacon , Vincenzo Frascino , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev , Linux ARM , Linux-MM , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 13, 2020 at 11:20 PM Andrey Konovalov wrote: > > There's a config option CONFIG_KASAN_STACK that has to be enabled for > KASAN to use stack instrumentation and perform validity checks for > stack variables. > > There's no need to unpoison stack when CONFIG_KASAN_STACK is not enabled. > Only call kasan_unpoison_task_stack[_below]() when CONFIG_KASAN_STACK is > enabled. > > Note, that CONFIG_KASAN_STACK is an option that is currently always > defined when CONFIG_KASAN is enabled, and therefore has to be tested > with #if instead of #ifdef. > > Signed-off-by: Andrey Konovalov > Reviewed-by: Marco Elver Reviewed-by: Dmitry Vyukov > Acked-by: Catalin Marinas > Link: https://linux-review.googlesource.com/id/If8a891e9fe01ea543e00b576852685afec0887e3 > --- > arch/arm64/kernel/sleep.S | 2 +- > arch/x86/kernel/acpi/wakeup_64.S | 2 +- > include/linux/kasan.h | 10 ++++++---- > mm/kasan/common.c | 2 ++ > 4 files changed, 10 insertions(+), 6 deletions(-) > > diff --git a/arch/arm64/kernel/sleep.S b/arch/arm64/kernel/sleep.S > index ba40d57757d6..bdadfa56b40e 100644 > --- a/arch/arm64/kernel/sleep.S > +++ b/arch/arm64/kernel/sleep.S > @@ -133,7 +133,7 @@ SYM_FUNC_START(_cpu_resume) > */ > bl cpu_do_resume > > -#ifdef CONFIG_KASAN > +#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK > mov x0, sp > bl kasan_unpoison_task_stack_below > #endif > diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S > index c8daa92f38dc..5d3a0b8fd379 100644 > --- a/arch/x86/kernel/acpi/wakeup_64.S > +++ b/arch/x86/kernel/acpi/wakeup_64.S > @@ -112,7 +112,7 @@ SYM_FUNC_START(do_suspend_lowlevel) > movq pt_regs_r14(%rax), %r14 > movq pt_regs_r15(%rax), %r15 > > -#ifdef CONFIG_KASAN > +#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK > /* > * The suspend path may have poisoned some areas deeper in the stack, > * which we now need to unpoison. > diff --git a/include/linux/kasan.h b/include/linux/kasan.h > index 0c89e6fdd29e..f2109bf0c5f9 100644 > --- a/include/linux/kasan.h > +++ b/include/linux/kasan.h > @@ -76,8 +76,6 @@ static inline void kasan_disable_current(void) {} > > void kasan_unpoison_range(const void *address, size_t size); > > -void kasan_unpoison_task_stack(struct task_struct *task); > - > void kasan_alloc_pages(struct page *page, unsigned int order); > void kasan_free_pages(struct page *page, unsigned int order); > > @@ -122,8 +120,6 @@ void kasan_restore_multi_shot(bool enabled); > > static inline void kasan_unpoison_range(const void *address, size_t size) {} > > -static inline void kasan_unpoison_task_stack(struct task_struct *task) {} > - > static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} > static inline void kasan_free_pages(struct page *page, unsigned int order) {} > > @@ -175,6 +171,12 @@ static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } > > #endif /* CONFIG_KASAN */ > > +#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK > +void kasan_unpoison_task_stack(struct task_struct *task); > +#else > +static inline void kasan_unpoison_task_stack(struct task_struct *task) {} > +#endif > + > #ifdef CONFIG_KASAN_GENERIC > > void kasan_cache_shrink(struct kmem_cache *cache); > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index 0a420f1dbc54..7648a2452a01 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -64,6 +64,7 @@ void kasan_unpoison_range(const void *address, size_t size) > unpoison_range(address, size); > } > > +#if CONFIG_KASAN_STACK > static void __kasan_unpoison_stack(struct task_struct *task, const void *sp) > { > void *base = task_stack_page(task); > @@ -90,6 +91,7 @@ asmlinkage void kasan_unpoison_task_stack_below(const void *watermark) > > unpoison_range(base, watermark - base); > } > +#endif /* CONFIG_KASAN_STACK */ > > void kasan_alloc_pages(struct page *page, unsigned int order) > { > -- > 2.29.2.299.gdc1121823c-goog >