From 2ad93674dc180e085e29d4986800f8cac9bb4891 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 11 Aug 2023 11:07:06 +0100 Subject: [PATCH 1/2] Fix potential corruption of IV for AES CBC If passed a zero length, AES CBC could potentially corrupt the passed in IV by memcpying it over itself. Although this might be ok with more recent compilers, its not for every compiler we support. Found by coverity. Signed-off-by: Paul Elliott --- library/aes.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/aes.c b/library/aes.c index 592ca6416..b55c08ab1 100644 --- a/library/aes.c +++ b/library/aes.c @@ -1094,6 +1094,11 @@ int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx, return MBEDTLS_ERR_AES_BAD_INPUT_DATA; } + /* Nothing to do if length is zero. */ + if (length == 0) { + return 0; + } + if (length % 16) { return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH; } From 83c2e321d926d033510b080008707e56d63e6cce Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 11 Aug 2023 15:58:30 +0100 Subject: [PATCH 2/2] Add changelog Signed-off-by: Paul Elliott --- ChangeLog.d/fix-aes-cbc-iv-corruption | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 ChangeLog.d/fix-aes-cbc-iv-corruption diff --git a/ChangeLog.d/fix-aes-cbc-iv-corruption b/ChangeLog.d/fix-aes-cbc-iv-corruption new file mode 100644 index 000000000..11eb9463e --- /dev/null +++ b/ChangeLog.d/fix-aes-cbc-iv-corruption @@ -0,0 +1,3 @@ +Bugfix + * Fix a potential corruption of the passed-in IV when mbedtls_aes_crypt_cbc() + is called with zero length and padlock is not enabled.