Skip to content

Commit a26321e

Browse files
committed
Merge tag 'hardening-v6.17-rc1-fix1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull hardening fixes from Kees Cook: "Notably, this contains the fix for for the GCC __init mess I created with the kstack_erase annotations. - staging: media: atomisp: Fix stack buffer overflow in gmin_get_var_int(). I was asked to carry this fix, so here it is. :) - fortify: Fix incorrect reporting of read buffer size - kstack_erase: Fix missed export of renamed KSTACK_ERASE_CFLAGS - compiler_types: Provide __no_kstack_erase to disable coverage only on Clang" * tag 'hardening-v6.17-rc1-fix1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: compiler_types: Provide __no_kstack_erase to disable coverage only on Clang fortify: Fix incorrect reporting of read buffer size kstack_erase: Fix missed export of renamed KSTACK_ERASE_CFLAGS staging: media: atomisp: Fix stack buffer overflow in gmin_get_var_int()
2 parents beb6c83 + f627b51 commit a26321e

File tree

7 files changed

+16
-8
lines changed

7 files changed

+16
-8
lines changed

arch/x86/include/asm/init.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#if defined(CONFIG_CC_IS_CLANG) && CONFIG_CLANG_VERSION < 170000
66
#define __head __section(".head.text") __no_sanitize_undefined __no_stack_protector
77
#else
8-
#define __head __section(".head.text") __no_sanitize_undefined __no_sanitize_coverage
8+
#define __head __section(".head.text") __no_sanitize_undefined __no_kstack_erase
99
#endif
1010

1111
struct x86_mapping_info {

drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,14 +1272,15 @@ static int gmin_get_config_var(struct device *maindev,
12721272
if (efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE))
12731273
status = efi.get_variable(var16, &GMIN_CFG_VAR_EFI_GUID, NULL,
12741274
(unsigned long *)out_len, out);
1275-
if (status == EFI_SUCCESS)
1275+
if (status == EFI_SUCCESS) {
12761276
dev_info(maindev, "found EFI entry for '%s'\n", var8);
1277-
else if (is_gmin)
1277+
return 0;
1278+
}
1279+
if (is_gmin)
12781280
dev_info(maindev, "Failed to find EFI gmin variable %s\n", var8);
12791281
else
12801282
dev_info(maindev, "Failed to find EFI variable %s\n", var8);
1281-
1282-
return ret;
1283+
return -ENOENT;
12831284
}
12841285

12851286
int gmin_get_var_int(struct device *dev, bool is_gmin, const char *var, int def)

include/linux/compiler-clang.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@
8989
#define __no_sanitize_coverage
9090
#endif
9191

92+
/* Only Clang needs to disable the coverage sanitizer for kstack_erase. */
93+
#define __no_kstack_erase __no_sanitize_coverage
94+
9295
#if __has_feature(shadow_call_stack)
9396
# define __noscs __attribute__((__no_sanitize__("shadow-call-stack")))
9497
#endif

include/linux/compiler_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@ struct ftrace_likely_data {
424424
# define randomized_struct_fields_end
425425
#endif
426426

427+
#ifndef __no_kstack_erase
428+
# define __no_kstack_erase
429+
#endif
430+
427431
#ifndef __noscs
428432
# define __noscs
429433
#endif

include/linux/fortify-string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_size_t size,
596596
if (p_size != SIZE_MAX && p_size < size)
597597
fortify_panic(func, FORTIFY_WRITE, p_size, size, true);
598598
else if (q_size != SIZE_MAX && q_size < size)
599-
fortify_panic(func, FORTIFY_READ, p_size, size, true);
599+
fortify_panic(func, FORTIFY_READ, q_size, size, true);
600600

601601
/*
602602
* Warn when writing beyond destination field size.

include/linux/init.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
discard it in modules) */
5252
#define __init __section(".init.text") __cold __latent_entropy \
5353
__noinitretpoline \
54-
__no_sanitize_coverage
54+
__no_kstack_erase
5555
#define __initdata __section(".init.data")
5656
#define __initconst __section(".init.rodata")
5757
#define __exitdata __section(".exit.data")

scripts/Makefile.kstack_erase

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ endif
1616

1717
KSTACK_ERASE_CFLAGS := $(kstack-erase-cflags-y)
1818

19-
export STACKLEAK_CFLAGS DISABLE_KSTACK_ERASE
19+
export KSTACK_ERASE_CFLAGS DISABLE_KSTACK_ERASE
2020

2121
KBUILD_CFLAGS += $(KSTACK_ERASE_CFLAGS)

0 commit comments

Comments
 (0)