Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit ce5a51b

Browse files
committed
Merge tag 'hardening-v6.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull hardening updates from Kees Cook: - lkdtm/bugs: add test for hung smp_call_function_single() (Mark Rutland) - gcc-plugins: Remove duplicate included header file stringpool.h (Thorsten Blum) - ARM: Remove address checking for MMUless devices (Yanjun Yang) - randomize_kstack: Clean up per-arch entropy and codegen - KCFI: Make FineIBT mode Kconfig selectable - fortify: Do not special-case 0-sized destinations * tag 'hardening-v6.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: randomize_kstack: Improve stack alignment codegen ARM: Remove address checking for MMUless devices gcc-plugins: Remove duplicate included header file stringpool.h randomize_kstack: Remove non-functional per-arch entropy filtering fortify: Do not special-case 0-sized destinations x86/alternatives: Make FineIBT mode Kconfig selectable lkdtm/bugs: add test for hung smp_call_function_single()
2 parents 8050258 + 872bb37 commit ce5a51b

File tree

10 files changed

+62
-26
lines changed

10 files changed

+62
-26
lines changed

arch/arm/mm/fault.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525

2626
#include "fault.h"
2727

28+
#ifdef CONFIG_MMU
29+
2830
bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
2931
{
3032
unsigned long addr = (unsigned long)unsafe_src;
3133

3234
return addr >= TASK_SIZE && ULONG_MAX - addr >= size;
3335
}
3436

35-
#ifdef CONFIG_MMU
36-
3737
/*
3838
* This is useful to dump out the page tables associated with
3939
* 'addr' in mm 'mm'.

arch/x86/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,6 +2414,15 @@ config STRICT_SIGALTSTACK_SIZE
24142414

24152415
Say 'N' unless you want to really enforce this check.
24162416

2417+
config CFI_AUTO_DEFAULT
2418+
bool "Attempt to use FineIBT by default at boot time"
2419+
depends on FINEIBT
2420+
default y
2421+
help
2422+
Attempt to use FineIBT by default at boot time. If enabled,
2423+
this is the same as booting with "cfi=auto". If disabled,
2424+
this is the same as booting with "cfi=kcfi".
2425+
24172426
source "kernel/livepatch/Kconfig"
24182427

24192428
endmenu

arch/x86/include/asm/cfi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
*
9494
*/
9595
enum cfi_mode {
96-
CFI_DEFAULT, /* FineIBT if hardware has IBT, otherwise kCFI */
96+
CFI_AUTO, /* FineIBT if hardware has IBT, otherwise kCFI */
9797
CFI_OFF, /* Taditional / IBT depending on .config */
9898
CFI_KCFI, /* Optionally CALL_PADDING, IBT, RETPOLINE */
9999
CFI_FINEIBT, /* see arch/x86/kernel/alternative.c */

arch/x86/kernel/alternative.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,8 @@ void __init_or_module apply_seal_endbr(s32 *start, s32 *end) { }
901901

902902
#endif /* CONFIG_X86_KERNEL_IBT */
903903

904-
#ifdef CONFIG_FINEIBT
905-
#define __CFI_DEFAULT CFI_DEFAULT
904+
#ifdef CONFIG_CFI_AUTO_DEFAULT
905+
#define __CFI_DEFAULT CFI_AUTO
906906
#elif defined(CONFIG_CFI_CLANG)
907907
#define __CFI_DEFAULT CFI_KCFI
908908
#else
@@ -1010,7 +1010,7 @@ static __init int cfi_parse_cmdline(char *str)
10101010
}
10111011

10121012
if (!strcmp(str, "auto")) {
1013-
cfi_mode = CFI_DEFAULT;
1013+
cfi_mode = CFI_AUTO;
10141014
} else if (!strcmp(str, "off")) {
10151015
cfi_mode = CFI_OFF;
10161016
cfi_rand = false;
@@ -1270,7 +1270,7 @@ static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline,
12701270
"FineIBT preamble wrong size: %ld", fineibt_preamble_size))
12711271
return;
12721272

