2
0

pr4948-fix-clang12-opt.patch 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. From 7c847235e8f0e0b877c505f19733b417bb65ff2e Mon Sep 17 00:00:00 2001
  2. From: Gilles Peskine <[email protected]>
  3. Date: Tue, 14 Sep 2021 00:13:05 +0200
  4. Subject: [PATCH] x86_64 MULADDC assembly: add missing constraints about memory
  5. MULADDC_CORE reads from (%%rsi) and writes to (%%rdi). This fragment is
  6. repeated up to 16 times, and %%rsi and %%rdi are s and d on entry
  7. respectively. Hence the complete asm statement reads 16 64-bit words
  8. from memory starting at s, and writes 16 64-bit words starting at d.
  9. Without any declaration of modified memory, Clang 12 and Clang 13 generated
  10. non-working code for mbedtls_mpi_mod_exp. The constraints make the unit
  11. tests pass with Clang 12.
  12. Signed-off-by: Gilles Peskine <[email protected]>
  13. ---
  14. include/mbedtls/bn_mul.h | 6 +++---
  15. 1 file changed, 3 insertions(+), 3 deletions(-)
  16. diff --git a/include/mbedtls/bn_mul.h b/include/mbedtls/bn_mul.h
  17. index 6f1201bf50a..f84f9650ddc 100644
  18. --- a/include/mbedtls/bn_mul.h
  19. +++ b/include/mbedtls/bn_mul.h
  20. @@ -256,9 +256,9 @@
  21. "addq $8, %%rdi\n"
  22. #define MULADDC_STOP \
  23. - : "+c" (c), "+D" (d), "+S" (s) \
  24. - : "b" (b) \
  25. - : "rax", "rdx", "r8" \
  26. + : "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \
  27. + : "b" (b), "m" (*(const uint64_t (*)[16]) s) \
  28. + : "rax", "rdx", "r8" \
  29. );
  30. #endif /* AMD64 */