From 49fb5d0812301435aa5e86315aae25931e490a3d Mon Sep 17 00:00:00 2001 From: Ioannis Glaropoulos Date: Mon, 9 Mar 2020 20:36:21 +0100 Subject: [PATCH] kernel: fatal: check for esf validity when inspecting nested IRQ For architectures that support detection of nested interrupts, we need to check the validity of the exception stack frame, before we can supply it as a pointer to the function that evaluates whether we are in a nested interrupt context. This commits adds the required esf pointer checks in z_fatal_error(). Signed-off-by: Ioannis Glaropoulos --- kernel/fatal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/fatal.c b/kernel/fatal.c index 7917945c992..d11b6cf9620 100644 --- a/kernel/fatal.c +++ b/kernel/fatal.c @@ -112,7 +112,7 @@ void z_fatal_error(unsigned int reason, const z_arch_esf_t *esf) * See #17656 */ #if defined(CONFIG_ARCH_HAS_NESTED_EXCEPTION_DETECTION) - if (arch_is_in_nested_exception(esf)) { + if ((esf != NULL) && arch_is_in_nested_exception(esf)) { LOG_ERR("Fault during interrupt handling\n"); } #endif @@ -140,7 +140,7 @@ void z_fatal_error(unsigned int reason, const z_arch_esf_t *esf) "Attempted to recover from a kernel panic condition"); /* FIXME: #17656 */ #if defined(CONFIG_ARCH_HAS_NESTED_EXCEPTION_DETECTION) - if (arch_is_in_nested_exception(esf)) { + if ((esf != NULL) && arch_is_in_nested_exception(esf)) { #if defined(CONFIG_STACK_SENTINEL) if (reason != K_ERR_STACK_CHK_FAIL) { __ASSERT(0, @@ -152,7 +152,7 @@ void z_fatal_error(unsigned int reason, const z_arch_esf_t *esf) } else { /* Test mode */ #if defined(CONFIG_ARCH_HAS_NESTED_EXCEPTION_DETECTION) - if (arch_is_in_nested_exception(esf)) { + if ((esf != NULL) && arch_is_in_nested_exception(esf)) { /* Abort the thread only on STACK Sentinel check fail. */ #if defined(CONFIG_STACK_SENTINEL) if (reason != K_ERR_STACK_CHK_FAIL) {