Skip to content
Permalink
Browse files

arch: arm: only allow OOPS and STACK_CHK_FAIL from nPRIV mode

User mode is only allowed to induce oopses and stack check
failures via software-triggered system fatal exceptions. This
commit forces a kernel oops if any other fatal exception reason
is enforced.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
  • Loading branch information...
ioannisg authored and andrewboie committed Jul 27, 2019
1 parent 55fce98 commit e78b61b187e7cd48dfe68284cdede24bcc044f3c
Showing with 20 additions and 1 deletion.
  1. +20 −1 arch/arm/core/fatal.c
@@ -52,7 +52,26 @@ void z_arm_fatal_error(unsigned int reason, const z_arch_esf_t *esf)

void z_do_kernel_oops(const z_arch_esf_t *esf)
{
z_arm_fatal_error(esf->basic.r0, esf);
/* Stacked R0 holds the exception reason. */
unsigned int reason = esf->basic.r0;

#if defined(CONFIG_USERSPACE)
if ((__get_CONTROL() & CONTROL_nPRIV_Msk) == CONTROL_nPRIV_Msk) {
/*
* Exception triggered from nPRIV mode.
*
* User mode is only allowed to induce oopses and stack check
* failures via software-triggered system fatal exceptions.
*/
if (!((esf->basic.r0 == K_ERR_KERNEL_OOPS) ||
(esf->basic.r0 == K_ERR_STACK_CHK_FAIL))) {

reason = K_ERR_KERNEL_OOPS;
}
}

#endif /* CONFIG_USERSPACE */
z_arm_fatal_error(reason, esf);
}

FUNC_NORETURN void z_arch_syscall_oops(void *ssf_ptr)

0 comments on commit e78b61b

Please sign in to comment.
You can’t perform that action at this time.