Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 1 | /* |
Juan Pablo Conde | ebd1b69 | 2022-06-30 17:47:35 -0400 | [diff] [blame] | 2 | * Copyright (c) 2019-2022, Arm Limited. All rights reserved. |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 7 | #include <pauth.h> |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 8 | #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 Gupta | 21a30ed | 2024-01-13 23:07:43 +0000 | [diff] [blame^] | 16 | #ifdef __aarch64__ |
| 17 | static uint128_t pauth_keys_before[NUM_KEYS]; |
| 18 | static uint128_t pauth_keys_after[NUM_KEYS]; |
| 19 | #endif |
| 20 | |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 21 | /* |
| 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 | */ |
| 26 | test_result_t test_pauth_reg_access(void) |
| 27 | { |
| 28 | SKIP_TEST_IF_AARCH32(); |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 29 | #ifdef __aarch64__ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 30 | SKIP_TEST_IF_PAUTH_NOT_SUPPORTED(); |
Shruti Gupta | 21a30ed | 2024-01-13 23:07:43 +0000 | [diff] [blame^] | 31 | pauth_test_lib_read_keys(pauth_keys_before); |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 32 | return TEST_RESULT_SUCCESS; |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 33 | #endif /* __aarch64__ */ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /* |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 37 | * Makes a call to PSCI version, and checks that the EL3 pauth keys are not |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 38 | * leaked when it returns |
| 39 | */ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 40 | test_result_t test_pauth_leakage(void) |
| 41 | { |
| 42 | SKIP_TEST_IF_AARCH32(); |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 43 | #ifdef __aarch64__ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 44 | SKIP_TEST_IF_PAUTH_NOT_SUPPORTED(); |
Shruti Gupta | 21a30ed | 2024-01-13 23:07:43 +0000 | [diff] [blame^] | 45 | pauth_test_lib_read_keys(pauth_keys_before); |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 46 | |
| 47 | tftf_get_psci_version(); |
| 48 | |
Shruti Gupta | 21a30ed | 2024-01-13 23:07:43 +0000 | [diff] [blame^] | 49 | return pauth_test_lib_compare_template(pauth_keys_before, pauth_keys_after); |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 50 | #endif /* __aarch64__ */ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 53 | /* Test execution of ARMv8.3-PAuth instructions */ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 54 | test_result_t test_pauth_instructions(void) |
| 55 | { |
| 56 | SKIP_TEST_IF_AARCH32(); |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 57 | #ifdef __aarch64__ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 58 | SKIP_TEST_IF_PAUTH_NOT_SUPPORTED(); |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 59 | |
| 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 Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 68 | return TEST_RESULT_SUCCESS; |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 69 | #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 Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 75 | #endif /* __aarch64__ */ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 76 | } |
| 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 Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 82 | test_result_t test_pauth_leakage_tsp(void) |
| 83 | { |
| 84 | SKIP_TEST_IF_AARCH32(); |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 85 | #ifdef __aarch64__ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 86 | smc_args tsp_svc_params; |
| 87 | smc_ret_values tsp_result = {0}; |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 88 | |
| 89 | SKIP_TEST_IF_PAUTH_NOT_SUPPORTED(); |
| 90 | SKIP_TEST_IF_TSP_NOT_PRESENT(); |
| 91 | |
Shruti Gupta | 21a30ed | 2024-01-13 23:07:43 +0000 | [diff] [blame^] | 92 | pauth_test_lib_fill_regs_and_template(pauth_keys_before); |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 93 | |
| 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 Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 105 | tsp_result.ret2 != 12) { |
| 106 | tftf_testcase_printf("TSP add returned wrong result: " |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 107 | "got %d %d %d expected: 0 8 12\n", |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 108 | (unsigned int)tsp_result.ret0, |
| 109 | (unsigned int)tsp_result.ret1, |
| 110 | (unsigned int)tsp_result.ret2); |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 111 | return TEST_RESULT_FAIL; |
| 112 | } |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 113 | |
Shruti Gupta | 21a30ed | 2024-01-13 23:07:43 +0000 | [diff] [blame^] | 114 | return pauth_test_lib_compare_template(pauth_keys_before, pauth_keys_after); |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 115 | #endif /* __aarch64__ */ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 116 | } |