From a23be2230845847df46c98a8ae54e18313de2dc4 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 22 Sep 2021 18:15:51 +0100 Subject: [PATCH 1/2] Fix aarch64 assembly for bignum multiplication Add memory constraints to the aarch64 inline assembly in MULADDC_STOP. This fixes an issue where Clang 12 and 13 were generating non-functional code on aarch64 platforms. See #4962, #4943 for further details. Signed-off-by: David Horstmann --- ChangeLog.d/muladdc-aarch64-memory.txt | 4 ++++ include/mbedtls/bn_mul.h | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 ChangeLog.d/muladdc-aarch64-memory.txt diff --git a/ChangeLog.d/muladdc-aarch64-memory.txt b/ChangeLog.d/muladdc-aarch64-memory.txt new file mode 100644 index 000000000..70addd253 --- /dev/null +++ b/ChangeLog.d/muladdc-aarch64-memory.txt @@ -0,0 +1,4 @@ +Bugfix + * Add missing memory constraints in aarch64 inline assembly for + bignum multiplication. + Fixes #4962. diff --git a/include/mbedtls/bn_mul.h b/include/mbedtls/bn_mul.h index 716bd3b81..31137cd4c 100644 --- a/include/mbedtls/bn_mul.h +++ b/include/mbedtls/bn_mul.h @@ -244,18 +244,18 @@ #define MULADDC_CORE \ "ldr x4, [%2], #8 \n\t" \ "ldr x5, [%1] \n\t" \ - "mul x6, x4, %3 \n\t" \ - "umulh x7, x4, %3 \n\t" \ + "mul x6, x4, %4 \n\t" \ + "umulh x7, x4, %4 \n\t" \ "adds x5, x5, x6 \n\t" \ "adc x7, x7, xzr \n\t" \ "adds x5, x5, %0 \n\t" \ "adc %0, x7, xzr \n\t" \ "str x5, [%1], #8 \n\t" -#define MULADDC_STOP \ - : "+r" (c), "+r" (d), "+r" (s) \ - : "r" (b) \ - : "x4", "x5", "x6", "x7", "cc" \ +#define MULADDC_STOP \ + : "+r" (c), "+r" (d), "+r" (s), "+m" (*(uint64_t (*)[16]) d) \ + : "r" (b), "m" (*(const uint64_t (*)[16]) s) \ + : "x4", "x5", "x6", "x7", "cc" \ ); #endif /* Aarch64 */ From 27d8b5c6808353146325a39a1e8380ada7aaf1dc Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Fri, 24 Sep 2021 15:18:44 +0100 Subject: [PATCH 2/2] Combine changelog entries for muladdc assembly fix Combine the changelog entries for the memory constraints fix on aarch64 and amd64, since these are essentially fixing the same issue. Signed-off-by: David Horstmann --- ChangeLog.d/muladdc-aarch64-memory.txt | 4 ---- ChangeLog.d/muladdc-amd64-memory.txt | 4 ---- ChangeLog.d/muladdc-memory.txt | 5 +++++ 3 files changed, 5 insertions(+), 8 deletions(-) delete mode 100644 ChangeLog.d/muladdc-aarch64-memory.txt delete mode 100644 ChangeLog.d/muladdc-amd64-memory.txt create mode 100644 ChangeLog.d/muladdc-memory.txt diff --git a/ChangeLog.d/muladdc-aarch64-memory.txt b/ChangeLog.d/muladdc-aarch64-memory.txt deleted file mode 100644 index 70addd253..000000000 --- a/ChangeLog.d/muladdc-aarch64-memory.txt +++ /dev/null @@ -1,4 +0,0 @@ -Bugfix - * Add missing memory constraints in aarch64 inline assembly for - bignum multiplication. - Fixes #4962. diff --git a/ChangeLog.d/muladdc-amd64-memory.txt b/ChangeLog.d/muladdc-amd64-memory.txt deleted file mode 100644 index b83433167..000000000 --- a/ChangeLog.d/muladdc-amd64-memory.txt +++ /dev/null @@ -1,4 +0,0 @@ -Bugfix - * Fix missing constraints on x86_64 assembly code for bignum multiplication - that broke some bignum operations with (at least) Clang 12. - Fixes #4116, #4786, #4917. diff --git a/ChangeLog.d/muladdc-memory.txt b/ChangeLog.d/muladdc-memory.txt new file mode 100644 index 000000000..218be5a60 --- /dev/null +++ b/ChangeLog.d/muladdc-memory.txt @@ -0,0 +1,5 @@ +Bugfix + * Fix missing constraints on x86_64 and aarch64 assembly code + for bignum multiplication that broke some bignum operations with + (at least) Clang 12. + Fixes #4116, #4786, #4917, #4962.