blob: ada2f1d7097e6eb39702af45ef2b07bb59e8cf2c [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)
61 /* Pointer authentication instructions */
62 __asm__ volatile (
63 "paciasp\n"
64 "autiasp\n"
65 "paciasp\n"
66 "xpaclri"
67 );
Joel Hutton8790f022019-03-15 14:47:02 +000068 return TEST_RESULT_SUCCESS;
Alexei Fedorovfb003382019-10-04 16:13:47 +010069#else
70 tftf_testcase_printf("Pointer Authentication instructions "
71 "are not supported on ARMv%u.%u\n",
72 ARM_ARCH_MAJOR, ARM_ARCH_MINOR);
73 return TEST_RESULT_SKIPPED;
74#endif /* ARM_ARCH_AT_LEAST(8, 3) */
Alexei Fedorovfb003382019-10-04 16:13:47 +010075#endif /* __aarch64__ */
Joel Hutton8790f022019-03-15 14:47:02 +000076}
77
78/*
79 * Makes a call to TSP ADD, and checks that the checks that the Secure World
80 * pauth keys are not leaked
81 */
Joel Hutton8790f022019-03-15 14:47:02 +000082test_result_t test_pauth_leakage_tsp(void)
83{
84 SKIP_TEST_IF_AARCH32();
Alexei Fedorovfb003382019-10-04 16:13:47 +010085#ifdef __aarch64__
Joel Hutton8790f022019-03-15 14:47:02 +000086 smc_args tsp_svc_params;
87 smc_ret_values tsp_result = {0};
Joel Hutton8790f022019-03-15 14:47:02 +000088
89 SKIP_TEST_IF_PAUTH_NOT_SUPPORTED();
90 SKIP_TEST_IF_TSP_NOT_PRESENT();
91
Shruti Gupta21a30ed2024-01-13 23:07:43 +000092 pauth_test_lib_fill_regs_and_template(pauth_keys_before);
Joel Hutton8790f022019-03-15 14:47:02 +000093
94 /* Standard SMC to ADD two numbers */
95 tsp_svc_params.fid = TSP_STD_FID(TSP_ADD);
96 tsp_svc_params.arg1 = 4;
97 tsp_svc_params.arg2 = 6;
98 tsp_result = tftf_smc(&tsp_svc_params);
99
100 /*
101 * Check the result of the addition-TSP_ADD will add
102 * the arguments to themselves and return
103 */
104 if (tsp_result.ret0 != 0 || tsp_result.ret1 != 8 ||
Alexei Fedorovfb003382019-10-04 16:13:47 +0100105 tsp_result.ret2 != 12) {
106 tftf_testcase_printf("TSP add returned wrong result: "
Joel Hutton8790f022019-03-15 14:47:02 +0000107 "got %d %d %d expected: 0 8 12\n",
Alexei Fedorovfb003382019-10-04 16:13:47 +0100108 (unsigned int)tsp_result.ret0,
109 (unsigned int)tsp_result.ret1,
110 (unsigned int)tsp_result.ret2);
Joel Hutton8790f022019-03-15 14:47:02 +0000111 return TEST_RESULT_FAIL;
112 }
Joel Hutton8790f022019-03-15 14:47:02 +0000113
Shruti Gupta21a30ed2024-01-13 23:07:43 +0000114 return pauth_test_lib_compare_template(pauth_keys_before, pauth_keys_after);
Alexei Fedorovfb003382019-10-04 16:13:47 +0100115#endif /* __aarch64__ */
Joel Hutton8790f022019-03-15 14:47:02 +0000116}