1. 12 10月, 2019 1 次提交
  2. 21 7月, 2019 1 次提交
    • H
      efi/bgrt: Drop BGRT status field reserved bits check · 627fdcc9
      Hans de Goede 提交于
      [ Upstream commit a483fcab38b43fb34a7f12ab1daadd3907f150e2 ]
      
      Starting with ACPI 6.2 bits 1 and 2 of the BGRT status field are no longer
      reserved. These bits are now used to indicate if the image needs to be
      rotated before being displayed.
      
      The first device using these bits has now shown up (the GPD MicroPC) and
      the reserved bits check causes us to reject the valid BGRT table on this
      device.
      
      Rather then changing the reserved bits check, allowing only the 2 new bits,
      instead just completely remove it so that we do not end up with a similar
      problem when more bits are added in the future.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      627fdcc9
  3. 11 6月, 2019 1 次提交
    • K
      pstore: Convert buf_lock to semaphore · d4128a1b
      Kees Cook 提交于
      commit ea84b580b95521644429cc6748b6c2bf27c8b0f3 upstream.
      
      Instead of running with interrupts disabled, use a semaphore. This should
      make it easier for backends that may need to sleep (e.g. EFI) when
      performing a write:
      
      |BUG: sleeping function called from invalid context at kernel/sched/completion.c:99
      |in_atomic(): 1, irqs_disabled(): 1, pid: 2236, name: sig-xstate-bum
      |Preemption disabled at:
      |[<ffffffff99d60512>] pstore_dump+0x72/0x330
      |CPU: 26 PID: 2236 Comm: sig-xstate-bum Tainted: G      D           4.20.0-rc3 #45
      |Call Trace:
      | dump_stack+0x4f/0x6a
      | ___might_sleep.cold.91+0xd3/0xe4
      | __might_sleep+0x50/0x90
      | wait_for_completion+0x32/0x130
      | virt_efi_query_variable_info+0x14e/0x160
      | efi_query_variable_store+0x51/0x1a0
      | efivar_entry_set_safe+0xa3/0x1b0
      | efi_pstore_write+0x109/0x140
      | pstore_dump+0x11c/0x330
      | kmsg_dump+0xa4/0xd0
      | oops_exit+0x22/0x30
      ...
      Reported-by: NSebastian Andrzej Siewior <bigeasy@linutronix.de>
      Fixes: 21b3ddd3 ("efi: Don't use spinlocks for efi vars")
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d4128a1b
  4. 08 5月, 2019 1 次提交
  5. 06 4月, 2019 3 次提交
    • A
      efi/arm/arm64: Allow SetVirtualAddressMap() to be omitted · ce80ebf7
      Ard Biesheuvel 提交于
      [ Upstream commit 4e46c2a956215482418d7b315749fb1b6c6bc224 ]
      
      The UEFI spec revision 2.7 errata A section 8.4 has the following to
      say about the virtual memory runtime services:
      
        "This section contains function definitions for the virtual memory
        support that may be optionally used by an operating system at runtime.
        If an operating system chooses to make EFI runtime service calls in a
        virtual addressing mode instead of the flat physical mode, then the
        operating system must use the services in this section to switch the
        EFI runtime services from flat physical addressing to virtual
        addressing."
      
      So it is pretty clear that calling SetVirtualAddressMap() is entirely
      optional, and so there is no point in doing so unless it achieves
      anything useful for us.
      
      This is not the case for 64-bit ARM. The identity mapping used by the
      firmware is arbitrarily converted into another permutation of userland
      addresses (i.e., bits [63:48] cleared), and the runtime code could easily
      deal with the original layout in exactly the same way as it deals with
      the converted layout. However, due to constraints related to page size
      differences if the OS is not running with 4k pages, and related to
      systems that may expose the individual sections of PE/COFF runtime
      modules as different memory regions, creating the virtual layout is a
      bit fiddly, and requires us to sort the memory map and reason about
      adjacent regions with identical memory types etc etc.
      
      So the obvious fix is to stop calling SetVirtualAddressMap() altogether
      on arm64 systems. However, to avoid surprises, which are notoriously
      hard to diagnose when it comes to OS<->firmware interactions, let's
      start by making it an opt-out feature, and implement support for the
      'efi=novamap' kernel command line parameter on ARM and arm64 systems.
      
      ( Note that 32-bit ARM generally does require SetVirtualAddressMap() to be
        used, given that the physical memory map and the kernel virtual address
        map are not guaranteed to be non-overlapping like on arm64. However,
        having support for efi=novamap,noruntime on 32-bit ARM, combined with
        the recently proposed support for earlycon=efifb, is likely to be useful
        to diagnose boot issues on such systems if they have no accessible serial
        port. )
      Tested-by: NJeffrey Hugo <jhugo@codeaurora.org>
      Tested-by: NBjorn Andersson <bjorn.andersson@linaro.org>
      Tested-by: NLee Jones <lee.jones@linaro.org>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
      Cc: Alexander Graf <agraf@suse.de>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/20190202094119.13230-8-ard.biesheuvel@linaro.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      ce80ebf7
    • A
      efi/memattr: Don't bail on zero VA if it equals the region's PA · b12a060a
      Ard Biesheuvel 提交于
      [ Upstream commit 5de0fef0230f3c8d75cff450a71740a7bf2db866 ]
      
      The EFI memory attributes code cross-references the EFI memory map with
      the more granular EFI memory attributes table to ensure that they are in
      sync before applying the strict permissions to the regions it describes.
      
      Since we always install virtual mappings for the EFI runtime regions to
      which these strict permissions apply, we currently perform a sanity check
      on the EFI memory descriptor, and ensure that the EFI_MEMORY_RUNTIME bit
      is set, and that the virtual address has been assigned.
      
      However, in cases where a runtime region exists at physical address 0x0,
      and the virtual mapping equals the physical mapping, e.g., when running
      in mixed mode on x86, we encounter a memory descriptor with the runtime
      attribute and virtual address 0x0, and incorrectly draw the conclusion
      that a runtime region exists for which no virtual mapping was installed,
      and give up altogether. The consequence of this is that firmware mappings
      retain their read-write-execute permissions, making the system more
      vulnerable to attacks.
      
      So let's only bail if the virtual address of 0x0 has been assigned to a
      physical region that does not reside at address 0x0.
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Acked-by: NSai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
      Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
      Cc: Alexander Graf <agraf@suse.de>
      Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
      Cc: Jeffrey Hugo <jhugo@codeaurora.org>
      Cc: Lee Jones <lee.jones@linaro.org>
      Cc: Leif Lindholm <leif.lindholm@linaro.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-efi@vger.kernel.org
      Fixes: 10f0d2f5 ("efi: Implement generic support for the Memory ...")
      Link: http://lkml.kernel.org/r/20190202094119.13230-4-ard.biesheuvel@linaro.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      b12a060a
    • R
      efi: cper: Fix possible out-of-bounds access · d60f458e
      Ross Lagerwall 提交于
      [ Upstream commit 45b14a4ffcc1e0b5caa246638f942cbe7eaea7ad ]
      
      When checking a generic status block, we iterate over all the generic
      data blocks. The loop condition only checks that the start of the
      generic data block is valid (within estatus->data_length) but not the
      whole block. Because the size of data blocks (excluding error data) may
      vary depending on the revision and the revision is contained within the
      data block, ensure that enough of the current data block is valid before
      dereferencing any members otherwise an out-of-bounds access may occur if
      estatus->data_length is invalid.
      
      This relies on the fact that struct acpi_hest_generic_data_v300 is a
      superset of the earlier version.  Also rework the other checks to avoid
      potential underflow.
      Signed-off-by: NRoss Lagerwall <ross.lagerwall@citrix.com>
      Acked-by: NBorislav Petkov <bp@suse.de>
      Tested-by: NTyler Baicar <baicar.tyler@gmail.com>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      d60f458e
  6. 20 2月, 2019 1 次提交
  7. 13 2月, 2019 1 次提交
    • A
      firmware/efi: Add NULL pointer checks in efivars API functions · eca31fc3
      Arend van Spriel 提交于
      [ Upstream commit ab2180a15ce54739fed381efb4cb12e78dfb1561 ]
      
      Since commit:
      
         ce2e6db554fa ("brcmfmac: Add support for getting nvram contents from EFI variables")
      
      we have a device driver accessing the efivars API. Several functions in
      the efivars API assume __efivars is set, i.e., that they will be accessed
      only after efivars_register() has been called. However, the following NULL
      pointer access was reported calling efivar_entry_size() from the brcmfmac
      device driver:
      
        Unable to handle kernel NULL pointer dereference at virtual address 00000008
        pgd = 60bfa5f1
        [00000008] *pgd=00000000
        Internal error: Oops: 5 [#1] SMP ARM
        ...
        Hardware name: NVIDIA Tegra SoC (Flattened Device Tree)
        Workqueue: events request_firmware_work_func
        PC is at efivar_entry_size+0x28/0x90
        LR is at brcmf_fw_complete_request+0x3f8/0x8d4 [brcmfmac]
        pc : [<c0c40718>]    lr : [<bf2a3ef4>]    psr: a00d0113
        sp : ede7fe28  ip : ee983410  fp : c1787f30
        r10: 00000000  r9 : 00000000  r8 : bf2b2258
        r7 : ee983000  r6 : c1604c48  r5 : ede7fe88  r4 : edf337c0
        r3 : 00000000  r2 : 00000000  r1 : ede7fe88  r0 : c17712c8
        Flags: NzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
        Control: 10c5387d  Table: ad16804a  DAC: 00000051
      
      Disassembly showed that the local static variable __efivars is NULL,
      which is not entirely unexpected given that it is a non-EFI platform.
      
      So add a NULL pointer check to efivar_entry_size(), and to related
      functions while at it. In efivars_register() a couple of sanity checks
      are added as well.
      Reported-by: NJon Hunter <jonathanh@nvidia.com>
      Signed-off-by: NArend van Spriel <arend.vanspriel@broadcom.com>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Bhupesh Sharma <bhsharma@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@intel.com>
      Cc: Eric Snowberg <eric.snowberg@oracle.com>
      Cc: Hans de Goede <hdegoede@redhat.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: Julien Thierry <julien.thierry@arm.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Marc Zyngier <marc.zyngier@arm.com>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Nathan Chancellor <natechancellor@gmail.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
      Cc: Sedat Dilek <sedat.dilek@gmail.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: YiFei Zhu <zhuyifei1999@gmail.com>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/20181129171230.18699-9-ard.biesheuvel@linaro.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      eca31fc3
  8. 26 1月, 2019 1 次提交
    • N
      efi/libstub: Disable some warnings for x86{,_64} · 50063ba9
      Nathan Chancellor 提交于
      [ Upstream commit 3db5e0ba8b8f4aee631d7ee04b7a11c56cfdc213 ]
      
      When building the kernel with Clang, some disabled warnings appear
      because this Makefile overrides KBUILD_CFLAGS for x86{,_64}. Add them to
      this list so that the build is clean again.
      
      -Wpointer-sign was disabled for the whole kernel before the beginning of Git history.
      
      -Waddress-of-packed-member was disabled for the whole kernel and for
      the early boot code in these commits:
      
        bfb38988 ("kbuild: clang: Disable 'address-of-packed-member' warning")
        20c6c189 ("x86/boot: Disable the address-of-packed-member compiler warning").
      
      -Wgnu was disabled for the whole kernel and for the early boot code in
      these commits:
      
        61163efa ("kbuild: LLVMLinux: Add Kbuild support for building kernel with Clang")
        6c3b56b1 ("x86/boot: Disable Clang warnings about GNU extensions").
      
       [ mingo: Made the changelog more readable. ]
      Tested-by: NSedat Dilek <sedat.dilek@gmail.com>
      Signed-off-by: NNathan Chancellor <natechancellor@gmail.com>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Reviewed-by: NSedat Dilek <sedat.dilek@gmail.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Arend van Spriel <arend.vanspriel@broadcom.com>
      Cc: Bhupesh Sharma <bhsharma@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@intel.com>
      Cc: Eric Snowberg <eric.snowberg@oracle.com>
      Cc: Hans de Goede <hdegoede@redhat.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: Jon Hunter <jonathanh@nvidia.com>
      Cc: Julien Thierry <julien.thierry@arm.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Marc Zyngier <marc.zyngier@arm.com>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: YiFei Zhu <zhuyifei1999@gmail.com>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/20181129171230.18699-8-ard.biesheuvel@linaro.org
      Link: https://github.com/ClangBuiltLinux/linux/issues/112Signed-off-by: NIngo Molnar <mingo@kernel.org>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      50063ba9
  9. 01 12月, 2018 2 次提交
  10. 21 11月, 2018 1 次提交
    • A
      efi/arm/libstub: Pack FDT after populating it · d1cbbc39
      Ard Biesheuvel 提交于
      commit 72a58a63a164b4e9d2d914e65caeb551846883f1 upstream.
      
      Commit:
      
        24d7c494 ("efi/arm-stub: Round up FDT allocation to mapping size")
      
      increased the allocation size for the FDT image created by the stub to a
      fixed value of 2 MB, to simplify the former code that made several
      attempts with increasing values for the size. This is reasonable
      given that the allocation is of type EFI_LOADER_DATA, which is released
      to the kernel unless it is explicitly memblock_reserve()d by the early
      boot code.
      
      However, this allocation size leaked into the 'size' field of the FDT
      header metadata, and so the entire allocation remains occupied by the
      device tree binary, even if most of it is not used to store device tree
      information.
      
      So call fdt_pack() to shrink the FDT data structure to its minimum size
      after populating all the fields, so that the remaining memory is no
      longer wasted.
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: <stable@vger.kernel.org> # v4.12+
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-efi@vger.kernel.org
      Fixes: 24d7c494 ("efi/arm-stub: Round up FDT allocation to mapping size")
      Link: http://lkml.kernel.org/r/20181114175544.12860-4-ard.biesheuvel@linaro.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d1cbbc39
  11. 12 9月, 2018 1 次提交
  12. 23 8月, 2018 1 次提交
  13. 31 7月, 2018 1 次提交
  14. 26 7月, 2018 1 次提交
  15. 23 7月, 2018 2 次提交
  16. 22 7月, 2018 2 次提交
  17. 17 7月, 2018 2 次提交
    • R
      mm: Allocate the mm_cpumask (mm->cpu_bitmap[]) dynamically based on nr_cpu_ids · c1a2f7f0
      Rik van Riel 提交于
      The mm_struct always contains a cpumask bitmap, regardless of
      CONFIG_CPUMASK_OFFSTACK. That means the first step can be to
      simplify things, and simply have one bitmask at the end of the
      mm_struct for the mm_cpumask.
      
      This does necessitate moving everything else in mm_struct into
      an anonymous sub-structure, which can be randomized when struct
      randomization is enabled.
      
      The second step is to determine the correct size for the
      mm_struct slab object from the size of the mm_struct
      (excluding the CPU bitmap) and the size the cpumask.
      
      For init_mm we can simply allocate the maximum size this
      kernel is compiled for, since we only have one init_mm
      in the system, anyway.
      
      Pointer magic by Mike Galbraith, to evade -Wstringop-overflow
      getting confused by the dynamically sized array.
      Tested-by: NSong Liu <songliubraving@fb.com>
      Signed-off-by: NRik van Riel <riel@surriel.com>
      Signed-off-by: NMike Galbraith <efault@gmx.de>
      Signed-off-by: NRik van Riel <riel@surriel.com>
      Acked-by: NDave Hansen <dave.hansen@intel.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: kernel-team@fb.com
      Cc: luto@kernel.org
      Link: http://lkml.kernel.org/r/20180716190337.26133-2-riel@surriel.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      c1a2f7f0
    • A
      efi/esrt: Only call efi_mem_reserve() for boot services memory · 61f0d555
      Ard Biesheuvel 提交于
      The following commit:
      
        7e1550b8 ("efi: Drop type and attribute checks in efi_mem_desc_lookup()")
      
      refactored the implementation of efi_mem_desc_lookup() so that the type
      check is moved to the callers, one of which is the x86 version of
      efi_arch_mem_reserve(), where we added a modified check that only takes
      EFI_BOOT_SERVICES_DATA regions into account.
      
      This is reasonable, since it is the only memory type that requires this,
      but doing so uncovered some unexpected behavior in the ESRT code, which
      permits the ESRT table to reside in other types of memory than what the
      UEFI spec mandates (i.e., EFI_BOOT_SERVICES_DATA), and unconditionally
      calls efi_mem_reserve() on the region in question. This may result in
      errors such as
      
        esrt: Reserving ESRT space from 0x000000009c810318 to 0x000000009c810350.
        efi: Failed to lookup EFI memory descriptor for 0x000000009c810318
      
      when the ESRT table is not in EFI_BOOT_SERVICES_DATA memory, but we try
      to reserve it nonetheless.
      
      So make the call to efi_mem_reserve() conditional on the memory type.
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-efi@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NIngo Molnar <mingo@kernel.org>
      61f0d555
  18. 16 7月, 2018 4 次提交
    • A
      efi: Drop type and attribute checks in efi_mem_desc_lookup() · 7e1550b8
      Ard Biesheuvel 提交于
      The current implementation of efi_mem_desc_lookup() includes the
      following check on the memory descriptor it returns:
      
          if (!(md->attribute & EFI_MEMORY_RUNTIME) &&
              md->type != EFI_BOOT_SERVICES_DATA &&
              md->type != EFI_RUNTIME_SERVICES_DATA) {
                  continue;
          }
      
      This means that only EfiBootServicesData or EfiRuntimeServicesData
      regions are considered, or any other region type provided that it
      has the EFI_MEMORY_RUNTIME attribute set.
      
      Given what the name of the function implies, and the fact that any
      physical address can be described in the UEFI memory map only a single
      time, it does not make sense to impose this condition in the body of the
      loop, but instead, should be imposed by the caller depending on the value
      that is returned to it.
      
      Two such callers exist at the moment:
      
      - The BGRT code when running on x86, via efi_mem_reserve() and
        efi_arch_mem_reserve(). In this case, the region is already known to
        be EfiBootServicesData, and so the check is redundant.
      
      - The ESRT handling code which introduced this function, which calls it
        both directly from efi_esrt_init() and again via efi_mem_reserve() and
        efi_arch_mem_reserve() [on x86].
      
      So let's move this check into the callers instead. This preserves the
      current behavior both for BGRT and ESRT handling, and allows the lookup
      routine to be reused by other [upcoming] users that don't have this
      limitation.
      
      In the ESRT case, keep the entire condition, so that platforms that
      deviate from the UEFI spec and use something other than
      EfiBootServicesData for the ESRT table will keep working as before.
      
      For x86's efi_arch_mem_reserve() implementation, limit the type to
      EfiBootServicesData, since it is the only type the reservation code
      expects to operate on in the first place.
      
      While we're at it, drop the __init annotation so that drivers can use it
      as well.
      Tested-by: NLaszlo Ersek <lersek@redhat.com>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Jones <pjones@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/20180711094040.12506-8-ard.biesheuvel@linaro.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      7e1550b8
    • A
      efi/libstub/arm: Add opt-in Kconfig option for the DTB loader · 3d7ee348
      Ard Biesheuvel 提交于
      There are various ways a platform can provide a device tree binary
      to the kernel, with different levels of sophistication:
      
      - ideally, the UEFI firmware, which is tightly coupled with the
        platform, provides a device tree image directly as a UEFI
        configuration table, and typically permits the contents to be
        manipulated either via menu options or via UEFI environment
        variables that specify a replacement image,
      
      - GRUB for ARM has a 'devicetree' directive which allows a device
        tree image to be loaded from any location accessible to GRUB, and
        supersede the one provided by the firmware,
      
      - the EFI stub implements a dtb= command line option that allows a
        device tree image to be loaded from a file residing in the same
        file system as the one the kernel image was loaded from.
      
      The dtb= command line option was never intended to be more than a
      development feature, to allow the other options to be implemented
      in parallel. So let's make it an opt-in feature that is disabled
      by default, but can be re-enabled at will.
      
      Note that we already disable the dtb= command line option when we
      detect that we are running with UEFI Secure Boot enabled.
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Reviewed-by: NAlexander Graf <agraf@suse.de>
      Acked-by: NLeif Lindholm <leif.lindholm@linaro.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/20180711094040.12506-7-ard.biesheuvel@linaro.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      3d7ee348
    • A
      efi/cper: Avoid using get_seconds() · 7bb49709
      Arnd Bergmann 提交于
      get_seconds() is deprecated because of the 32-bit time overflow
      in y2038/y2106 on 32-bit architectures. The way it is used in
      cper_next_record_id() causes an overflow in 2106 when unsigned UTC
      seconds overflow, even on 64-bit architectures.
      
      This starts using ktime_get_real_seconds() to give us more than 32 bits
      of timestamp on all architectures, and then changes the algorithm to use
      39 bits for the timestamp after the y2038 wrap date, plus an always-1
      bit at the top. This gives us another 127 epochs of 136 years, with
      strictly monotonically increasing sequence numbers across boots.
      
      This is almost certainly overkill, but seems better than just extending
      the deadline from 2038 to 2106.
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/20180711094040.12506-5-ard.biesheuvel@linaro.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      7bb49709
    • S
      efi: Use a work queue to invoke EFI Runtime Services · 3eb420e7
      Sai Praneeth 提交于
      Presently, when a user process requests the kernel to execute any
      UEFI runtime service, the kernel temporarily switches to a separate
      set of page tables that describe the virtual mapping of the UEFI
      runtime services regions in memory. Since UEFI runtime services are
      typically invoked with interrupts enabled, any code that may be called
      during this time, will have an incorrect view of the process's address
      space. Although it is unusual for code running in interrupt context to
      make assumptions about the process context it runs in, there are cases
      (such as the perf subsystem taking samples) where this causes problems.
      
      So let's set up a work queue for calling UEFI runtime services, so that
      the actual calls are made when the work queue items are dispatched by a
      work queue worker running in a separate kernel thread. Such threads are
      not expected to have userland mappings in the first place, and so the
      additional mappings created for the UEFI runtime services can never
      clash with any.
      
      The ResetSystem() runtime service is not covered by the work queue
      handling, since it is not expected to return, and may be called at a
      time when the kernel is torn down to the point where we cannot expect
      work queues to still be operational.
      
      The non-blocking variants of SetVariable() and QueryVariableInfo()
      are also excluded: these are intended to be used from atomic context,
      which obviously rules out waiting for a completion to be signalled by
      another thread. Note that these variants are currently only used for
      UEFI runtime services calls that occur very early in the boot, and
      for ones that occur in critical conditions, e.g., to flush kernel logs
      to UEFI variables via efi-pstore.
      Suggested-by: NAndy Lutomirski <luto@kernel.org>
      Signed-off-by: NSai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
      [ardb: exclude ResetSystem() from the workqueue treatment
             merge from 2 separate patches and rewrite commit log]
      Signed-off-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-efi@vger.kernel.org
      Link: http://lkml.kernel.org/r/20180711094040.12506-4-ard.biesheuvel@linaro.orgSigned-off-by: NIngo Molnar <mingo@kernel.org>
      3eb420e7
  19. 03 7月, 2018 1 次提交
  20. 22 6月, 2018 1 次提交
  21. 15 6月, 2018 1 次提交
  22. 13 6月, 2018 1 次提交
    • K
      treewide: kzalloc() -> kcalloc() · 6396bb22
      Kees Cook 提交于
      The kzalloc() function has a 2-factor argument form, kcalloc(). This
      patch replaces cases of:
      
              kzalloc(a * b, gfp)
      
      with:
              kcalloc(a * b, gfp)
      
      as well as handling cases of:
      
              kzalloc(a * b * c, gfp)
      
      with:
      
              kzalloc(array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              kzalloc_array(array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              kzalloc(4 * 1024, gfp)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      type TYPE;
      expression THING, E;
      @@
      
      (
        kzalloc(
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        kzalloc(
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        kzalloc(
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      identifier SIZE, COUNT;
      @@
      
      - kzalloc
      + kcalloc
        (
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        kzalloc(
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        kzalloc(
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kzalloc(
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        kzalloc(
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products,
      // when they're not all constants...
      @@
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        kzalloc(C1 * C2 * C3, ...)
      |
        kzalloc(
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants,
      // keeping sizeof() as the second factor argument.
      @@
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        kzalloc(sizeof(THING) * C2, ...)
      |
        kzalloc(sizeof(TYPE) * C2, ...)
      |
        kzalloc(C1 * C2 * C3, ...)
      |
        kzalloc(C1 * C2, ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: NKees Cook <keescook@chromium.org>
      6396bb22
  23. 06 6月, 2018 1 次提交
  24. 19 5月, 2018 1 次提交
  25. 17 5月, 2018 1 次提交
    • A
      device property: Get rid of union aliasing · 63dcc709
      Andy Shevchenko 提交于
      Commit 318a1971 (device property: refactor built-in properties
      support) went way too far and brought a union aliasing. Partially
      revert it here to get rid of union aliasing.
      
      Note, all Apple properties are considered as u8 arrays. To get a value
      of any of them the caller must use device_property_read_u8_array().
      
      What's union aliasing?
      ~~~~~~~~~~~~~~~~~~~~~~
      
      The C99 standard in section 6.2.5 paragraph 20 defines union type as
      "an overlapping nonempty set of member objects". It also states in
      section 6.7.2.1 paragraph 14 that "the value of at most one of the
      members can be stored in a union object at any time'.
      
      Union aliasing is a type punning mechanism using union members to store
      as one type and read back as another.
      
      Why it's not good?
      ~~~~~~~~~~~~~~~~~~
      
      Section 6.2.6.1 paragraph 6 says that a union object may not be a trap
      representation, although its member objects may be.
      
      Meanwhile annex J.1 says that "the value of a union member other than
      the last one stored into" is unspecified [removed in C11].
      
      In TC3, a footnote is added which specifies that accessing a member of a
      union other than the last one stored causes "the object representation"
      to be re-interpreted in the new type and specifically refers to this as
      "type punning". This conflicts to some degree with Annex J.1.
      
      While it's working in Linux with GCC, the use of union members to do
      type punning is not clear area in the C standard and might lead to
      unspecified behaviour.
      
      More information is available in this [1] blog post.
      
      [1]: https://davmac.wordpress.com/2010/02/26/c99-revisited/Signed-off-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Acked-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
      Reviewed-by: NMika Westerberg <mika.westerberg@linux.intel.com>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      63dcc709
  26. 14 5月, 2018 6 次提交