Joel Hutton | 9e60563 | 2019-02-25 15:18:56 +0000 | [diff] [blame] | 1 | +----------------+-------------------------------------------------------------+ |
| 2 | | Title | RO memory is always executable at AArch64 Secure EL1 | |
| 3 | +================+=============================================================+ |
Paul Beesley | 75017f2 | 2019-03-05 17:10:07 +0000 | [diff] [blame] | 4 | | CVE ID | `CVE-2017-7563`_ | |
Joel Hutton | 9e60563 | 2019-02-25 15:18:56 +0000 | [diff] [blame] | 5 | +----------------+-------------------------------------------------------------+ |
| 6 | | Date | 06 Apr 2017 | |
| 7 | +----------------+-------------------------------------------------------------+ |
| 8 | | Versions | v1.3 (since `Pull Request #662`_) | |
| 9 | | Affected | | |
| 10 | +----------------+-------------------------------------------------------------+ |
| 11 | | Configurations | AArch64 BL2, TSP or other users of xlat_tables library | |
| 12 | | Affected | executing at AArch64 Secure EL1 | |
| 13 | +----------------+-------------------------------------------------------------+ |
| 14 | | Impact | Unexpected Privilege Escalation | |
| 15 | +----------------+-------------------------------------------------------------+ |
| 16 | | Fix Version | `Pull Request #924`_ | |
| 17 | +----------------+-------------------------------------------------------------+ |
| 18 | | Credit | ARM | |
| 19 | +----------------+-------------------------------------------------------------+ |
| 20 | |
| 21 | The translation table library in ARM Trusted Firmware (TF) (under |
| 22 | ``lib/xlat_tables`` and ``lib/xlat_tables_v2``) provides APIs to help program |
| 23 | translation tables in the MMU. The xlat\_tables client specifies its required |
| 24 | memory mappings in the form of ``mmap_region`` structures. Each ``mmap_region`` |
| 25 | has memory attributes represented by the ``mmap_attr_t`` enumeration type. This |
| 26 | contains flags to control data access permissions (``MT_RO``/``MT_RW``) and |
| 27 | instruction execution permissions (``MT_EXECUTE``/``MT_EXECUTE_NEVER``). Thus a |
| 28 | mapping specifying both ``MT_RO`` and ``MT_EXECUTE_NEVER`` should result in a |
| 29 | Read-Only (RO), non-executable memory region. |
| 30 | |
| 31 | This feature does not work correctly for AArch64 images executing at Secure EL1. |
| 32 | Any memory region mapped as RO will always be executable, regardless of whether |
| 33 | the client specified ``MT_EXECUTE`` or ``MT_EXECUTE_NEVER``. |
| 34 | |
| 35 | The vulnerability is known to affect the BL2 and Test Secure Payload (TSP) |
| 36 | images on platforms that enable the ``SEPARATE_CODE_AND_RODATA`` build option, |
| 37 | which includes all ARM standard platforms, and the upstream Xilinx and NVidia |
| 38 | platforms. The RO data section for these images on these platforms is |
| 39 | unexpectedly executable instead of non-executable. Other platforms or |
| 40 | ``xlat_tables`` clients may also be affected. |
| 41 | |
| 42 | The vulnerability primarily manifests itself after `Pull Request #662`_. Before |
| 43 | that, ``xlat_tables`` clients could not specify instruction execution |
| 44 | permissions separately to data access permissions. All RO normal memory regions |
| 45 | were implicitly executable. Before `Pull Request #662`_. the vulnerability |
| 46 | would only manifest itself for device memory mapped as RO; use of this mapping |
| 47 | is considered rare, although the upstream QEMU platform uses this mapping when |
| 48 | the ``DEVICE2_BASE`` build option is used. |
| 49 | |
| 50 | Note that one or more separate vulnerabilities are also required to exploit this |
| 51 | vulnerability. |
| 52 | |
| 53 | The vulnerability is due to incorrect handling of the execute-never bits in the |
| 54 | translation tables. The EL3 translation regime uses a single ``XN`` bit to |
| 55 | determine whether a region is executable. The Secure EL1&0 translation regime |
| 56 | handles 2 Virtual Address (VA) ranges and so uses 2 bits, ``UXN`` and ``PXN``. |
| 57 | The ``xlat_tables`` library only handles the ``XN`` bit, which maps to ``UXN`` |
| 58 | in the Secure EL1&0 regime. As a result, this programs the Secure EL0 execution |
| 59 | permissions but always leaves the memory as executable at Secure EL1. |
| 60 | |
| 61 | The vulnerability is mitigated by the following factors: |
| 62 | |
| 63 | - The xlat\_tables library ensures that all Read-Write (RW) memory regions are |
| 64 | non-executable by setting the ``SCTLR_ELx.WXN`` bit. This overrides any value |
| 65 | of the ``XN``, ``UXN`` or ``PXN`` bits in the translation tables. See the |
| 66 | ``enable_mmu()`` function: |
| 67 | |
| 68 | .. code:: c |
| 69 | |
| 70 | sctlr = read_sctlr_el##_el(); \ |
| 71 | sctlr |= SCTLR_WXN_BIT | SCTLR_M_BIT; \ |
| 72 | |
| 73 | - AArch32 configurations are unaffected. Here the ``XN`` bit controls execution |
| 74 | privileges of the currently executing translation regime, which is the desired |
| 75 | behaviour. |
| 76 | |
| 77 | - ARM TF EL3 code (for example BL1 and BL31) ensures that all non-secure memory |
| 78 | mapped into the secure world is non-executable by setting the ``SCR_EL3.SIF`` |
| 79 | bit. See the ``el3_arch_init_common`` macro in ``el3_common_macros.S``. |
| 80 | |
Paul Beesley | 75017f2 | 2019-03-05 17:10:07 +0000 | [diff] [blame] | 81 | .. _CVE-2017-7563: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-7563 |
Joel Hutton | 9e60563 | 2019-02-25 15:18:56 +0000 | [diff] [blame] | 82 | .. _Pull Request #662: https://github.com/ARM-software/arm-trusted-firmware/pull/662 |
| 83 | .. _Pull Request #924: https://github.com/ARM-software/arm-trusted-firmware/pull/924 |