Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp530091pxb; Fri, 8 Jan 2021 11:01:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyPgM7Z0CT1ZtYp6uYuo8al1lGKu5Xd7sTfy+5RxuY6id4rlMFQodtdr8yPf9fnohlEVkFx X-Received: by 2002:a17:906:e247:: with SMTP id gq7mr3685185ejb.27.1610132474228; Fri, 08 Jan 2021 11:01:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610132474; cv=none; d=google.com; s=arc-20160816; b=vx9YTu5T/+n1AEqQ+9jy3C0RB4UElt+pr3iQaF/J7zMRnEgYUPnPWNHjb+4KUFGUke g2bvqCbzWqlhekrLpnFTAFyyyYhyz+AHrkhJ1WVrwk4gIm7sKMaoMvdt7W9o4yMqC31H wtxZ81R+SXBS1iNGgqMr/zDJVtx9Xhz/nm59NmfnXgOKkjEsOMdwWM8Bb1i4d4IjS6V0 TCSYX63ELK5PU+aIEo7RUObpzUS+qbL7ewdFI/6bNvWInhRQdQodSy3tSBUt8Q+bRWJi w1VtdBxecL7Pow06DJ9yvOJdO/HRKyKyVDhDeJhdZx+YhmYQ8c6subto6j5GtnF8vGqy jOog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=GU+9P9R4Nfik1tMFFGFZP2iMEdTwiDCN49DQfnWs2Fg=; b=QqLeR18r/hcHSVMoBKQZb7voGtxF/NowRIS7X/hck/rJc2WZOKvnhreQjmJqGvfPOi 4EoG0AA8X6ykegZUO9SEYRiuZfEeqgIBVWmc5QI7/csSRy6kGuAxV7U66OwxuowhzmGS cjLoVLDU2OU1IyMUyswz3kF1Q0lKpf/R4VnR/xMFjoWOijV3opNl/L7H70VdGXkxufJO x9AfZjhWfavwu0hOWS6bxt2cIYvsxLYg0zF8/a5p0YnP61RdGjS0N8IZzMX7RRnd6wft t7dJ4aNievLH4QUqQUjnCD5fU3iZSzYWYBEHbRSlB+D4su1taPpj5koGnQt2M/vzSuSr OR9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=rI9Nkb8R; 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 kt6si3773493ejb.378.2021.01.08.11.00.50; Fri, 08 Jan 2021 11:01:14 -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=rI9Nkb8R; 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 S1728649AbhAHS5M (ORCPT + 99 others); Fri, 8 Jan 2021 13:57:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726059AbhAHS5M (ORCPT ); Fri, 8 Jan 2021 13:57:12 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2C90C061380 for ; Fri, 8 Jan 2021 10:56:31 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id q20so3538027pfu.8 for ; Fri, 08 Jan 2021 10:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GU+9P9R4Nfik1tMFFGFZP2iMEdTwiDCN49DQfnWs2Fg=; b=rI9Nkb8RfNTcTNbl8NxZxLJ39gag+j+T/gQqjA5/GLP8/a6JWhmsyDjiHIujKO31pX WexouWXBO2fBxlvSWK+GPUAusO6MvbVgF5lhXzUcQQQK21DNH/bM0KIQuT7kOcPn/zOt BKyBvSIi3uajiYuS5vTWMdSzxaECBh3Hbhem3N44/iKt4+ok9fVmqu7JOmyOtrktI8/C 0hqcQ5cv7QqwytzTCvxrlktKxVqSoWQ6TRHOEYgqk5ooC3JeBTefaGAL0vg09qcg6mqC 2Ki51DivAFOtIZjQ34u2xZ/hLPodMNtEJMz5bLVkAwwromMV56RD0betFF9tXYDP/gTB 7J6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GU+9P9R4Nfik1tMFFGFZP2iMEdTwiDCN49DQfnWs2Fg=; b=VJflRui/bknGpSWLVZAJEBtar7/7qk+nQaknUV7uoHAXRbVeaD/tTbBpO1pZOGEvHr TZ6BSDXe/Gdj/nkE2SNOy9zDulmNlajVKE9/rWh50DfERUipCkyj6i/PzrVOjkDKXA0O Q6C+9etrYl1hO7z+bEpxBIqbnaK6cLdtNfVXXn4wOWj0N4NcD6px1jx8Xl8efZ7XtrE+ npwqYTBrVmnr8rCwRysfuFQQ8qgTuD3G3CS46vhnu9yy14IpocFeqShC1cCvQdRNFP/Z +sqYGS6iXD2eSoCO5OTSqzHX4uoXn9PR3st0rWZ8aqDI9HeJtYm2lHI9fZxrOnx/eByX BckQ== X-Gm-Message-State: AOAM533qi0zcD8vf/9NrZJLcWaBpbiJy6h6oPiIrAIYEk+CldkK79SXs z4eghv3NcD05UNva6hJ0/yxMDM8+Qcn9z2SHMZwGAg== X-Received: by 2002:a62:e309:0:b029:1ae:5b4a:3199 with SMTP id g9-20020a62e3090000b02901ae5b4a3199mr5032496pfh.24.1610132191222; Fri, 08 Jan 2021 10:56:31 -0800 (PST) MIME-Version: 1.0 References: <20210108040940.1138-1-walter-zh.wu@mediatek.com> In-Reply-To: <20210108040940.1138-1-walter-zh.wu@mediatek.com> From: Andrey Konovalov Date: Fri, 8 Jan 2021 19:56:20 +0100 Message-ID: Subject: Re: [PATCH v3] kasan: remove redundant config option To: Walter Wu , Arnd Bergmann Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Andrew Morton , Nathan Chancellor , kasan-dev , Linux Memory Management List , LKML , Linux ARM , wsd_upstream , linux-mediatek@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 8, 2021 at 5:09 AM Walter Wu wrote: > > 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 AFAIR, Arnd wanted to avoid having KASAN_STACK to be enabled by default when compiling with Clang, since Clang instrumentation leads to very large kernel stacks, which, in turn, lead to compile-time warnings. What I don't remember is why there are two configs. Arnd, is that correct? What was the reason behind having two configs?