Skip to contentSkip to conversation

kasan: turn off asan-stack for clang-8 and earlier

PATCH Superseded Arnd Bergmann 8 participants 22 messages Feb 19, 2019 – Feb 21, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kasan: turn off asan-stack for clang-8 and earlier

Building an arm64 allmodconfig kernel with clang results in over 140 warnings about overly large stack frames, the worst ones being:

drivers/gpu/drm/panel/panel-sitronix-st7789v.c:196:12: error: stack frame size of 20224 bytes in function 'st7789v_prepare' drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td028ttec1.c:196:12: error: stack frame size of 13120 bytes in function 'td028ttec1_panel_enable' drivers/usb/host/max3421-hcd.c:1395:1: error: stack frame size of 10048 bytes in function 'max3421_spi_thread' drivers/net/wan/slic_ds26522.c:209:12: error: stack frame size of 9664 bytes in function 'slic_ds26522_probe' drivers/crypto/ccp/ccp-ops.c:2434:5: error: stack frame size of 8832 bytes in function 'ccp_run_cmd' drivers/media/dvb-frontends/stv0367.c:1005:12: error: stack frame size of 7840 bytes in function 'stv0367ter_algo'

None of these happen with gcc today, and almost all of these are the result of a single known bug in llvm. Hopefully it will eventually get fixed with the clang-9 release.

In the meantime, the best idea I have is to turn off asan-stack for clang-8 and earlier, so we can produce a kernel that is safe to run.

I have posted three patches that address the frame overflow warnings that are not addressed by turning off asan-stack, so in combination with this change, we get much closer to a clean allmodconfig build, which in turn is necessary to do meaningful build regression testing.

---
 lib/Kconfig.kasan      | 13 +++++++++++++
 scripts/Makefile.kasan |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)
lib/Kconfig.kasan +13 -0
index 67d7d1309c52..219cddc913ac 100644
@@ -103,6 +103,19 @@ config KASAN_INLINE
 
 endchoice
 
+config KASAN_STACK
+	int
+	default 0 if CC_IS_CLANG && (CLANG_VERSION < 90000)
+	default 1
+	help
+	  The LLVM stack address sanitizer has a know bug that
+	  causes excessive stack usage in a lot of functions, see
+	  https://bugs.llvm.org/show_bug.cgi?id=38809
+	  Disabling asan-stack makes it safe to run kernels build
+	  with clang-8 with KASAN enabled, though it loses some of
+	  the functionality.  We assume that clang-9 will have a fix,
+	  so the feature can be used.
+
 config KASAN_S390_4_LEVEL_PAGING
 	bool "KASan: use 4-level paging"
 	depends on KASAN && S390
scripts/Makefile.kasan +1 -1
index f1fb8e502657..6410bd22fe38 100644
@@ -26,7 +26,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=1) \
+	 $(call cc-param,asan-stack=$(CONFIG_KASAN_STACK)) \
 	 $(call cc-param,asan-instrument-allocas=1)
 endif
 
Signature · 1 line
2.20.0
#1 lore raw
Quoted 21 lines · Arnd Bergmann

Building an arm64 allmodconfig kernel with clang results in over 140 warnings about overly large stack frames, the worst ones being:

drivers/gpu/drm/panel/panel-sitronix-st7789v.c:196:12: error: stack frame size of 20224 bytes in function 'st7789v_prepare' drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td028ttec1.c:196:12:
error: stack frame size of 13120 bytes in function 'td028ttec1_panel_enable' drivers/usb/host/max3421-hcd.c:1395:1: error: stack frame size of 10048 bytes in function 'max3421_spi_thread' drivers/net/wan/slic_ds26522.c:209:12: error: stack frame size of 9664 bytes in function 'slic_ds26522_probe' drivers/crypto/ccp/ccp-ops.c:2434:5: error: stack frame size of 8832 bytes in function 'ccp_run_cmd' drivers/media/dvb-frontends/stv0367.c:1005:12: error: stack frame size of 7840 bytes in function 'stv0367ter_algo'

None of these happen with gcc today, and almost all of these are the result of a single known bug in llvm.  Hopefully it will eventually get fixed with the
clang-9 release.

Quoted 7 lines

In the meantime, the best idea I have is to turn off asan-stack for clang-8 and earlier, so we can produce a kernel that is safe to run.

I have posted three patches that address the frame overflow warnings that are not addressed by turning off asan-stack, so in combination with this change, we get much closer to a clean allmodconfig build, which in turn is necessary to do meaningful build regression testing.

Well, I am using clang 8.0 on arm64 and running the kernel just fine for a few weeks now and never trigger a single stack overflow (THREAD_SHIFT = 15) because I never use any of those drivers you mentioned above. I don't think it is a good idea to blankly remove the testing coverage here and affect people don't use all those offensive functions at all.

#2 lore raw

+ Evgenii, Kostya for KASAN

Quoted 18 lines · Qian Cai
Quoted 16 lines · Arnd Bergmann

Building an arm64 allmodconfig kernel with clang results in over 140 warnings about overly large stack frames, the worst ones being:

drivers/gpu/drm/panel/panel-sitronix-st7789v.c:196:12: error: stack frame size of 20224 bytes in function 'st7789v_prepare' drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td028ttec1.c:196:12:
error: stack frame size of 13120 bytes in function 'td028ttec1_panel_enable' drivers/usb/host/max3421-hcd.c:1395:1: error: stack frame size of 10048 bytes in function 'max3421_spi_thread' drivers/net/wan/slic_ds26522.c:209:12: error: stack frame size of 9664 bytes in function 'slic_ds26522_probe' drivers/crypto/ccp/ccp-ops.c:2434:5: error: stack frame size of 8832 bytes in function 'ccp_run_cmd' drivers/media/dvb-frontends/stv0367.c:1005:12: error: stack frame size of 7840 bytes in function 'stv0367ter_algo'

Quoted 4 lines
Quoted 4 lines

None of these happen with gcc today, and almost all of these are the result of a single known bug in llvm. Hopefully it will eventually get fixed with the
clang-9 release.

