From patchwork Mon Nov 23 20:14:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926665 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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,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 66EFAC2D0E4 for ; Mon, 23 Nov 2020 20:33: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 031E720715 for ; Mon, 23 Nov 2020 20:33:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="0Pvwpyac"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="SgzwKhZ3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 031E720715 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=NNhAsJPNKAIQKCgnZ5GxJc80zLIzQm8QrTlLdqqTQNA=; b=0PvwpyacKNQPjMz+Y2cmLTYdc idM5ADv/iRI4QqUuVCRJtJWzxCDkg9+QMFE4xh3WpHt1n7KneLdaNGOCnxKpNDKas75p63f49+fg1 sjZZ+duf9Ppfg6cdAGB7lqaKtSdvzt5c5qQr4dyGhLC0hebrdzxmfE+UC4F6ILokCi6IL0MHR3ivW wFaOHrFb3seUZQ+kO1rxGe8bHAGgc3gtzY/4P0kpOD9WL9J3PTWj13CJhuEp5DBtEQ+kjLnB3ins+ ned4gjdjo0m+O33r5X/sgBJzihDrUpfPIrMa5rtfG73pmItRSW/ixH/H9WQNCCWZk+17wjQGKK89G 1aghfXW0Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIUA-0000nc-JY; Mon, 23 Nov 2020 20:30:54 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIEz-0002Ai-I8 for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:22 +0000 Received: by mail-wm1-x34a.google.com with SMTP id c131so167905wma.0 for ; Mon, 23 Nov 2020 12:15:04 -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=+fKBF8tk63anOpwt8A+LLR3Qf9R2P9gh2kXJ7NwYZig=; b=SgzwKhZ3R7W8sEp5bQojT95yPgII8yrnXK5PJm+8HBvCo7ZvvLUdSItbJK1GypiV78 xMXJN2ddUn+Rv5nTs1g2AGrivz1eSBhSPLPPA0QfNA5m8rvl5htFaDg+0OiuZ7J/Z4dS pBPZAOVwDwTyJETT3lYeHe/k41kbPwac0mKH7x+6K9Awsno7hCRm9BB3ODF4CwyYxbBb G/yNMKKAjoXIdmarVhQ6zhe2BlfpgbEKX1VJckdMF2Vp3Qmqjp1x2TA8rHeXavGGXT3o pguxCy6HrmCIuVEzT6REGnEXnVZH6DRhHApxMhlMXIOz6uRXZ/7IANmJlnuv3lgicWs2 YVrA== 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=+fKBF8tk63anOpwt8A+LLR3Qf9R2P9gh2kXJ7NwYZig=; b=fcFYMCcFZPn6PMQDe4e810wtIoxMTsxUsiKgLBHS8tlzWEfu4WJNvysToJNmQC5IEW qt/NFrMUaxRAUYru3C+dQS7ve9R2NPKKUN8zTySIyKFy7Izlb1NQdp06xyULJIhEiEey 9UCfs1Xj9lCr1ffvUWnR2alryU64cO6jc7OIyeyVd8sdC4bvHmhKzI8yilUiBuQckQ1C mrnxUS/4JaL0vjzqtqs1fRoCW+0TblJfrYKVHRmeVTnCy4E2kOgOvKUzrDpPHHhwagpt 4zU6mYb3qqelD3/wlJK5DGgChpyGp4vQ6z0bMIvTHcjOtwa5poroWiL1sTJk+glvVuoQ uYKw== X-Gm-Message-State: AOAM533wYyQYJmv5cRUzIE+DtA5+ujEJk9TCB5nXzo5VZ7FyLGjoY8ZN qKTduByLLkjkj/RlLAQouiS1RKAgUCVdOkA5 X-Google-Smtp-Source: ABdhPJy/rTCKa1eqa4mc4yEePlJFS2fAIHVEaaW/JgmCKkRtM+WiCe9SRu9w0wLP/xG8lUZlsreU6FcBRJ22hAo7 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:600c:ce:: with SMTP id u14mr639471wmm.150.1606162503128; Mon, 23 Nov 2020 12:15:03 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:34 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 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-20201123_151514_625545_EE9EE652 X-CRM114-Status: GOOD ( 17.01 ) 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 Reviewed-by: Dmitry Vyukov 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) {