Skip to content

Commit

Permalink
samples/bpf: Add -fsanitize=bounds to userspace programs
Browse files Browse the repository at this point in the history
The sanitizer flag, which is supported by both clang and gcc, would make
it easier to debug array index out-of-bounds problems in these programs.

Make the Makfile smarter to detect ubsan support from the compiler and
add the '-fsanitize=bounds' accordingly.

Suggested-by: Mimi Zohar <[email protected]>
Signed-off-by: Jinghao Jia <[email protected]>
Signed-off-by: Jinghao Jia <[email protected]>
Signed-off-by: Ruowen Qin <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Tested-by: Jiri Olsa <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
chinrw authored and anakryiko committed Sep 28, 2023
1 parent 0e73ef1 commit 9e09b75
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions samples/bpf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ endif
TPROGS_CFLAGS += -Wall -O2
TPROGS_CFLAGS += -Wmissing-prototypes
TPROGS_CFLAGS += -Wstrict-prototypes
TPROGS_CFLAGS += $(call try-run,\
printf "int main() { return 0; }" |\
$(CC) -Werror -fsanitize=bounds -x c - -o "$$TMP",-fsanitize=bounds,)

TPROGS_CFLAGS += -I$(objtree)/usr/include
TPROGS_CFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
Expand Down

0 comments on commit 9e09b75

Please sign in to comment.