Skip to content

Instantly share code, notes, and snippets.

@nickdesaulniers
Created January 27, 2022 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickdesaulniers/84aa12aa059da2c8a058cd92f2d034a9 to your computer and use it in GitHub Desktop.
Save nickdesaulniers/84aa12aa059da2c8a058cd92f2d034a9 to your computer and use it in GitHub Desktop.
diff --git a/kernel/panic.c b/kernel/panic.c
index cefd7d82366f..f664d9682668 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -681,10 +681,11 @@ device_initcall(register_warn_debugfs);
*/
__visible noinstr void __stack_chk_fail(void)
{
- instrumentation_begin();
+begin:
panic("stack-protector: Kernel stack is corrupted in: %pB",
__builtin_return_address(0));
- instrumentation_end();
+end:
+ instrumentation(begin, end);
}
EXPORT_SYMBOL(__stack_chk_fail);
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __LINUX_INSTRUMENTATION_H
#define __LINUX_INSTRUMENTATION_H
#if defined(CONFIG_DEBUG_ENTRY) && defined(CONFIG_STACK_VALIDATION)
/* Begin/end of an instrumentation safe region */
#define instrumentation_begin(label) do { \
asm goto (".pushsection .discard.instr_begin\n\t" \
".long %l0 - .\n\t" \
".popsection"::::label); \
} while (0)
#define instrumentation_end(label) do { \
asm (".pushsection .discard.instr_end\n\t" \
".long %l0 - .\n\t" \
".popsection"::::label); \
} while (0)
#define instrumentation(begin_label, end_label) do { \
instrumentation_being(begin); \
instrumentation_end(end_label); \
}
#else
# define instrumentation_begin() do { } while(0)
# define instrumentation_end() do { } while(0)
# define instrumentation(begin_label, end_label) do { } while (0)
#endif
#endif /* __LINUX_INSTRUMENTATION_H */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment