* [PATCH v4 0/4] stackleak: Support Clang stack depth tracking
@ 2025-07-24 5:50 Kees Cook
2025-07-24 5:50 ` [PATCH v4 1/4] arm64: Handle KCOV __init vs inline mismatches Kees Cook
` (4 more replies)
0 siblings, 5 replies; 12+ messages in thread
From: Kees Cook @ 2025-07-24 5:50 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Kees Cook, Will Deacon, Ard Biesheuvel, Catalin Marinas,
Jonathan Cameron, Gavin Shan, Russell King (Oracle), James Morse,
Oza Pawandeep, Anshuman Khandual, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, H. Peter Anvin, Paolo Bonzini,
Mike Rapoport, Vitaly Kuznetsov, Henrique de Moraes Holschuh,
Hans de Goede, Ilpo Järvinen, Rafael J. Wysocki, Len Brown,
Masami Hiramatsu, Michal Wilczynski, Juergen Gross,
Andy Shevchenko, Kirill A. Shutemov, Roger Pau Monne,
David Woodhouse, Usama Arif, Guilherme G. Piccoli, Thomas Huth,
Brian Gerst, Marco Elver, Andrey Konovalov, Andrey Ryabinin,
Hou Wenlong, Andrew Morton, Masahiro Yamada,
Peter Zijlstra (Intel), Luis Chamberlain, Sami Tolvanen,
Christophe Leroy, Nathan Chancellor, Nicolas Schier,
Gustavo A. R. Silva, Andy Lutomirski, Baoquan He, Alexander Graf,
Changyuan Lyu, Paul Moore, James Morris, Serge E. Hallyn,
Nick Desaulniers, Bill Wendling, Justin Stitt, Jan Beulich,
Boqun Feng, Viresh Kumar, Paul E. McKenney, Bibo Mao,
linux-kernel, linux-arm-kernel, x86, kvm, ibm-acpi-devel,
platform-driver-x86, linux-acpi, linux-trace-kernel, linux-efi,
linux-mm, kasan-dev, linux-kbuild, linux-hardening, kexec,
linux-security-module, llvm
v4:
- rebase on for-next/hardening tree (took subset of v3 patches)
- improve commit logs for x86 and arm64 changes (Mike, Will, Ard)
v3: https://lore.kernel.org/lkml/20250717231756.make.423-kees@kernel.org/
v2: https://lore.kernel.org/lkml/20250523043251.it.550-kees@kernel.org/
v1: https://lore.kernel.org/lkml/20250507180852.work.231-kees@kernel.org/
Hi,
These are the remaining changes needed to support Clang stack depth
tracking for kstack_erase (nee stackleak).
Thanks!
-Kees
Kees Cook (4):
arm64: Handle KCOV __init vs inline mismatches
x86: Handle KCOV __init vs inline mismatches
init.h: Disable sanitizer coverage for __init and __head
kstack_erase: Support Clang stack depth tracking
security/Kconfig.hardening | 5 ++++-
scripts/Makefile.kstack_erase | 6 ++++++
arch/arm64/include/asm/acpi.h | 2 +-
arch/x86/include/asm/acpi.h | 4 ++--
arch/x86/include/asm/init.h | 2 +-
arch/x86/include/asm/realmode.h | 2 +-
include/linux/acpi.h | 4 ++--
include/linux/bootconfig.h | 2 +-
include/linux/efi.h | 2 +-
include/linux/init.h | 4 +++-
include/linux/memblock.h | 2 +-
include/linux/smp.h | 2 +-
arch/x86/kernel/kvm.c | 2 +-
arch/x86/mm/init_64.c | 2 +-
kernel/kexec_handover.c | 4 ++--
15 files changed, 28 insertions(+), 17 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v4 1/4] arm64: Handle KCOV __init vs inline mismatches
2025-07-24 5:50 [PATCH v4 0/4] stackleak: Support Clang stack depth tracking Kees Cook
@ 2025-07-24 5:50 ` Kees Cook
2025-07-29 8:10 ` Will Deacon
2025-07-24 5:50 ` [PATCH v4 2/4] x86: " Kees Cook
` (3 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Kees Cook @ 2025-07-24 5:50 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Kees Cook, Will Deacon, Ard Biesheuvel, Catalin Marinas,
Jonathan Cameron, Gavin Shan, Russell King (Oracle), James Morse,
Oza Pawandeep, Anshuman Khandual, linux-arm-kernel,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Paolo Bonzini, Mike Rapoport, Vitaly Kuznetsov,
Henrique de Moraes Holschuh, Hans de Goede, Ilpo Järvinen,
Rafael J. Wysocki, Len Brown, Masami Hiramatsu, Michal Wilczynski,
Juergen Gross, Andy Shevchenko, Kirill A. Shutemov,
Roger Pau Monne, David Woodhouse, Usama Arif,
Guilherme G. Piccoli, Thomas Huth, Brian Gerst, Marco Elver,
Andrey Konovalov, Andrey Ryabinin, Hou Wenlong, Andrew Morton,
Masahiro Yamada, Peter Zijlstra (Intel), Luis Chamberlain,
Sami Tolvanen, Christophe Leroy, Nathan Chancellor,
Nicolas Schier, Gustavo A. R. Silva, Andy Lutomirski, Baoquan He,
Alexander Graf, Changyuan Lyu, Paul Moore, James Morris,
Serge E. Hallyn, Nick Desaulniers, Bill Wendling, Justin Stitt,
Jan Beulich, Boqun Feng, Viresh Kumar, Paul E. McKenney, Bibo Mao,
linux-kernel, x86, kvm, ibm-acpi-devel, platform-driver-x86,
linux-acpi, linux-trace-kernel, linux-efi, linux-mm, kasan-dev,
linux-kbuild, linux-hardening, kexec, linux-security-module, llvm
GCC appears to have kind of fragile inlining heuristics, in the
sense that it can change whether or not it inlines something based on
optimizations. It looks like the kcov instrumentation being added (or in
this case, removed) from a function changes the optimization results,
and some functions marked "inline" are _not_ inlined. In that case,
we end up with __init code calling a function not marked __init, and we
get the build warnings I'm trying to eliminate in the coming patch that
adds __no_sanitize_coverage to __init functions:
WARNING: modpost: vmlinux: section mismatch in reference: acpi_get_enable_method+0x1c (section: .text.unlikely) -> acpi_psci_present (section: .init.text)
This problem is somewhat fragile (though using either __always_inline
or __init will deterministically solve it), but we've tripped over
this before with GCC and the solution has usually been to just use
__always_inline and move on.
For arm64 this requires forcing one ACPI function to be inlined with
__always_inline.
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Will Deacon <will@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Gavin Shan <gshan@redhat.com>
Cc: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
Cc: James Morse <james.morse@arm.com>
Cc: Oza Pawandeep <quic_poza@quicinc.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: <linux-arm-kernel@lists.infradead.org>
---
arch/arm64/include/asm/acpi.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h
index a407f9cd549e..c07a58b96329 100644
--- a/arch/arm64/include/asm/acpi.h
+++ b/arch/arm64/include/asm/acpi.h
@@ -150,7 +150,7 @@ acpi_set_mailbox_entry(int cpu, struct acpi_madt_generic_interrupt *processor)
{}
#endif
-static inline const char *acpi_get_enable_method(int cpu)
+static __always_inline const char *acpi_get_enable_method(int cpu)
{
if (acpi_psci_present())
return "psci";
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v4 2/4] x86: Handle KCOV __init vs inline mismatches
2025-07-24 5:50 [PATCH v4 0/4] stackleak: Support Clang stack depth tracking Kees Cook
2025-07-24 5:50 ` [PATCH v4 1/4] arm64: Handle KCOV __init vs inline mismatches Kees Cook
@ 2025-07-24 5:50 ` Kees Cook
2025-07-29 8:28 ` Mike Rapoport
2025-07-29 9:34 ` Arnd Bergmann
2025-07-24 5:50 ` [PATCH v4 3/4] init.h: Disable sanitizer coverage for __init and __head Kees Cook
` (2 subsequent siblings)
4 siblings, 2 replies; 12+ messages in thread
From: Kees Cook @ 2025-07-24 5:50 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Kees Cook, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, Paolo Bonzini, Mike Rapoport,
Ard Biesheuvel, Vitaly Kuznetsov, Henrique de Moraes Holschuh,
Hans de Goede, Ilpo Järvinen, Rafael J. Wysocki, Len Brown,
Masami Hiramatsu, Michal Wilczynski, Juergen Gross,
Andy Shevchenko, Kirill A. Shutemov, Roger Pau Monne,
David Woodhouse, Usama Arif, Guilherme G. Piccoli, Thomas Huth,
Brian Gerst, kvm, ibm-acpi-devel, platform-driver-x86, linux-acpi,
linux-trace-kernel, linux-efi, linux-mm, Will Deacon,
Catalin Marinas, Jonathan Cameron, Gavin Shan,
Russell King (Oracle), James Morse, Oza Pawandeep,
Anshuman Khandual, Hans de Goede, Kirill A. Shutemov, Marco Elver,
Andrey Konovalov, Andrey Ryabinin, Hou Wenlong, Andrew Morton,
Masahiro Yamada, Peter Zijlstra (Intel), Luis Chamberlain,
Sami Tolvanen, Christophe Leroy, Nathan Chancellor,
Nicolas Schier, Gustavo A. R. Silva, Andy Lutomirski, Baoquan He,
Alexander Graf, Changyuan Lyu, Paul Moore, James Morris,
Serge E. Hallyn, Nick Desaulniers, Bill Wendling, Justin Stitt,
Jan Beulich, Boqun Feng, Viresh Kumar, Paul E. McKenney, Bibo Mao,
linux-kernel, linux-arm-kernel, kasan-dev, linux-kbuild,
linux-hardening, kexec, linux-security-module, llvm
GCC appears to have kind of fragile inlining heuristics, in the
sense that it can change whether or not it inlines something based on
optimizations. It looks like the kcov instrumentation being added (or in
this case, removed) from a function changes the optimization results,
and some functions marked "inline" are _not_ inlined. In that case,
we end up with __init code calling a function not marked __init, and we
get the build warnings I'm trying to eliminate in the coming patch that
adds __no_sanitize_coverage to __init functions:
WARNING: modpost: vmlinux: section mismatch in reference: xbc_exit+0x8 (section: .text.unlikely) -> _xbc_exit (section: .init.text)
WARNING: modpost: vmlinux: section mismatch in reference: real_mode_size_needed+0x15 (section: .text.unlikely) -> real_mode_blob_end (section: .init.data)
WARNING: modpost: vmlinux: section mismatch in reference: __set_percpu_decrypted+0x16 (section: .text.unlikely) -> early_set_memory_decrypted (section: .init.text)
WARNING: modpost: vmlinux: section mismatch in reference: memblock_alloc_from+0x26 (section: .text.unlikely) -> memblock_alloc_try_nid (section: .init.text)
WARNING: modpost: vmlinux: section mismatch in reference: acpi_arch_set_root_pointer+0xc (section: .text.unlikely) -> x86_init (section: .init.data)
WARNING: modpost: vmlinux: section mismatch in reference: acpi_arch_get_root_pointer+0x8 (section: .text.unlikely) -> x86_init (section: .init.data)
WARNING: modpost: vmlinux: section mismatch in reference: efi_config_table_is_usable+0x16 (section: .text.unlikely) -> xen_efi_config_table_is_usable (section: .init.text)
This problem is somewhat fragile (though using either __always_inline
or __init will deterministically solve it), but we've tripped over
this before with GCC and the solution has usually been to just use
__always_inline and move on.
For x86 this means forcing several functions to be inline with
__always_inline.
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: <x86@kernel.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Len Brown <lenb@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Michal Wilczynski <michal.wilczynski@intel.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Roger Pau Monne <roger.pau@citrix.com>
Cc: David Woodhouse <dwmw@amazon.co.uk>
Cc: Usama Arif <usama.arif@bytedance.com>
Cc: "Guilherme G. Piccoli" <gpiccoli@igalia.com>
Cc: Thomas Huth <thuth@redhat.com>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: <kvm@vger.kernel.org>
Cc: <ibm-acpi-devel@lists.sourceforge.net>
Cc: <platform-driver-x86@vger.kernel.org>
Cc: <linux-acpi@vger.kernel.org>
Cc: <linux-trace-kernel@vger.kernel.org>
Cc: <linux-efi@vger.kernel.org>
Cc: <linux-mm@kvack.org>
---
arch/x86/include/asm/acpi.h | 4 ++--
arch/x86/include/asm/realmode.h | 2 +-
include/linux/acpi.h | 4 ++--
include/linux/bootconfig.h | 2 +-
include/linux/efi.h | 2 +-
include/linux/memblock.h | 2 +-
include/linux/smp.h | 2 +-
arch/x86/kernel/kvm.c | 2 +-
arch/x86/mm/init_64.c | 2 +-
kernel/kexec_handover.c | 4 ++--
10 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/arch/x86/include/asm/acpi.h b/arch/x86/include/asm/acpi.h
index 5ab1a4598d00..a03aa6f999d1 100644
--- a/arch/x86/include/asm/acpi.h
+++ b/arch/x86/include/asm/acpi.h
@@ -158,13 +158,13 @@ static inline bool acpi_has_cpu_in_madt(void)
}
#define ACPI_HAVE_ARCH_SET_ROOT_POINTER
-static inline void acpi_arch_set_root_pointer(u64 addr)
+static __always_inline void acpi_arch_set_root_pointer(u64 addr)
{
x86_init.acpi.set_root_pointer(addr);
}
#define ACPI_HAVE_ARCH_GET_ROOT_POINTER
-static inline u64 acpi_arch_get_root_pointer(void)
+static __always_inline u64 acpi_arch_get_root_pointer(void)
{
return x86_init.acpi.get_root_pointer();
}
diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
index f607081a022a..e406a1e92c63 100644
--- a/arch/x86/include/asm/realmode.h
+++ b/arch/x86/include/asm/realmode.h
@@ -78,7 +78,7 @@ extern unsigned char secondary_startup_64[];
extern unsigned char secondary_startup_64_no_verify[];
#endif
-static inline size_t real_mode_size_needed(void)
+static __always_inline size_t real_mode_size_needed(void)
{
if (real_mode_header)
return 0; /* already allocated. */
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 71e692f95290..1c5bb1e887cd 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -759,13 +759,13 @@ int acpi_arch_timer_mem_init(struct arch_timer_mem *timer_mem, int *timer_count)
#endif
#ifndef ACPI_HAVE_ARCH_SET_ROOT_POINTER
-static inline void acpi_arch_set_root_pointer(u64 addr)
+static __always_inline void acpi_arch_set_root_pointer(u64 addr)
{
}
#endif
#ifndef ACPI_HAVE_ARCH_GET_ROOT_POINTER
-static inline u64 acpi_arch_get_root_pointer(void)
+static __always_inline u64 acpi_arch_get_root_pointer(void)
{
return 0;
}
diff --git a/include/linux/bootconfig.h b/include/linux/bootconfig.h
index 3f4b4ac527ca..25df9260d206 100644
--- a/include/linux/bootconfig.h
+++ b/include/linux/bootconfig.h
@@ -290,7 +290,7 @@ int __init xbc_get_info(int *node_size, size_t *data_size);
/* XBC cleanup data structures */
void __init _xbc_exit(bool early);
-static inline void xbc_exit(void)
+static __always_inline void xbc_exit(void)
{
_xbc_exit(false);
}
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 50db7df0efab..a98cc39e7aaa 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -1336,7 +1336,7 @@ struct linux_efi_initrd {
bool xen_efi_config_table_is_usable(const efi_guid_t *guid, unsigned long table);
-static inline
+static __always_inline
bool efi_config_table_is_usable(const efi_guid_t *guid, unsigned long table)
{
if (!IS_ENABLED(CONFIG_XEN_EFI))
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index bb19a2534224..b96746376e17 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -463,7 +463,7 @@ static inline void *memblock_alloc_raw(phys_addr_t size,
NUMA_NO_NODE);
}
-static inline void *memblock_alloc_from(phys_addr_t size,
+static __always_inline void *memblock_alloc_from(phys_addr_t size,
phys_addr_t align,
phys_addr_t min_addr)
{
diff --git a/include/linux/smp.h b/include/linux/smp.h
index bea8d2826e09..18e9c918325e 100644
--- a/include/linux/smp.h
+++ b/include/linux/smp.h
@@ -221,7 +221,7 @@ static inline void wake_up_all_idle_cpus(void) { }
#ifdef CONFIG_UP_LATE_INIT
extern void __init up_late_init(void);
-static inline void smp_init(void) { up_late_init(); }
+static __always_inline void smp_init(void) { up_late_init(); }
#else
static inline void smp_init(void) { }
#endif
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 921c1c783bc1..8ae750cde0c6 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -420,7 +420,7 @@ static u64 kvm_steal_clock(int cpu)
return steal;
}
-static inline void __set_percpu_decrypted(void *ptr, unsigned long size)
+static inline __init void __set_percpu_decrypted(void *ptr, unsigned long size)
{
early_set_memory_decrypted((unsigned long) ptr, size);
}
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index fdb6cab524f0..76e33bd7c556 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -805,7 +805,7 @@ kernel_physical_mapping_change(unsigned long paddr_start,
}
#ifndef CONFIG_NUMA
-static inline void x86_numa_init(void)
+static __always_inline void x86_numa_init(void)
{
memblock_set_node(0, PHYS_ADDR_MAX, &memblock.memory, 0);
}
diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c
index 49634cc3fb43..e49743ae52c5 100644
--- a/kernel/kexec_handover.c
+++ b/kernel/kexec_handover.c
@@ -310,8 +310,8 @@ static int kho_mem_serialize(struct kho_serialization *ser)
return -ENOMEM;
}
-static void deserialize_bitmap(unsigned int order,
- struct khoser_mem_bitmap_ptr *elm)
+static void __init deserialize_bitmap(unsigned int order,
+ struct khoser_mem_bitmap_ptr *elm)
{
struct kho_mem_phys_bits *bitmap = KHOSER_LOAD_PTR(elm->bitmap);
unsigned long bit;
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v4 3/4] init.h: Disable sanitizer coverage for __init and __head
2025-07-24 5:50 [PATCH v4 0/4] stackleak: Support Clang stack depth tracking Kees Cook
2025-07-24 5:50 ` [PATCH v4 1/4] arm64: Handle KCOV __init vs inline mismatches Kees Cook
2025-07-24 5:50 ` [PATCH v4 2/4] x86: " Kees Cook
@ 2025-07-24 5:50 ` Kees Cook
2025-07-24 5:50 ` [PATCH v4 4/4] kstack_erase: Support Clang stack depth tracking Kees Cook
2025-07-26 0:43 ` [PATCH v4 0/4] stackleak: " Nathan Chancellor
4 siblings, 0 replies; 12+ messages in thread
From: Kees Cook @ 2025-07-24 5:50 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Kees Cook, Marco Elver, Andrey Konovalov, Andrey Ryabinin,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Ard Biesheuvel, Kirill A. Shutemov, Hou Wenlong,
Andrew Morton, Masahiro Yamada, Peter Zijlstra (Intel),
Luis Chamberlain, Sami Tolvanen, Christophe Leroy, kasan-dev,
Will Deacon, Catalin Marinas, Jonathan Cameron, Gavin Shan,
Russell King (Oracle), James Morse, Oza Pawandeep,
Anshuman Khandual, Paolo Bonzini, Mike Rapoport, Vitaly Kuznetsov,
Henrique de Moraes Holschuh, Hans de Goede, Ilpo Järvinen,
Rafael J. Wysocki, Len Brown, Masami Hiramatsu, Michal Wilczynski,
Juergen Gross, Andy Shevchenko, Kirill A. Shutemov,
Roger Pau Monne, David Woodhouse, Usama Arif,
Guilherme G. Piccoli, Thomas Huth, Brian Gerst, Nathan Chancellor,
Nicolas Schier, Gustavo A. R. Silva, Andy Lutomirski, Baoquan He,
Alexander Graf, Changyuan Lyu, Paul Moore, James Morris,
Serge E. Hallyn, Nick Desaulniers, Bill Wendling, Justin Stitt,
Jan Beulich, Boqun Feng, Viresh Kumar, Paul E. McKenney, Bibo Mao,
linux-kernel, linux-arm-kernel, kvm, ibm-acpi-devel,
platform-driver-x86, linux-acpi, linux-trace-kernel, linux-efi,
linux-mm, linux-kbuild, linux-hardening, kexec,
linux-security-module, llvm
While __noinstr already contained __no_sanitize_coverage, it needs to
be added to __init and __head section markings to support the Clang
implementation of CONFIG_KSTACK_ERASE. This is to make sure the stack
depth tracking callback is not executed in unsupported contexts.
The other sanitizer coverage options (trace-pc and trace-cmp) aren't
needed in __head nor __init either ("We are interested in code coverage
as a function of a syscall inputs"[1]), so this is fine to disable for
them as well.
Link: https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/kcov.c?h=v6.14#n179 [1]
Acked-by: Marco Elver <elver@google.com>
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Marco Elver <elver@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: <x86@kernel.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Hou Wenlong <houwenlong.hwl@antgroup.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: <kasan-dev@googlegroups.com>
---
arch/x86/include/asm/init.h | 2 +-
include/linux/init.h | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/init.h b/arch/x86/include/asm/init.h
index 8b1b1abcef15..6bfdaeddbae8 100644
--- a/arch/x86/include/asm/init.h
+++ b/arch/x86/include/asm/init.h
@@ -5,7 +5,7 @@
#if defined(CONFIG_CC_IS_CLANG) && CONFIG_CLANG_VERSION < 170000
#define __head __section(".head.text") __no_sanitize_undefined __no_stack_protector
#else
-#define __head __section(".head.text") __no_sanitize_undefined
+#define __head __section(".head.text") __no_sanitize_undefined __no_sanitize_coverage
#endif
struct x86_mapping_info {
diff --git a/include/linux/init.h b/include/linux/init.h
index ee1309473bc6..c65a050d52a7 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -49,7 +49,9 @@
/* These are for everybody (although not all archs will actually
discard it in modules) */
-#define __init __section(".init.text") __cold __latent_entropy __noinitretpoline
+#define __init __section(".init.text") __cold __latent_entropy \
+ __noinitretpoline \
+ __no_sanitize_coverage
#define __initdata __section(".init.data")
#define __initconst __section(".init.rodata")
#define __exitdata __section(".exit.data")
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v4 4/4] kstack_erase: Support Clang stack depth tracking
2025-07-24 5:50 [PATCH v4 0/4] stackleak: Support Clang stack depth tracking Kees Cook
` (2 preceding siblings ...)
2025-07-24 5:50 ` [PATCH v4 3/4] init.h: Disable sanitizer coverage for __init and __head Kees Cook
@ 2025-07-24 5:50 ` Kees Cook
2025-07-24 13:08 ` Nicolas Schier
2025-07-26 0:43 ` [PATCH v4 0/4] stackleak: " Nathan Chancellor
4 siblings, 1 reply; 12+ messages in thread
From: Kees Cook @ 2025-07-24 5:50 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Kees Cook, Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
Marco Elver, Andrey Konovalov, Andrey Ryabinin, Ard Biesheuvel,
Gustavo A. R. Silva, linux-kbuild, kasan-dev, linux-hardening,
Will Deacon, Catalin Marinas, Jonathan Cameron, Gavin Shan,
Russell King (Oracle), James Morse, Oza Pawandeep,
Anshuman Khandual, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin, Paolo Bonzini, Mike Rapoport,
Vitaly Kuznetsov, Henrique de Moraes Holschuh, Hans de Goede,
Ilpo Järvinen, Rafael J. Wysocki, Len Brown,
Masami Hiramatsu, Michal Wilczynski, Juergen Gross,
Andy Shevchenko, Kirill A. Shutemov, Roger Pau Monne,
David Woodhouse, Usama Arif, Guilherme G. Piccoli, Thomas Huth,
Brian Gerst, Hou Wenlong, Andrew Morton, Peter Zijlstra (Intel),
Luis Chamberlain, Sami Tolvanen, Christophe Leroy,
Andy Lutomirski, Baoquan He, Alexander Graf, Changyuan Lyu,
Paul Moore, James Morris, Serge E. Hallyn, Nick Desaulniers,
Bill Wendling, Justin Stitt, Jan Beulich, Boqun Feng,
Viresh Kumar, Paul E. McKenney, Bibo Mao, linux-kernel,
linux-arm-kernel, x86, kvm, ibm-acpi-devel, platform-driver-x86,
linux-acpi, linux-trace-kernel, linux-efi, linux-mm, kexec,
linux-security-module, llvm
Wire up CONFIG_KSTACK_ERASE to Clang 21's new stack depth tracking
callback[1] option.
Link: https://clang.llvm.org/docs/SanitizerCoverage.html#tracing-stack-depth [1]
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas.schier@linux.dev>
Cc: Marco Elver <elver@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: <linux-kbuild@vger.kernel.org>
Cc: <kasan-dev@googlegroups.com>
Cc: <linux-hardening@vger.kernel.org>
---
security/Kconfig.hardening | 5 ++++-
scripts/Makefile.kstack_erase | 6 ++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening
index f7aa2024ab25..b9a5bc3430aa 100644
--- a/security/Kconfig.hardening
+++ b/security/Kconfig.hardening
@@ -82,10 +82,13 @@ choice
endchoice
+config CC_HAS_SANCOV_STACK_DEPTH_CALLBACK
+ def_bool $(cc-option,-fsanitize-coverage-stack-depth-callback-min=1)
+
config KSTACK_ERASE
bool "Poison kernel stack before returning from syscalls"
depends on HAVE_ARCH_KSTACK_ERASE
- depends on GCC_PLUGINS
+ depends on GCC_PLUGINS || CC_HAS_SANCOV_STACK_DEPTH_CALLBACK
help
This option makes the kernel erase the kernel stack before
returning from system calls. This has the effect of leaving
diff --git a/scripts/Makefile.kstack_erase b/scripts/Makefile.kstack_erase
index 5223d3a35817..c7bc2379e113 100644
--- a/scripts/Makefile.kstack_erase
+++ b/scripts/Makefile.kstack_erase
@@ -8,6 +8,12 @@ kstack-erase-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK_VERBOSE) += -fplugin-arg-stack
DISABLE_KSTACK_ERASE := -fplugin-arg-stackleak_plugin-disable
endif
+ifdef CONFIG_CC_IS_CLANG
+kstack-erase-cflags-y += -fsanitize-coverage=stack-depth
+kstack-erase-cflags-y += -fsanitize-coverage-stack-depth-callback-min=$(CONFIG_KSTACK_ERASE_TRACK_MIN_SIZE)
+DISABLE_KSTACK_ERASE := -fno-sanitize-coverage=stack-depth
+endif
+
KSTACK_ERASE_CFLAGS := $(kstack-erase-cflags-y)
export STACKLEAK_CFLAGS DISABLE_KSTACK_ERASE
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v4 4/4] kstack_erase: Support Clang stack depth tracking
2025-07-24 5:50 ` [PATCH v4 4/4] kstack_erase: Support Clang stack depth tracking Kees Cook
@ 2025-07-24 13:08 ` Nicolas Schier
0 siblings, 0 replies; 12+ messages in thread
From: Nicolas Schier @ 2025-07-24 13:08 UTC (permalink / raw)
To: Kees Cook
Cc: Arnd Bergmann, Masahiro Yamada, Nathan Chancellor, Marco Elver,
Andrey Konovalov, Andrey Ryabinin, Ard Biesheuvel,
Gustavo A. R. Silva, linux-kbuild, kasan-dev, linux-hardening,
Will Deacon, Catalin Marinas, Jonathan Cameron, Gavin Shan,
Russell King (Oracle), James Morse, Oza Pawandeep,
Anshuman Khandual, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin, Paolo Bonzini, Mike Rapoport,
Vitaly Kuznetsov, Henrique de Moraes Holschuh, Hans de Goede,
Ilpo Järvinen, Rafael J. Wysocki, Len Brown,
Masami Hiramatsu, Michal Wilczynski, Juergen Gross,
Andy Shevchenko, Kirill A. Shutemov, Roger Pau Monne,
David Woodhouse, Usama Arif, Guilherme G. Piccoli, Thomas Huth,
Brian Gerst, Hou Wenlong, Andrew Morton, Peter Zijlstra (Intel),
Luis Chamberlain, Sami Tolvanen, Christophe Leroy,
Andy Lutomirski, Baoquan He, Alexander Graf, Changyuan Lyu,
Paul Moore, James Morris, Serge E. Hallyn, Nick Desaulniers,
Bill Wendling, Justin Stitt, Jan Beulich, Boqun Feng,
Viresh Kumar, Paul E. McKenney, Bibo Mao, linux-kernel,
linux-arm-kernel, x86, kvm, ibm-acpi-devel, platform-driver-x86,
linux-acpi, linux-trace-kernel, linux-efi, linux-mm, kexec,
linux-security-module, llvm
On Wed, Jul 23, 2025 at 10:50:28PM -0700, Kees Cook wrote:
> Wire up CONFIG_KSTACK_ERASE to Clang 21's new stack depth tracking
> callback[1] option.
>
> Link: https://clang.llvm.org/docs/SanitizerCoverage.html#tracing-stack-depth [1]
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: Nicolas Schier <nicolas.schier@linux.dev>
> Cc: Marco Elver <elver@google.com>
> Cc: Andrey Konovalov <andreyknvl@gmail.com>
> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: <linux-kbuild@vger.kernel.org>
> Cc: <kasan-dev@googlegroups.com>
> Cc: <linux-hardening@vger.kernel.org>
> ---
Acked-by: Nicolas Schier <n.schier@avm.de>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 0/4] stackleak: Support Clang stack depth tracking
2025-07-24 5:50 [PATCH v4 0/4] stackleak: Support Clang stack depth tracking Kees Cook
` (3 preceding siblings ...)
2025-07-24 5:50 ` [PATCH v4 4/4] kstack_erase: Support Clang stack depth tracking Kees Cook
@ 2025-07-26 0:43 ` Nathan Chancellor
2025-07-26 6:27 ` Kees Cook
2025-07-26 21:47 ` Kees Cook
4 siblings, 2 replies; 12+ messages in thread
From: Nathan Chancellor @ 2025-07-26 0:43 UTC (permalink / raw)
To: Kees Cook
Cc: Arnd Bergmann, Will Deacon, Ard Biesheuvel, Catalin Marinas,
Jonathan Cameron, Gavin Shan, Russell King (Oracle), James Morse,
Oza Pawandeep, Anshuman Khandual, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, H. Peter Anvin, Paolo Bonzini,
Mike Rapoport, Vitaly Kuznetsov, Henrique de Moraes Holschuh,
Hans de Goede, Ilpo Järvinen, Rafael J. Wysocki, Len Brown,
Masami Hiramatsu, Michal Wilczynski, Juergen Gross,
Andy Shevchenko, Kirill A. Shutemov, Roger Pau Monne,
David Woodhouse, Usama Arif, Guilherme G. Piccoli, Thomas Huth,
Brian Gerst, Marco Elver, Andrey Konovalov, Andrey Ryabinin,
Hou Wenlong, Andrew Morton, Masahiro Yamada,
Peter Zijlstra (Intel), Luis Chamberlain, Sami Tolvanen,
Christophe Leroy, Nicolas Schier, Gustavo A. R. Silva,
Andy Lutomirski, Baoquan He, Alexander Graf, Changyuan Lyu,
Paul Moore, James Morris, Serge E. Hallyn, Nick Desaulniers,
Bill Wendling, Justin Stitt, Jan Beulich, Boqun Feng,
Viresh Kumar, Paul E. McKenney, Bibo Mao, linux-kernel,
linux-arm-kernel, x86, kvm, ibm-acpi-devel, platform-driver-x86,
linux-acpi, linux-trace-kernel, linux-efi, linux-mm, kasan-dev,
linux-kbuild, linux-hardening, kexec, linux-security-module, llvm
Hi Kees,
On Wed, Jul 23, 2025 at 10:50:24PM -0700, Kees Cook wrote:
> v4:
> - rebase on for-next/hardening tree (took subset of v3 patches)
> - improve commit logs for x86 and arm64 changes (Mike, Will, Ard)
> v3: https://lore.kernel.org/lkml/20250717231756.make.423-kees@kernel.org/
> v2: https://lore.kernel.org/lkml/20250523043251.it.550-kees@kernel.org/
> v1: https://lore.kernel.org/lkml/20250507180852.work.231-kees@kernel.org/
>
> Hi,
>
> These are the remaining changes needed to support Clang stack depth
> tracking for kstack_erase (nee stackleak).
A few build issues that I see when building next-20250725, which seem
related to this series.
1. I see
ld.lld: error: undefined symbol: __sanitizer_cov_stack_depth
>>> referenced by atags_to_fdt.c
>>> arch/arm/boot/compressed/atags_to_fdt.o:(atags_to_fdt)
make[5]: *** [arch/arm/boot/compressed/Makefile:152: arch/arm/boot/compressed/vmlinux] Error 1
when building ARCH=arm allmodconfig on next-20250725. The following diff appears to cure that one.
diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
index f9075edfd773..f6142946b162 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -9,7 +9,6 @@ OBJS =
HEAD = head.o
OBJS += misc.o decompress.o
-CFLAGS_decompress.o += $(DISABLE_KSTACK_ERASE)
ifeq ($(CONFIG_DEBUG_UNCOMPRESS),y)
OBJS += debug.o
AFLAGS_head.o += -DDEBUG
@@ -96,7 +95,7 @@ KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
ccflags-y := -fpic $(call cc-option,-mno-single-pic-base,) -fno-builtin \
-I$(srctree)/scripts/dtc/libfdt -fno-stack-protector \
- -I$(obj)
+ -I$(obj) $(DISABLE_KSTACK_ERASE)
ccflags-remove-$(CONFIG_FUNCTION_TRACER) += -pg
asflags-y := -DZIMAGE
--
2. I see
kernel/kstack_erase.c:168:2: warning: function with attribute 'no_caller_saved_registers' should only call a function with attribute 'no_caller_saved_registers' or be compiled with '-mgeneral-regs-only' [-Wexcessive-regsave]
168 | BUILD_BUG_ON(CONFIG_KSTACK_ERASE_TRACK_MIN_SIZE > KSTACK_ERASE_SEARCH_DEPTH);
| ^
include/linux/build_bug.h:50:2: note: expanded from macro 'BUILD_BUG_ON'
50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
| ^
include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^
include/linux/compiler_types.h:568:2: note: expanded from macro 'compiletime_assert'
568 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
include/linux/compiler_types.h:556:2: note: expanded from macro '_compiletime_assert'
556 | __compiletime_assert(condition, msg, prefix, suffix)
| ^
include/linux/compiler_types.h:549:4: note: expanded from macro '__compiletime_assert'
549 | prefix ## suffix(); \
| ^
<scratch space>:97:1: note: expanded from here
97 | __compiletime_assert_521
| ^
kernel/kstack_erase.c:168:2: note: '__compiletime_assert_521' declared here
include/linux/build_bug.h:50:2: note: expanded from macro 'BUILD_BUG_ON'
50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
| ^
include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^
include/linux/compiler_types.h:568:2: note: expanded from macro 'compiletime_assert'
568 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
include/linux/compiler_types.h:556:2: note: expanded from macro '_compiletime_assert'
556 | __compiletime_assert(condition, msg, prefix, suffix)
| ^
include/linux/compiler_types.h:546:26: note: expanded from macro '__compiletime_assert'
546 | __noreturn extern void prefix ## suffix(void) \
| ^
<scratch space>:96:1: note: expanded from here
96 | __compiletime_assert_521
| ^
kernel/kstack_erase.c:172:11: warning: function with attribute 'no_caller_saved_registers' should only call a function with attribute 'no_caller_saved_registers' or be compiled with '-mgeneral-regs-only' [-Wexcessive-regsave]
172 | if (sp < current->lowest_stack &&
| ^
arch/x86/include/asm/current.h:28:17: note: expanded from macro 'current'
28 | #define current get_current()
| ^
arch/x86/include/asm/current.h:20:44: note: 'get_current' declared here
20 | static __always_inline struct task_struct *get_current(void)
| ^
kernel/kstack_erase.c:173:37: warning: function with attribute 'no_caller_saved_registers' should only call a function with attribute 'no_caller_saved_registers' or be compiled with '-mgeneral-regs-only' [-Wexcessive-regsave]
173 | sp >= stackleak_task_low_bound(current)) {
| ^
arch/x86/include/asm/current.h:28:17: note: expanded from macro 'current'
28 | #define current get_current()
| ^
arch/x86/include/asm/current.h:20:44: note: 'get_current' declared here
20 | static __always_inline struct task_struct *get_current(void)
| ^
when building ARCH=i386 allmodconfig.
3. I see
In file included from kernel/fork.c:96:
include/linux/kstack_erase.h:29:37: error: passing 'const struct task_struct *' to parameter of type 'struct task_struct *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
29 | return (unsigned long)end_of_stack(tsk) + sizeof(unsigned long);
| ^~~
include/linux/sched/task_stack.h:56:63: note: passing argument to parameter 'p' here
56 | static inline unsigned long *end_of_stack(struct task_struct *p)
| ^
when building ARCH=loongarch allmodconfig, which does not support
CONFIG_THREAD_INFO_IN_TASK it seems.
Cheers,
Nathan
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v4 0/4] stackleak: Support Clang stack depth tracking
2025-07-26 0:43 ` [PATCH v4 0/4] stackleak: " Nathan Chancellor
@ 2025-07-26 6:27 ` Kees Cook
2025-07-26 21:47 ` Kees Cook
1 sibling, 0 replies; 12+ messages in thread
From: Kees Cook @ 2025-07-26 6:27 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Arnd Bergmann, Will Deacon, Ard Biesheuvel, Catalin Marinas,
Jonathan Cameron, Gavin Shan, Russell King (Oracle), James Morse,
Oza Pawandeep, Anshuman Khandual, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, H. Peter Anvin, Paolo Bonzini,
Mike Rapoport, Vitaly Kuznetsov, Henrique de Moraes Holschuh,
Hans de Goede, Ilpo Järvinen, Rafael J. Wysocki, Len Brown,
Masami Hiramatsu, Michal Wilczynski, Juergen Gross,
Andy Shevchenko, Kirill A. Shutemov, Roger Pau Monne,
David Woodhouse, Usama Arif, Guilherme G. Piccoli, Thomas Huth,
Brian Gerst, Marco Elver, Andrey Konovalov, Andrey Ryabinin,
Hou Wenlong, Andrew Morton, Masahiro Yamada,
Peter Zijlstra (Intel), Luis Chamberlain, Sami Tolvanen,
Christophe Leroy, Nicolas Schier, Gustavo A. R. Silva,
Andy Lutomirski, Baoquan He, Alexander Graf, Changyuan Lyu,
Paul Moore, James Morris, Serge E. Hallyn, Nick Desaulniers,
Bill Wendling, Justin Stitt, Jan Beulich, Boqun Feng,
Viresh Kumar, Paul E. McKenney, Bibo Mao, linux-kernel,
linux-arm-kernel, x86, kvm, ibm-acpi-devel, platform-driver-x86,
linux-acpi, linux-trace-kernel, linux-efi, linux-mm, kasan-dev,
linux-kbuild, linux-hardening, kexec, linux-security-module, llvm
On Fri, Jul 25, 2025 at 05:43:13PM -0700, Nathan Chancellor wrote:
> A few build issues that I see when building next-20250725, which seem
> related to this series.
AH! Thank you for letting me know!
> 1. I see
>
> ld.lld: error: undefined symbol: __sanitizer_cov_stack_depth
> >>> referenced by atags_to_fdt.c
> >>> arch/arm/boot/compressed/atags_to_fdt.o:(atags_to_fdt)
> make[5]: *** [arch/arm/boot/compressed/Makefile:152: arch/arm/boot/compressed/vmlinux] Error 1
>
> when building ARCH=arm allmodconfig on next-20250725. The following diff appears to cure that one.
Ah-ha perfect. Yes, that matches what I was expecting to fix it, I was
just about to start working on it, but you beat me to it. :) The same
was reported here:
https://lore.kernel.org/all/CA+G9fYtBk8qnpWvoaFwymCx5s5i-5KXtPGpmf=_+UKJddCOnLA@mail.gmail.com
> 2. I see
>
> kernel/kstack_erase.c:168:2: warning: function with attribute 'no_caller_saved_registers' should only call a function with attribute 'no_caller_saved_registers' or be compiled with '-mgeneral-regs-only' [-Wexcessive-regsave]
> [...]
> when building ARCH=i386 allmodconfig.
Oh, hm, I will figure that out.
> 3. I see
>
> In file included from kernel/fork.c:96:
> include/linux/kstack_erase.h:29:37: error: passing 'const struct task_struct *' to parameter of type 'struct task_struct *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> 29 | return (unsigned long)end_of_stack(tsk) + sizeof(unsigned long);
> | ^~~
> include/linux/sched/task_stack.h:56:63: note: passing argument to parameter 'p' here
> 56 | static inline unsigned long *end_of_stack(struct task_struct *p)
> | ^
>
> when building ARCH=loongarch allmodconfig, which does not support
> CONFIG_THREAD_INFO_IN_TASK it seems.
Oh, eek. Yeah, I'll need to make an explicit dependency I guess? ("How
did this ever work?")
Thanks again!
--
Kees Cook
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 0/4] stackleak: Support Clang stack depth tracking
2025-07-26 0:43 ` [PATCH v4 0/4] stackleak: " Nathan Chancellor
2025-07-26 6:27 ` Kees Cook
@ 2025-07-26 21:47 ` Kees Cook
1 sibling, 0 replies; 12+ messages in thread
From: Kees Cook @ 2025-07-26 21:47 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Arnd Bergmann, Will Deacon, Ard Biesheuvel, Catalin Marinas,
Jonathan Cameron, Gavin Shan, Russell King (Oracle), James Morse,
Oza Pawandeep, Anshuman Khandual, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, H. Peter Anvin, Paolo Bonzini,
Mike Rapoport, Vitaly Kuznetsov, Henrique de Moraes Holschuh,
Hans de Goede, Ilpo Järvinen, Rafael J. Wysocki, Len Brown,
Masami Hiramatsu, Michal Wilczynski, Juergen Gross,
Andy Shevchenko, Kirill A. Shutemov, Roger Pau Monne,
David Woodhouse, Usama Arif, Guilherme G. Piccoli, Thomas Huth,
Brian Gerst, Marco Elver, Andrey Konovalov, Andrey Ryabinin,
Hou Wenlong, Andrew Morton, Masahiro Yamada,
Peter Zijlstra (Intel), Luis Chamberlain, Sami Tolvanen,
Christophe Leroy, Nicolas Schier, Gustavo A. R. Silva,
Andy Lutomirski, Baoquan He, Alexander Graf, Changyuan Lyu,
Paul Moore, James Morris, Serge E. Hallyn, Nick Desaulniers,
Bill Wendling, Justin Stitt, Jan Beulich, Boqun Feng,
Viresh Kumar, Paul E. McKenney, Bibo Mao, linux-kernel,
linux-arm-kernel, x86, kvm, ibm-acpi-devel, platform-driver-x86,
linux-acpi, linux-trace-kernel, linux-efi, linux-mm, kasan-dev,
linux-kbuild, linux-hardening, kexec, linux-security-module, llvm
On Fri, Jul 25, 2025 at 05:43:13PM -0700, Nathan Chancellor wrote:
> ld.lld: error: undefined symbol: __sanitizer_cov_stack_depth
> >>> referenced by atags_to_fdt.c
Proposed fix:
https://lore.kernel.org/lkml/20250726212945.work.975-kees@kernel.org/
> kernel/kstack_erase.c:168:2: warning: function with attribute 'no_caller_saved_registers' should only call a function with attribute 'no_caller_saved_registers' or be compiled with '-mgeneral-regs-only' [-Wexcessive-regsave]
Proposed fix:
https://lore.kernel.org/lkml/20250726212615.work.800-kees@kernel.org/
> In file included from kernel/fork.c:96:
> include/linux/kstack_erase.h:29:37: error: passing 'const struct task_struct *' to parameter of type 'struct task_struct *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> 29 | return (unsigned long)end_of_stack(tsk) + sizeof(unsigned long);
> | ^~~
> include/linux/sched/task_stack.h:56:63: note: passing argument to parameter 'p' here
> 56 | static inline unsigned long *end_of_stack(struct task_struct *p)
> | ^
Proposed fix:
https://lore.kernel.org/lkml/20250726210641.work.114-kees@kernel.org/
Thanks for the reports! :)
-Kees
--
Kees Cook
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 1/4] arm64: Handle KCOV __init vs inline mismatches
2025-07-24 5:50 ` [PATCH v4 1/4] arm64: Handle KCOV __init vs inline mismatches Kees Cook
@ 2025-07-29 8:10 ` Will Deacon
0 siblings, 0 replies; 12+ messages in thread
From: Will Deacon @ 2025-07-29 8:10 UTC (permalink / raw)
To: Kees Cook
Cc: Arnd Bergmann, Ard Biesheuvel, Catalin Marinas, Jonathan Cameron,
Gavin Shan, Russell King (Oracle), James Morse, Oza Pawandeep,
Anshuman Khandual, linux-arm-kernel, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, H. Peter Anvin, Paolo Bonzini,
Mike Rapoport, Vitaly Kuznetsov, Henrique de Moraes Holschuh,
Hans de Goede, Ilpo Järvinen, Rafael J. Wysocki, Len Brown,
Masami Hiramatsu, Michal Wilczynski, Juergen Gross,
Andy Shevchenko, Kirill A. Shutemov, Roger Pau Monne,
David Woodhouse, Usama Arif, Guilherme G. Piccoli, Thomas Huth,
Brian Gerst, Marco Elver, Andrey Konovalov, Andrey Ryabinin,
Hou Wenlong, Andrew Morton, Masahiro Yamada,
Peter Zijlstra (Intel), Luis Chamberlain, Sami Tolvanen,
Christophe Leroy, Nathan Chancellor, Nicolas Schier,
Gustavo A. R. Silva, Andy Lutomirski, Baoquan He, Alexander Graf,
Changyuan Lyu, Paul Moore, James Morris, Serge E. Hallyn,
Nick Desaulniers, Bill Wendling, Justin Stitt, Jan Beulich,
Boqun Feng, Viresh Kumar, Paul E. McKenney, Bibo Mao,
linux-kernel, x86, kvm, ibm-acpi-devel, platform-driver-x86,
linux-acpi, linux-trace-kernel, linux-efi, linux-mm, kasan-dev,
linux-kbuild, linux-hardening, kexec, linux-security-module, llvm
On Wed, Jul 23, 2025 at 10:50:25PM -0700, Kees Cook wrote:
> GCC appears to have kind of fragile inlining heuristics, in the
> sense that it can change whether or not it inlines something based on
> optimizations. It looks like the kcov instrumentation being added (or in
> this case, removed) from a function changes the optimization results,
> and some functions marked "inline" are _not_ inlined. In that case,
> we end up with __init code calling a function not marked __init, and we
> get the build warnings I'm trying to eliminate in the coming patch that
> adds __no_sanitize_coverage to __init functions:
>
> WARNING: modpost: vmlinux: section mismatch in reference: acpi_get_enable_method+0x1c (section: .text.unlikely) -> acpi_psci_present (section: .init.text)
>
> This problem is somewhat fragile (though using either __always_inline
> or __init will deterministically solve it), but we've tripped over
> this before with GCC and the solution has usually been to just use
> __always_inline and move on.
>
> For arm64 this requires forcing one ACPI function to be inlined with
> __always_inline.
>
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
> Cc: Will Deacon <will@kernel.org>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Gavin Shan <gshan@redhat.com>
> Cc: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
> Cc: James Morse <james.morse@arm.com>
> Cc: Oza Pawandeep <quic_poza@quicinc.com>
> Cc: Anshuman Khandual <anshuman.khandual@arm.com>
> Cc: <linux-arm-kernel@lists.infradead.org>
> ---
> arch/arm64/include/asm/acpi.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h
> index a407f9cd549e..c07a58b96329 100644
> --- a/arch/arm64/include/asm/acpi.h
> +++ b/arch/arm64/include/asm/acpi.h
> @@ -150,7 +150,7 @@ acpi_set_mailbox_entry(int cpu, struct acpi_madt_generic_interrupt *processor)
> {}
> #endif
>
> -static inline const char *acpi_get_enable_method(int cpu)
> +static __always_inline const char *acpi_get_enable_method(int cpu)
> {
> if (acpi_psci_present())
> return "psci";
Thanks for improving the commit message:
Acked-by: Will Deacon <will@kernel.org>
Will
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 2/4] x86: Handle KCOV __init vs inline mismatches
2025-07-24 5:50 ` [PATCH v4 2/4] x86: " Kees Cook
@ 2025-07-29 8:28 ` Mike Rapoport
2025-07-29 9:34 ` Arnd Bergmann
1 sibling, 0 replies; 12+ messages in thread
From: Mike Rapoport @ 2025-07-29 8:28 UTC (permalink / raw)
To: Kees Cook
Cc: Arnd Bergmann, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, Paolo Bonzini, Ard Biesheuvel,
Vitaly Kuznetsov, Henrique de Moraes Holschuh, Hans de Goede,
Ilpo Järvinen, Rafael J. Wysocki, Len Brown,
Masami Hiramatsu, Michal Wilczynski, Juergen Gross,
Andy Shevchenko, Kirill A. Shutemov, Roger Pau Monne,
David Woodhouse, Usama Arif, Guilherme G. Piccoli, Thomas Huth,
Brian Gerst, kvm, ibm-acpi-devel, platform-driver-x86, linux-acpi,
linux-trace-kernel, linux-efi, linux-mm, Will Deacon,
Catalin Marinas, Jonathan Cameron, Gavin Shan,
Russell King (Oracle), James Morse, Oza Pawandeep,
Anshuman Khandual, Hans de Goede, Kirill A. Shutemov, Marco Elver,
Andrey Konovalov, Andrey Ryabinin, Hou Wenlong, Andrew Morton,
Masahiro Yamada, Peter Zijlstra (Intel), Luis Chamberlain,
Sami Tolvanen, Christophe Leroy, Nathan Chancellor,
Nicolas Schier, Gustavo A. R. Silva, Andy Lutomirski, Baoquan He,
Alexander Graf, Changyuan Lyu, Paul Moore, James Morris,
Serge E. Hallyn, Nick Desaulniers, Bill Wendling, Justin Stitt,
Jan Beulich, Boqun Feng, Viresh Kumar, Paul E. McKenney, Bibo Mao,
linux-kernel, linux-arm-kernel, kasan-dev, linux-kbuild,
linux-hardening, kexec, linux-security-module, llvm
On Wed, Jul 23, 2025 at 10:50:26PM -0700, Kees Cook wrote:
> GCC appears to have kind of fragile inlining heuristics, in the
> sense that it can change whether or not it inlines something based on
> optimizations. It looks like the kcov instrumentation being added (or in
> this case, removed) from a function changes the optimization results,
> and some functions marked "inline" are _not_ inlined. In that case,
> we end up with __init code calling a function not marked __init, and we
> get the build warnings I'm trying to eliminate in the coming patch that
> adds __no_sanitize_coverage to __init functions:
>
> WARNING: modpost: vmlinux: section mismatch in reference: xbc_exit+0x8 (section: .text.unlikely) -> _xbc_exit (section: .init.text)
> WARNING: modpost: vmlinux: section mismatch in reference: real_mode_size_needed+0x15 (section: .text.unlikely) -> real_mode_blob_end (section: .init.data)
> WARNING: modpost: vmlinux: section mismatch in reference: __set_percpu_decrypted+0x16 (section: .text.unlikely) -> early_set_memory_decrypted (section: .init.text)
> WARNING: modpost: vmlinux: section mismatch in reference: memblock_alloc_from+0x26 (section: .text.unlikely) -> memblock_alloc_try_nid (section: .init.text)
> WARNING: modpost: vmlinux: section mismatch in reference: acpi_arch_set_root_pointer+0xc (section: .text.unlikely) -> x86_init (section: .init.data)
> WARNING: modpost: vmlinux: section mismatch in reference: acpi_arch_get_root_pointer+0x8 (section: .text.unlikely) -> x86_init (section: .init.data)
> WARNING: modpost: vmlinux: section mismatch in reference: efi_config_table_is_usable+0x16 (section: .text.unlikely) -> xen_efi_config_table_is_usable (section: .init.text)
>
> This problem is somewhat fragile (though using either __always_inline
> or __init will deterministically solve it), but we've tripped over
> this before with GCC and the solution has usually been to just use
> __always_inline and move on.
>
> For x86 this means forcing several functions to be inline with
> __always_inline.
>
> Signed-off-by: Kees Cook <kees@kernel.org>
For memblock bit:
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 2/4] x86: Handle KCOV __init vs inline mismatches
2025-07-24 5:50 ` [PATCH v4 2/4] x86: " Kees Cook
2025-07-29 8:28 ` Mike Rapoport
@ 2025-07-29 9:34 ` Arnd Bergmann
1 sibling, 0 replies; 12+ messages in thread
From: Arnd Bergmann @ 2025-07-29 9:34 UTC (permalink / raw)
To: Kees Cook
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Paolo Bonzini, Mike Rapoport, Ard Biesheuvel,
Vitaly Kuznetsov, Henrique de Moraes Holschuh, Hans de Goede,
Ilpo Järvinen, Rafael J . Wysocki, Len Brown,
Masami Hiramatsu, Michal Wilczynski, Juergen Gross,
Andy Shevchenko, Kirill A. Shutemov, Roger Pau Monne,
David Woodhouse, Usama Arif, Guilherme G. Piccoli, Thomas Huth,
Brian Gerst, kvm, ibm-acpi-devel, platform-driver-x86, linux-acpi,
linux-trace-kernel, linux-efi, linux-mm, Will Deacon,
Catalin Marinas, Jonathan Cameron, Gavin Shan, Russell King,
James Morse, Oza Pawandeep, Anshuman Khandual, Hans de Goede,
Kirill A. Shutemov, Marco Elver, Andrey Konovalov,
Andrey Ryabinin, Hou Wenlong, Andrew Morton, Masahiro Yamada,
Peter Zijlstra, Luis Chamberlain, Sami Tolvanen, Christophe Leroy,
Nathan Chancellor, Nicolas Schier, Gustavo A. R. Silva,
Andy Lutomirski, Baoquan He, Alexander Graf, Changyuan Lyu,
Paul Moore, James Morris, Serge E. Hallyn, Nick Desaulniers,
Bill Wendling, Justin Stitt, Jan Beulich, Boqun Feng,
Viresh Kumar, Paul E. McKenney, Bibo Mao, linux-kernel,
linux-arm-kernel, kasan-dev, linux-kbuild, linux-hardening, kexec,
linux-security-module, llvm
On Thu, Jul 24, 2025, at 07:50, Kees Cook wrote:
> GCC appears to have kind of fragile inlining heuristics, in the
> sense that it can change whether or not it inlines something based on
> optimizations. It looks like the kcov instrumentation being added (or in
> this case, removed) from a function changes the optimization results,
> and some functions marked "inline" are _not_ inlined. In that case,
> we end up with __init code calling a function not marked __init, and we
> get the build warnings I'm trying to eliminate in the coming patch that
> adds __no_sanitize_coverage to __init functions:
>
> WARNING: modpost: vmlinux: section mismatch in reference: xbc_exit+0x8
> (section: .text.unlikely) -> _xbc_exit (section: .init.text)
> WARNING: modpost: vmlinux: section mismatch in reference:
> real_mode_size_needed+0x15 (section: .text.unlikely) ->
> real_mode_blob_end (section: .init.data)
> WARNING: modpost: vmlinux: section mismatch in reference:
> __set_percpu_decrypted+0x16 (section: .text.unlikely) ->
> early_set_memory_decrypted (section: .init.text)
> WARNING: modpost: vmlinux: section mismatch in reference:
> memblock_alloc_from+0x26 (section: .text.unlikely) ->
> memblock_alloc_try_nid (section: .init.text)
> WARNING: modpost: vmlinux: section mismatch in reference:
> acpi_arch_set_root_pointer+0xc (section: .text.unlikely) -> x86_init
> (section: .init.data)
> WARNING: modpost: vmlinux: section mismatch in reference:
> acpi_arch_get_root_pointer+0x8 (section: .text.unlikely) -> x86_init
> (section: .init.data)
> WARNING: modpost: vmlinux: section mismatch in reference:
> efi_config_table_is_usable+0x16 (section: .text.unlikely) ->
> xen_efi_config_table_is_usable (section: .init.text)
>
> This problem is somewhat fragile (though using either __always_inline
> or __init will deterministically solve it), but we've tripped over
> this before with GCC and the solution has usually been to just use
> __always_inline and move on.
>
> For x86 this means forcing several functions to be inline with
> __always_inline.
>
> Signed-off-by: Kees Cook <kees@kernel.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
In my randconfig tests, I got these ones as well:
WARNING: modpost: vmlinux: section mismatch in reference: early_page_ext_enabled+0x14 (section: .text.unlikely) -> early_
page_ext (section: .init.data)
x86_64-linux-ld: lm75.c:(.text+0xd25): undefined reference to `i3c_device_do_priv_xfers'
And one more with a private patch of mine.
These are the fixups that make it build for arm/arm64/x86
randconfigs for me, so you could fold them as well in
as well. I have already sent the i3c patch for upstream
but not the page_ext.h patch.
--- a/include/linux/page_ext.h
+++ b/include/linux/page_ext.h
@@ -57,7 +57,7 @@ extern bool early_page_ext;
extern unsigned long page_ext_size;
extern void pgdat_page_ext_init(struct pglist_data *pgdat);
-static inline bool early_page_ext_enabled(void)
+static __always_inline bool early_page_ext_enabled(void)
{
return early_page_ext;
}
@@ -189,7 +189,7 @@ static inline struct page_ext *page_ext_iter_get(const struct page_ext_iter *ite
#else /* !CONFIG_PAGE_EXTENSION */
struct page_ext;
-static inline bool early_page_ext_enabled(void)
+static __always_inline bool early_page_ext_enabled(void)
{
return false;
}
--- a/include/linux/i3c/device.h
+++ b/include/linux/i3c/device.h
@@ -245,7 +245,7 @@ void i3c_driver_unregister(struct i3c_driver *drv);
*
* Return: 0 if both registrations succeeds, a negative error code otherwise.
*/
-static inline int i3c_i2c_driver_register(struct i3c_driver *i3cdrv,
+static __always_inline int i3c_i2c_driver_register(struct i3c_driver *i3cdrv,
struct i2c_driver *i2cdrv)
{
int ret;
@@ -270,7 +270,7 @@ static inline int i3c_i2c_driver_register(struct i3c_driver *i3cdrv,
* Note that when CONFIG_I3C is not enabled, this function only unregisters the
* @i2cdrv.
*/
-static inline void i3c_i2c_driver_unregister(struct i3c_driver *i3cdrv,
+static __always_inline void i3c_i2c_driver_unregister(struct i3c_driver *i3cdrv,
struct i2c_driver *i2cdrv)
{
if (IS_ENABLED(CONFIG_I3C))
As I understand, the underlying problem is less gcc inlining
being fragile, but more that gcc does not inline functions
when they have different __no_sanitize_coverage attributes.
Arnd
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2025-07-29 9:35 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-24 5:50 [PATCH v4 0/4] stackleak: Support Clang stack depth tracking Kees Cook
2025-07-24 5:50 ` [PATCH v4 1/4] arm64: Handle KCOV __init vs inline mismatches Kees Cook
2025-07-29 8:10 ` Will Deacon
2025-07-24 5:50 ` [PATCH v4 2/4] x86: " Kees Cook
2025-07-29 8:28 ` Mike Rapoport
2025-07-29 9:34 ` Arnd Bergmann
2025-07-24 5:50 ` [PATCH v4 3/4] init.h: Disable sanitizer coverage for __init and __head Kees Cook
2025-07-24 5:50 ` [PATCH v4 4/4] kstack_erase: Support Clang stack depth tracking Kees Cook
2025-07-24 13:08 ` Nicolas Schier
2025-07-26 0:43 ` [PATCH v4 0/4] stackleak: " Nathan Chancellor
2025-07-26 6:27 ` Kees Cook
2025-07-26 21:47 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).