From 93f0080265a700ab9060783807b53c39e1b536b1 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Tue, 31 Mar 2015 17:28:12 +0200 Subject: [PATCH] aesni: Align all class instances to 16 byte boundaries While the required members are aligned in the struct as required, on 32-bit platforms the allocator aligns the structures itself to 8 bytes only. This results in non-aligned struct members, and invalid memory accesses. --- src/libstrongswan/plugins/aesni/aesni_cbc.c | 4 ++-- src/libstrongswan/plugins/aesni/aesni_ccm.c | 4 ++-- src/libstrongswan/plugins/aesni/aesni_cmac.c | 4 ++-- src/libstrongswan/plugins/aesni/aesni_ctr.c | 4 ++-- src/libstrongswan/plugins/aesni/aesni_gcm.c | 4 ++-- src/libstrongswan/plugins/aesni/aesni_key.c | 4 ++-- src/libstrongswan/plugins/aesni/aesni_xcbc.c | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/libstrongswan/plugins/aesni/aesni_cbc.c b/src/libstrongswan/plugins/aesni/aesni_cbc.c index cf18faf4b..f2fce0f13 100644 --- a/src/libstrongswan/plugins/aesni/aesni_cbc.c +++ b/src/libstrongswan/plugins/aesni/aesni_cbc.c @@ -693,7 +693,7 @@ METHOD(crypter_t, destroy, void, { DESTROY_IF(this->ekey); DESTROY_IF(this->dkey); - free(this); + free_align(this); } /** @@ -720,7 +720,7 @@ aesni_cbc_t *aesni_cbc_create(encryption_algorithm_t algo, size_t key_size) return NULL; } - INIT(this, + INIT_ALIGN(this, sizeof(__m128i), .public = { .crypter = { .encrypt = _encrypt, diff --git a/src/libstrongswan/plugins/aesni/aesni_ccm.c b/src/libstrongswan/plugins/aesni/aesni_ccm.c index 20f2e4fe1..0e4a24f30 100644 --- a/src/libstrongswan/plugins/aesni/aesni_ccm.c +++ b/src/libstrongswan/plugins/aesni/aesni_ccm.c @@ -902,7 +902,7 @@ METHOD(aead_t, destroy, void, { DESTROY_IF(this->key); this->iv_gen->destroy(this->iv_gen); - free(this); + free_align(this); } /** @@ -949,7 +949,7 @@ aesni_ccm_t *aesni_ccm_create(encryption_algorithm_t algo, return NULL; } - INIT(this, + INIT_ALIGN(this, sizeof(__m128i), .public = { .aead = { .encrypt = _encrypt, diff --git a/src/libstrongswan/plugins/aesni/aesni_cmac.c b/src/libstrongswan/plugins/aesni/aesni_cmac.c index f94960dc6..a35445fb4 100644 --- a/src/libstrongswan/plugins/aesni/aesni_cmac.c +++ b/src/libstrongswan/plugins/aesni/aesni_cmac.c @@ -314,7 +314,7 @@ METHOD(mac_t, destroy, void, DESTROY_IF(this->k); memwipe(&this->k1, sizeof(this->k1)); memwipe(&this->k2, sizeof(this->k2)); - free(this); + free_align(this); } /* @@ -324,7 +324,7 @@ mac_t *aesni_cmac_create(encryption_algorithm_t algo, size_t key_size) { private_mac_t *this; - INIT(this, + INIT_ALIGN(this, sizeof(__m128i), .public = { .get_mac = _get_mac, .get_mac_size = _get_mac_size, diff --git a/src/libstrongswan/plugins/aesni/aesni_ctr.c b/src/libstrongswan/plugins/aesni/aesni_ctr.c index e6830c1af..e6f9b841a 100644 --- a/src/libstrongswan/plugins/aesni/aesni_ctr.c +++ b/src/libstrongswan/plugins/aesni/aesni_ctr.c @@ -623,7 +623,7 @@ METHOD(crypter_t, destroy, void, private_aesni_ctr_t *this) { DESTROY_IF(this->key); - free(this); + free_align(this); } /** @@ -650,7 +650,7 @@ aesni_ctr_t *aesni_ctr_create(encryption_algorithm_t algo, size_t key_size) return NULL; } - INIT(this, + INIT_ALIGN(this, sizeof(__m128i), .public = { .crypter = { .encrypt = _crypt, diff --git a/src/libstrongswan/plugins/aesni/aesni_gcm.c b/src/libstrongswan/plugins/aesni/aesni_gcm.c index f6bbea2c6..6296ad2fd 100644 --- a/src/libstrongswan/plugins/aesni/aesni_gcm.c +++ b/src/libstrongswan/plugins/aesni/aesni_gcm.c @@ -1465,7 +1465,7 @@ METHOD(aead_t, destroy, void, memwipe(&this->hhh, sizeof(this->hhh)); memwipe(&this->hhhh, sizeof(this->hhhh)); this->iv_gen->destroy(this->iv_gen); - free(this); + free_align(this); } /** @@ -1512,7 +1512,7 @@ aesni_gcm_t *aesni_gcm_create(encryption_algorithm_t algo, return NULL; } - INIT(this, + INIT_ALIGN(this, sizeof(__m128i), .public = { .aead = { .encrypt = _encrypt, diff --git a/src/libstrongswan/plugins/aesni/aesni_key.c b/src/libstrongswan/plugins/aesni/aesni_key.c index 4d7948dd7..523266a30 100644 --- a/src/libstrongswan/plugins/aesni/aesni_key.c +++ b/src/libstrongswan/plugins/aesni/aesni_key.c @@ -244,7 +244,7 @@ METHOD(aesni_key_t, destroy, void, private_aesni_key_t *this) { memwipe(this, sizeof(*this) + (this->public.rounds + 1) * AES_BLOCK_SIZE); - free(this); + free_align(this); } /** @@ -270,7 +270,7 @@ aesni_key_t *aesni_key_create(bool encrypt, chunk_t key) return NULL; } - INIT_EXTRA(this, (rounds + 1) * AES_BLOCK_SIZE, + INIT_EXTRA_ALIGN(this, (rounds + 1) * AES_BLOCK_SIZE, sizeof(__m128i), .public = { .destroy = _destroy, .rounds = rounds, diff --git a/src/libstrongswan/plugins/aesni/aesni_xcbc.c b/src/libstrongswan/plugins/aesni/aesni_xcbc.c index 13bc2cc3f..b2e8cd5ca 100644 --- a/src/libstrongswan/plugins/aesni/aesni_xcbc.c +++ b/src/libstrongswan/plugins/aesni/aesni_xcbc.c @@ -309,7 +309,7 @@ METHOD(mac_t, destroy, void, DESTROY_IF(this->k1); memwipe(&this->k2, sizeof(this->k2)); memwipe(&this->k3, sizeof(this->k3)); - free(this); + free_align(this); } /* @@ -319,7 +319,7 @@ mac_t *aesni_xcbc_create(encryption_algorithm_t algo, size_t key_size) { private_aesni_mac_t *this; - INIT(this, + INIT_ALIGN(this, sizeof(__m128i), .public = { .get_mac = _get_mac, .get_mac_size = _get_mac_size,