security-advisory-tfv-8.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. Advisory TFV-8 (CVE-2018-19440)
  2. ===============================
  3. +----------------+-------------------------------------------------------------+
  4. | Title | Not saving x0 to x3 registers can leak information from one |
  5. | | Normal World SMC client to another |
  6. +================+=============================================================+
  7. | CVE ID | `CVE-2018-19440`_ |
  8. +----------------+-------------------------------------------------------------+
  9. | Date | 27 Nov 2018 |
  10. +----------------+-------------------------------------------------------------+
  11. | Versions | All |
  12. | Affected | |
  13. +----------------+-------------------------------------------------------------+
  14. | Configurations | Multiple normal world SMC clients calling into AArch64 BL31 |
  15. | Affected | |
  16. +----------------+-------------------------------------------------------------+
  17. | Impact | Leakage of SMC return values from one normal world SMC |
  18. | | client to another |
  19. +----------------+-------------------------------------------------------------+
  20. | Fix Version | `Pull Request #1710`_ |
  21. +----------------+-------------------------------------------------------------+
  22. | Credit | Secmation |
  23. +----------------+-------------------------------------------------------------+
  24. When taking an exception to EL3, BL31 saves the CPU context. The aim is to
  25. restore it before returning into the lower exception level software that called
  26. into the firmware. However, for an SMC exception, the general purpose registers
  27. ``x0`` to ``x3`` are not part of the CPU context saved on the stack.
  28. As per the `SMC Calling Convention`_, up to 4 values may be returned to the
  29. caller in registers ``x0`` to ``x3``. In TF-A, these return values are written
  30. into the CPU context, typically using one of the ``SMC_RETx()`` macros provided
  31. in the ``include/lib/aarch64/smccc_helpers.h`` header file.
  32. Before returning to the caller, the ``restore_gp_registers()`` function is
  33. called. It restores the values of all general purpose registers taken from the
  34. CPU context stored on the stack. This includes registers ``x0`` to ``x3``, as
  35. can be seen in the ``lib/el3_runtime/aarch64/context.S`` file at line 339
  36. (referring to the version of the code as of `commit c385955`_):
  37. ::
  38. /*
  39. * This function restores all general purpose registers except x30 from the
  40. * CPU context. x30 register must be explicitly restored by the caller.
  41. */
  42. func restore_gp_registers
  43. ldp x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0]
  44. ldp x2, x3, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2]
  45. In the case of an SMC handler that does not use all 4 return values, the
  46. remaining ones are left unchanged in the CPU context. As a result,
  47. ``restore_gp_registers()`` restores the stale values saved by a previous SMC
  48. request (or asynchronous exception to EL3) that used these return values.
  49. In the presence of multiple normal world SMC clients, this behaviour might leak
  50. some of the return values from one client to another. For example, if a victim
  51. client first sends an SMC that returns 4 values, a malicious client may then
  52. send a second SMC expecting no return values (for example, a
  53. ``SDEI_EVENT_COMPLETE`` SMC) to get the 4 return values of the victim client.
  54. In general, the responsibility for mitigating threats due to the presence of
  55. multiple normal world SMC clients lies with EL2 software. When present, EL2
  56. software must trap SMC calls from EL1 software to ensure secure behaviour.
  57. For this reason, TF-A does not save ``x0`` to ``x3`` in the CPU context on an
  58. SMC synchronous exception. It has behaved this way since the first version.
  59. We can confirm that at least upstream KVM-based systems mitigate this threat,
  60. and are therefore unaffected by this issue. Other EL2 software should be audited
  61. to assess the impact of this threat.
  62. EL2 software might find mitigating this threat somewhat onerous, because for all
  63. SMCs it would need to be aware of which return registers contain valid data, so
  64. it can sanitise any unused return registers. On the other hand, mitigating this
  65. in EL3 is relatively easy and cheap. Therefore, TF-A will now ensure that no
  66. information is leaked through registers ``x0`` to ``x3``, by preserving the
  67. register state over the call.
  68. Note that AArch32 TF-A is not affected by this issue. The SMC handling code in
  69. ``SP_MIN`` already saves all general purpose registers - including ``r0`` to
  70. ``r3``, as can be seen in the ``include/lib/aarch32/smccc_macros.S`` file at
  71. line 19 (referring to the version of the code as of `commit c385955`_):
  72. .. code:: c
  73. /*
  74. * Macro to save the General purpose registers (r0 - r12), the banked
  75. * spsr, lr, sp registers and the `scr` register to the SMC context on entry
  76. * due a SMC call. The `lr` of the current mode (monitor) is expected to be
  77. * already saved. The `sp` must point to the `smc_ctx_t` to save to.
  78. * Additionally, also save the 'pmcr' register as this is updated whilst
  79. * executing in the secure world.
  80. */
  81. .macro smccc_save_gp_mode_regs
  82. /* Save r0 - r12 in the SMC context */
  83. stm sp, {r0-r12}
  84. .. _CVE-2018-19440: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-19440
  85. .. _commit c385955: https://github.com/ARM-software/arm-trusted-firmware/commit/c385955
  86. .. _SMC Calling Convention: https://developer.arm.com/docs/den0028/latest
  87. .. _Pull Request #1710: https://github.com/ARM-software/arm-trusted-firmware/pull/1710