From patchwork Tue Nov 10 22:20:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895717 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 4BB69C388F7 for ; Tue, 10 Nov 2020 22:34:25 +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 CF18E2068D for ; Tue, 10 Nov 2020 22:34:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="UooeAdqQ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Lw7P323O" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF18E2068D 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=Eiuwe9ZxlgzkK1ApszIEQegHUApEPLB8PwkcTwccVUE=; b=UooeAdqQ2x0JeX/ZPdAw/Kqss rO/U/AGBajgyNzrU5Go3eP5bqWH5jiXwUNt8GOLEqpUuOg+rxO2tUZAzPNtLKVc6TJGMHKNXuxlkJ P/RiE6J2d3I18eVRY+aS3v0sunVk1JwaYA+JCyNbbdwQNlMun0YGTeKGoI90l5cBIZxjs3CFvFMHa I5XzE4q88zUq61zydPoY0BA18wmSNHwg1bVaVwqwwlDlebw5HRlkpAGjzn6aFn/SZCvq58FOuZsna K76USJc8xxAi5DchUNDMrXMMSrUD81oEtYGKXGnuvPliOAOg6JvWItZsQgtM6R9VHJvEszdBHgsPd 5fe95MWwA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kccBx-0005dT-Sr; Tue, 10 Nov 2020 22:32:46 +0000 Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcc0J-0000EQ-MB for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2020 22:20:56 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id ca17so86048qvb.1 for ; Tue, 10 Nov 2020 14:20:40 -0800 (PST) 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=tEdtRhABI1InYFpD5ltmIm/evviW/mtmaENcJYt1lmc=; b=Lw7P323OF/2i72kWQuJ4l8inThWAnZLsOW9ThJ12RKxjoJxpzU7FXD1KV+6+q4wFpg l/r4+g+lNCXzgzXgK1lygyyUKCtzwpfHl/3OlTnMhhMRfVDtB2PdYon8ei3bzhD2Vqtt Wo3uUi7dX96xLBACxd53V6ueiGeSZymzkpvnmaVcbe+7AHrMitDwaS52oyIZ68DrTouD k4aflKbowlt0EK7lot+JEbexzRr4RzOeeQC1v96jGdm7Fx8vBNCN0QhyaFYecRjubCKf y4BPPQEw0TRxyeg4FETviyB1G271O7T0w4aKkUqb+DvRw5ABtXAGXbngmp+oaS/px1Mw omsA== 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=tEdtRhABI1InYFpD5ltmIm/evviW/mtmaENcJYt1lmc=; b=Ijwm4sytMG9+U/0FeK3FtOcPRdk2ZZbi35NKOEMNu523A9Ig+3Tgmmt81PbZtEbUmW FucEKKgF4G1bNOSyrCu3P+m+l4KRn4Y5uCu1elJxO32DK53YntlXknfcpkbmpSqsJkoJ 6GRWU7U2gaSscOAE1sHi3aSGn8DW3Sq2lip3xazkXru8UULKZt+C+YWQgsHf3NT7vpA1 xjPKM0TaQPn2ltmkAPhrv1+RhuUwnQCdVPPUJsz37bH5tuO9xSokR+lzxIUsj7wzg0pa YdJND8sqnVzqljt+7Mf3jjt4PYgWEt2Ugv5Hee0qqF4yxYH/6zOksPAD76+cN48iajq6 78Bg== X-Gm-Message-State: AOAM533DmJe52XcnrG0w6XXCcPwchAYEtmfsRv/T9Y8IwLAVeiMIl5Zn hjpbuIgCGy2sNmV57x9FPBwUEZOeMiK9YIZl X-Google-Smtp-Source: ABdhPJxqgq6UfWHyoMS9rSSpgTD3+0B/UNYGVxM4mfhk/kYijiMY8uMFuj8WQnHSvWCojmtQAUsNukGtycyjiBdC X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:6a7:: with SMTP id s7mr22500256qvz.2.1605046838323; Tue, 10 Nov 2020 14:20:38 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:08 +0100 In-Reply-To: Message-Id: <7e95d4739f5617b2c1acf52f37e01f1ca83750b5.1605046662.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 04/20] kasan, arm64: unpoison stack only with CONFIG_KASAN_STACK From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201110_172044_221861_7E8BDCDE X-CRM114-Status: GOOD ( 16.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 , Catalin Marinas , Kevin Brodsky , Will Deacon , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Andrey Konovalov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Evgenii Stepanov 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. 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 Link: https://linux-review.googlesource.com/id/If8a891e9fe01ea543e00b576852685afec0887e3 Reviewed-by: Marco Elver Acked-by: Catalin Marinas --- 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 f22bdef82111..b9b9db335d87 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_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); @@ -122,8 +120,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) {} @@ -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 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) {