Skip to content

Commit 5d5f049

Browse files
taltenbachnordicjm
authored andcommitted
bootutil: Fix AES and SHA-256 contexts not zeroized with mbedTLS
For some reason, the calls to mbedtls_aes_free, mbedtls_nist_kw_free and mbedtls_sha256_free_drop were commented out which means the AES and SHA-256 contexts were not properly de-initialized after usage when mbedTLS is used. In the case of AES-KW it seems that might lead to a memory leak depending on the mbedTLS configuration, but in any case and independently of the mbedTLS configuration, this leads to the contexts not be zeroized after usage. Not zeroizing a context means it stays in RAM an undefined amount of time, which might enable an attacker to access it and to dump the sensitive data it contains. Signed-off-by: Thomas Altenbach <[email protected]>
1 parent ca06b9f commit 5d5f049

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

boot/bootutil/include/bootutil/crypto/aes_ctr.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ static inline void bootutil_aes_ctr_init(bootutil_aes_ctr_context *ctx)
5353

5454
static inline void bootutil_aes_ctr_drop(bootutil_aes_ctr_context *ctx)
5555
{
56-
/* XXX: config defines MBEDTLS_PLATFORM_NO_STD_FUNCTIONS so no need to free */
57-
/* (void)mbedtls_aes_free(ctx); */
58-
(void)ctx;
56+
mbedtls_aes_free(ctx);
5957
}
6058

6159
static inline int bootutil_aes_ctr_set_key(bootutil_aes_ctr_context *ctx, const uint8_t *k)

boot/bootutil/include/bootutil/crypto/aes_kw.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ static inline void bootutil_aes_kw_init(bootutil_aes_kw_context *ctx)
4545

4646
static inline void bootutil_aes_kw_drop(bootutil_aes_kw_context *ctx)
4747
{
48-
/* XXX: config defines MBEDTLS_PLATFORM_NO_STD_FUNCTIONS so no need to free */
49-
/* (void)mbedtls_aes_free(ctx); */
50-
(void)ctx;
48+
mbedtls_nist_kw_free(ctx);
5149
}
5250

5351
static inline int bootutil_aes_kw_set_unwrap_key(bootutil_aes_kw_context *ctx, const uint8_t *k, uint32_t klen)

boot/bootutil/include/bootutil/crypto/sha.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ static inline int bootutil_sha_init(bootutil_sha_context *ctx)
126126

127127
static inline int bootutil_sha_drop(bootutil_sha_context *ctx)
128128
{
129-
/* XXX: config defines MBEDTLS_PLATFORM_NO_STD_FUNCTIONS so no need to free */
130-
/* (void)mbedtls_sha256_free(ctx); */
131-
(void)ctx;
129+
mbedtls_sha256_free(ctx);
132130
return 0;
133131
}
134132

0 commit comments

Comments
 (0)