From patchwork Thu Nov 5 00:02:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883129 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 3C0E7C00A89 for ; Thu, 5 Nov 2020 04:24:45 +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 BC6EA20795 for ; Thu, 5 Nov 2020 04:24:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="s7Mk4dy+"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="RHfIBJGI"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="PRQZtB1d" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC6EA20795 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=M6hnCYCv8zmGWktrGOkW6ubQAFdn3UCjF5fkyWLQDr8=; b=s7Mk4dy+r/O06wUvv+B/S3w38 UGk7Q2rXcSUlIbuM34fBFvRrliaGHC1smQdFTfoMhFNxgVWPl70VA0mUPBHWGeNuSB2fpO32Cv1Pv P94GX835FfR/YwufUBPJ/1UiHbHPH2Yrd2qaliPTACF9Ub54W+nAdQxq3KlJS/R18/aPAXd/ewPh0 LI8ZiU5M3me6C/HoHtYG9fE7zOMzYjIjvGTyHxDokevmzpHE0x6IRLjw4tHvmHA19gBNk97UMGnc6 6rNT/teoTlABkyIVpSlT+39gqALDNobMrp5MGokYJPW3ppZS0+VEOJFi8bNbu8rwzO0LTh8i/M/bR 3suOW8ISg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWnj-0006Pt-Vd; Thu, 05 Nov 2020 04:23:08 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW3s-00016k-UY for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:35:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=75cYXImCPyiWQ9SKzSdNGkBAnxoIkaWvKX26xtnhUe0=; b=RHfIBJGIapbZ80NiMIeneE92WT n2Q9Y4cu1Mt7jB5yVNhM1PpaviCb+gAibad76iGB1lZtyOLycLUvzjHFOIYzZpaymNSjsGOtJ1hHQ WGjDt8OdqPCCu/6mEgEBWcvslHkpkxWgQr4CmyGDLfBe6Haf/OF119PXwOyjVEe6GOsmg42WmxvUM BjVibITT5JxHWtKGAPu7x7MOT6H0QZzy9jp+/eJjuH4lXprC4SFTTv9c8NgVKRWoevSw+85YbmTDQ q6e7Co1mGZfhwg/qiCK1gNsirAmyvJVf9dAuciAQX9Ui+cMe9TKcWVyiz4tCp0mZ8mu7TlwaMkLB3 srP7Pa6w==; Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaSkm-0000oC-R0 for linux-arm-kernel@lists.infradead.org; Thu, 05 Nov 2020 00:03:53 +0000 Received: by mail-qv1-xf49.google.com with SMTP id dd7so50032qvb.6 for ; Wed, 04 Nov 2020 16:03:48 -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=75cYXImCPyiWQ9SKzSdNGkBAnxoIkaWvKX26xtnhUe0=; b=PRQZtB1dufXLPUzgGaqIbaWhMXmesRjAadeDWIt74dEP8Lfsgm2ryEy6s7q8fzmlIV IWJOdm09vXFCNhnpM8EQA7rqqWqjMR9RQQq+tdXuXK3ckY+h7vf59jeSgqtX019vBSLK j8ygqaBGulNwu0YsR9bBAAvVI10PL05Y3wtvXuXQxic2EsEZyEkhcax1ETvG7h0+ymCX e50LJMX71RYCnHJ+gYJyjhKhP+EGhLi7Hl2CmIlnTEpAV9+5QzbT4cIQ3P6MRc7P6q8P Mm3sjdpxfFKeB/L9pqme/H+/pNL5HjbpvJH5LX3yE30dm0HKjUCMmqsnucEmfIgriAJ6 xrLA== 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=75cYXImCPyiWQ9SKzSdNGkBAnxoIkaWvKX26xtnhUe0=; b=r7+P/284kK3Vjh/Io2w38/Z8Vsfd6h1DU/NRLECWO974El6DX63Ka32ePzzNWkT1Qq Rc6z2sNWVpV87qcH5CO472/Aw/7W0+TItXIM9W3Vj7dnCeIFDOEAMFXsFI4StjU5ZVKM UoeRrvJJ4GFrGMY/h8CvNANSa1roULSdf7+rXfXE1pTKYId1i1hfV0zeNXp/ou/qteuc sJeIe01bS27cgC+lyfaL4zudZHf/VBu11cArY++vk4eqZygO+Cb4A4/9FCPR5EBk36ta CI4RQv6ETXfz/V3OfIfT0OS70sKO1xDkyJFCSmWHYgbq1smf5fv7bi6/66bO5Z+UZ4vf Cm1g== X-Gm-Message-State: AOAM5328vcGDbYcZ5jP1vx1wyKTm28fGZb+MR+1scHa+oCUJ0h/KaWiC c8ZVZc+O5m/eKKoPRLsV4Z2Cg5M2/FCofwBd X-Google-Smtp-Source: ABdhPJw7NtC8X2ma+DihzOyHxYwzEo/bH3H1mERPSZkcC0cm1czCOnJJGd/mJicu4ukRtxMsLfXt8UL78l7IEHSt X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:4443:: with SMTP id l3mr356156qvt.53.1604534564913; Wed, 04 Nov 2020 16:02:44 -0800 (PST) Date: Thu, 5 Nov 2020 01:02:14 +0100 In-Reply-To: Message-Id: <16e48c6ca3f6ea0cb80d3555723a723bef85270d.1604534322.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH 04/20] kasan, arm64: 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-20201105_000349_117175_B775CC15 X-CRM114-Status: GOOD ( 14.89 ) 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 , Andrey Konovalov , Kevin Brodsky , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Andrey Ryabinin , Andrew Morton , 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 --- 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 42a556c5d67c..2c37a39b76ed 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -74,8 +74,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); @@ -120,8 +118,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) {} @@ -173,6 +169,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) {