1From 6d47284d5e9704cfa0ef0e4e9b997595288856c9 Mon Sep 17 00:00:00 2001
2From: Jens Wiklander <jens.wiklander@linaro.org>
3Date: Wed, 4 May 2022 12:39:59 +0200
4Subject: [PATCH] Pass upper 32 bits of TEE_PropSetHandle in value.b
5
6With MTE enabled 64-bit pointer usually use the upper 32 bits too while
7the GP tests assumes that 32 bits are enough. Fix this by passing the
8upper 32 bits in value.b
9
10Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
11---
12 .../TTA_TCF/TTA_TCF/code_files/TTA_TCF.c      | 33 +++++++++++++++----
13 1 file changed, 27 insertions(+), 6 deletions(-)
14
15diff --git a/TTAs_Internal_API_1_1_1/TTA_TCF/TTA_TCF/code_files/TTA_TCF.c b/TTAs_Internal_API_1_1_1/TTA_TCF/TTA_TCF/code_files/TTA_TCF.c
16index 0c7c743b34f9..30ba37788662 100644
17--- a/TTAs_Internal_API_1_1_1/TTA_TCF/TTA_TCF/code_files/TTA_TCF.c
18+++ b/TTAs_Internal_API_1_1_1/TTA_TCF/TTA_TCF/code_files/TTA_TCF.c
19@@ -154,6 +154,24 @@ void TA_EXPORT TA_CloseSessionEntryPoint(
20 	TEE_Free(pSessionContext);
21 }
22
23+static TEE_Param ptr_to_param(void *ptr)
24+{
25+	uint64_t u = (unsigned long)ptr;
26+	TEE_Param param;
27+
28+	param.value.a = u;
29+	param.value.b = u >> 32;
30+
31+	return param;
32+}
33+
34+static void *param_to_ptr(TEE_Param *param)
35+{
36+	unsigned long u = ((uint64_t)param->value.b << 32) | param->value.a;
37+
38+	return (void *)u;
39+}
40+
41 bool isPropertySet (TEE_PropSetHandle propsetOrEnumerator)
42 {
43 	if((propsetOrEnumerator == TEE_PROPSET_CURRENT_TA)||
44@@ -772,6 +790,7 @@ TEE_Result CmdTEEAllocatePropertyEnumerator(
45 {
46 	/** VARIABLES **/
47 	TEE_Result cmdResult;
48+	TEE_PropSetHandle h;
49
50 	S_VAR_NOT_USED(pSessionContext);
51
52@@ -782,7 +801,8 @@ TEE_Result CmdTEEAllocatePropertyEnumerator(
53 		return TRUSTED_APP_ERROR_BAD_PARAMETERS;
54 	}
55
56-	cmdResult = TEE_AllocatePropertyEnumerator((TEE_PropSetHandle*) &pParams[0].value.a);
57+	cmdResult = TEE_AllocatePropertyEnumerator(&h);
58+	pParams[0] = ptr_to_param(h);
59
60 	return cmdResult;
61 }
62@@ -804,7 +824,8 @@ TEE_Result CmdTEEStartPropertyEnumerator(
63 		return TRUSTED_APP_ERROR_BAD_PARAMETERS;
64 	}
65
66-	TEE_StartPropertyEnumerator((TEE_PropSetHandle) pParams[0].value.a, (TEE_PropSetHandle) pParams[1].value.a);
67+	TEE_StartPropertyEnumerator(param_to_ptr(pParams),
68+				    param_to_ptr(pParams + 1));
69
70 	return TEE_SUCCESS;
71 }
72@@ -825,7 +846,7 @@ TEE_Result CmdTEEGetNextPropertyEnumerator_notStarted(
73 		return TRUSTED_APP_ERROR_BAD_PARAMETERS;
74 	}
75
76-	return TEE_GetNextProperty((TEE_PropSetHandle) pParams[0].value.a);
77+	return TEE_GetNextProperty(param_to_ptr(pParams));
78 }
79
80 TEE_Result CmdTEEResetPropertyEnumerator(
81@@ -844,7 +865,7 @@ TEE_Result CmdTEEResetPropertyEnumerator(
82 		return TRUSTED_APP_ERROR_BAD_PARAMETERS;
83 	}
84
85-	TEE_ResetPropertyEnumerator((TEE_PropSetHandle) pParams[0].value.a);
86+	TEE_ResetPropertyEnumerator(param_to_ptr(pParams));
87 	return TEE_SUCCESS;
88 }
89
90@@ -864,7 +885,7 @@ TEE_Result CmdTEEFreePropertyEnumerator(
91 		return TRUSTED_APP_ERROR_BAD_PARAMETERS;
92 	}
93
94-	TEE_FreePropertyEnumerator((TEE_PropSetHandle) pParams[0].value.a);
95+	TEE_FreePropertyEnumerator(param_to_ptr(pParams));
96
97 	return TEE_SUCCESS;
98 }
99@@ -887,7 +908,7 @@ TEE_Result CmdTEEGetPropertyName(
100 		return TRUSTED_APP_ERROR_BAD_PARAMETERS;
101 	}
102
103-	cmdResult = TEE_GetPropertyName((TEE_PropSetHandle) pParams[0].value.a, pParams[1].memref.buffer, &pParams[1].memref.size);
104+	cmdResult = TEE_GetPropertyName(param_to_ptr(pParams), pParams[1].memref.buffer, &pParams[1].memref.size);
105
106 	return cmdResult;
107 }
108--
1092.31.1
110
111