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 | |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 16 | /* |
| 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 | */ |
| 21 | test_result_t test_pauth_reg_access(void) |
| 22 | { |
| 23 | SKIP_TEST_IF_AARCH32(); |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 24 | #ifdef __aarch64__ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 25 | SKIP_TEST_IF_PAUTH_NOT_SUPPORTED(); |
Shruti Gupta | 9d0cfe8 | 2023-04-17 10:57:26 +0100 | [diff] [blame] | 26 | pauth_test_lib_read_keys(); |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 27 | return TEST_RESULT_SUCCESS; |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 28 | #endif /* __aarch64__ */ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | /* |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 32 | * 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] | 33 | * leaked when it returns |
| 34 | */ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 35 | test_result_t test_pauth_leakage(void) |
| 36 | { |
| 37 | SKIP_TEST_IF_AARCH32(); |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 38 | #ifdef __aarch64__ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 39 | SKIP_TEST_IF_PAUTH_NOT_SUPPORTED(); |
Shruti Gupta | 9d0cfe8 | 2023-04-17 10:57:26 +0100 | [diff] [blame] | 40 | pauth_test_lib_read_keys(); |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 41 | |
| 42 | tftf_get_psci_version(); |
| 43 | |
Shruti Gupta | 9d0cfe8 | 2023-04-17 10:57:26 +0100 | [diff] [blame] | 44 | return pauth_test_lib_compare_template(); |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 45 | #endif /* __aarch64__ */ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 48 | /* Test execution of ARMv8.3-PAuth instructions */ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 49 | test_result_t test_pauth_instructions(void) |
| 50 | { |
| 51 | SKIP_TEST_IF_AARCH32(); |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 52 | #ifdef __aarch64__ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 53 | SKIP_TEST_IF_PAUTH_NOT_SUPPORTED(); |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 54 | |
| 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 Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 63 | return TEST_RESULT_SUCCESS; |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 64 | #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 Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 70 | #endif /* __aarch64__ */ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 71 | } |
| 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 Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 77 | test_result_t test_pauth_leakage_tsp(void) |
| 78 | { |
| 79 | SKIP_TEST_IF_AARCH32(); |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 80 | #ifdef __aarch64__ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 81 | smc_args tsp_svc_params; |
| 82 | smc_ret_values tsp_result = {0}; |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 83 | |
| 84 | SKIP_TEST_IF_PAUTH_NOT_SUPPORTED(); |
| 85 | SKIP_TEST_IF_TSP_NOT_PRESENT(); |
| 86 | |
Shruti Gupta | 9d0cfe8 | 2023-04-17 10:57:26 +0100 | [diff] [blame] | 87 | pauth_test_lib_fill_regs_and_template(); |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 88 | |
| 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 Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 100 | tsp_result.ret2 != 12) { |
| 101 | tftf_testcase_printf("TSP add returned wrong result: " |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 102 | "got %d %d %d expected: 0 8 12\n", |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 103 | (unsigned int)tsp_result.ret0, |
| 104 | (unsigned int)tsp_result.ret1, |
| 105 | (unsigned int)tsp_result.ret2); |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 106 | return TEST_RESULT_FAIL; |
| 107 | } |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 108 | |
Shruti Gupta | 9d0cfe8 | 2023-04-17 10:57:26 +0100 | [diff] [blame] | 109 | return pauth_test_lib_compare_template(); |
Alexei Fedorov | fb00338 | 2019-10-04 16:13:47 +0100 | [diff] [blame] | 110 | #endif /* __aarch64__ */ |
Joel Hutton | 8790f02 | 2019-03-15 14:47:02 +0000 | [diff] [blame] | 111 | } |