Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1494742pxb; Fri, 13 Nov 2020 14:26:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBMYFguhPnqyIkUm+Vp6YSWBdG5/2iyCn5tNU/szCQHdRSdXt8P4IQyTEpxXQxH7SdRwyR X-Received: by 2002:a17:906:c357:: with SMTP id ci23mr3977601ejb.311.1605306369781; Fri, 13 Nov 2020 14:26:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605306369; cv=none; d=google.com; s=arc-20160816; b=ADm4xSace5HrUHAncLN62aTOA/cZHUlW6ITzrah7uo38sY9b1nmz8z99kSkwQ2q7Tr 4mUVMlTPMKWGrb/5aGrVORbAPBGk1RZDxfLIg21nLv+9YHx3qG2dltIhNQJlfR/lFpgr xDtqz/wDcnXsNyEmSpmYN19EPddExL5bLNVVAiw349/+bCCS1yF5F3Ow3CRcKdizx+aD 0eBiNPa6TeHDTzL6Mm+jFbrjRhe79wHZRTTeQmiQ1K/bWIwd5fc0pnkhKT1s0bh+Zw8+ 1aH7ECngkEuQiznqTEXjlz5X4/R1tMK/lCaM5xtQ9vCGCbEaR9RETnugaqnLBy7KMlOx HiKA== 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=u0fQxCBxmUxhMOfySImDDJJwP6bRFOpgmkJnBahaSB0=; b=ZWQRXb3QAv8YTSnSbi6TG8RWaLCEgHH0GsIqcQycEvtPSxCC9BH5gGOi47T7dsBDgB KPQjLbURZ4rA1KR52tZ323jUjV0jIQimzSw22+DSP0mu8xZ0fn3FX74vj1tirhiVuwXv IfGfaqB3AldhAjk9RfZkJo04XJMdouZcmnnOcuzFdox6KkIzLYGuoIkjNXbEg01Yjt8r ySG5F+0kHypmnHZBD5o4l2qs+Qc20XxIjxy8sojf0aTdrSg+bbNCtJQYOyqwz1gqbKfN fME64ESkmQXT2ky58kpx4V6wfe7rq9qRE9S71+8UZAxNWGjL10Xt8bkCph1HIZ+3MT0O 5ZXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=r1t8fKl4; 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 v16si6727417ejf.28.2020.11.13.14.25.47; Fri, 13 Nov 2020 14:26:09 -0800 (PST) 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=r1t8fKl4; 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 S1726808AbgKMWWS (ORCPT + 99 others); Fri, 13 Nov 2020 17:22:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726754AbgKMWUZ (ORCPT ); Fri, 13 Nov 2020 17:20:25 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A422CC0617A7 for ; Fri, 13 Nov 2020 14:20:25 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id x85so7614123qka.14 for ; Fri, 13 Nov 2020 14:20:25 -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=TxJUD8v97JGPMAbWj3VXNb2eVqe5mEu7x3U03b5wZtCLswFczmTkoimG0+iORs+bWM UMm2+iqTVIxxEP9JeA7rVYZG90stsYMCT7X7WJI0dineekBRlwUKvQXX9EBcSezq5WbM M7y6CX6Z8FSaQXXtNf/Nocy1qvDdMZTr+UvNR4yPmSxd7PTDjmKq0iR1weOO2+d7fVhJ 6JsO/qxDSFd+Kv4tg9KQaqiGCOhRUzHGsWMbK0DlgGXIc//VNiBDwGzKsmWYGGP7tvTS aK1AAX7KOyZE7wRGTSvPJdPNPjVroyg5AiskkH5pAywYrSpchedBiyGBbbTCM2GE9SGS x8Ew== X-Gm-Message-State: AOAM531ooAlUgAQ5lEqYa7sPKAkwGV0M3RBnjPxk0GQEINgtwRau/AWt 7lvV4CPwTI399Cmk7qFWk0suIJaJncgB0z3i 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: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 Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , 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. 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 --- 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) { -- 2.29.2.299.gdc1121823c-goog