From patchwork Fri Nov 13 22:19:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11905135 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 CBD37C63697 for ; Fri, 13 Nov 2020 23:52:06 +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 682B320791 for ; Fri, 13 Nov 2020 23:52:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="aOlHgkAZ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="r1t8fKl4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 682B320791 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=GUJVJnGNb5Z2qwdbMtoHJmVhv8uOgsL2xH67/GbWrFI=; b=aOlHgkAZPl1VrmTOiT2fwFIIs 1Q8E7oOPbbTs1DeM1Ja9r0YtfTJsAAnYQp9ksysWxsZlYZuAiUbvYmQ+2O3lsHYmeJUiAKl6zaIrY XHADBhYCYhnwmln4O7DBIRQxTRerG2ddIZ6lUSaInJcJNxWfdffxtUKLMc9s24M9GtSs2orAgGDhm fQSVAsmZvm9wSyWbIj7u6Optq5/IjYBI/34jFNrMAqMouzlaItwEOeYGSMofYP42x0MT0umw5nnYV beGqHisq/m9JaZWSf4PQVCEyuN3OSY9/ROeaqPzpTcxcYRP1ir4GsaiEYhGiKAYTudmVjrGOCaERn uqXbonsjA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdiqb-0002yW-IN; Fri, 13 Nov 2020 23:51:17 +0000 Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdhQl-0001US-Vv for linux-arm-kernel@lists.infradead.org; Fri, 13 Nov 2020 22:20:34 +0000 Received: by mail-qv1-xf49.google.com with SMTP id x9so5109287qvt.16 for ; Fri, 13 Nov 2020 14:20:26 -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=u0fQxCBxmUxhMOfySImDDJJwP6bRFOpgmkJnBahaSB0=; b=r1t8fKl4uuOcWcbL/ueqRvVuuGcEPqzKT8WznSgyrrTLeFP98TCZYmgIsxP7hJRUIL UA2CQ6RqwhXxL5pbj5UZBnxHKj7OqZYU4/ykEQ2vFSNoEairvQ5DffreXNn7ZA2OblFy QESP9jI3hM9x5J9EegrsAz0SQtx2s5rUZfj8PzVPUbblnIVhT9ZUQxrQqGv9gkaVNgN4 FoHyoW9HuPpwVeg7Pseve3oFgp2LEz2IWTH0SpHtt2ViCmh+xEMyYIdlpbP6QcyHVd4l Q3Oork8GgswLd4lgBz2p5tzr6rmuu2fvDobA96l+nwV1GonWfuKd/exDswWmQ0+mJ1rw 1u+g== 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=u0fQxCBxmUxhMOfySImDDJJwP6bRFOpgmkJnBahaSB0=; b=Lv42cSjbw70yi4R36hy+GPmZ0vJ+I4gYf8yO/g1UGAv4mKO448x13iB70SuHboZpR+ cL7nIfcuMfZFtObSgnBNUIxuDFjN7RHwrSWFZd6TiXh+OF325KE7aq/OLM6G6Iv0l1Il 1O52+YRiHvuleYakcwwz5ToVlKdH+dGIHX/A4ZFMJbRiWLBioNZqWoPPJr3MXtTDGe42 Jryah+FWuHAB5G5FjYJ7p7O5D0RdjetajWh44SUYQzOulHDu47XfIuKD+K0nH9Q+xeCF dCD5SiCCXU5PjOjMVQxKAXBeCb26nzp98/Db37YVUnjp2p9d95kZ0F/VyqrnzVIsxFPj K+6w== X-Gm-Message-State: AOAM533jiQKpBd1bocEkok7xOEGZpmyJbUfRhHg7FtUOEyrw2DrX9Mk4 6sFTzADvFaCo7cJUDXxZPVP2wrxj2zCspCtn X-Google-Smtp-Source: ABdhPJzDRObTBajDl9iT1PbNpJcek6LGpoJ9nw4zlOW0zvL70FxU0UTFPIEWguVxCkQFV3wqiBJkCh4vS4JR1wzJ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:f9c8:: with SMTP id j8mr4873782qvo.17.1605306024802; Fri, 13 Nov 2020 14:20:24 -0800 (PST) Date: Fri, 13 Nov 2020 23:19:54 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH mm v3 04/19] kasan, arm64: unpoison stack only with CONFIG_KASAN_STACK From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201113_172032_382925_DBBE18F6 X-CRM114-Status: GOOD ( 16.74 ) 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: linux-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov 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 Reviewed-by: Marco Elver Acked-by: Catalin Marinas Link: https://linux-review.googlesource.com/id/If8a891e9fe01ea543e00b576852685afec0887e3 Reviewed-by: Dmitry Vyukov --- 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) {