blob: b29e5d024a474f7cbe42d5a440555644757c689e [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
Joel Hutton8790f022019-03-15 14:47:02 +000016/*
17 * TF-A is expected to allow access to key registers from lower EL's,
18 * reading the keys excercises this, on failure this will trap to
19 * EL3 and crash.
20 */
21test_result_t test_pauth_reg_access(void)
22{
23 SKIP_TEST_IF_AARCH32();
Alexei Fedorovfb003382019-10-04 16:13:47 +010024#ifdef __aarch64__
Joel Hutton8790f022019-03-15 14:47:02 +000025 SKIP_TEST_IF_PAUTH_NOT_SUPPORTED();
Shruti Gupta9d0cfe82023-04-17 10:57:26 +010026 pauth_test_lib_read_keys();
Joel Hutton8790f022019-03-15 14:47:02 +000027 return TEST_RESULT_SUCCESS;
Alexei Fedorovfb003382019-10-04 16:13:47 +010028#endif /* __aarch64__ */
Joel Hutton8790f022019-03-15 14:47:02 +000029}
30
31/*
Alexei Fedorovfb003382019-10-04 16:13:47 +010032 * Makes a call to PSCI version, and checks that the EL3 pauth keys are not
Joel Hutton8790f022019-03-15 14:47:02 +000033 * leaked when it returns
34 */
Joel Hutton8790f022019-03-15 14:47:02 +000035test_result_t test_pauth_leakage(void)
36{
37 SKIP_TEST_IF_AARCH32();
Alexei Fedorovfb003382019-10-04 16:13:47 +010038#ifdef __aarch64__
Joel Hutton8790f022019-03-15 14:47:02 +000039 SKIP_TEST_IF_PAUTH_NOT_SUPPORTED();
Shruti Gupta9d0cfe82023-04-17 10:57:26 +010040 pauth_test_lib_read_keys();
Joel Hutton8790f022019-03-15 14:47:02 +000041
42 tftf_get_psci_version();
43
Shruti Gupta9d0cfe82023-04-17 10:57:26 +010044 return pauth_test_lib_compare_template();
Alexei Fedorovfb003382019-10-04 16:13:47 +010045#endif /* __aarch64__ */
Joel Hutton8790f022019-03-15 14:47:02 +000046}
47
Alexei Fedorovfb003382019-10-04 16:13:47 +010048/* Test execution of ARMv8.3-PAuth instructions */
Joel Hutton8790f022019-03-15 14:47:02 +000049test_result_t test_pauth_instructions(void)
50{
51 SKIP_TEST_IF_AARCH32();
Alexei Fedorovfb003382019-10-04 16:13:47 +010052#ifdef __aarch64__
Joel Hutton8790f022019-03-15 14:47:02 +000053 SKIP_TEST_IF_PAUTH_NOT_SUPPORTED();
Alexei Fedorovfb003382019-10-04 16:13:47 +010054
55#if ARM_ARCH_AT_LEAST(8, 3)
56 /* Pointer authentication instructions */
57 __asm__ volatile (
58 "paciasp\n"
59 "autiasp\n"
60 "paciasp\n"
61 "xpaclri"
62 );
Joel Hutton8790f022019-03-15 14:47:02 +000063 return TEST_RESULT_SUCCESS;
Alexei Fedorovfb003382019-10-04 16:13:47 +010064#else
65 tftf_testcase_printf("Pointer Authentication instructions "
66 "are not supported on ARMv%u.%u\n",
67 ARM_ARCH_MAJOR, ARM_ARCH_MINOR);
68 return TEST_RESULT_SKIPPED;
69#endif /* ARM_ARCH_AT_LEAST(8, 3) */
Alexei Fedorovfb003382019-10-04 16:13:47 +010070#endif /* __aarch64__ */
Joel Hutton8790f022019-03-15 14:47:02 +000071}
72
73/*
74 * Makes a call to TSP ADD, and checks that the checks that the Secure World
75 * pauth keys are not leaked
76 */
Joel Hutton8790f022019-03-15 14:47:02 +000077test_result_t test_pauth_leakage_tsp(void)
78{
79 SKIP_TEST_IF_AARCH32();
Alexei Fedorovfb003382019-10-04 16:13:47 +010080#ifdef __aarch64__
Joel Hutton8790f022019-03-15 14:47:02 +000081 smc_args tsp_svc_params;
82 smc_ret_values tsp_result = {0};
Joel Hutton8790f022019-03-15 14:47:02 +000083
84 SKIP_TEST_IF_PAUTH_NOT_SUPPORTED();
85 SKIP_TEST_IF_TSP_NOT_PRESENT();
86
Shruti Gupta9d0cfe82023-04-17 10:57:26 +010087 pauth_test_lib_fill_regs_and_template();
Joel Hutton8790f022019-03-15 14:47:02 +000088
89 /* Standard SMC to ADD two numbers */
90 tsp_svc_params.fid = TSP_STD_FID(TSP_ADD);
91 tsp_svc_params.arg1 = 4;
92 tsp_svc_params.arg2 = 6;
93 tsp_result = tftf_smc(&tsp_svc_params);
94
95 /*
96 * Check the result of the addition-TSP_ADD will add
97 * the arguments to themselves and return
98 */
99 if (tsp_result.ret0 != 0 || tsp_result.ret1 != 8 ||
Alexei Fedorovfb003382019-10-04 16:13:47 +0100100 tsp_result.ret2 != 12) {
101 tftf_testcase_printf("TSP add returned wrong result: "
Joel Hutton8790f022019-03-15 14:47:02 +0000102 "got %d %d %d expected: 0 8 12\n",
Alexei Fedorovfb003382019-10-04 16:13:47 +0100103 (unsigned int)tsp_result.ret0,
104 (unsigned int)tsp_result.ret1,
105 (unsigned int)tsp_result.ret2);
Joel Hutton8790f022019-03-15 14:47:02 +0000106 return TEST_RESULT_FAIL;
107 }
Joel Hutton8790f022019-03-15 14:47:02 +0000108
Shruti Gupta9d0cfe82023-04-17 10:57:26 +0100109 return pauth_test_lib_compare_template();
Alexei Fedorovfb003382019-10-04 16:13:47 +0100110#endif /* __aarch64__ */
Joel Hutton8790f022019-03-15 14:47:02 +0000111}