diff mbox series

[v2,1/1] linux-gen: crypto: fix openssl_lock pointer type

Message ID 1510045214-25000-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v2,1/1] linux-gen: crypto: fix openssl_lock pointer type | expand

Commit Message

Github ODP bot Nov. 7, 2017, 9 a.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Wrong pointer type (pointer to pointer) to openssl_lock array
caused data overlapping when running on other than 64-bit
machines.

Fixed pointer type and simplified global data structure to
contain only one dynamically sized array (openssl locks).
Session array was already fixed size but was not defined as
such.

Fixes bug: https://bugs.linaro.org/show_bug.cgi?id=3411

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

Signed-off-by: Viktor Tikkanen <viktor.tikkanen@nokia.com>

---
/** Email created from pull request 274 (psavol:master-openssl-lock)
 ** https://github.com/Linaro/odp/pull/274
 ** Patch: https://github.com/Linaro/odp/pull/274.patch
 ** Base sha: 2dd964e170d71078cfe03d4c9e00c6f592b4326b
 ** Merge commit sha: e069ae9f65ab3e029f2a61b5d60ab0180b4b6ea9
 **/
 platform/linux-generic/odp_crypto.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c
index 40b6d74b4..9cf903d03 100644
--- a/platform/linux-generic/odp_crypto.c
+++ b/platform/linux-generic/odp_crypto.c
@@ -83,9 +83,9 @@  typedef struct odp_crypto_global_s odp_crypto_global_t;
 
 struct odp_crypto_global_s {
 	odp_spinlock_t                lock;
-	odp_ticketlock_t **openssl_lock;
 	odp_crypto_generic_session_t *free;
-	odp_crypto_generic_session_t  sessions[0];
+	odp_crypto_generic_session_t  sessions[MAX_SESSIONS];
+	odp_ticketlock_t              openssl_lock[0];
 };
 
 static odp_crypto_global_t *global;
@@ -961,11 +961,9 @@  static void ODP_UNUSED openssl_lock(int mode, int n,
 				    int line ODP_UNUSED)
 {
 	if (mode & CRYPTO_LOCK)
-		odp_ticketlock_lock((odp_ticketlock_t *)
-				    &global->openssl_lock[n]);
+		odp_ticketlock_lock(&global->openssl_lock[n]);
 	else
-		odp_ticketlock_unlock((odp_ticketlock_t *)
-				      &global->openssl_lock[n]);
+		odp_ticketlock_unlock(&global->openssl_lock[n]);
 }
 
 int
@@ -977,8 +975,7 @@  odp_crypto_init_global(void)
 	int nlocks = CRYPTO_num_locks();
 
 	/* Calculate the memory size we need */
-	mem_size  = sizeof(*global);
-	mem_size += (MAX_SESSIONS * sizeof(odp_crypto_generic_session_t));
+	mem_size  = sizeof(odp_crypto_global_t);
 	mem_size += nlocks * sizeof(odp_ticketlock_t);
 
 	/* Allocate our globally shared memory */
@@ -998,12 +995,8 @@  odp_crypto_init_global(void)
 	odp_spinlock_init(&global->lock);
 
 	if (nlocks > 0) {
-		global->openssl_lock =
-			(odp_ticketlock_t **)&global->sessions[MAX_SESSIONS];
-
 		for (idx = 0; idx < nlocks; idx++)
-			odp_ticketlock_init((odp_ticketlock_t *)
-					    &global->openssl_lock[idx]);
+			odp_ticketlock_init(&global->openssl_lock[idx]);
 
 		CRYPTO_THREADID_set_callback(openssl_thread_id);
 		CRYPTO_set_locking_callback(openssl_lock);