From 304766ffa89eb5a0a09def996de4fc217955ab63 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 26 Apr 2024 18:30:11 +0100 Subject: [PATCH 1/2] Add early exit if zero length AEAD AD passed in. With multipart AEAD, if we attempt to add zero length additional data, then with the buffer sharing fixes this can now lead to undefined behaviour when using gcm. Fix this by returning early, as there is nothing to do if the input length is zero. Signed-off-by: Paul Elliott --- library/psa_crypto.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 969c695ac0..0a9011ad84 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -5194,6 +5194,12 @@ psa_status_t psa_aead_update_ad(psa_aead_operation_t *operation, goto exit; } + /* No input to add (zero length), nothing to do. */ + if (input_length == 0) { + status = PSA_SUCCESS; + goto exit; + } + if (operation->lengths_set) { if (operation->ad_remaining < input_length) { status = PSA_ERROR_INVALID_ARGUMENT; From 405d1f6434fd7e6a7a339d2083d32b3dc5f9808f Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 26 Apr 2024 18:53:51 +0100 Subject: [PATCH 2/2] Add Changelog entry Signed-off-by: Paul Elliott --- ChangeLog.d/fix_ubsan_mp_aead_gcm.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 ChangeLog.d/fix_ubsan_mp_aead_gcm.txt diff --git a/ChangeLog.d/fix_ubsan_mp_aead_gcm.txt b/ChangeLog.d/fix_ubsan_mp_aead_gcm.txt new file mode 100644 index 0000000000..e4726a45d7 --- /dev/null +++ b/ChangeLog.d/fix_ubsan_mp_aead_gcm.txt @@ -0,0 +1,3 @@ +Bugfix + * Fix undefined behaviour (incrementing a NULL pointer by zero length) when + passing in zero length additional data to multipart AEAD.