From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D16BC55179 for ; Thu, 22 Oct 2020 13:22:42 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8C32D2098B for ; Thu, 22 Oct 2020 13:22:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Rpouxkxc"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="nyVZvbQw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8C32D2098B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=mhkYV3okNsxJ9iUCoeChR2w1RQFQxxRa+aW8Tk510gs=; b=Rpouxkxc/KDGzNIV0/geqa6jW bDENWHjTSS2GWH6JrYlWxFxeX2pwAVncilACmzJyHcrkjYd9wuXYTVAw4Rc9QTm2b73R/dpNwQ2Ev jKw7V7Il9xNsB8PmGLK/sNsBwPczqDdl6dUmCyKJn7DypsUa8FY0bjWG0N16wmL3agKG05pKMjd2D niLFQF62B9wRLEAmkoDTSufF4W0aSbGW2T4YhaOMgoRrXitXRkM/3zi9pDXyDdRlVmt5ku1DrDfdZ Bpoo2KGJLxN475TDCGG9vC1RK7903fL7aQUSaZCRsPYLMso4E4/zZh4Qpm7xD+UVf76cLV6lJBhGC eHtTBGn7Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVaWO-00043u-QX; Thu, 22 Oct 2020 13:20:48 +0000 Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVaVH-0003fe-3C for linux-arm-kernel@lists.infradead.org; Thu, 22 Oct 2020 13:19:44 +0000 Received: by mail-qt1-x84a.google.com with SMTP id d22so1039156qtn.0 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=SsfxuUpJH8u39B59L2Jg2ILr+eH6WdseZUjr5pOYkroIvLaSXBVCl6ofQKSZf2rD2d ksP83EtIMYFOCVV6UGGmskSg6W/XUaTynd83znGd+2JXObB0CzMQE/Soj/E7jaeRxMZf wLnhpYij4rOdpyIFd8dG5m+7g7Vjt/Pclvu2efmWz5m/Fum8tHgr/VEbJHcRcrpDnmFn EyEnXEeHr5ocAXx1+GSx4zDF1nEhJ8TD1vNyTF/1MMFdEzd3PV0Ee593zuAyyMzVAomd B1MdbN65CuLCoSKTObR3/xVXvxDs20+jhTgujOlOCVnLUKKqQOWFbkfmmoFP9TSM6uwu qp4w== X-Gm-Message-State: AOAM531kEOibuxX/mNgZ1p6JxsEiHbDXocuJYByuH1q08o5TJ/ExgKxu /iG0dw28om8GH3b+3jl3j2BPqpolVqumCSL6 X-Google-Smtp-Source: ABdhPJxC+cHl3A6vxbAhEsJcstIa/YPUKLBxMm0Gygy5clgGTysFnJWscf3YLAf5go7mTyNLfj4cOUScq3LNKTs9 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201022_091939_200447_80228EF7 X-CRM114-Status: GOOD ( 15.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Branislav Rankov , Elena Petrova , linux-mm@kvack.org, Andrey Konovalov , Kevin Brodsky , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Kostya Serebryany , linux-arm-kernel@lists.infradead.org, Serban Constantinescu , Andrey Ryabinin , Andrew Morton , Peter Collingbourne , Evgenii Stepanov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel