History

kbuild: Switch from -Wvla to -Wvla-larger-than=1

Variable Length Arrays (VLAs) on the stack must not be used in the kernel. Function parameter VLAs[1] should be usable, but -Wvla will warn for those. For example, this will produce a warning but it is not using a stack VLA: int something(size_t n, int array[n]) { ... Clang has no way yet to distinguish between the VLA types[2], so depend on GCC for now to keep stack VLAs out of the tree by using GCC's -Wvla-larger-than=N option (though GCC may split -Wvla similarly[3] to how Clang is planning to). While GCC 8+ supports -Wvla-larger-than, only 9+ supports ...=0[4], so use -Wvla-larger-than=1. Adjust mm/kasan/Makefile to remove it from CFLAGS (GCC <9 appears unable to disable the warning correctly[5]). The VLA usage in lib/test_ubsan.c was removed in commit 9d7ca61b1366 ("lib/test_ubsan.c: VLA no longer used in kernel") so the lib/Makefile disabling of VLA checking can be entirely removed.

Kees Cook committed 1 year ago

Commit 5e88c481 parent 5106c653 files · +9 −4Browse files

Unified · Split

3 files
  1. lib/Makefile +0 −1
  2. mm/kasan/Makefile +2 −1
  3. scripts/Makefile.extrawarn +7 −2
lib/Makefile+0−1
@@ -71,7 +71,6 @@ CFLAGS_test_bitops.o += -Werror · 70 unmodified lines
71obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o71obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o
72obj-$(CONFIG_TEST_IDA) += test_ida.o72obj-$(CONFIG_TEST_IDA) += test_ida.o
73obj-$(CONFIG_TEST_UBSAN) += test_ubsan.o73obj-$(CONFIG_TEST_UBSAN) += test_ubsan.o
74CFLAGS_test_ubsan.o += $(call cc-disable-warning, vla)
75CFLAGS_test_ubsan.o += $(call cc-disable-warning, unused-but-set-variable)74CFLAGS_test_ubsan.o += $(call cc-disable-warning, unused-but-set-variable)
76UBSAN_SANITIZE_test_ubsan.o := y75UBSAN_SANITIZE_test_ubsan.o := y
77obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o76obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
mm/kasan/Makefile+2−1
@@ -35,7 +35,7 @@ CFLAGS_shadow.o := $(CC_FLAGS_KASAN_RUNTIME) · 34 unmodified lines
35CFLAGS_hw_tags.o := $(CC_FLAGS_KASAN_RUNTIME)35CFLAGS_hw_tags.o := $(CC_FLAGS_KASAN_RUNTIME)
36CFLAGS_sw_tags.o := $(CC_FLAGS_KASAN_RUNTIME)36CFLAGS_sw_tags.o := $(CC_FLAGS_KASAN_RUNTIME)
37 37
38CFLAGS_KASAN_TEST := $(CFLAGS_KASAN) $(call cc-disable-warning, vla)38CFLAGS_KASAN_TEST := $(CFLAGS_KASAN)
39ifndef CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX39ifndef CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
40# If compiler instruments memintrinsics by prefixing them with __asan/__hwasan,40# If compiler instruments memintrinsics by prefixing them with __asan/__hwasan,
41# we need to treat them normally (as builtins), otherwise the compiler won't41# we need to treat them normally (as builtins), otherwise the compiler won't
@@ -44,6 +44,7 @@ ifndef CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX · 2 unmodified lines
44CFLAGS_KASAN_TEST += -fno-builtin44CFLAGS_KASAN_TEST += -fno-builtin
45endif45endif
46 46
47CFLAGS_REMOVE_kasan_test_c.o += $(call cc-option, -Wvla-larger-than=1)
47CFLAGS_kasan_test_c.o := $(CFLAGS_KASAN_TEST)48CFLAGS_kasan_test_c.o := $(CFLAGS_KASAN_TEST)
48RUSTFLAGS_kasan_test_rust.o := $(RUSTFLAGS_KASAN)49RUSTFLAGS_kasan_test_rust.o := $(RUSTFLAGS_KASAN)
49 50
scripts/Makefile.extrawarn+7−2
@@ -45,8 +45,13 @@ endif · 44 unmodified lines
45# These result in bogus false positives45# These result in bogus false positives
46KBUILD_CFLAGS += $(call cc-disable-warning, dangling-pointer)46KBUILD_CFLAGS += $(call cc-disable-warning, dangling-pointer)
47 47
48# Variable Length Arrays (VLAs) should not be used anywhere in the kernel48# Stack Variable Length Arrays (VLAs) must not be used in the kernel.
49KBUILD_CFLAGS += -Wvla49# Function array parameters should, however, be usable, but -Wvla will
50# warn for those. Clang has no way yet to distinguish between the VLA
51# types, so depend on GCC for now to keep stack VLAs out of the tree.
52# https://github.com/llvm/llvm-project/issues/57098
53# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98217
54KBUILD_CFLAGS += $(call cc-option,-Wvla-larger-than=1)
50 55
51# disable pointer signed / unsigned warnings in gcc 4.056# disable pointer signed / unsigned warnings in gcc 4.0
52KBUILD_CFLAGS += -Wno-pointer-sign57KBUILD_CFLAGS += -Wno-pointer-sign

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t