summaryrefslogtreecommitdiff
path: root/tests/runtime_services
diff options
context:
space:
mode:
authorRoberto Vargas <roberto.vargas@arm.com>2017-08-14 08:49:58 +0100
committerRoberto Vargas <roberto.vargas@arm.com>2017-11-08 08:11:41 +0000
commit721a59349d3c9c8df5301fc8775ac5b7df1f53bf (patch)
tree0a50ffb23efa2cc5b51a49b73641df98e94db17c /tests/runtime_services
parent222992feee0f726042948d851b9c663ecb47a137 (diff)
Add test for PSCI mem_protect
Mem_protect is an optional PSCI feature that allows to the caller to enable a mechanism that overwrite all the visible memory of the caller when the system boots. This mechanism is intented to protect secrets stored in memory after a reset. Change-Id: I00aa04f8b0d07412d9da491b0114e6d95359e5b3 Signed-off-by: Roberto Vargas <roberto.vargas@arm.com>
Diffstat (limited to 'tests/runtime_services')
-rw-r--r--tests/runtime_services/standard_service/psci/api_tests/mem_protect/test_mem_protect.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/tests/runtime_services/standard_service/psci/api_tests/mem_protect/test_mem_protect.c b/tests/runtime_services/standard_service/psci/api_tests/mem_protect/test_mem_protect.c
new file mode 100644
index 0000000..ffa1cf0
--- /dev/null
+++ b/tests/runtime_services/standard_service/psci/api_tests/mem_protect/test_mem_protect.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of ARM nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <debug.h>
+#include <stdlib.h>
+#include <psci.h>
+#include <test_helpers.h>
+#include <tftf_lib.h>
+
+#define SENTINEL 0x55
+#define MEM_PROT_ENABLED 1
+#define MEM_PROT_DISABLED 0
+/*
+ * Test to verify that mem_protect is executed in next boot after calling
+ * the PSCI mem_protect function
+ *
+ * Returns:
+ * TEST_RESULT_SUCCESS : when after rebooting mem_protect is activated
+ * and the sentinel is detected to have been reset.
+ * TEST_RESULT_FAIL : when some of the calls to mem_protect fails or
+ * sentinel is not cleared after resetting.
+ */
+test_result_t test_mem_protect(void)
+{
+ int ret;
+ unsigned char value;
+ extern unsigned char __TFTF_END__[];
+
+ ret = tftf_get_psci_feature_info(SMC_PSCI_MEM_PROTECT);
+ if (ret == PSCI_E_NOT_SUPPORTED)
+ return TEST_RESULT_SKIPPED;
+
+ if (tftf_is_rebooted()) {
+ value = *__TFTF_END__;
+ if (value != 0 && value != SENTINEL) {
+ tftf_testcase_printf("Sentinel address modified out of mem_protect:%d\n",
+ value);
+ return TEST_RESULT_FAIL;
+ }
+ if (value == SENTINEL) {
+ tftf_testcase_printf("Sentinel address not cleared by mem_protect\n");
+ return TEST_RESULT_FAIL;
+ }
+ return TEST_RESULT_SUCCESS;
+ }
+
+ ret = psci_mem_protect(MEM_PROT_DISABLED);
+ if (ret != MEM_PROT_ENABLED && ret != MEM_PROT_DISABLED) {
+ INFO("Mem_protect failed %d\n", ret);
+ return TEST_RESULT_FAIL;
+ }
+
+ /* mem_protect mechanism should be disabled at this point */
+ ret = psci_mem_protect(MEM_PROT_ENABLED);
+ if (ret != MEM_PROT_DISABLED) {
+ tftf_testcase_printf("Mem_protect failed %d\n", ret);
+ return TEST_RESULT_FAIL;
+ }
+
+ /* mem_protect mechanism should be enabled at this point */
+ ret = psci_mem_protect(MEM_PROT_ENABLED);
+ if (ret != MEM_PROT_ENABLED) {
+ tftf_testcase_printf("Mem_protect failed %d\n", ret);
+ return TEST_RESULT_FAIL;
+ }
+
+ *__TFTF_END__ = SENTINEL;
+
+ /* Notify that we are rebooting now. */
+ tftf_notify_reboot();
+
+ psci_system_reset();
+ /*
+ * psci_reset shouldn't return
+ */
+ return TEST_RESULT_FAIL;
+}