1. 16 May, 2022 5 commits
    • Reinette Chatre's avatar
      x86/sgx: Fix race between reclaimer and page fault handler · af117837
      Reinette Chatre authored
      Haitao reported encountering a WARN triggered by the ENCLS[ELDU]
      instruction faulting with a #GP.
      
      The WARN is encountered when the reclaimer evicts a range of
      pages from the enclave when the same pages are faulted back right away.
      
      Consider two enclave pages (ENCLAVE_A and ENCLAVE_B)
      sharing a PCMD page (PCMD_AB). ENCLAVE_A is in the
      enclave memory and ENCLAVE_B is in the backing store. PCMD_AB contains
      just one entry, that of ENCLAVE_B.
      
      Scenario proceeds where ENCLAVE_A is being evicted from the enclave
      while ENCLAVE_B is faulted in.
      
      sgx_reclaim_pages() {
      
        ...
      
        /*
         * Reclaim ENCLAVE_A
         */
        mutex_lock(&encl->lock);
        /*
         * Get a reference to ENCLAVE_A's
         * shmem page where enclave page
         * encrypted data will be stored
         * as well as a reference to the
         * enclave page's PCMD data page,
         * PCMD_AB.
         * Release mutex before writing
         * any data to the shmem pages.
         */
        sgx_encl_get_backing(...);
        encl_page->desc |= SGX_ENCL_PAGE_BEING_RECLAIMED;
        mutex_unlock(&encl->lock);
      
                                          /*
                                           * Fault ENCLAVE_B
                                           */
      
                                          sgx_vma_fault() {
      
                                            mutex_lock(&encl->lock);
                                            /*
                                             * Get reference to
                                             * ENCLAVE_B's shmem page
                                             * as well as PCMD_AB.
                                             */
                                            sgx_encl_get_backing(...)
                                           /*
                                            * Load page back into
                                            * enclave via ELDU.
                                            */
                                           /*
                                            * Release reference to
                                            * ENCLAVE_B' shmem page and
                                            * PCMD_AB.
                                            */
                                           sgx_encl_put_backing(...);
                                           /*
                                            * PCMD_AB is found empty so
                                            * it and ENCLAVE_B's shmem page
                                            * are truncated.
                                            */
                                           /* Truncate ENCLAVE_B backing page */
                                           sgx_encl_truncate_backing_page();
                                           /* Truncate PCMD_AB */
                                           sgx_encl_truncate_backing_page();
      
                                           mutex_unlock(&encl->lock);
      
                                           ...
                                           }
        mutex_lock(&encl->lock);
        encl_page->desc &=
             ~SGX_ENCL_PAGE_BEING_RECLAIMED;
        /*
        * Write encrypted contents of
        * ENCLAVE_A to ENCLAVE_A shmem
        * page and its PCMD data to
        * PCMD_AB.
        */
        sgx_encl_put_backing(...)
      
        /*
         * Reference to PCMD_AB is
         * dropped and it is truncated.
         * ENCLAVE_A's PCMD data is lost.
         */
        mutex_unlock(&encl->lock);
      }
      
      What happens next depends on whether it is ENCLAVE_A being faulted
      in or ENCLAVE_B being evicted - but both end up with ENCLS[ELDU] faulting
      with a #GP.
      
      If ENCLAVE_A is faulted then at the time sgx_encl_get_backing() is called
      a new PCMD page is allocated and providing the empty PCMD data for
      ENCLAVE_A would cause ENCLS[ELDU] to #GP
      
      If ENCLAVE_B is evicted first then a new PCMD_AB would be allocated by the
      reclaimer but later when ENCLAVE_A is faulted the ENCLS[ELDU] instruction
      would #GP during its checks of the PCMD value and the WARN would be
      encountered.
      
      Noting that the reclaimer sets SGX_ENCL_PAGE_BEING_RECLAIMED at the time
      it obtains a reference to the backing store pages of an enclave page it
      is in the process of reclaiming, fix the race by only truncating the PCMD
      page after ensuring that no page sharing the PCMD page is in the process
      of being reclaimed.
      
      Cc: stable@vger.kernel.org
      Fixes: 08999b24 ("x86/sgx: Free backing memory after faulting the enclave page")
      Reported-by: default avatarHaitao Huang <haitao.huang@intel.com>
      Signed-off-by: default avatarReinette Chatre <reinette.chatre@intel.com>
      Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Tested-by: default avatarHaitao Huang <haitao.huang@intel.com>
      Link: https://lkml.kernel.org/r/ed20a5db516aa813873268e125680041ae11dfcf.1652389823.git.reinette.chatre@intel.com
      af117837
    • Reinette Chatre's avatar
      x86/sgx: Obtain backing storage page with enclave mutex held · 0e4e729a
      Reinette Chatre authored
      Haitao reported encountering a WARN triggered by the ENCLS[ELDU]
      instruction faulting with a #GP.
      
      The WARN is encountered when the reclaimer evicts a range of
      pages from the enclave when the same pages are faulted back
      right away.
      
      The SGX backing storage is accessed on two paths: when there
      are insufficient free pages in the EPC the reclaimer works
      to move enclave pages to the backing storage and as enclaves
      access pages that have been moved to the backing storage
      they are retrieved from there as part of page fault handling.
      
      An oversubscribed SGX system will often run the reclaimer and
      page fault handler concurrently and needs to ensure that the
      backing store is accessed safely between the reclaimer and
      the page fault handler. This is not the case because the
      reclaimer accesses the backing store without the enclave mutex
      while the page fault handler accesses the backing store with
      the enclave mutex.
      
      Consider the scenario where a page is faulted while a page sharing
      a PCMD page with the faulted page is being reclaimed. The
      consequence is a race between the reclaimer and page fault
      handler, the reclaimer attempting to access a PCMD at the
      same time it is truncated by the page fault handler. This
      could result in lost PCMD data. Data may still be
      lost if the reclaimer wins the race, this is addressed in
      the following patch.
      
      The reclaimer accesses pages from the backing storage without
      holding the enclave mutex and runs the risk of concurrently
      accessing the backing storage with the page fault handler that
      does access the backing storage with the enclave mutex held.
      
      In the scenario below a PCMD page is truncated from the backing
      store after all its pages have been loaded in to the enclave
      at the same time the PCMD page is loaded from the backing store
      when one of its pages are reclaimed:
      
      sgx_reclaim_pages() {              sgx_vma_fault() {
                                           ...
                                           mutex_lock(&encl->lock);
                                           ...
                                           __sgx_encl_eldu() {
                                             ...
                                             if (pcmd_page_empty) {
      /*
       * EPC page being reclaimed              /*
       * shares a PCMD page with an             * PCMD page truncated
       * enclave page that is being             * while requested from
       * faulted in.                            * reclaimer.
       */                                       */
      sgx_encl_get_backing()  <---------->      sgx_encl_truncate_backing_page()
                                              }
                                             mutex_unlock(&encl->lock);
      }                                    }
      
      In this scenario there is a race between the reclaimer and the page fault
      handler when the reclaimer attempts to get access to the same PCMD page
      that is being truncated. This could result in the reclaimer writing to
      the PCMD page that is then truncated, causing the PCMD data to be lost,
      or in a new PCMD page being allocated. The lost PCMD data may still occur
      after protecting the backing store access with the mutex - this is fixed
      in the next patch. By ensuring the backing store is accessed with the mutex
      held the enclave page state can be made accurate with the
      SGX_ENCL_PAGE_BEING_RECLAIMED flag accurately reflecting that a page
      is in the process of being reclaimed.
      
      Consistently protect the reclaimer's backing store access with the
      enclave's mutex to ensure that it can safely run concurrently with the
      page fault handler.
      
      Cc: stable@vger.kernel.org
      Fixes: 1728ab54 ("x86/sgx: Add a page reclaimer")
      Reported-by: default avatarHaitao Huang <haitao.huang@intel.com>
      Signed-off-by: default avatarReinette Chatre <reinette.chatre@intel.com>
      Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Tested-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Tested-by: default avatarHaitao Huang <haitao.huang@intel.com>
      Link: https://lkml.kernel.org/r/fa2e04c561a8555bfe1f4e7adc37d60efc77387b.1652389823.git.reinette.chatre@intel.com
      0e4e729a
    • Reinette Chatre's avatar
      x86/sgx: Mark PCMD page as dirty when modifying contents · 2154e1c1
      Reinette Chatre authored
      Recent commit 08999b24 ("x86/sgx: Free backing memory
      after faulting the enclave page") expanded __sgx_encl_eldu()
      to clear an enclave page's PCMD (Paging Crypto MetaData)
      from the PCMD page in the backing store after the enclave
      page is restored to the enclave.
      
      Since the PCMD page in the backing store is modified the page
      should be marked as dirty to ensure the modified data is retained.
      
      Cc: stable@vger.kernel.org
      Fixes: 08999b24 ("x86/sgx: Free backing memory after faulting the enclave page")
      Signed-off-by: default avatarReinette Chatre <reinette.chatre@intel.com>
      Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Tested-by: default avatarHaitao Huang <haitao.huang@intel.com>
      Link: https://lkml.kernel.org/r/00cd2ac480db01058d112e347b32599c1a806bc4.1652389823.git.reinette.chatre@intel.com
      2154e1c1
    • Reinette Chatre's avatar
      x86/sgx: Disconnect backing page references from dirty status · 6bd42964
      Reinette Chatre authored
      SGX uses shmem backing storage to store encrypted enclave pages
      and their crypto metadata when enclave pages are moved out of
      enclave memory. Two shmem backing storage pages are associated with
      each enclave page - one backing page to contain the encrypted
      enclave page data and one backing page (shared by a few
      enclave pages) to contain the crypto metadata used by the
      processor to verify the enclave page when it is loaded back into
      the enclave.
      
      sgx_encl_put_backing() is used to release references to the
      backing storage and, optionally, mark both backing store pages
      as dirty.
      
      Managing references and dirty status together in this way results
      in both backing store pages marked as dirty, even if only one of
      the backing store pages are changed.
      
      Additionally, waiting until the page reference is dropped to set
      the page dirty risks a race with the page fault handler that
      may load outdated data into the enclave when a page is faulted
      right after it is reclaimed.
      
      Consider what happens if the reclaimer writes a page to the backing
      store and the page is immediately faulted back, before the reclaimer
      is able to set the dirty bit of the page:
      
      sgx_reclaim_pages() {                    sgx_vma_fault() {
        ...
        sgx_encl_get_backing();
        ...                                      ...
        sgx_reclaimer_write() {
          mutex_lock(&encl->lock);
          /* Write data to backing store */
          mutex_unlock(&encl->lock);
        }
                                                 mutex_lock(&encl->lock);
                                                 __sgx_encl_eldu() {
                                                   ...
                                                   /*
                                                    * Enclave backing store
                                                    * page not released
                                                    * nor marked dirty -
                                                    * contents may not be
                                                    * up to date.
                                                    */
                                                    sgx_encl_get_backing();
                                                    ...
                                                    /*
                                                     * Enclave data restored
                                                     * from backing store
                                                     * and PCMD pages that
                                                     * are not up to date.
                                                     * ENCLS[ELDU] faults
                                                     * because of MAC or PCMD
                                                     * checking failure.
                                                     */
                                                     sgx_encl_put_backing();
                                                  }
                                                  ...
        /* set page dirty */
        sgx_encl_put_backing();
        ...
                                                  mutex_unlock(&encl->lock);
      }                                        }
      
      Remove the option to sgx_encl_put_backing() to set the backing
      pages as dirty and set the needed pages as dirty right after
      receiving important data while enclave mutex is held. This ensures that
      the page fault handler can get up to date data from a page and prepares
      the code for a following change where only one of the backing pages
      need to be marked as dirty.
      
      Cc: stable@vger.kernel.org
      Fixes: 1728ab54 ("x86/sgx: Add a page reclaimer")
      Suggested-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
      Signed-off-by: default avatarReinette Chatre <reinette.chatre@intel.com>
      Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Tested-by: default avatarHaitao Huang <haitao.huang@intel.com>
      Link: https://lore.kernel.org/linux-sgx/8922e48f-6646-c7cc-6393-7c78dcf23d23@intel.com/
      Link: https://lkml.kernel.org/r/fa9f98986923f43e72ef4c6702a50b2a0b3c42e3.1652389823.git.reinette.chatre@intel.com
      6bd42964
    • Linus Torvalds's avatar
      Linux 5.18-rc7 · 42226c98
      Linus Torvalds authored
      42226c98
  2. 15 May, 2022 8 commits
    • Linus Torvalds's avatar
      Merge tag 'driver-core-5.18-rc7' of... · 0cdd776e
      Linus Torvalds authored
      Merge tag 'driver-core-5.18-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
      
      Pull driver core fixes from Greg KH:
       "Here is one fix, and three documentation updates for 5.18-rc7.
      
        The fix is for the firmware loader which resolves a long-reported
        problem where the credentials of the firmware loader could be set to a
        userspace process without enough permissions to actually load the
        firmware image. Many Android vendors have been reporting this for
        quite some time.
      
        The documentation updates are for the embargoed-hardware-issues.rst
        file to add a new entry, change an existing one, and sort the list to
        make changes easier in the future.
      
        All of these have been in linux-next for a while with no reported
        issues"
      
      * tag 'driver-core-5.18-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core:
        Documentation/process: Update ARM contact for embargoed hardware issues
        Documentation/process: Add embargoed HW contact for Ampere Computing
        Documentation/process: Make groups alphabetical and use tabs consistently
        firmware_loader: use kernel credentials when reading firmware
      0cdd776e
    • Linus Torvalds's avatar
      Merge tag 'char-misc-5.18-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc · 5becde60
      Linus Torvalds authored
      Pull char/misc driver fixes from Greg KH:
       "Here are two small driver fixes for 5.18-rc7 that resolve reported
        problems:
      
         - slimbus driver irq bugfix
      
         - interconnect sync state bugfix
      
        Both of these have been in linux-next with no reported problems"
      
      * tag 'char-misc-5.18-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc:
        slimbus: qcom: Fix IRQ check in qcom_slim_probe
        interconnect: Restore sync state by ignoring ipa-virt in provider count
      5becde60
    • Linus Torvalds's avatar
      Merge tag 'tty-5.18-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty · 6811a466
      Linus Torvalds authored
      Pull tty/serial driver fixes from Greg KH:
       "Here are some small tty n_gsm and serial driver fixes for 5.18-rc7
        that resolve reported problems. They include:
      
         - n_gsm fixes for reported issues
      
         - 8250_mtk driver fixes for some platforms
      
         - fsl_lpuart driver fix for reported problem.
      
         - digicolor driver fix for reported problem.
      
        All have been in linux-next for a while with no reported problems"
      
      * tag 'tty-5.18-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty:
        fsl_lpuart: Don't enable interrupts too early
        tty: n_gsm: fix invalid gsmtty_write_room() result
        tty: n_gsm: fix mux activation issues in gsm_config()
        tty: n_gsm: fix buffer over-read in gsm_dlci_data()
        serial: 8250_mtk: Fix register address for XON/XOFF character
        serial: 8250_mtk: Make sure to select the right FEATURE_SEL
        serial: 8250_mtk: Fix UART_EFR register address
        tty/serial: digicolor: fix possible null-ptr-deref in digicolor_uart_probe()
      6811a466
    • Linus Torvalds's avatar
      Merge tag 'usb-5.18-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb · fc49583c
      Linus Torvalds authored
      Pull USB fixes from Greg KH:
       "Here are some small fixes for reported issues with some USB drivers.
        They include:
      
         - xhci fixes for xhci-mtk platform driver
      
         - typec driver fixes for reported problems.
      
         - cdc-wdm read-stuck fix
      
         - gadget driver fix for reported race condition
      
         - new usb-serial driver ids
      
        All of these have been in linux-next with no reported problems"
      
      * tag 'usb-5.18-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb:
        usb: xhci-mtk: remove bandwidth budget table
        usb: xhci-mtk: fix fs isoc's transfer error
        usb: gadget: fix race when gadget driver register via ioctl
        usb: typec: tcpci_mt6360: Update for BMC PHY setting
        usb: gadget: uvc: allow for application to cleanly shutdown
        usb: typec: tcpci: Don't skip cleanup in .remove() on error
        usb: cdc-wdm: fix reading stuck on device close
        USB: serial: qcserial: add support for Sierra Wireless EM7590
        USB: serial: option: add Fibocom MA510 modem
        USB: serial: option: add Fibocom L610 modem
        USB: serial: pl2303: add device id for HP LM930 Display
      fc49583c
    • Linus Torvalds's avatar
      Merge tag 'powerpc-5.18-5' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux · bc403203
      Linus Torvalds authored
      Pull powerpc fix from Michael Ellerman:
      
       - Fix KVM PR on 32-bit, which was broken by some MMU code refactoring.
      
      Thanks to: Alexander Graf, and Matt Evans.
      
      * tag 'powerpc-5.18-5' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux:
        KVM: PPC: Book3S PR: Enable MSR_DR for switch_mmu_context()
      bc403203
    • Linus Torvalds's avatar
      Merge tag 'x86-urgent-2022-05-15' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip · 79dc4fc2
      Linus Torvalds authored
      Pull x86 fix from Thomas Gleixner:
       "A single fix for the handling of unpopulated sub-pmd spaces.
      
        The copy & pasta from the corresponding s390 code screwed up the
        address calculation for marking the sub-pmd ranges via memset by
        omitting the ALIGN_DOWN() to calculate the proper start address.
      
        It's a mystery why this code is not generic and shared because there
        is nothing architecture specific in there, but that's too intrusive
        for a backportable fix"
      
      * tag 'x86-urgent-2022-05-15' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
        x86/mm: Fix marking of unused sub-pmd ranges
      79dc4fc2
    • Linus Torvalds's avatar
      Merge tag 'sched-urgent-2022-05-15' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip · 990e798d
      Linus Torvalds authored
      Pull scheduler fix from Thomas Gleixner:
       "The recent expansion of the sched switch tracepoint inserted a new
        argument in the middle of the arguments. This reordering broke BPF
        programs which relied on the old argument list.
      
        While tracepoints are not considered stable ABI, it's not trivial to
        make BPF cope with such a change, but it's being worked on. For now
        restore the original argument order and move the new argument to the
        end of the argument list"
      
      * tag 'sched-urgent-2022-05-15' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
        sched/tracing: Append prev_state to tp args instead
      990e798d
    • Linus Torvalds's avatar
      Merge tag 'irq-urgent-2022-05-15' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip · fb756280
      Linus Torvalds authored
      Pull irq fix from Thomas Gleixner:
       "A single fix for a recent (introduced in 5.16) regression in the core
        interrupt code.
      
        The consolidation of the interrupt handler invocation code added an
        unconditional warning when generic_handle_domain_irq() is invoked from
        outside hard interrupt context. That's overbroad as the requirement
        for invoking these handlers in hard interrupt context is only required
        for certain interrupt types. The subsequently called code already
        contains a warning which triggers conditionally for interrupt chips
        which indicate this requirement in their properties.
      
        Remove the overbroad one"
      
      * tag 'irq-urgent-2022-05-15' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
        genirq: Remove WARN_ON_ONCE() in generic_handle_domain_irq()
      fb756280
  3. 14 May, 2022 1 commit
  4. 13 May, 2022 25 commits
  5. 12 May, 2022 1 commit