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

Showing the changes to scripts (1 of 3 files). Show all

Unified · Split

scripts/Makefile.extrawarn+7−2
@@ -45,8 +45,13 @@ endif · 44 unmodified lines
4545 # These result in bogus false positives
4646 KBUILD_CFLAGS += $(call cc-disable-warning, dangling-pointer)
4747
48−# Variable Length Arrays (VLAs) should not be used anywhere in the kernel
49−KBUILD_CFLAGS += -Wvla
48+# Stack Variable Length Arrays (VLAs) must not be used in the kernel.
49+# 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
54+KBUILD_CFLAGS += $(call cc-option,-Wvla-larger-than=1)
5055
5156 # disable pointer signed / unsigned warnings in gcc 4.0
5257 KBUILD_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