Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp22856pxb; Thu, 7 Jan 2021 20:12:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXiK2PNM4cFdwbTqrOJ37M2fJFy+Ge6scEw+BWtwZ1bR6Yvi/v1N6BNotWJ54PHb5guqW2 X-Received: by 2002:a17:906:4c85:: with SMTP id q5mr1377820eju.375.1610079120606; Thu, 07 Jan 2021 20:12:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610079120; cv=none; d=google.com; s=arc-20160816; b=AC2mwbXpd9O/qGmUeHCx09v01GecrU6jNvHyyShTCe3VhJfQmYOm/ZYEK8eujUWFJT 0MdsZSq3rs2jjlpOPbT1ZZj77XSYieq/9YIhiGsXtSEjY2IbdaXvDLFNTcy1u4KWttpS yLfsSM8hHBJIwZyD1fYy8onLnqrkEwsUYqzWuhrWx14bmWqDcOOFKQAx5Ts4rxXAG5Bj MRtqGfibQNlj3eCzHkW3jawYKilZURRErUiH+F9ptwAFCSgb62muPzvBbj/n2SymDxiC 4RuOlXoqkBEWPw6+Q2JJiGcfMEUg87T5wK24Wl3psqaqEAGLX9LeKpJGK4bBwCNvjGMA 0TBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=YNx5mVZPUPmOS4xpBXmTyHhhhBm5xCadXkxbs/3brdI=; b=S7ms2+4nBOlwN69w+UmEL7i5u6I/N465H2kJBHoP7iodFVy9cHzktB5xjclkz4RuzY pLBCAB7Kj+E+9KRXxsgUJy/6i3d1W1KTEd8f5HvSY2e7Q0Rlg1DJXH9V43zhzWpNwLRi Uf6Gs6IPgyWdnqPJ0hGgWAyA7fepuQhyZE5EpGcoWtmwFd0gVz6QM1gwrqanUAM4JfNm OSAyOlLKqkoYi1QGBZcRcIDrKX8A4J+/oDYmD8e296STDpu5f6WhYE0roVwgXZ28FFQg 5R4UcpZo5QDyfqD+eWs3ud/Grukp3UrW/RZMQrGyucy4MMPf+HJ1PtqP2wtV/DY5CAkJ Q2kw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h8si3027011ejf.491.2021.01.07.20.11.36; Thu, 07 Jan 2021 20:12:00 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726703AbhAHEKa (ORCPT + 99 others); Thu, 7 Jan 2021 23:10:30 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:48986 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726600AbhAHEKa (ORCPT ); Thu, 7 Jan 2021 23:10:30 -0500 X-UUID: 95460ae080ac436fa08532eb34eb7458-20210108 X-UUID: 95460ae080ac436fa08532eb34eb7458-20210108 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 438929673; Fri, 08 Jan 2021 12:09:44 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 8 Jan 2021 12:09:41 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 8 Jan 2021 12:09:41 +0800 From: Walter Wu To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Andrey Konovalov , Andrew Morton , Nathan Chancellor CC: , , , , wsd_upstream , , Walter Wu Subject: [PATCH v3] kasan: remove redundant config option Date: Fri, 8 Jan 2021 12:09:40 +0800 Message-ID: <20210108040940.1138-1-walter-zh.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: A0BC49EDB6B8B99BD15B778B5C0058C077F8B25104FB38FF69F13199E1903C002000:8 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org CONFIG_KASAN_STACK and CONFIG_KASAN_STACK_ENABLE both enable KASAN stack instrumentation, but we should only need one config, so that we remove CONFIG_KASAN_STACK_ENABLE and make CONFIG_KASAN_STACK workable. see [1]. When enable KASAN stack instrumentation, then for gcc we could do no prompt and default value y, and for clang prompt and default value n. [1]: https://bugzilla.kernel.org/show_bug.cgi?id=210221 Signed-off-by: Walter Wu Suggested-by: Dmitry Vyukov Cc: Andrey Ryabinin Cc: Dmitry Vyukov Cc: Andrey Konovalov Cc: Alexander Potapenko Cc: Andrew Morton Cc: Nathan Chancellor --- v2: make commit log to be more readable. v3: remain CONFIG_KASAN_STACK_ENABLE setting fix the pre-processors syntax --- arch/arm64/kernel/sleep.S | 2 +- arch/x86/kernel/acpi/wakeup_64.S | 2 +- include/linux/kasan.h | 2 +- lib/Kconfig.kasan | 8 ++------ mm/kasan/common.c | 2 +- mm/kasan/kasan.h | 2 +- mm/kasan/report_generic.c | 2 +- scripts/Makefile.kasan | 10 ++++++++-- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kernel/sleep.S b/arch/arm64/kernel/sleep.S index 6bdef7362c0e..7c44ede122a9 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 -#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK +#if defined(CONFIG_KASAN) && defined(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 5d3a0b8fd379..c7f412f4e07d 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 -#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK +#if defined(CONFIG_KASAN) && defined(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 5e0655fb2a6f..35d1e9b2cbfa 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -302,7 +302,7 @@ static inline void kasan_kfree_large(void *ptr, unsigned long ip) {} #endif /* CONFIG_KASAN */ -#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK +#if defined(CONFIG_KASAN) && defined(CONFIG_KASAN_STACK) void kasan_unpoison_task_stack(struct task_struct *task); #else static inline void kasan_unpoison_task_stack(struct task_struct *task) {} diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index f5fa4ba126bf..fde82ec85f8f 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -138,9 +138,10 @@ config KASAN_INLINE endchoice -config KASAN_STACK_ENABLE +config KASAN_STACK bool "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && !COMPILE_TEST depends on KASAN_GENERIC || KASAN_SW_TAGS + default y if CC_IS_GCC help The LLVM stack address sanitizer has a know problem that causes excessive stack usage in a lot of functions, see @@ -154,11 +155,6 @@ config KASAN_STACK_ENABLE CONFIG_COMPILE_TEST. On gcc it is assumed to always be safe to use and enabled by default. -config KASAN_STACK - int - default 1 if KASAN_STACK_ENABLE || CC_IS_GCC - default 0 - config KASAN_SW_TAGS_IDENTIFY bool "Enable memory corruption identification" depends on KASAN_SW_TAGS diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 38ba2aecd8f4..bf8b073eed62 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -63,7 +63,7 @@ void __kasan_unpoison_range(const void *address, size_t size) unpoison_range(address, size); } -#if CONFIG_KASAN_STACK +#ifdef CONFIG_KASAN_STACK /* Unpoison the entire stack for a task. */ void kasan_unpoison_task_stack(struct task_struct *task) { diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index cc4d9e1d49b1..bdfdb1cff653 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -224,7 +224,7 @@ void *find_first_bad_addr(void *addr, size_t size); const char *get_bug_type(struct kasan_access_info *info); void metadata_fetch_row(char *buffer, void *row); -#if defined(CONFIG_KASAN_GENERIC) && CONFIG_KASAN_STACK +#if defined(CONFIG_KASAN_GENERIC) && defined(CONFIG_KASAN_STACK) void print_address_stack_frame(const void *addr); #else static inline void print_address_stack_frame(const void *addr) { } diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c index 8a9c889872da..4e16518d9877 100644 --- a/mm/kasan/report_generic.c +++ b/mm/kasan/report_generic.c @@ -128,7 +128,7 @@ void metadata_fetch_row(char *buffer, void *row) memcpy(buffer, kasan_mem_to_shadow(row), META_BYTES_PER_ROW); } -#if CONFIG_KASAN_STACK +#ifdef CONFIG_KASAN_STACK static bool __must_check tokenize_frame_descr(const char **frame_descr, char *token, size_t max_tok_len, unsigned long *value) diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan index 1e000cc2e7b4..abf231d209b1 100644 --- a/scripts/Makefile.kasan +++ b/scripts/Makefile.kasan @@ -2,6 +2,12 @@ CFLAGS_KASAN_NOSANITIZE := -fno-builtin KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET) +ifdef CONFIG_KASAN_STACK + stack_enable := 1 +else + stack_enable := 0 +endif + ifdef CONFIG_KASAN_GENERIC ifdef CONFIG_KASAN_INLINE @@ -27,7 +33,7 @@ else CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \ $(call cc-param,asan-globals=1) \ $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \ - $(call cc-param,asan-stack=$(CONFIG_KASAN_STACK)) \ + $(call cc-param,asan-stack=$(stack_enable)) \ $(call cc-param,asan-instrument-allocas=1) endif @@ -42,7 +48,7 @@ else endif CFLAGS_KASAN := -fsanitize=kernel-hwaddress \ - -mllvm -hwasan-instrument-stack=$(CONFIG_KASAN_STACK) \ + -mllvm -hwasan-instrument-stack=$(stack_enable) \ -mllvm -hwasan-use-short-granules=0 \ $(instrumentation_flags) -- 2.18.0