Would it be better to disable outright if CC_IS_CLANG, then go back and adjust it once we know explicitly which version it lands in? (Maybe I'm being too pessimistic about when it may be fixed).

Quoted 9 lines
Quoted 8 lines

In the meantime, the best idea I have is to turn off asan-stack for clang-8 and earlier, so we can produce a kernel that is safe to run.

I have posted three patches that address the frame overflow warnings that are not addressed by turning off asan-stack, so in combination with this change, we get much closer to a clean allmodconfig build, which in turn is necessary to do meaningful build regression testing.

Quoted 5 lines

Well, I am using clang 8.0 on arm64 and running the kernel just fine for a few weeks now and never trigger a single stack overflow (THREAD_SHIFT = 15) because I never use any of those drivers you mentioned above. I don't think it is a good idea to blankly remove the testing coverage here and affect people don't use all those offensive functions at all.

Thanks for the patch, Arnd! Hopefully we can fix that up in Clang soon. Qian, I guess the alternative would be to add -mllvm -asan-stack=0 on potentially up to 140 Makefiles?

Signature · 2 lines
Thanks,
~Nick Desaulniers
#3 lore raw
Quoted 26 lines · Nick Desaulniers

+ Evgenii, Kostya for KASAN

Quoted 22 lines · Qian Cai
Quoted 20 lines · Arnd Bergmann

Building an arm64 allmodconfig kernel with clang results in over 140 warnings about overly large stack frames, the worst ones being:

drivers/gpu/drm/panel/panel-sitronix-st7789v.c:196:12: error: stack frame size of 20224 bytes in function 'st7789v_prepare' drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td028ttec1.c:196:12:
error: stack frame size of 13120 bytes in function 'td028ttec1_panel_enable' drivers/usb/host/max3421-hcd.c:1395:1: error: stack frame size of 10048 bytes in function 'max3421_spi_thread' drivers/net/wan/slic_ds26522.c:209:12: error: stack frame size of 9664 bytes in function 'slic_ds26522_probe' drivers/crypto/ccp/ccp-ops.c:2434:5: error: stack frame size of 8832 bytes in function 'ccp_run_cmd' drivers/media/dvb-frontends/stv0367.c:1005:12: error: stack frame size of 7840 bytes in function 'stv0367ter_algo'

None of these happen with gcc today, and almost all of these are the result of a single known bug in llvm. Hopefully it will eventually get fixed with the
clang-9 release.

I am not confident we can fix this in clang.
The difference between gcc and clang, AFAICT, is not in the asan instrumentation, but in inining.
Looking at the reproducer from https://bugs.llvm.org/show_bug.cgi?id=38809#c4,
if I change ltv350qv_write_reg to always inline, gcc also produces a huge 10K stack frame,
and making it noinline fixes the stack frame for both gcc and clang.

Quoted 27 lines

Would it be better to disable outright if CC_IS_CLANG, then go back and adjust it once we know explicitly which version it lands in? (Maybe I'm being too pessimistic about when it may be fixed).

Quoted 9 lines
Quoted 8 lines

In the meantime, the best idea I have is to turn off asan-stack for clang-8 and earlier, so we can produce a kernel that is safe to run.

I have posted three patches that address the frame overflow warnings that are not addressed by turning off asan-stack, so in combination with this change, we get much closer to a clean allmodconfig build, which in turn is necessary to do meaningful build regression testing.

Quoted 5 lines

Well, I am using clang 8.0 on arm64 and running the kernel just fine for a few weeks now and never trigger a single stack overflow (THREAD_SHIFT = 15) because I never use any of those drivers you mentioned above. I don't think it is a good idea to blankly remove the testing coverage here and affect people don't use all those offensive functions at all.

Thanks for the patch, Arnd! Hopefully we can fix that up in Clang soon. Qian, I guess the alternative would be to add -mllvm -asan-stack=0 on potentially up to 140 Makefiles?

--
Thanks,
~Nick Desaulniers

#4 lore raw
Quoted 9 lines · Kostya Serebryany
Quoted 9 lines
Quoted 5 lines

Well, I am using clang 8.0 on arm64 and running the kernel just fine for a few weeks now and never trigger a single stack overflow (THREAD_SHIFT = 15) because I never use any of those drivers you mentioned above. I don't think it is a good idea to blankly remove the testing coverage here and affect people don't use all those offensive functions at all.

Thanks for the patch, Arnd! Hopefully we can fix that up in Clang soon. Qian, I guess the alternative would be to add -mllvm -asan-stack=0 on potentially up to 140 Makefiles?

Depends on the exact stack consumption of those 140 functions. For example, I don't care if you turn-off -asan-stack if the current stack size is < 32k.

For those functions always consume like a lot of stack like 8k or more, fix them in Makefile if not too many of them.

reviewer
#5 lore raw
In reply to Kostya Serebryany
Quoted 30 lines · Kostya Serebryany
Quoted 26 lines · Nick Desaulniers

+ Evgenii, Kostya for KASAN

Quoted 22 lines · Qian Cai
Quoted 20 lines · Arnd Bergmann

Building an arm64 allmodconfig kernel with clang results in over 140 warnings about overly large stack frames, the worst ones being:

drivers/gpu/drm/panel/panel-sitronix-st7789v.c:196:12: error: stack frame size of 20224 bytes in function 'st7789v_prepare' drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td028ttec1.c:196:12:
error: stack frame size of 13120 bytes in function 'td028ttec1_panel_enable' drivers/usb/host/max3421-hcd.c:1395:1: error: stack frame size of 10048 bytes in function 'max3421_spi_thread' drivers/net/wan/slic_ds26522.c:209:12: error: stack frame size of 9664 bytes in function 'slic_ds26522_probe' drivers/crypto/ccp/ccp-ops.c:2434:5: error: stack frame size of 8832 bytes in function 'ccp_run_cmd' drivers/media/dvb-frontends/stv0367.c:1005:12: error: stack frame size of 7840 bytes in function 'stv0367ter_algo'

None of these happen with gcc today, and almost all of these are the result of a single known bug in llvm. Hopefully it will eventually get fixed with the
clang-9 release.

Quoted 7 lines

I am not confident we can fix this in clang.
The difference between gcc and clang, AFAICT, is not in the asan instrumentation, but in inining.
Looking at the reproducer from https://bugs.llvm.org/show_bug.cgi?id=38809#c4,
if I change ltv350qv_write_reg to always inline, gcc also produces a huge 10K stack frame,
and making it noinline fixes the stack frame for both gcc and clang.

Does your gcc have fix for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 ?

For me gcc rejects to inline it:

gcc version 7.3.0 (Debian 7.3.0-5)

$ gcc /tmp/test.c -Wframe-larger-than=128 -c -fsanitize=kernel-address
-O2 --param asan-stack=1
/tmp/test.c:23:13: warning: always_inline function might not be
inlinable [-Wattributes]
 static void ltv350qv_write_reg(void) {
             ^~~~~~~~~~~~~~~~~~
/tmp/test.c: In function ‘ltv350qv_power_on’:
/tmp/test.c:57:1: warning: the frame size of 416 bytes is larger than
128 bytes [-Wframe-larger-than=]
 }
 ^
#6 lore raw
Quoted 42 lines · Dmitry Vyukov
Quoted 30 lines · Kostya Serebryany
Quoted 26 lines · Nick Desaulniers

+ Evgenii, Kostya for KASAN

Quoted 22 lines · Qian Cai
Quoted 20 lines · Arnd Bergmann

Building an arm64 allmodconfig kernel with clang results in over 140 warnings about overly large stack frames, the worst ones being:

drivers/gpu/drm/panel/panel-sitronix-st7789v.c:196:12: error: stack frame size of 20224 bytes in function 'st7789v_prepare' drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td028ttec1.c:196:12:
error: stack frame size of 13120 bytes in function 'td028ttec1_panel_enable' drivers/usb/host/max3421-hcd.c:1395:1: error: stack frame size of 10048 bytes in function 'max3421_spi_thread' drivers/net/wan/slic_ds26522.c:209:12: error: stack frame size of 9664 bytes in function 'slic_ds26522_probe' drivers/crypto/ccp/ccp-ops.c:2434:5: error: stack frame size of 8832 bytes in function 'ccp_run_cmd' drivers/media/dvb-frontends/stv0367.c:1005:12: error: stack frame size of 7840 bytes in function 'stv0367ter_algo'

None of these happen with gcc today, and almost all of these are the result of a single known bug in llvm. Hopefully it will eventually get fixed with the
clang-9 release.

Quoted 7 lines

I am not confident we can fix this in clang.
The difference between gcc and clang, AFAICT, is not in the asan instrumentation, but in inining.
Looking at the reproducer from https://bugs.llvm.org/show_bug.cgi?id=38809#c4,
if I change ltv350qv_write_reg to always inline, gcc also produces a huge 10K stack frame,
and making it noinline fixes the stack frame for both gcc and clang.

Does your gcc have fix for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 ?

Quoted 8 lines

For me gcc rejects to inline it:

gcc version 7.3.0 (Debian 7.3.0-5)

$ gcc /tmp/test.c -Wframe-larger-than=128 -c -fsanitize=kernel-address
-O2 --param asan-stack=1
/tmp/test.c:23:13: warning: always_inline function might not be
inlinable [-Wattributes]

I don't see that warning here

Quoted 6 lines
 static void ltv350qv_write_reg(void) {
             ^~~~~~~~~~~~~~~~~~

/tmp/test.c: In function ‘ltv350qv_power_on’:
/tmp/test.c:57:1: warning: the frame size of 416 bytes is larger than 128 bytes [-Wframe-larger-than=]
}

but I also see the small stack size here: https://godbolt.org/z/Uz5Ruv

gcc definitely inlines the function here but only has one copy of spi_message and spi_transfer on the stack, while clang inserts a call to __asan_report_store8_noabort() and has one copy per inlined call to ltv350qv_write_reg().

Arnd

#7 lore raw
In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

Building an arm64 allmodconfig kernel with clang results in over 140 warnings about overly large stack frames, the worst ones being:

drivers/gpu/drm/panel/panel-sitronix-st7789v.c:196:12: error: stack frame size of 20224 bytes in function 'st7789v_prepare' drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td028ttec1.c:196:12: error: stack frame size of 13120 bytes in function 'td028ttec1_panel_enable' drivers/usb/host/max3421-hcd.c:1395:1: error: stack frame size of 10048 bytes in function 'max3421_spi_thread' drivers/net/wan/slic_ds26522.c:209:12: error: stack frame size of 9664 bytes in function 'slic_ds26522_probe' drivers/crypto/ccp/ccp-ops.c:2434:5: error: stack frame size of 8832 bytes in function 'ccp_run_cmd' drivers/media/dvb-frontends/stv0367.c:1005:12: error: stack frame size of 7840 bytes in function 'stv0367ter_algo'

Quoted 6 lines

None of these happen with gcc today, and almost all of these are the result of a single known bug in llvm. Hopefully it will eventually get fixed with the clang-9 release.

In the meantime, the best idea I have is to turn off asan-stack for clang-8 and earlier, so we can produce a kernel that is safe to run.

Hi Arnd,

I don't think it's good to disable KASAN stack instrumentation for the whole kernel by default with clang. It makes more sense to disable stack instrumentation only for these few drivers.

Thanks!

Quoted 58 lines

I have posted three patches that address the frame overflow warnings that are not addressed by turning off asan-stack, so in combination with this change, we get much closer to a clean allmodconfig build, which in turn is necessary to do meaningful build regression testing.

---
 lib/Kconfig.kasan      | 13 +++++++++++++
 scripts/Makefile.kasan |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)
lib/Kconfig.kasan +13 -0
index 67d7d1309c52..219cddc913ac 100644
@@ -103,6 +103,19 @@ config KASAN_INLINE
 
 endchoice
 
+config KASAN_STACK
+       int
+       default 0 if CC_IS_CLANG && (CLANG_VERSION < 90000)
+       default 1
+       help
+         The LLVM stack address sanitizer has a know bug that
+         causes excessive stack usage in a lot of functions, see
+         https://bugs.llvm.org/show_bug.cgi?id=38809
+         Disabling asan-stack makes it safe to run kernels build
+         with clang-8 with KASAN enabled, though it loses some of
+         the functionality.  We assume that clang-9 will have a fix,
+         so the feature can be used.
+
 config KASAN_S390_4_LEVEL_PAGING
        bool "KASan: use 4-level paging"
        depends on KASAN && S390
scripts/Makefile.kasan +1 -2
index f1fb8e502657..6410bd22fe38 100644
@@ -26,7 +26,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=1) \
+        $(call cc-param,asan-stack=$(CONFIG_KASAN_STACK)) \
         $(call cc-param,asan-instrument-allocas=1)
 endif
 
