blob: f9642662976edbb0d4473d680dd2070f3c66ce56 [file] [log] [blame]
Joel Hutton8790f022019-03-15 14:47:02 +00001/*
Juan Pablo Condeebd1b692022-06-30 17:47:35 -04002 * Copyright (c) 2019-2022, Arm Limited. All rights reserved.
Joel Hutton8790f022019-03-15 14:47:02 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Alexei Fedorovfb003382019-10-04 16:13:47 +01007#include <pauth.h>
Joel Hutton8790f022019-03-15 14:47:02 +00008#include <psci.h>
9#include <smccc.h>
10#include <test_helpers.h>
11#include <tftf_lib.h>
12#include <tftf.h>
13#include <tsp.h>
14#include <string.h>
15
Shruti Gupta21a30ed2024-01-13 23:07:43 +000016#ifdef __aarch64__
17static uint128_t pauth_keys_before[NUM_KEYS];
18static uint128_t pauth_keys_after[NUM_KEYS];
19#endif
20
Joel Hutton8790f022019-03-15 14:47:02 +000021/*
22 * TF-A is expected to allow access to key registers from lower EL's,
23 * reading the keys excercises this, on failure this will trap to
24 * EL3 and crash.
25 */
26test_result_t test_pauth_reg_access(void)
27{
28 SKIP_TEST_IF_AARCH32();
Alexei Fedorovfb003382019-10-04 16:13:47 +010029#ifdef __aarch64__
Joel Hutton8790f022019-03-15 14:47:02 +000030 SKIP_TEST_IF_PAUTH_NOT_SUPPORTED();
Shruti Gupta21a30ed2024-01-13 23:07:43 +000031 pauth_test_lib_read_keys(pauth_keys_before);
Joel Hutton8790f022019-03-15 14:47:02 +000032 return TEST_RESULT_SUCCESS;
Alexei Fedorovfb003382019-10-04 16:13:47 +010033#endif /* __aarch64__ */
Joel Hutton8790f022019-03-15 14:47:02 +000034}
35
36/*
Alexei Fedorovfb003382019-10-04 16:13:47 +010037 * Makes a call to PSCI version, and checks that the EL3 pauth keys are not
Joel Hutton8790f022019-03-15 14:47:02 +000038 * leaked when it returns
39 */
Joel Hutton8790f022019-03-15 14:47:02 +000040test_result_t test_pauth_leakage(void)
41{
42 SKIP_TEST_IF_AARCH32();
Alexei Fedorovfb003382019-10-04 16:13:47 +010043#ifdef __aarch64__
Joel Hutton8790f022019-03-15 14:47:02 +000044 SKIP_TEST_IF_PAUTH_NOT_SUPPORTED();
Shruti Gupta21a30ed2024-01-13 23:07:43 +000045 pauth_test_lib_read_keys(pauth_keys_before);
Joel Hutton8790f022019-03-15 14:47:02 +000046
47 tftf_get_psci_version();
48
Shruti Gupta21a30ed2024-01-13 23:07:43 +000049 return pauth_test_lib_compare_template(pauth_keys_before, pauth_keys_after);
Alexei Fedorovfb003382019-10-04 16:13:47 +010050#endif /* __aarch64__ */
Joel Hutton8790f022019-03-15 14:47:02 +000051}
52
Alexei Fedorovfb003382019-10-04 16:13:47 +010053/* Test execution of ARMv8.3-PAuth instructions */
Joel Hutton8790f022019-03-15 14:47:02 +000054test_result_t test_pauth_instructions(void)
55{
56 SKIP_TEST_IF_AARCH32();
Alexei Fedorovfb003382019-10-04 16:13:47 +010057#ifdef __aarch64__
Joel Hutton8790f022019-03-15 14:47:02 +000058 SKIP_TEST_IF_PAUTH_NOT_SUPPORTED();
Alexei Fedorovfb003382019-10-04 16:13:47 +010059
60#if ARM_ARCH_AT_LEAST(8, 3)
Andre Przywara06de4bf2025-04-04 13:29:35 +010061 u_register_t reg = 42;
62
Alexei Fedorovfb003382019-10-04 16:13:47 +010063 /* Pointer authentication instructions */
Andre Przywara06de4bf2025-04-04 13:29:35 +010064 __asm__ volatile ("pacdza %0\n" : "+r"(reg));
Joel Hutton8790f022019-03-15 14:47:02 +000065 return TEST_RESULT_SUCCESS;
Alexei Fedorovfb003382019-10-04 16:13:47 +010066#else
67 tftf_testcase_printf("Pointer Authentication instructions "
68 "are not supported on ARMv%u.%u\n",
69 ARM_ARCH_MAJOR, ARM_ARCH_MINOR);
70 return TEST_RESULT_SKIPPED;
71#endif /* ARM_ARCH_AT_LEAST(8, 3) */
Alexei Fedorovfb003382019-10-04 16:13:47 +010072#endif /* __aarch64__ */
Joel Hutton8790f022019-03-15 14:47:02 +000073}
74
75/*
76 * Makes a call to TSP ADD, and checks that the checks that the Secure World
77 * pauth keys are not leaked
78 */
Joel Hutton8790f022019-03-15 14:47:02 +000079test_result_t test_pauth_leakage_tsp(void)
80{
81 SKIP_TEST_IF_AARCH32();
Alexei Fedorovfb003382019-10-04 16:13:47 +010082#ifdef __aarch64__
Joel Hutton8790f022019-03-15 14:47:02 +000083 smc_args tsp_svc_params;
84 smc_ret_values tsp_result = {0};
Joel Hutton8790f022019-03-15 14:47:02 +000085
86 SKIP_TEST_IF_PAUTH_NOT_SUPPORTED();
87 SKIP_TEST_IF_TSP_NOT_PRESENT();
88
Shruti Gupta21a30ed2024-01-13 23:07:43 +000089 pauth_test_lib_fill_regs_and_template(pauth_keys_before);
Joel Hutton8790f022019-03-15 14:47:02 +000090
91 /* Standard SMC to ADD two numbers */
92 tsp_svc_params.fid = TSP_STD_FID(TSP_ADD);
93 tsp_svc_params.arg1 = 4;
94 tsp_svc_params.arg2 = 6;
95 tsp_result = tftf_smc(&tsp_svc_params);
96
97 /*
98 * Check the result of the addition-TSP_ADD will add
99 * the arguments to themselves and return
100 */
101 if (tsp_result.ret0 != 0 || tsp_result.ret1 != 8 ||
Alexei Fedorovfb003382019-10-04 16:13:47 +0100102 tsp_result.ret2 != 12) {
103 tftf_testcase_printf("TSP add returned wrong result: "
Joel Hutton8790f022019-03-15 14:47:02 +0000104 "got %d %d %d expected: 0 8 12\n",
Alexei Fedorovfb003382019-10-04 16:13:47 +0100105 (unsigned int)tsp_result.ret0,
106 (unsigned int)tsp_result.ret1,
107 (unsigned int)tsp_result.ret2);
Joel Hutton8790f022019-03-15 14:47:02 +0000108 return TEST_RESULT_FAIL;
109 }
Joel Hutton8790f022019-03-15 14:47:02 +0000110
Shruti Gupta21a30ed2024-01-13 23:07:43 +0000111 return pauth_test_lib_compare_template(pauth_keys_before, pauth_keys_after);
Alexei Fedorovfb003382019-10-04 16:13:47 +0100112#endif /* __aarch64__ */
Joel Hutton8790f022019-03-15 14:47:02 +0000113}