Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5869407pxu; Thu, 22 Oct 2020 13:11:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwfIUwZ5s6iBkSYv7kVJnY+ShhT3CY9/Xfdj7OZjXoN+/AjLpZt3+2T0gJ0Iv1S81dMzfE X-Received: by 2002:aa7:d0c3:: with SMTP id u3mr3887079edo.76.1603397506337; Thu, 22 Oct 2020 13:11:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603397506; cv=none; d=google.com; s=arc-20160816; b=Y/UAwAMZ11VDXpnVFmbo7mfFgVhJA2bzr1sWEeDI5fEZIVGAy0KqQ7RpVnBKVLayIT znbg0Vh5FGK4yTe7aUWlk5NXWh/ySWcR0/VeIJh5eJng7/PUy6malpLWK/RW72/HX1O9 t0vPGHKrFKnvljMrHnJfy9Uj57SFcq/Y+rSJE+9RFA/SAjAY9HhCHZDGcwPWWIpn/cTj fOTtnw/XccFt5idqvAKnBPQOAuw9brWOWVm8Ue1E9LYNjTbFyou5nLvbEpIJ0oDAmjqF sjv8F0ScOSzqiIFK0H23JOHNfu+n1yF4za5ih6Kadhy5t678maNZDWkNClslVGSZJhl9 B+nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=cQVLrwUdxN7VB2XZ42Engk9gK33XrCOfDjGCi6TbRVk=; b=Ye+LPStFs87HIqqEZ9cb2stjl5J2HHlDx/eyq1jFWmpnUK0ZOYsaOsbeMHIehj580t HeC2N23E6HJNtRAHLvvQIFcg/RrnvY+RG9U6zSyTrefAFjmdsHQXMre/V/VpaZ88pGUz a/4llOQ6JTxAeZsrJbmOotdcQnxL5gDEqxkY4eMBGODlnkGERB2YTv6biGJHC3KkQl9J /EO0KN/QRIXhItm78yheM1bZ9wIZFRi6L689NkzN7ikAfXW8X8SYsII8sUCajzDVYQhb vsQdh/dMYqbD1m+pGOcFm8eTQpfzdB3ib+TdiDXGG2VLhZA6oMjWVyh1EUyky77cNCOk TYpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nyVZvbQw; 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 z27si1597325edi.577.2020.10.22.13.11.23; Thu, 22 Oct 2020 13:11:46 -0700 (PDT) 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=nyVZvbQw; 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 S2899530AbgJVNTj (ORCPT + 99 others); Thu, 22 Oct 2020 09:19:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2899517AbgJVNTf (ORCPT ); Thu, 22 Oct 2020 09:19:35 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 450B9C0613CF for ; Thu, 22 Oct 2020 06:19:35 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id s8so987573qvv.18 for ; Thu, 22 Oct 2020 06:19:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=cQVLrwUdxN7VB2XZ42Engk9gK33XrCOfDjGCi6TbRVk=; b=nyVZvbQwJKil209qrPnO1RCGT8S27NaIYZ+peNzRSTQdYpzmUd0ad8fLlhrZa50gj4 gdPyukkf/2bC3V42Nncw/TB2lVLlGPZUIC+cxatTMcyLZabxnDwUt+X/Si61f992QEeq YZQBzLESYkrhPi1KwM0Vgtn48uzxCHcFz9p1euPx9/0q76h5gy/QkRzdVgRfzyhwvDmU 1WxQSmIYXBlzSGw9Tq9CZqbkXLjaJcYB2SLWAUOGTswZt0RId0kVTIk2achigNnTltJr OcpVpY6ya0cbCiVJN/73hIRgW1YHoBYcRZ8MV/y8Dg8Q5N6vzjMI/KWadh5Z+kyvbt+k 7lcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=cQVLrwUdxN7VB2XZ42Engk9gK33XrCOfDjGCi6TbRVk=; b=uYPWuPgMdPjLA6di3cSWNg7r1nbA6g2PeewJnKOl2mlbRmUob/pXlxyj5WHhNAkqMs gQ1i0UpgiHpmq0uefqRjvHuuAoQXShRcMSBDDbajBAJICOOMn+f8YJ72Wtmo4OPFsGxV JTfoUDkccmOMBd2tyrIQbFIQc8lpGDyh226hkc9C3KZFv0egfnxmi8/WhUYMNn2+8iAk 56lSMXbzonq48Gce7fRQ+yrFuxym9aVeyoiHJnLWrkIxLvSf0FeTcYg53cvhU/Igskt0 uz8Dg7IJiNnWDu3/5PVAOsI/uAMP3hv5t2NfwiLS1Jijwj2bFqph7eTy2oUmq0BXZFKu GMEA== X-Gm-Message-State: AOAM532a6DzRWO8PH0NPBXRitDr5IZRAnmMsfMID86TRHEl6IrgSbwFh dS0gF4S/0wqMA6lSINi+Kcj1HyFiALJ8nR2J Sender: "andreyknvl via sendgmr" X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:4ba8:: with SMTP id i8mr2332119qvw.59.1603372774241; Thu, 22 Oct 2020 06:19:34 -0700 (PDT) Date: Thu, 22 Oct 2020 15:18:56 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog Subject: [PATCH RFC v2 04/21] kasan: unpoison stack only with CONFIG_KASAN_STACK From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Evgenii Stepanov , Kostya Serebryany , Peter Collingbourne , Serban Constantinescu , Andrey Ryabinin , Elena Petrova , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Andrey Konovalov 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 3f3f541e5d5f..7be9fb9146ac 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -68,8 +68,6 @@ static inline void kasan_disable_current(void) {} void kasan_unpoison_memory(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); @@ -114,8 +112,6 @@ void kasan_restore_multi_shot(bool enabled); static inline void kasan_unpoison_memory(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) {} @@ -167,6 +163,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 a880e5a547ed..a3e67d49b893 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -58,6 +58,7 @@ void kasan_disable_current(void) } #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ +#if CONFIG_KASAN_STACK static void __kasan_unpoison_stack(struct task_struct *task, const void *sp) { void *base = task_stack_page(task); @@ -84,6 +85,7 @@ asmlinkage void kasan_unpoison_task_stack_below(const void *watermark) kasan_unpoison_memory(base, watermark - base); } +#endif /* CONFIG_KASAN_STACK */ void kasan_alloc_pages(struct page *page, unsigned int order) { -- 2.29.0.rc1.297.gfa9743e501-goog