--

2.20.0

#8 lore raw
Quoted 17 lines · Andrey Konovalov
Quoted 15 lines · Arnd Bergmann

Building an arm64 allmodconfig kernel with clang results in over 140 warnings about overly large stack frames, the worst ones being:

drivers/gpu/drm/panel/panel-sitronix-st7789v.c:196:12: error: stack frame size of 20224 bytes in function 'st7789v_prepare' drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td028ttec1.c:196:12: error: stack frame size of 13120 bytes in function 'td028ttec1_panel_enable' drivers/usb/host/max3421-hcd.c:1395:1: error: stack frame size of 10048 bytes in function 'max3421_spi_thread' drivers/net/wan/slic_ds26522.c:209:12: error: stack frame size of 9664 bytes in function 'slic_ds26522_probe' drivers/crypto/ccp/ccp-ops.c:2434:5: error: stack frame size of 8832 bytes in function 'ccp_run_cmd' drivers/media/dvb-frontends/stv0367.c:1005:12: error: stack frame size of 7840 bytes in function 'stv0367ter_algo'

None of these happen with gcc today, and almost all of these are the result of a single known bug in llvm. Hopefully it will eventually get fixed with the clang-9 release.

Quoted 8 lines
Quoted 2 lines

In the meantime, the best idea I have is to turn off asan-stack for clang-8 and earlier, so we can produce a kernel that is safe to run.