1273-
if (cfi_mode == CFI_DEFAULT) {
1273+
if (cfi_mode == CFI_AUTO) {
12741274
cfi_mode = CFI_KCFI;
12751275
if (HAS_KERNEL_IBT && cpu_feature_enabled(X86_FEATURE_IBT))
12761276
cfi_mode = CFI_FINEIBT;

drivers/misc/lkdtm/bugs.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,35 @@ static void lkdtm_HARDLOCKUP(void)
286286
cpu_relax();
287287
}
288288

289+
static void __lkdtm_SMP_CALL_LOCKUP(void *unused)
290+
{
291+
for (;;)
292+
cpu_relax();
293+
}
294+
295+
static void lkdtm_SMP_CALL_LOCKUP(void)
296+
{
297+
unsigned int cpu, target;
298+
299+
cpus_read_lock();
300+
301+
cpu = get_cpu();
302+
target = cpumask_any_but(cpu_online_mask, cpu);
303+
304+
if (target >= nr_cpu_ids) {
305+
pr_err("FAIL: no other online CPUs\n");
306+
goto out_put_cpus;
307+
}
308+
309+
smp_call_function_single(target, __lkdtm_SMP_CALL_LOCKUP, NULL, 1);
310+
311+
pr_err("FAIL: did not hang\n");
312+
313+
out_put_cpus:
314+
put_cpu();
315+
cpus_read_unlock();
316+
}
317+
289318
static void lkdtm_SPINLOCKUP(void)
290319
{
291320
/* Must be called twice to trigger. */
@@ -680,6 +709,7 @@ static struct crashtype crashtypes[] = {
680709
CRASHTYPE(UNALIGNED_LOAD_STORE_WRITE),
681710
CRASHTYPE(SOFTLOCKUP),
682711
CRASHTYPE(HARDLOCKUP),
712+
CRASHTYPE(SMP_CALL_LOCKUP),
683713
CRASHTYPE(SPINLOCKUP),
684714
CRASHTYPE(HUNG_TASK),
685715
CRASHTYPE(OVERFLOW_SIGNED),

include/linux/fortify-string.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -601,19 +601,15 @@ __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_size_t size,
601601
/*
602602
* Warn when writing beyond destination field size.
603603
*
604-
* We must ignore p_size_field == 0 for existing 0-element
605-
* fake flexible arrays, until they are all converted to
606-
* proper flexible arrays.
607-
*
608-
* The implementation of __builtin_*object_size() behaves
604+
* Note the implementation of __builtin_*object_size() behaves
609605
* like sizeof() when not directly referencing a flexible
610606
* array member, which means there will be many bounds checks
611607
* that will appear at run-time, without a way for them to be
612608
* detected at compile-time (as can be done when the destination
613609
* is specifically the flexible array member).
614610
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101832
615611
*/
616-
if (p_size_field != 0 && p_size_field != SIZE_MAX &&
612+
if (p_size_field != SIZE_MAX &&
617613
p_size != p_size_field && p_size_field < size)
618614
return true;
619615

include/linux/randomize_kstack.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@ DECLARE_PER_CPU(u32, kstack_offset);
3232
#endif
3333

3434
/*
35-
* Use, at most, 10 bits of entropy. We explicitly cap this to keep the
36-
* "VLA" from being unbounded (see above). 10 bits leaves enough room for
37-
* per-arch offset masks to reduce entropy (by removing higher bits, since
38-
* high entropy may overly constrain usable stack space), and for
39-
* compiler/arch-specific stack alignment to remove the lower bits.
35+
* Use, at most, 6 bits of entropy (on 64-bit; 8 on 32-bit). This cap is
36+
* to keep the "VLA" from being unbounded (see above). Additionally clear
37+
* the bottom 4 bits (on 64-bit systems, 2 for 32-bit), since stack
38+
* alignment will always be at least word size. This makes the compiler
39+
* code gen better when it is applying the actual per-arch alignment to
40+
* the final offset. The resulting randomness is reasonable without overly
41+
* constraining usable stack space.
4042
*/
41-
#define KSTACK_OFFSET_MAX(x) ((x) & 0x3FF)
43+
#ifdef CONFIG_64BIT
44+
#define KSTACK_OFFSET_MAX(x) ((x) & 0b1111110000)
45+
#else
46+
#define KSTACK_OFFSET_MAX(x) ((x) & 0b1111111100)
47+
#endif
4248

4349
/**
4450
* add_random_kstack_offset - Increase stack utilization by previously

lib/fortify_kunit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,10 +910,9 @@ static void fortify_test_##memfunc(struct kunit *test) \
910910
memfunc(zero.buf, srcB, 0 + unconst); \
911911
KUNIT_EXPECT_EQ(test, fortify_read_overflows, 0); \
912912
KUNIT_EXPECT_EQ(test, fortify_write_overflows, 0); \
913-
/* We currently explicitly ignore zero-sized dests. */ \
914913
memfunc(zero.buf, srcB, 1 + unconst); \
915914
KUNIT_EXPECT_EQ(test, fortify_read_overflows, 0); \
916-
KUNIT_EXPECT_EQ(test, fortify_write_overflows, 0); \
915+
KUNIT_EXPECT_EQ(test, fortify_write_overflows, 1); \
917916
}
918917
__fortify_test(memcpy)
919918
__fortify_test(memmove)

scripts/gcc-plugins/gcc-common.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@
6262
#include "pass_manager.h"
6363
#include "predict.h"
6464
#include "ipa-utils.h"
65-
66-
#if BUILDING_GCC_VERSION >= 8000
6765
#include "stringpool.h"
68-
#endif
69-
7066
#include "attribs.h"
7167
#include "varasm.h"
7268
#include "stor-layout.h"
@@ -78,7 +74,6 @@
7874
#include "context.h"
7975
#include "tree-ssa-alias.h"
8076
#include "tree-ssa.h"
81-
#include "stringpool.h"
8277
#if BUILDING_GCC_VERSION >= 7000
8378
#include "tree-vrp.h"
8479
#endif

tools/testing/selftests/lkdtm/tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ SLAB_FREE_CROSS
3131
SLAB_FREE_PAGE
3232
#SOFTLOCKUP Hangs the system
3333
#HARDLOCKUP Hangs the system
34+
#SMP_CALL_LOCKUP Hangs the system
3435
#SPINLOCKUP Hangs the system
3536
#HUNG_TASK Hangs the system
3637
EXEC_DATA

0 commit comments

Comments
 (0)