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: 11895645 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 263B4138B for ; Tue, 10 Nov 2020 22:20:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D3359206B2 for ; Tue, 10 Nov 2020 22:20:41 +0000 (UTC) Authentication-Results: mail.kernel.org; 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 D3359206B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 680E26B007B; Tue, 10 Nov 2020 17:20:40 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 59A8C6B007D; Tue, 10 Nov 2020 17:20:40 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 486826B007E; Tue, 10 Nov 2020 17:20:40 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0228.hostedemail.com [216.40.44.228]) by kanga.kvack.org (Postfix) with ESMTP id 110B16B007B for ; Tue, 10 Nov 2020 17:20:40 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B699A181AEF10 for ; Tue, 10 Nov 2020 22:20:39 +0000 (UTC) X-FDA: 77469928998.21.mark58_5300170272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 6FAA2180442C0 for ; Tue, 10 Nov 2020 22:20:39 +0000 (UTC) X-Spam-Summary: 1,0,0,fe65eef9cd8ed5c1,d41d8cd98f00b204,3nhkrxwokcaslyo2p9vy6wrzzrwp.nzxwty58-xxv6lnv.z2r@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:966:967:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:1981:2194:2196:2198:2199:2200:2201:2393:2525:2553:2559:2563:2682:2685:2731:2859:2896:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3354:3865:3866:3867:3868:3870:3871:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4118:4250:4321:4385:4425:4605:5007:6261:6653:6742:7875:8603:8660:9025:9592:9969:10004:10400:11026:11473:11657:11658:11914:12043:12295:12296:12297:12438:12555:12679:12895:12986:13148:13161:13180:13229:13230:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21939:21990:30003:30054:30090,0,RBL:209.85.222.201:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yrmqdw4p5qd8zkfkx7sjmn54e5 topysm9p X-HE-Tag: mark58_5300170272f8 X-Filterd-Recvd-Size: 7151 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:20:38 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id w4so186369qki.20 for ; Tue, 10 Nov 2020 14:20:38 -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=D1Jw+/fOFkG/nkGg27dhce/b2FxMT/pwR0y2OuhFhk/+MTr6ramjeqfOvuL63JlEwY pbo9iQYQ15JDOT3JYKKu/WQWf86H1ilwLvggiYiNeOc5ZHbKeQaIZqU2R2Q8mBz58el/ s2cKND9r2NJkNxHvowpU2TyuwEGsqIySckfECOWx/6JbvYwydh8dlDxXLj+DqtR4BJP2 a6AncKnfnvL/BZz1deR7BFDU7/91qAwruzpn2MZvnYUipOqe5cldnY8tRLuq02149ZO0 IWh5+ykXXtD1D+Ew9q6c6FXMsfDtaSTxSaqLlpPLuQvceGTJkjjQD4LJLhDjYGX2ZbzS qzzg== X-Gm-Message-State: AOAM5309Z8AMj/Qj/Tu/GdqocFHo2cNBct/YhnLGoMUtGIPIycW1a0ji 4S4J7rA1tdmwQipwL5zJlCbBlicUQMR6xiu3 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 Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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) {