Hi Arnd,

I don't think it's good to disable KASAN stack instrumentation for the whole kernel by default with clang. It makes more sense to disable stack instrumentation only for these few drivers.

Do you mean just the 114 files that we get warnings for in allmodconfig, or also those that run into the same bug but stay below the warning limit, and the ones that don't warn in allmodconfig but do warn in other configurations?

I would have to some more research, but I expect several hundred patches before we get to a clean randconfig build with a broken compiler.

Arnd

#9 lore raw
Quoted 27 lines · Arnd Bergmann
Quoted 17 lines · Andrey Konovalov
Quoted 15 lines · Arnd Bergmann

Building an arm64 allmodconfig kernel with clang results in over 140 warnings about overly large stack frames, the worst ones being:

drivers/gpu/drm/panel/panel-sitronix-st7789v.c:196:12: error: stack frame size of 20224 bytes in function 'st7789v_prepare' drivers/video/fbdev/omap2/omapfb/displays/panel-tpo-td028ttec1.c:196:12: error: stack frame size of 13120 bytes in function 'td028ttec1_panel_enable' drivers/usb/host/max3421-hcd.c:1395:1: error: stack frame size of 10048 bytes in function 'max3421_spi_thread' drivers/net/wan/slic_ds26522.c:209:12: error: stack frame size of 9664 bytes in function 'slic_ds26522_probe' drivers/crypto/ccp/ccp-ops.c:2434:5: error: stack frame size of 8832 bytes in function 'ccp_run_cmd' drivers/media/dvb-frontends/stv0367.c:1005:12: error: stack frame size of 7840 bytes in function 'stv0367ter_algo'

None of these happen with gcc today, and almost all of these are the result of a single known bug in llvm. Hopefully it will eventually get fixed with the clang-9 release.

Quoted 8 lines
Quoted 2 lines

In the meantime, the best idea I have is to turn off asan-stack for clang-8 and earlier, so we can produce a kernel that is safe to run.

Hi Arnd,

I don't think it's good to disable KASAN stack instrumentation for the whole kernel by default with clang. It makes more sense to disable stack instrumentation only for these few drivers.

Quoted 8 lines

Do you mean just the 114 files that we get warnings for in allmodconfig, or also those that run into the same bug but stay below the warning limit, and the ones that don't warn in allmodconfig but do warn in other configurations?

I would have to some more research, but I expect several hundred patches before we get to a clean randconfig build with a broken compiler.

Manually maintaining asan-stack parameter for the sake of one broken compiler isn't a great idea either.

Couple alternative suggestions:

1) If we can't fix the problem or the cost of fixing is too high, maybe just hide it? Disable -Wframe-larger-then on pre clang-9 compilers.

2) Fallback cflags. The idea is to try to compile every the file with "-mllvm -asan-stack=1 -Wframe-larger-than=2048 -Werror" at first,
and fallback to "-mllvm -asan-stack=0" if failed. So it would be something similar to $(call cc-option, -mllvm -asan-stack=1 -Wframe-larger-than=2048 -Werror, -mllvm -asan-stack=0) except that "cc-option" tries options only once on some code example while we need to try options on every file that we actually compile.
Honestly, I'm not sure that it's worthy to hack Kbuild engine for that particular use-case.

#10 lore raw
Quoted 8 lines · Andrey Ryabinin
Quoted 4 lines · Arnd Bergmann

On Wed, Feb 20, 2019 at 3:45 PM Andrey Konovalov <[email protected]> wrote:
I would have to some more research, but I expect several hundred patches before we get to a clean randconfig build with a broken compiler.

Manually maintaining asan-stack parameter for the sake of one broken compiler isn't a great idea either.

Quoted 8 lines

Couple alternative suggestions:

1) If we can't fix the problem or the cost of fixing is too high, maybe just hide it? Disable -Wframe-larger-then on pre clang-9 compilers.

2) Fallback cflags. The idea is to try to compile every the file with "-mllvm -asan-stack=1 -Wframe-larger-than=2048 -Werror" at first,
and fallback to "-mllvm -asan-stack=0" if failed. So it would be something similar to $(call cc-option, -mllvm -asan-stack=1 -Wframe-larger-than=2048 -Werror, -mllvm -asan-stack=0) except that "cc-option" tries options only once on some code example while we need to try options on every file that we actually compile.
Honestly, I'm not sure that it's worthy to hack Kbuild engine for that particular use-case.

My original plan was to put this under CONFIG_KASAN_EXTRA to allow you to still enable it in older compilers, but you just removed that option ;-)

Maybe bringing it back would be a compromise? That way it's hidden from all the build testing bots (because of the !CONFIG_COMPILE_TEST dependency), but anyone who really wants it can still have the option, and set CONFIG_FRAME_WARN
to whichever value they like.

Arnd

#11 lore raw

+ Evgenii

Quoted 22 lines · Arnd Bergmann
Quoted 8 lines · Andrey Ryabinin
Quoted 4 lines · Arnd Bergmann

On Wed, Feb 20, 2019 at 3:45 PM Andrey Konovalov <[email protected]> wrote:
I would have to some more research, but I expect several hundred patches before we get to a clean randconfig build with a broken compiler.

Manually maintaining asan-stack parameter for the sake of one broken compiler isn't a great idea either.

Quoted 8 lines

Couple alternative suggestions:

