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