xtensa-fix-memory-corruption-by-broken-sysregs.patch 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. From 3c8788dbb70b40e737d4b8e30cab81406e5c5091 Mon Sep 17 00:00:00 2001
  2. From: Max Filippov <jcmvbkbc@gmail.com>
  3. Date: Wed, 2 Aug 2017 00:36:05 -0700
  4. Subject: [PATCH] xtensa: fix memory corruption by broken sysregs
  5. In some xtensa configurations there may be system/user registers in
  6. xtensa-modules with negative index. ISA initialization for such config
  7. may clobber heap and result in program termination.
  8. Don't update lookup table entries for register with negative indices.
  9. They are not directly accessible via RSR/WSR/XSR or RUR/WUR, so this
  10. change should not affect processing of valid assembly/binary code.
  11. bfd/
  12. 2017-08-02 Max Filippov <jcmvbkbc@gmail.com>
  13. * xtensa-isa.c (xtensa_isa_init): Don't update lookup table
  14. entries for sysregs with negative indices.
  15. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
  16. ---
  17. Backported from: d84ed528d4817b0ff854006b65a9f6ec75f0407a
  18. bfd/xtensa-isa.c | 3 ++-
  19. 1 file changed, 2 insertions(+), 1 deletion(-)
  20. diff --git a/bfd/xtensa-isa.c b/bfd/xtensa-isa.c
  21. index 8da75bea8109..8c6ee88fdeae 100644
  22. --- a/bfd/xtensa-isa.c
  23. +++ b/bfd/xtensa-isa.c
  24. @@ -292,7 +292,8 @@ xtensa_isa_init (xtensa_isa_status *errno_p, char **error_msg_p)
  25. xtensa_sysreg_internal *sreg = &isa->sysregs[n];
  26. is_user = sreg->is_user;
  27. - isa->sysreg_table[is_user][sreg->number] = n;
  28. + if (sreg->number >= 0)
  29. + isa->sysreg_table[is_user][sreg->number] = n;
  30. }
  31. /* Set up the interface lookup table. */
  32. --
  33. 2.1.4