1) If we can't fix the problem or the cost of fixing is too high, maybe just hide it? Disable -Wframe-larger-then on pre clang-9 compilers.

2) Fallback cflags. The idea is to try to compile every the file with "-mllvm -asan-stack=1 -Wframe-larger-than=2048 -Werror" at first,
and fallback to "-mllvm -asan-stack=0" if failed. So it would be something similar to $(call cc-option, -mllvm -asan-stack=1 -Wframe-larger-than=2048 -Werror, -mllvm -asan-stack=0) except that "cc-option" tries options only once on some code example while we need to try options on every file that we actually compile.
Honestly, I'm not sure that it's worthy to hack Kbuild engine for that particular use-case.

My original plan was to put this under CONFIG_KASAN_EXTRA to allow you to still enable it in older compilers, but you just removed that option ;-)

Quoted 7 lines

Maybe bringing it back would be a compromise? That way it's hidden from all the build testing bots (because of the !CONFIG_COMPILE_TEST dependency), but anyone who really wants it can still have the option, and set CONFIG_FRAME_WARN
to whichever value they like.

Arnd

I like Evgenii's idea:
https://bugs.llvm.org/show_bug.cgi?id=38809#c10

Even though something like that wouldn't make the clang-8 train, I think it's ok.

While I myself share Arnd's goal of driving compiler warnings to zero, in general I'd prefer not to disable warning-producing-features or disable warnings outright for cases where we have some ideas of changes we can make to the compiler. There's probably a list now of false warnings produced by old versions of Clang from bugs in Clang that we fixed. I'm not interested in additionally trying to work around those somehow in kernel sources.

Qian previously pointed out that most drivers don't produce this warning under KASAN+Clang. While 114 is a lot, what are the chances that someone NEEDS a KASAN+Clang build to compile warning free and happen to include one of these problematic drivers? And if there is a chance they do observe the warning, are we doing a disservice by disabling the feature (-asan-stack=1) outright for the whole kernel, or disabling the warning (-Wstack-frame-larger-than=) which can flag issues unrelated to KASAN?

To Evgenii's idea, I vote that the compiler is incorrect here, and we shouldn't start turning things off. Evgenii, do you have some sense of how to tune the inliner as you described?

Signature · 2 lines
Thanks,
~Nick Desaulniers
#12 lore raw
Quoted 2 lines · Nick Desaulniers

I like Evgenii's idea:
https://bugs.llvm.org/show_bug.cgi?id=38809#c10

That's a suggestion to tune the inlining heuristics.

Quoted 7 lines

While I myself share Arnd's goal of driving compiler warnings to zero, in general I'd prefer not to disable warning-producing-features or disable warnings outright for cases where we have some ideas of changes we can make to the compiler. There's probably a list now of false warnings produced by old versions of Clang from bugs in Clang that we fixed. I'm not interested in additionally trying to work around those somehow in kernel sources.

We do have infrastructure in the kernel for managing warnings based on compiler version (Arnd was looking at some improvements to that IIRC), if we've got a kernel that builds with a given compiler it's worth looking at tuning what we do with that compiler. If newer versions of the compiler work better or have new options we can turn things on for them.

Quoted 8 lines

Qian previously pointed out that most drivers don't produce this warning under KASAN+Clang. While 114 is a lot, what are the chances that someone NEEDS a KASAN+Clang build to compile warning free and happen to include one of these problematic drivers? And if there is a chance they do observe the warning, are we doing a disservice by disabling the feature (-asan-stack=1) outright for the whole kernel, or disabling the warning (-Wstack-frame-larger-than=) which can flag issues unrelated to KASAN?

People doing treewide work and subsystem maintainers are a reasonably important target for this sort of thing - for example people looking at the kernelci output. It's a lot easier to pay attention to problems if you don't have to wade through large numbers of false positives.

#13 lore raw
Quoted 7 lines · Mark Brown
Quoted 2 lines · Nick Desaulniers

I like Evgenii's idea:
https://bugs.llvm.org/show_bug.cgi?id=38809#c10

That's a suggestion to tune the inlining heuristics.

Yes; but it will also improve KASAN (if feasible).

Quoted 8 lines
Quoted 7 lines

While I myself share Arnd's goal of driving compiler warnings to zero, in general I'd prefer not to disable warning-producing-features or disable warnings outright for cases where we have some ideas of changes we can make to the compiler. There's probably a list now of false warnings produced by old versions of Clang from bugs in Clang that we fixed. I'm not interested in additionally trying to work around those somehow in kernel sources.

Quoted 6 lines

We do have infrastructure in the kernel for managing warnings based on compiler version (Arnd was looking at some improvements to that IIRC), if we've got a kernel that builds with a given compiler it's worth looking at tuning what we do with that compiler. If newer versions of the compiler work better or have new options we can turn things on for them.

so maybe something like (pseudocode):
if kasan && clang && clang_version < 9:
disable -Wframe-larger-than=

If you overrun the stack with KASAN, a warning would be nice, but you'll hopefully find out the hard way at runtime. And that doesn't require up to 114 Makefile changes, which would be kind of obnoxious for this papercut.

Quoted 10 lines
Quoted 9 lines

Qian previously pointed out that most drivers don't produce this warning under KASAN+Clang. While 114 is a lot, what are the chances that someone NEEDS a KASAN+Clang build to compile warning free and happen to include one of these problematic drivers? And if there is a chance they do observe the warning, are we doing a disservice by disabling the feature (-asan-stack=1) outright for the whole kernel, or disabling the warning (-Wstack-frame-larger-than=) which can flag issues unrelated to KASAN?

Quoted 4 lines

People doing treewide work and subsystem maintainers are a reasonably important target for this sort of thing - for example people looking at the kernelci output. It's a lot easier to pay attention to problems if you don't have to wade through large numbers of false positives.

