Skip to content

Commit

Permalink
tests: protection: skip XD tests on IA32
Browse files Browse the repository at this point in the history
Ancient 2-level IA32 page tables don't support "eXecute Disable".
Skip the test scenarios for them.

Signed-off-by: Andrew Boie <[email protected]>
  • Loading branch information
Andrew Boie authored and nashif committed Aug 25, 2020
1 parent 069aca2 commit 4b3f50b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/kernel/mem_protect/protection/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

#include "targets.h"

/* 32-bit IA32 page tables have no mechanism to restrict execution */
#if defined(CONFIG_X86) && !defined(CONFIG_X86_64) && !defined(CONFIG_X86_PAE)
#define SKIP_EXECUTE_TESTS
#endif

#define INFO(fmt, ...) printk(fmt, ##__VA_ARGS__)

void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *pEsf)
Expand Down Expand Up @@ -42,6 +47,7 @@ static int __attribute__((noinline)) add_one(int i)
return (i + 1);
}

#ifndef SKIP_EXECUTE_TESTS
static void execute_from_buffer(uint8_t *dst)
{
void *src = FUNC_TO_PTR(add_one);
Expand All @@ -68,6 +74,7 @@ static void execute_from_buffer(uint8_t *dst)
INFO("Did not get expected return value!\n");
}
}
#endif /* SKIP_EXECUTE_TESTS */

/**
* @brief Test write to read only section
Expand Down Expand Up @@ -136,8 +143,12 @@ static void test_write_text(void)
*/
static void test_exec_data(void)
{
#ifdef SKIP_EXECUTE_TESTS
ztest_test_skip();
#else
execute_from_buffer(data_buf);
zassert_unreachable("Execute from data did not fault");
#endif
}

/**
Expand All @@ -147,18 +158,22 @@ static void test_exec_data(void)
*/
static void test_exec_stack(void)
{
#ifdef SKIP_EXECUTE_TESTS
ztest_test_skip();
#else
uint8_t stack_buf[BUF_SIZE] __aligned(sizeof(int));

execute_from_buffer(stack_buf);
zassert_unreachable("Execute from stack did not fault");
#endif
}

/**
* @brief Test execution from heap
*
* @ingroup kernel_memprotect_tests
*/
#if (CONFIG_HEAP_MEM_POOL_SIZE > 0)
#if (CONFIG_HEAP_MEM_POOL_SIZE > 0) && !defined(SKIP_EXECUTE_TESTS)
static void test_exec_heap(void)
{
uint8_t *heap_buf = k_malloc(BUF_SIZE);
Expand Down

0 comments on commit 4b3f50b

Please sign in to comment.