Skip to content
Permalink
Browse files

kernel: cover k_array_index_sanitize()

Needed an explicit test for this function for code
coverage purposes; we were relying indirectly on
other code using it.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
  • Loading branch information...
andrewboie authored and nashif committed Jun 30, 2019
1 parent a3a89ed commit 06d7746cd228a9e951d304357bc58d3acd4004bf
Showing with 22 additions and 1 deletion.
  1. +1 −0 tests/kernel/common/prj.conf
  2. +21 −1 tests/kernel/common/src/main.c
@@ -7,3 +7,4 @@ CONFIG_BOOT_DELAY=500
CONFIG_IRQ_OFFLOAD=y
CONFIG_TEST_USERSPACE=y
CONFIG_SMP=n
CONFIG_BOUNDS_CHECK_BYPASS_MITIGATION=y
@@ -7,6 +7,7 @@

#include <ztest.h>
#include <kernel_version.h>
#include <misc/speculation.h>
#include "version.h"

extern void test_byteorder_memcpy_swap(void);
@@ -68,6 +69,24 @@ static void test_version(void)

}

static void test_bounds_check_mitigation(void)
{
/* Very hard to test against speculation attacks, but we can
* at least assert that logically this function does
* what it says it does.
*/

int index = 17;

index = k_array_index_sanitize(index, 24);
zassert_equal(index, 17, "bad index");

#ifdef CONFIG_USERSPACE
index = k_array_index_sanitize(index, 5);
zassert_equal(index, 0, "bad index");
#endif
}

void test_main(void)
{
ztest_test_suite(common,
@@ -86,7 +105,8 @@ void test_main(void)
ztest_unit_test(test_clock_cycle),
ztest_unit_test(test_version),
ztest_unit_test(test_multilib),
ztest_unit_test(test_thread_context)
ztest_unit_test(test_thread_context),
ztest_unit_test(test_bounds_check_mitigation)
);

ztest_run_test_suite(common);

0 comments on commit 06d7746

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