OpenCloudOS-Kernel/drivers/misc/lkdtm
Christophe Leroy 8bfdbddd68 lkdtm/bugs: Don't expect thread termination without CONFIG_UBSAN_TRAP
When you don't select CONFIG_UBSAN_TRAP, you get:

  # echo ARRAY_BOUNDS > /sys/kernel/debug/provoke-crash/DIRECT
[  102.265827] ================================================================================
[  102.278433] UBSAN: array-index-out-of-bounds in drivers/misc/lkdtm/bugs.c:342:16
[  102.287207] index 8 is out of range for type 'char [8]'
[  102.298722] ================================================================================
[  102.313712] lkdtm: FAIL: survived array bounds overflow!
[  102.318770] lkdtm: Unexpected! This kernel (5.16.0-rc1-s3k-dev-01884-g720dcf79314a ppc) was built with CONFIG_UBSAN_BOUNDS=y

It is not correct because when CONFIG_UBSAN_TRAP is not selected
you can't expect array bounds overflow to kill the thread.

Modify the logic so that when the kernel is built with
CONFIG_UBSAN_BOUNDS but without CONFIG_UBSAN_TRAP, you get a warning
about CONFIG_UBSAN_TRAP not been selected instead.

This also require a fix of pr_expected_config(), otherwise the
following error is encountered.

  CC      drivers/misc/lkdtm/bugs.o
drivers/misc/lkdtm/bugs.c: In function 'lkdtm_ARRAY_BOUNDS':
drivers/misc/lkdtm/bugs.c:351:2: error: 'else' without a previous 'if'
  351 |  else
      |  ^~~~

Fixes: c75be56e35 ("lkdtm/bugs: Add ARRAY_BOUNDS to selftests")
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/363b58690e907c677252467a94fe49444c80ea76.1649704381.git.christophe.leroy@csgroup.eu
2022-04-12 16:16:48 -07:00
..
Makefile Char/Misc and other driver changes for 5.17-rc1 2022-01-14 16:02:28 +01:00
bugs.c lkdtm/bugs: Don't expect thread termination without CONFIG_UBSAN_TRAP 2022-04-12 16:16:48 -07:00
cfi.c lkdtm: Add CONFIG hints in errors where possible 2021-06-24 15:32:08 +02:00
core.c lkdtm: Add a test for function descriptors protection 2022-02-16 23:25:12 +11:00
fortify.c lkdtm/fortify: Swap memcpy() for strncpy() 2022-02-25 12:11:01 +01:00
heap.c lkdtm/heap: Note conditions for SLAB_LINEAR_OVERFLOW 2022-04-12 16:11:49 -07:00
lkdtm.h lkdtm/bugs: Don't expect thread termination without CONFIG_UBSAN_TRAP 2022-04-12 16:16:48 -07:00
perms.c lkdtm: Add a test for function descriptors protection 2022-02-16 23:25:12 +11:00
powerpc.c lkdtm/powerpc: Add SLB multihit test 2020-12-04 01:01:34 +11:00
refcount.c lkdtm: Remove references to CONFIG_REFCOUNT_FULL 2019-11-25 09:15:46 +01:00
rodata.c lkdtm: don't move ctors to .rodata 2020-12-09 15:51:14 +01:00
stackleak.c lkdtm: Add CONFIG hints in errors where possible 2021-06-24 15:32:08 +02:00
usercopy.c lkdtm/usercopy: Expand size of "out of frame" object 2022-04-12 16:11:50 -07:00