Skip to content

Commit 51094a2

Browse files
committed
Merge tag 'hardening-v6.2-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull kernel hardening fixes from Kees Cook: - Fix CFI failure with KASAN (Sami Tolvanen) - Fix LKDTM + CFI under GCC 7 and 8 (Kristina Martsenko) - Limit CONFIG_ZERO_CALL_USED_REGS to Clang > 15.0.6 (Nathan Chancellor) - Ignore "contents" argument in LoadPin's LSM hook handling - Fix paste-o in /sys/kernel/warn_count API docs - Use READ_ONCE() consistently for oops/warn limit reading * tag 'hardening-v6.2-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: cfi: Fix CFI failure with KASAN exit: Use READ_ONCE() for all oops/warn limit reads security: Restrict CONFIG_ZERO_CALL_USED_REGS to gcc or clang > 15.0.6 lkdtm: cfi: Make PAC test work with GCC 7 and 8 docs: Fix path paste-o for /sys/kernel/warn_count LoadPin: Ignore the "contents" argument of the LSM hooks
2 parents edb2312 + cf80164 commit 51094a2

File tree

7 files changed

+36
-21
lines changed

7 files changed

+36
-21
lines changed

Documentation/ABI/testing/sysfs-kernel-warn_count

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
What: /sys/kernel/oops_count
1+
What: /sys/kernel/warn_count
22
Date: November 2022
33
KernelVersion: 6.2.0
44
Contact: Linux Kernel Hardening List <linux-hardening@vger.kernel.org>

drivers/misc/lkdtm/cfi.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ static void lkdtm_CFI_FORWARD_PROTO(void)
5454
# ifdef CONFIG_ARM64_BTI_KERNEL
5555
# define __no_pac "branch-protection=bti"
5656
# else
57-
# define __no_pac "branch-protection=none"
57+
# ifdef CONFIG_CC_HAS_BRANCH_PROT_PAC_RET
58+
# define __no_pac "branch-protection=none"
59+
# else
60+
# define __no_pac "sign-return-address=none"
61+
# endif
5862
# endif
5963
# define __no_ret_protection __noscs __attribute__((__target__(__no_pac)))
6064
#else

kernel/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ UBSAN_SANITIZE_kcov.o := n
4141
KMSAN_SANITIZE_kcov.o := n
4242
CFLAGS_kcov.o := $(call cc-option, -fno-conserve-stack) -fno-stack-protector
4343

44-
# Don't instrument error handlers
45-
CFLAGS_REMOVE_cfi.o := $(CC_FLAGS_CFI)
46-
4744
obj-y += sched/
4845
obj-y += locking/
4946
obj-y += power/

kernel/exit.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,7 @@ void __noreturn make_task_dead(int signr)
931931
* Then do everything else.
932932
*/
933933
struct task_struct *tsk = current;
934+
unsigned int limit;
934935

935936
if (unlikely(in_interrupt()))
936937
panic("Aiee, killing interrupt handler!");
@@ -954,8 +955,9 @@ void __noreturn make_task_dead(int signr)
954955
* To make sure this can't happen, place an upper bound on how often the
955956
* kernel may oops without panic().
956957
*/
957-
if (atomic_inc_return(&oops_count) >= READ_ONCE(oops_limit) && oops_limit)
958-
panic("Oopsed too often (kernel.oops_limit is %d)", oops_limit);
958+
limit = READ_ONCE(oops_limit);
959+
if (atomic_inc_return(&oops_count) >= limit && limit)
960+
panic("Oopsed too often (kernel.oops_limit is %d)", limit);
959961

960962
/*
961963
* We're taking recursive faults here in make_task_dead. Safest is to just

kernel/panic.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,15 @@ static void panic_print_sys_info(bool console_flush)
232232

233233
void check_panic_on_warn(const char *origin)
234234
{
235+
unsigned int limit;
236+
235237
if (panic_on_warn)
236238
panic("%s: panic_on_warn set ...\n", origin);
237239

238-
if (atomic_inc_return(&warn_count) >= READ_ONCE(warn_limit) && warn_limit)
240+
limit = READ_ONCE(warn_limit);
241+
if (atomic_inc_return(&warn_count) >= limit && limit)
239242
panic("%s: system warned too often (kernel.warn_limit is %d)",
240-
origin, warn_limit);
243+
origin, limit);
241244
}
242245

243246
/**

security/Kconfig.hardening

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ config INIT_ON_FREE_DEFAULT_ON
257257

258258
config CC_HAS_ZERO_CALL_USED_REGS
259259
def_bool $(cc-option,-fzero-call-used-regs=used-gpr)
260+
# https://github.com/ClangBuiltLinux/linux/issues/1766
261+
# https://github.com/llvm/llvm-project/issues/59242
262+
depends on !CC_IS_CLANG || CLANG_VERSION > 150006
260263

261264
config ZERO_CALL_USED_REGS
262265
bool "Enable register zeroing on function exit"

security/loadpin/loadpin.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,11 @@ static void loadpin_sb_free_security(struct super_block *mnt_sb)
122122
}
123123
}
124124

125-
static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
126-
bool contents)
125+
static int loadpin_check(struct file *file, enum kernel_read_file_id id)
127126
{
128127
struct super_block *load_root;
129128
const char *origin = kernel_read_file_id_str(id);
130129

131-
/*
132-
* If we will not know that we'll be seeing the full contents
133-
* then we cannot trust a load will be complete and unchanged
134-
* off disk. Treat all contents=false hooks as if there were
135-
* no associated file struct.
136-
*/
137-
if (!contents)
138-
file = NULL;
139-
140130
/* If the file id is excluded, ignore the pinning. */
141131
if ((unsigned int)id < ARRAY_SIZE(ignore_read_file_id) &&
142132
ignore_read_file_id[id]) {
@@ -192,9 +182,25 @@ static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
192182
return 0;
193183
}
194184

185+
static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
186+
bool contents)
187+
{
188+
/*
189+
* LoadPin only cares about the _origin_ of a file, not its
190+
* contents, so we can ignore the "are full contents available"
191+
* argument here.
192+
*/
193+
return loadpin_check(file, id);
194+
}
195+
195196
static int loadpin_load_data(enum kernel_load_data_id id, bool contents)
196197
{
197-
return loadpin_read_file(NULL, (enum kernel_read_file_id) id, contents);
198+
/*
199+
* LoadPin only cares about the _origin_ of a file, not its
200+
* contents, so a NULL file is passed, and we can ignore the
201+
* state of "contents".
202+
*/
203+
return loadpin_check(NULL, (enum kernel_read_file_id) id);
198204
}
199205

200206
static struct security_hook_list loadpin_hooks[] __lsm_ro_after_init = {

0 commit comments

Comments
 (0)