bpf: increase frame warning limit in verifier when using KASAN or KCSAN
PATCH 1/1 bpf: increase frame warning limit in verifier when using KASAN or KCSAN
From: Peng Hao <[email protected]>
When building kernel with clang, which will typically
have sanitizers enabled, there is a warning about a large stack frame.
kernel/bpf/verifier.c:21163:5: error: stack frame size (2392) exceeds limit (2048) in 'bpf_check' [-Werror,-Wframe-larger-than]
int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u32 uattr_size)
^
632/2392 (26.42%) spills, 1760/2392 (73.58%) variables
so increase the limit for configurations that have KASAN or KCSAN enabled for not breaking the majority of builds.
--- kernel/bpf/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/bpf/Makefile +6 -0
@@ -6,6 +6,12 @@ cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse endif CFLAGS_core.o += -Wno-override-init $(cflags-nogcse-yy) +ifneq ($(CONFIG_FRAME_WARN),0) +ifeq ($(filter y,$(CONFIG_KASAN)$(CONFIG_KCSAN)),y) +CFLAGS_verifier.o = -Wframe-larger-than=2392 +endif +endif + obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o log.o token.o obj-$(CONFIG_BPF_SYSCALL) += bpf_iter.o map_iter.o task_iter.o prog_iter.o link_iter.o obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o bpf_lru_list.o lpm_trie.o map_in_map.o bloom_filter.o
Signature · 1 line
2.27.0
Quoted 25 lines · On Wed, Jun 12, 2024 at 7:19 PM <[email protected]> wrote:
From: Peng Hao <[email protected]>
When building kernel with clang, which will typically
have sanitizers enabled, there is a warning about a large stack frame.
kernel/bpf/verifier.c:21163:5: error: stack frame size (2392) exceeds limit (2048) in 'bpf_check' [-Werror,-Wframe-larger-than]
intbpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u32 uattr_size)^632/2392 (26.42%) spills, 1760/2392 (73.58%) variables
so increase the limit for configurations that have KASAN or KCSAN enabled for not breaking the majority of builds.Signed-off-by Peng Hao <[email protected]>--- kernel/bpf/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)kernel/bpf/Makefile +0
-0
kernel/bpf/Makefile cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse · line 11
Quoted 6 lines
kernel/bpf/Makefile +3
-0@@ -6,6 +6,12 @@ cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse endif CFLAGS_core.o += -Wno-override-init $(cflags-nogcse-yy) +ifneq ($(CONFIG_FRAME_WARN),0) +ifeq ($(filter y,$(CONFIG_KASAN)$(CONFIG_KCSAN)),y) +CFLAGS_verifier.o = -Wframe-larger-than=2392
that's very compiler specific.
version +-1 will have different results.
Please investigate what is causing the large stack size instead.
pw-bot: cr
Quoted 30 lines · Alexei Starovoitov
Quoted 28 lines · On Wed, Jun 12, 2024 at 7:19 PM <[email protected]> wrote:
From: Peng Hao <[email protected]>
When building kernel with clang, which will typically
have sanitizers enabled, there is a warning about a large stack frame.
kernel/bpf/verifier.c:21163:5: error: stack frame size (2392) exceeds limit (2048) in 'bpf_check' [-Werror,-Wframe-larger-than]
intbpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u32 uattr_size)^632/2392 (26.42%) spills, 1760/2392 (73.58%) variables
so increase the limit for configurations that have KASAN or KCSAN enabled for not breaking the majority of builds.Signed-off-by Peng Hao <[email protected]>--- kernel/bpf/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)kernel/bpf/Makefile +0
-0@@ -6,6 +6,12 @@ cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse endif CFLAGS_core.o += -Wno-override-init $(cflags-nogcse-yy)
Quoted 8 lines
kernel/bpf/Makefile cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse · line 11
Quoted 3 lines
kernel/bpf/Makefile +3
-0+ifneq ($(CONFIG_FRAME_WARN),0) +ifeq ($(filter y,$(CONFIG_KASAN)$(CONFIG_KCSAN)),y) +CFLAGS_verifier.o = -Wframe-larger-than=2392that's very compiler specific.
version +-1 will have different results.
Please investigate what is causing the large stack size instead.
pw-bot: cr
This increase in stack frame size only occurs when KASAN or KCSAN is configured. KASAN or
KCSAN will cause the stack frame size to increase, and it will insert additional code and data
structures to detect memory errors during compilation. These additional checks will increase
the stack space requirements of the function.
Thanks.
Quoted 41 lines · Hao Peng
Quoted 30 lines · Alexei Starovoitov
Quoted 28 lines · On Wed, Jun 12, 2024 at 7:19 PM <[email protected]> wrote:
From: Peng Hao <[email protected]>
When building kernel with clang, which will typically
have sanitizers enabled, there is a warning about a large stack frame.
kernel/bpf/verifier.c:21163:5: error: stack frame size (2392) exceeds limit (2048) in 'bpf_check' [-Werror,-Wframe-larger-than]
intbpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u32 uattr_size)^632/2392 (26.42%) spills, 1760/2392 (73.58%) variables
so increase the limit for configurations that have KASAN or KCSAN enabled for not breaking the majority of builds.Signed-off-by Peng Hao <[email protected]>--- kernel/bpf/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)kernel/bpf/Makefile +0
-0@@ -6,6 +6,12 @@ cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse endif CFLAGS_core.o += -Wno-override-init $(cflags-nogcse-yy)Quoted 8 lines
kernel/bpf/Makefile cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse · line 11
Quoted 3 lines
kernel/bpf/Makefile +3
-0+ifneq ($(CONFIG_FRAME_WARN),0) +ifeq ($(filter y,$(CONFIG_KASAN)$(CONFIG_KCSAN)),y) +CFLAGS_verifier.o = -Wframe-larger-than=2392that's very compiler specific.
version +-1 will have different results.
Please investigate what is causing the large stack size instead.
pw-bot: cr
Quoted 7 lines
This increase in stack frame size only occurs when KASAN or KCSAN is configured. KASAN or
KCSAN will cause the stack frame size to increase, and it will insert additional code and data
structures to detect memory errors during compilation. These additional checks will increase
the stack space requirements of the function.
This generic statement about kasan is not helpful.
Figure out which exact variables and what functions are causing this kasan behavior.