Good point. Current reports are a flood of -Wframe-larger-than= because of KASAN (we've fixed just about everything else), and I have to pick out what's new from that sea of false positives. I would hate for these warnings from KASAN to be the last thing before people start taking clang builds seriously due to false positive warnings.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#14 lore raw
Quoted 11 lines · Nick Desaulniers
Quoted 7 lines · Mark Brown
Quoted 2 lines · Nick Desaulniers

I like Evgenii's idea:
https://bugs.llvm.org/show_bug.cgi?id=38809#c10

That's a suggestion to tune the inlining heuristics.

Yes; but it will also improve KASAN (if feasible).

From my experiments that I cited in the bug report, very few cases seem to actually be the result of different inlining decisions, and those that are tend to be kernel bugs (e.g. in drivers/scsi/bfa/bfa_fcs_lport.c clang reports a larger stack than gcc because it combines two functions that individually use 800 bytes each, but if one calls the other, we use even more stack than the combined function).

In the example in https://bugs.llvm.org/show_bug.cgi?id=38809#c12
(https://godbolt.org/z/ylsGSQ) there is no inlining, yet clang uses over ten times as much stack space as gcc, for reasons I still can't explain. My assumption right now is that the underlying bug causes most of the problems with excessive stack usage in allmodconfig kernels.

Quoted 15 lines
Quoted 8 lines
Quoted 7 lines

While I myself share Arnd's goal of driving compiler warnings to zero, in general I'd prefer not to disable warning-producing-features or disable warnings outright for cases where we have some ideas of changes we can make to the compiler. There's probably a list now of false warnings produced by old versions of Clang from bugs in Clang that we fixed. I'm not interested in additionally trying to work around those somehow in kernel sources.

Quoted 6 lines

We do have infrastructure in the kernel for managing warnings based on compiler version (Arnd was looking at some improvements to that IIRC), if we've got a kernel that builds with a given compiler it's worth looking at tuning what we do with that compiler. If newer versions of the compiler work better or have new options we can turn things on for them.

Quoted 8 lines

so maybe something like (pseudocode):
if kasan && clang && clang_version < 9:
disable -Wframe-larger-than=

If you overrun the stack with KASAN, a warning would be nice, but you'll hopefully find out the hard way at runtime. And that doesn't require up to 114 Makefile changes, which would be kind of obnoxious for this papercut.

That would mean that build testing allmodconfig with clang would ignore all the interesting stack overflow bugs that happen in real user systems without KASAN.

Arnd

#15 lore raw
Quoted 7 lines · Arnd Bergmann

In the example in https://bugs.llvm.org/show_bug.cgi?id=38809#c12
(https://godbolt.org/z/ylsGSQ) there is no inlining, yet clang uses over ten times as much stack space as gcc, for reasons I still can't explain. My assumption right now is that the underlying bug causes most of the problems with excessive stack usage in allmodconfig kernels.

Here is an even more minimal example:

struct s { int i[5]; } f(void);
void g(void) { f(); f();}

https://godbolt.org/z/d_KWkh

It's clear that clang does /something/ here when asan-stack=1 is set, but I fail to see what it is, or why that is necessary.

The output of clang with asan-stack=0 is the expected code, and basically identical to what gcc produces with or without asan-stack.

Arnd

#16 lore raw
Quoted 10 lines · Arnd Bergmann
Quoted 7 lines · Arnd Bergmann

In the example in https://bugs.llvm.org/show_bug.cgi?id=38809#c12
(https://godbolt.org/z/ylsGSQ) there is no inlining, yet clang uses over ten times as much stack space as gcc, for reasons I still can't explain. My assumption right now is that the underlying bug causes most of the problems with excessive stack usage in allmodconfig kernels.

Quoted 4 lines

Here is an even more minimal example:

struct s { int i[5]; } f(void);
void g(void) { f(); f();}

On this example I can see some stupidity that clang/asan is doing. Let me try fixing it and see if it helps bigger cases. Thanks for reducing the case!

This is the input we get in the asan instrumentation:

; Function Attrs: noinline nounwind optnone sanitize_address uwtable define dso_local void @g() #0 {
entry:
%tmp = alloca %struct.s, align 4 <<<<<<<<<<<<<<<<<<<<<<< %tmp1 = alloca %struct.s, align 4
%0 = bitcast %struct.s* %tmp to i8*
call void @llvm.lifetime.start.p0i8(i64 20, i8* %0) #3 call void @f(%struct.s* sret %tmp)
%1 = bitcast %struct.s* %tmp to i8* <<<<<<<<<<<<<<<<<<<<< call void @llvm.lifetime.end.p0i8(i64 20, i8* %1) #3
%2 = bitcast %struct.s* %tmp1 to i8*
call void @llvm.lifetime.start.p0i8(i64 20, i8* %2) #3 <<<<<<<<<<<<< call void @f(%struct.s* sret %tmp1)
%3 = bitcast %struct.s* %tmp1 to i8*
call void @llvm.lifetime.end.p0i8(i64 20, i8* %3) #3
ret void
}

the stack variables are not *really* used, but since they are "used" inside the lifetime markers they are not eliminated by asan,
and so asan instruments them, after which no one can remove them any more...

Quoted 11 lines

https://godbolt.org/z/d_KWkh

It's clear that clang does /something/ here when asan-stack=1 is set, but I fail to see what it is, or why that is necessary.

The output of clang with asan-stack=0 is the expected code, and basically identical to what gcc produces with or without asan-stack.

Arnd

#17 lore raw
Quoted 32 lines · Kostya Serebryany
Quoted 10 lines · Arnd Bergmann
Quoted 7 lines · Arnd Bergmann

In the example in https://bugs.llvm.org/show_bug.cgi?id=38809#c12
(https://godbolt.org/z/ylsGSQ) there is no inlining, yet clang uses over ten times as much stack space as gcc, for reasons I still can't explain. My assumption right now is that the underlying bug causes most of the problems with excessive stack usage in allmodconfig kernels.

Quoted 4 lines

Here is an even more minimal example:

struct s { int i[5]; } f(void);
void g(void) { f(); f();}

On this example I can see some stupidity that clang/asan is doing. Let me try fixing it and see if it helps bigger cases. Thanks for reducing the case!

This is the input we get in the asan instrumentation:

; Function Attrs: noinline nounwind optnone sanitize_address uwtable define dso_local void @g() #0 {
entry:
%tmp = alloca %struct.s, align 4 <<<<<<<<<<<<<<<<<<<<<<< %tmp1 = alloca %struct.s, align 4
%0 = bitcast %struct.s* %tmp to i8*
call void @llvm.lifetime.start.p0i8(i64 20, i8* %0) #3 call void @f(%struct.s* sret %tmp)
%1 = bitcast %struct.s* %tmp to i8* <<<<<<<<<<<<<<<<<<<<<

Quoted 8 lines

call void @llvm.lifetime.end.p0i8(i64 20, i8* %1) #3
%2 = bitcast %struct.s* %tmp1 to i8*
call void @llvm.lifetime.start.p0i8(i64 20, i8* %2) #3 <<<<<<<<<<<<< call void @f(%struct.s* sret %tmp1)
%3 = bitcast %struct.s* %tmp1 to i8*
call void @llvm.lifetime.end.p0i8(i64 20, i8* %3) #3
ret void
}

Err.. taking my words back.
These allocas *are* used other then in lifetime markers, since they are passed to f() as 'sret'.
And we can not drop instrumentation for such allocas. Example:

static volatile int zero = 0;
typedef struct {
int ar[5];
} S;
S foo() {
S s;
s.ar[zero + 6] = 42;
return s;
}
int main(int argc, char **argv) {
S s = foo();
return s.ar[argc];
}

% clang -g -O1 -fsanitize=address sret.c && ./a.out

==5822==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffcad027f78 at pc 0x0000004f878d bp 0x7ffcad027f20 sp 0x7ffcad027f18
WRITE of size 4 at 0x7ffcad027f78 thread T0

    #0 0x4f878c in foo sret.c:7:18
    #1 0x4f8838 in main sret.c:11:9
Address 0x7ffcad027f78 is located in stack of thread T0 at offset 56 in frame
    #0 0x4f879f in main sret.c:10

This frame has 1 object(s):

    [32, 52) 's' (line 11) <== Memory access at offset 56 overflows

this variable

Here we have a struct return that needs to be instrumented inside main so that a buffer overflow in foo() is detected.

Now, I am also not confident that the reduced case reflects the real problem.

--kcc

Quoted 19 lines

the stack variables are not *really* used, but since they are "used" inside the lifetime markers they are not eliminated by asan,
and so asan instruments them, after which no one can remove them any more...

Quoted 11 lines

https://godbolt.org/z/d_KWkh

It's clear that clang does /something/ here when asan-stack=1 is set, but I fail to see what it is, or why that is necessary.

The output of clang with asan-stack=0 is the expected code, and basically identical to what gcc produces with or without asan-stack.

Arnd

#18 lore raw
Quoted 43 lines · Kostya Serebryany
Quoted 32 lines · Kostya Serebryany
Quoted 10 lines · Arnd Bergmann
Quoted 7 lines · Arnd Bergmann

In the example in https://bugs.llvm.org/show_bug.cgi?id=38809#c12
(https://godbolt.org/z/ylsGSQ) there is no inlining, yet clang uses over ten times as much stack space as gcc, for reasons I still can't explain. My assumption right now is that the underlying bug causes most of the problems with excessive stack usage in allmodconfig kernels.

Quoted 4 lines

Here is an even more minimal example:

struct s { int i[5]; } f(void);
void g(void) { f(); f();}

On this example I can see some stupidity that clang/asan is doing. Let me try fixing it and see if it helps bigger cases. Thanks for reducing the case!

This is the input we get in the asan instrumentation:

; Function Attrs: noinline nounwind optnone sanitize_address uwtable define dso_local void @g() #0 {
entry:
%tmp = alloca %struct.s, align 4 <<<<<<<<<<<<<<<<<<<<<<< %tmp1 = alloca %struct.s, align 4
%0 = bitcast %struct.s* %tmp to i8*
call void @llvm.lifetime.start.p0i8(i64 20, i8* %0) #3 call void @f(%struct.s* sret %tmp)
%1 = bitcast %struct.s* %tmp to i8* <<<<<<<<<<<<<<<<<<<<<

Quoted 8 lines

call void @llvm.lifetime.end.p0i8(i64 20, i8* %1) #3
%2 = bitcast %struct.s* %tmp1 to i8*
call void @llvm.lifetime.start.p0i8(i64 20, i8* %2) #3 <<<<<<<<<<<<< call void @f(%struct.s* sret %tmp1)
%3 = bitcast %struct.s* %tmp1 to i8*
call void @llvm.lifetime.end.p0i8(i64 20, i8* %3) #3
ret void
}

Quoted 3 lines

Err.. taking my words back.
These allocas *are* used other then in lifetime markers, since they are passed to f() as 'sret'.

Thanks a lot for the analysis!

Quoted 27 lines

And we can not drop instrumentation for such allocas. Example:

static volatile int zero = 0;
typedef struct {
int ar[5];
} S;
S foo() {
S s;
s.ar[zero + 6] = 42;
return s;
}
int main(int argc, char **argv) {
S s = foo();
return s.ar[argc];
}

% clang -g -O1 -fsanitize=address sret.c && ./a.out

==5822==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffcad027f78 at pc 0x0000004f878d bp 0x7ffcad027f20 sp 0x7ffcad027f18
WRITE of size 4 at 0x7ffcad027f78 thread T0

    #0 0x4f878c in foo sret.c:7:18
    #1 0x4f8838 in main sret.c:11:9
Address 0x7ffcad027f78 is located in stack of thread T0 at offset 56 in frame
    #0 0x4f879f in main sret.c:10
Quoted 6 lines

This frame has 1 object(s):

    [32, 52) 's' (line 11) <== Memory access at offset 56 overflows

this variable

Here we have a struct return that needs to be instrumented inside main so that a buffer overflow in foo() is detected.

I tried reproducing this with gcc. The example you list above will generate very similar code on gcc. However, if I change main() to not assign the return value of foo() to a local variable, I get a trivial main main function without sanitizer code, but foo() still detects the overflow:

=================================================================
==3442660==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff5682bd58 at pc 0x0000004009c3 bp 0x7fff5682bd10 sp 0x7fff5682bd00
WRITE of size 4 at 0x7fff5682bd58 thread T0

    #0 0x4009c2 in foo (/tmp/a.out+0x4009c2)
    #1 0x4009dd in main (/tmp/a.out+0x4009dd)
    #2 0x7fc6f0ce482f in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #3 0x400808 in _start (/tmp/a.out+0x400808)

Address 0x7fff5682bd58 is located in stack of thread T0 at offset 56 in frame

    #0 0x4008c6 in foo (/tmp/a.out+0x4008c6)

This frame has 1 object(s):

    [32, 52) 's' <== Memory access at offset 56 overflows this variable

HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow (/tmp/a.out+0x4009c2) in foo

The other difference is that with gcc, we only get one copy of each stack variable even when it adds code from asan-stack to check it, while clang generally creates one copy per instance when asan-stack=1 is set (but doesn't otherwise).

Quoted 1 line

Now, I am also not confident that the reduced case reflects the real problem.

No, it probably doesn't, but it seems vaguely related. This is a problem of using creduce, it sometimes reduces the test cases too much and runs into a different symptom.

The case we frequently see in the kernel is probably more like

void extf(long *);
static inline __attribute__((always_inline)) void f(void)

{
    long i = 7;
    extg(&i);
}
int main(void)
{
     f();
     f();
}

https://godbolt.org/z/ReEQLo

Here, both gcc and clang add sanitizing for 'i', but clang has multiple copies, while gcc only has one. This happens for both scalars and structs, and inline functions as well as open-coded blocks or macros with the same code in them. Using the inline function for illustration above since that is the most common way it appears in the kernel.

Arnd

#19 lore raw
In reply to Arnd Bergmann
Quoted 18 lines · Arnd Bergmann
Quoted 8 lines · Andrey Ryabinin
Quoted 4 lines · Arnd Bergmann

On Wed, Feb 20, 2019 at 3:45 PM Andrey Konovalov <[email protected]> wrote:
I would have to some more research, but I expect several hundred patches before we get to a clean randconfig build with a broken compiler.

Manually maintaining asan-stack parameter for the sake of one broken compiler isn't a great idea either.

Quoted 8 lines

Couple alternative suggestions:

1) If we can't fix the problem or the cost of fixing is too high, maybe just hide it? Disable -Wframe-larger-then on pre clang-9 compilers.

2) Fallback cflags. The idea is to try to compile every the file with "-mllvm -asan-stack=1 -Wframe-larger-than=2048 -Werror" at first,
and fallback to "-mllvm -asan-stack=0" if failed. So it would be something similar to $(call cc-option, -mllvm -asan-stack=1 -Wframe-larger-than=2048 -Werror, -mllvm -asan-stack=0) except that "cc-option" tries options only once on some code example while we need to try options on every file that we actually compile.
Honestly, I'm not sure that it's worthy to hack Kbuild engine for that particular use-case.

Quoted 9 lines

My original plan was to put this under CONFIG_KASAN_EXTRA to allow you to still enable it in older compilers, but you just removed that option ;-)

Maybe bringing it back would be a compromise? That way it's hidden from all the build testing bots (because of the !CONFIG_COMPILE_TEST dependency), but anyone who really wants it can still have the option, and set CONFIG_FRAME_WARN
to whichever value they like.

I think there is much simpler solution:

---
 lib/Kconfig.kasan | 2 ++
 1 file changed, 2 insertions(+)
lib/Kconfig.kasan +2 -0
index 219cddc913ac..6cd035f06cee 100644
@@ -105,6 +105,8 @@ endchoice
 
 config KASAN_STACK
 	int
+	range 0 1
+	prompt "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && (CLANG_VERSION < 90000)
 	default 0 if CC_IS_CLANG && (CLANG_VERSION < 90000)
 	default 1
 	help
Signature · 2 lines
AFAIK, randconfig is not able to randomize int config options, so it will be disabled for build robots,
but users still will be able to enable it.
#20 lore raw
Quoted 34 lines · Andrey Ryabinin
Quoted 9 lines · Arnd Bergmann
Quoted 1 line · Andrey Ryabinin

On 2/20/19 5:51 PM, Arnd Bergmann wrote:

Maybe bringing it back would be a compromise? That way it's hidden from all the build testing bots (because of the !CONFIG_COMPILE_TEST dependency), but anyone who really wants it can still have the option, and set CONFIG_FRAME_WARN
to whichever value they like.

I think there is much simpler solution:

---
 lib/Kconfig.kasan | 2 ++
 1 file changed, 2 insertions(+)
lib/Kconfig.kasan +2 -1
index 219cddc913ac..6cd035f06cee 100644
@@ -105,6 +105,8 @@ endchoice
 
 config KASAN_STACK
        int
+       range 0 1
+       prompt "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && (CLANG_VERSION < 90000)
        default 0 if CC_IS_CLANG && (CLANG_VERSION < 90000)
        default 1
        help
--
Quoted 2 lines

AFAIK, randconfig is not able to randomize int config options, so it will be disabled for build robots, but users still will be able to enable it.

Right, this will work, but I find it a bit awkward to require users to enter 0 or 1.

My assumption is that build bots turn on CONFIG_COMPILE_TEST, so having a bool option that depends on COMPILE_TEST would be more conventional. We can debate whether it should also depend on CONFIG_EXPERT or not. Something like

config KASAN_STACK
bool "Enable stack instrumentation (unsafe)" if CC_IS_CLANG
&& !COMPILE_TEST

         default CC_IS_GCC || (CLANG_VERSION >= 90000)

And then a simpler Makefile logic (could also be done in Kconfig) to turn that bool symbol into an integer argument for asan-stack=

Arnd

#21 lore raw
Quoted 47 lines · Arnd Bergmann
Quoted 34 lines · Andrey Ryabinin
Quoted 9 lines · Arnd Bergmann
Quoted 1 line · Andrey Ryabinin

On 2/20/19 5:51 PM, Arnd Bergmann wrote:

Maybe bringing it back would be a compromise? That way it's hidden from all the build testing bots (because of the !CONFIG_COMPILE_TEST dependency), but anyone who really wants it can still have the option, and set CONFIG_FRAME_WARN
to whichever value they like.

I think there is much simpler solution:

---
 lib/Kconfig.kasan | 2 ++
 1 file changed, 2 insertions(+)
lib/Kconfig.kasan +2 -1
index 219cddc913ac..6cd035f06cee 100644
@@ -105,6 +105,8 @@ endchoice
 
 config KASAN_STACK
        int
+       range 0 1
+       prompt "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && (CLANG_VERSION < 90000)
        default 0 if CC_IS_CLANG && (CLANG_VERSION < 90000)
        default 1
        help
--
Quoted 2 lines

AFAIK, randconfig is not able to randomize int config options, so it will be disabled for build robots, but users still will be able to enable it.

Right, this will work, but I find it a bit awkward to require users to enter 0 or 1.

My assumption is that build bots turn on CONFIG_COMPILE_TEST, so having a bool option that depends on COMPILE_TEST would be more conventional. We can debate whether it should also depend on CONFIG_EXPERT or not. Something like

Quoted 8 lines

config KASAN_STACK
bool "Enable stack instrumentation (unsafe)" if CC_IS_CLANG
&& !COMPILE_TEST

         default CC_IS_GCC || (CLANG_VERSION >= 90000)

And then a simpler Makefile logic (could also be done in Kconfig) to turn that bool symbol into an integer argument for asan-stack=

Sounds good.