1. 25 6月, 2022 1 次提交
    • A
      efi: vars: Move efivar caching layer into efivarfs · 2d82e622
      Ard Biesheuvel 提交于
      Move the fiddly bits of the efivar layer into its only remaining user,
      efivarfs, and confine its use to that particular module. All other uses
      of the EFI variable store have no need for this additional layer of
      complexity, given that they either only read variables, or read and
      write variables into a separate GUIDed namespace, and cannot be used to
      manipulate EFI variables that are covered by the EFI spec and/or affect
      the boot flow.
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      2d82e622
  2. 20 6月, 2022 1 次提交
    • A
      efi: avoid efivars layer when loading SSDTs from variables · 3881ee0b
      Ard Biesheuvel 提交于
      The efivars intermediate variable access layer provides an abstraction
      that permits the EFI variable store to be replaced by something else
      that implements a compatible interface, and caches all variables in the
      variable store for fast access via the efivarfs pseudo-filesystem.
      
      The SSDT override feature does not take advantage of either feature, as
      it is only used when the generic EFI implementation of efivars is used,
      and it traverses all variables only once to find the ones it is
      interested in, and frees all data structures that the efivars layer
      keeps right after.
      
      So in this case, let's just call EFI's code directly, using the function
      pointers in struct efi.
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      3881ee0b
  3. 15 6月, 2022 1 次提交
  4. 14 4月, 2022 3 次提交
  5. 01 3月, 2022 1 次提交
    • R
      efi: fix return value of __setup handlers · 9feaf8b3
      Randy Dunlap 提交于
      When "dump_apple_properties" is used on the kernel boot command line,
      it causes an Unknown parameter message and the string is added to init's
      argument strings:
      
        Unknown kernel command line parameters "dump_apple_properties
          BOOT_IMAGE=/boot/bzImage-517rc6 efivar_ssdt=newcpu_ssdt", will be
          passed to user space.
      
       Run /sbin/init as init process
         with arguments:
           /sbin/init
           dump_apple_properties
         with environment:
           HOME=/
           TERM=linux
           BOOT_IMAGE=/boot/bzImage-517rc6
           efivar_ssdt=newcpu_ssdt
      
      Similarly when "efivar_ssdt=somestring" is used, it is added to the
      Unknown parameter message and to init's environment strings, polluting
      them (see examples above).
      
      Change the return value of the __setup functions to 1 to indicate
      that the __setup options have been handled.
      
      Fixes: 58c5475a ("x86/efi: Retrieve and assign Apple device properties")
      Fixes: 475fb4e8 ("efi / ACPI: load SSTDs from EFI variables")
      Signed-off-by: NRandy Dunlap <rdunlap@infradead.org>
      Reported-by: NIgor Zhbanov <i.zhbanov@omprussia.ru>
      Link: lore.kernel.org/r/64644a2f-4a20-bab3-1e15-3b2cdd0defe3@omprussia.ru
      Cc: Ard Biesheuvel <ardb@kernel.org>
      Cc: linux-efi@vger.kernel.org
      Cc: Lukas Wunner <lukas@wunner.de>
      Cc: Octavian Purdila <octavian.purdila@intel.com>
      Cc: "Rafael J. Wysocki" <rafael@kernel.org>
      Cc: Matt Fleming <matt@codeblueprint.co.uk>
      Link: https://lore.kernel.org/r/20220301041851.12459-1-rdunlap@infradead.orgSigned-off-by: NArd Biesheuvel <ardb@kernel.org>
      9feaf8b3
  6. 23 1月, 2022 1 次提交
    • A
      efi: runtime: avoid EFIv2 runtime services on Apple x86 machines · f5390cd0
      Ard Biesheuvel 提交于
      Aditya reports [0] that his recent MacbookPro crashes in the firmware
      when using the variable services at runtime. The culprit appears to be a
      call to QueryVariableInfo(), which we did not use to call on Apple x86
      machines in the past as they only upgraded from EFI v1.10 to EFI v2.40
      firmware fairly recently, and QueryVariableInfo() (along with
      UpdateCapsule() et al) was added in EFI v2.00.
      
      The only runtime service introduced in EFI v2.00 that we actually use in
      Linux is QueryVariableInfo(), as the capsule based ones are optional,
      generally not used at runtime (all the LVFS/fwupd firmware update
      infrastructure uses helper EFI programs that invoke capsule update at
      boot time, not runtime), and not implemented by Apple machines in the
      first place. QueryVariableInfo() is used to 'safely' set variables,
      i.e., only when there is enough space. This prevents machines with buggy
      firmwares from corrupting their NVRAMs when they run out of space.
      
      Given that Apple machines have been using EFI v1.10 services only for
      the longest time (the EFI v2.0 spec was released in 2006, and Linux
      support for the newly introduced runtime services was added in 2011, but
      the MacbookPro12,1 released in 2015 still claims to be EFI v1.10 only),
      let's avoid the EFI v2.0 ones on all Apple x86 machines.
      
      [0] https://lore.kernel.org/all/6D757C75-65B1-468B-842D-10410081A8E4@live.com/
      
      Cc: <stable@vger.kernel.org>
      Cc: Jeremy Kerr <jk@ozlabs.org>
      Cc: Matthew Garrett <mjg59@srcf.ucam.org>
      Reported-by: NAditya Garg <gargaditya08@live.com>
      Tested-by: NOrlando Chamberlain <redecorating@protonmail.com>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Tested-by: NAditya Garg <gargaditya08@live.com>
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=215277
      f5390cd0
  7. 29 9月, 2021 2 次提交
  8. 17 7月, 2021 1 次提交
    • M
      firmware/efi: Tell memblock about EFI iomem reservations · 2bab693a
      Marc Zyngier 提交于
      kexec_load_file() relies on the memblock infrastructure to avoid
      stamping over regions of memory that are essential to the survival
      of the system.
      
      However, nobody seems to agree how to flag these regions as reserved,
      and (for example) EFI only publishes its reservations in /proc/iomem
      for the benefit of the traditional, userspace based kexec tool.
      
      On arm64 platforms with GICv3, this can result in the payload being
      placed at the location of the LPI tables. Shock, horror!
      
      Let's augment the EFI reservation code with a memblock_reserve() call,
      protecting our dear tables from the secondary kernel invasion.
      Reported-by: NMoritz Fischer <mdf@kernel.org>
      Tested-by: NMoritz Fischer <mdf@kernel.org>
      Signed-off-by: NMarc Zyngier <maz@kernel.org>
      Cc: stable@vger.kernel.org
      Cc: Ard Biesheuvel <ardb@kernel.org>
      Cc: James Morse <james.morse@arm.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      2bab693a
  9. 19 3月, 2021 1 次提交
  10. 16 12月, 2020 1 次提交
    • J
      mm/gup: prevent gup_fast from racing with COW during fork · 57efa1fe
      Jason Gunthorpe 提交于
      Since commit 70e806e4 ("mm: Do early cow for pinned pages during
      fork() for ptes") pages under a FOLL_PIN will not be write protected
      during COW for fork.  This means that pages returned from
      pin_user_pages(FOLL_WRITE) should not become write protected while the pin
      is active.
      
      However, there is a small race where get_user_pages_fast(FOLL_PIN) can
      establish a FOLL_PIN at the same time copy_present_page() is write
      protecting it:
      
              CPU 0                             CPU 1
         get_user_pages_fast()
          internal_get_user_pages_fast()
                                             copy_page_range()
                                               pte_alloc_map_lock()
                                                 copy_present_page()
                                                   atomic_read(has_pinned) == 0
      					     page_maybe_dma_pinned() == false
           atomic_set(has_pinned, 1);
           gup_pgd_range()
            gup_pte_range()
             pte_t pte = gup_get_pte(ptep)
             pte_access_permitted(pte)
             try_grab_compound_head()
                                                   pte = pte_wrprotect(pte)
      	                                     set_pte_at();
                                               pte_unmap_unlock()
            // GUP now returns with a write protected page
      
      The first attempt to resolve this by using the write protect caused
      problems (and was missing a barrrier), see commit f3c64eda ("mm: avoid
      early COW write protect games during fork()")
      
      Instead wrap copy_p4d_range() with the write side of a seqcount and check
      the read side around gup_pgd_range().  If there is a collision then
      get_user_pages_fast() fails and falls back to slow GUP.
      
      Slow GUP is safe against this race because copy_page_range() is only
      called while holding the exclusive side of the mmap_lock on the src
      mm_struct.
      
      [akpm@linux-foundation.org: coding style fixes]
        Link: https://lore.kernel.org/r/CAHk-=wi=iCnYCARbPGjkVJu9eyYeZ13N64tZYLdOB8CP5Q_PLw@mail.gmail.com
      
      Link: https://lkml.kernel.org/r/2-v4-908497cf359a+4782-gup_fork_jgg@nvidia.com
      Fixes: f3c64eda ("mm: avoid early COW write protect games during fork()")
      Signed-off-by: NJason Gunthorpe <jgg@nvidia.com>
      Suggested-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Reviewed-by: NJohn Hubbard <jhubbard@nvidia.com>
      Reviewed-by: NJan Kara <jack@suse.cz>
      Reviewed-by: NPeter Xu <peterx@redhat.com>
      Acked-by: "Ahmed S. Darwish" <a.darwish@linutronix.de>	[seqcount_t parts]
      Cc: Andrea Arcangeli <aarcange@redhat.com>
      Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Hugh Dickins <hughd@google.com>
      Cc: Jann Horn <jannh@google.com>
      Cc: Kirill Shutemov <kirill@shutemov.name>
      Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
      Cc: Leon Romanovsky <leonro@nvidia.com>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      57efa1fe
  11. 25 11月, 2020 1 次提交
  12. 26 9月, 2020 1 次提交
  13. 16 9月, 2020 1 次提交
    • L
      efi: Support for MOK variable config table · 58c90902
      Lenny Szubowicz 提交于
      Because of system-specific EFI firmware limitations, EFI volatile
      variables may not be capable of holding the required contents of
      the Machine Owner Key (MOK) certificate store when the certificate
      list grows above some size. Therefore, an EFI boot loader may pass
      the MOK certs via a EFI configuration table created specifically for
      this purpose to avoid this firmware limitation.
      
      An EFI configuration table is a much more primitive mechanism
      compared to EFI variables and is well suited for one-way passage
      of static information from a pre-OS environment to the kernel.
      
      This patch adds initial kernel support to recognize, parse,
      and validate the EFI MOK configuration table, where named
      entries contain the same data that would otherwise be provided
      in similarly named EFI variables.
      
      Additionally, this patch creates a sysfs binary file for each
      EFI MOK configuration table entry found. These files are read-only
      to root and are provided for use by user space utilities such as
      mokutil.
      
      A subsequent patch will load MOK certs into the trusted platform
      key ring using this infrastructure.
      Signed-off-by: NLenny Szubowicz <lszubowi@redhat.com>
      Link: https://lore.kernel.org/r/20200905013107.10457-2-lszubowi@redhat.comSigned-off-by: NArd Biesheuvel <ardb@kernel.org>
      58c90902
  14. 20 8月, 2020 1 次提交
  15. 09 7月, 2020 1 次提交
    • A
      efi/efivars: Expose RT service availability via efivars abstraction · f88814cc
      Ard Biesheuvel 提交于
      Commit
      
        bf67fad1 ("efi: Use more granular check for availability for variable services")
      
      introduced a check into the efivarfs, efi-pstore and other drivers that
      aborts loading of the module if not all three variable runtime services
      (GetVariable, SetVariable and GetNextVariable) are supported. However, this
      results in efivarfs being unavailable entirely if only SetVariable support
      is missing, which is only needed if you want to make any modifications.
      Also, efi-pstore and the sysfs EFI variable interface could be backed by
      another implementation of the 'efivars' abstraction, in which case it is
      completely irrelevant which services are supported by the EFI firmware.
      
      So make the generic 'efivars' abstraction dependent on the availibility of
      the GetVariable and GetNextVariable EFI runtime services, and add a helper
      'efivar_supports_writes()' to find out whether the currently active efivars
      abstraction supports writes (and wire it up to the availability of
      SetVariable for the generic one).
      
      Then, use the efivar_supports_writes() helper to decide whether to permit
      efivarfs to be mounted read-write, and whether to enable efi-pstore or the
      sysfs EFI variable interface altogether.
      
      Fixes: bf67fad1 ("efi: Use more granular check for availability for variable services")
      Reported-by: NHeinrich Schuchardt <xypron.glpk@gmx.de>
      Acked-by: NIlias Apalodimas <ilias.apalodimas@linaro.org>
      Tested-by: NIlias Apalodimas <ilias.apalodimas@linaro.org>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      f88814cc
  16. 16 6月, 2020 1 次提交
  17. 15 6月, 2020 1 次提交
    • G
      efi: Replace zero-length array and use struct_size() helper · 29637951
      Gustavo A. R. Silva 提交于
      The current codebase makes use of the zero-length array language
      extension to the C90 standard, but the preferred mechanism to declare
      variable-length types such as these ones is a flexible array member[1][2],
      introduced in C99:
      
      struct foo {
              int stuff;
              struct boo array[];
      };
      
      By making use of the mechanism above, we will get a compiler warning
      in case the flexible array does not occur last in the structure, which
      will help us prevent some kind of undefined behavior bugs from being
      inadvertently introduced[3] to the codebase from now on.
      
      Also, notice that, dynamic memory allocations won't be affected by
      this change:
      
      "Flexible array members have incomplete type, and so the sizeof operator
      may not be applied. As a quirk of the original implementation of
      zero-length arrays, sizeof evaluates to zero."[1]
      
      sizeof(flexible-array-member) triggers a warning because flexible array
      members have incomplete type[1]. There are some instances of code in
      which the sizeof operator is being incorrectly/erroneously applied to
      zero-length arrays and the result is zero. Such instances may be hiding
      some bugs. So, this work (flexible-array member conversions) will also
      help to get completely rid of those sorts of issues.
      
      Lastly, make use of the sizeof_field() helper instead of an open-coded
      version.
      
      This issue was found with the help of Coccinelle and audited _manually_.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
      [2] https://github.com/KSPP/linux/issues/21
      [3] commit 76497732 ("cxgb3/l2t: Fix undefined behaviour")
      Signed-off-by: NGustavo A. R. Silva <gustavoars@kernel.org>
      Reviewed-by: NKees Cook <keescook@chromium.org>
      Link: https://lore.kernel.org/r/20200527171425.GA4053@embeddedorSigned-off-by: NArd Biesheuvel <ardb@kernel.org>
      29637951
  18. 10 6月, 2020 1 次提交
  19. 17 5月, 2020 1 次提交
  20. 24 4月, 2020 2 次提交
    • A
      efi: Move arch_tables check to caller · 4eb8320b
      Ard Biesheuvel 提交于
      Instead of making match_config_table() test its table_types pointer for
      NULL-ness, omit the call entirely if no arch_tables pointer was provided
      to efi_config_parse_tables().
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      4eb8320b
    • A
      efi: Clean up config table description arrays · 4e9a0f73
      Ard Biesheuvel 提交于
      Increase legibility by adding whitespace to the efi_config_table_type_t
      arrays that describe which EFI config tables we look for when going over
      the firmware provided list. While at it, replace the 'name' char pointer
      with a char array, which is more space efficient on relocatable 64-bit
      kernels, as it avoids a 8 byte pointer and the associated relocation
      data (24 bytes when using RELA format)
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      4e9a0f73
  21. 08 3月, 2020 1 次提交
    • A
      efi/x86: Ignore the memory attributes table on i386 · dd09fad9
      Ard Biesheuvel 提交于
      Commit:
      
        3a6b6c6f ("efi: Make EFI_MEMORY_ATTRIBUTES_TABLE initialization common across all architectures")
      
      moved the call to efi_memattr_init() from ARM specific to the generic
      EFI init code, in order to be able to apply the restricted permissions
      described in that table on x86 as well.
      
      We never enabled this feature fully on i386, and so mapping and
      reserving this table is pointless. However, due to the early call to
      memblock_reserve(), the memory bookkeeping gets confused to the point
      where it produces the splat below when we try to map the memory later
      on:
      
        ------------[ cut here ]------------
        ioremap on RAM at 0x3f251000 - 0x3fa1afff
        WARNING: CPU: 0 PID: 0 at arch/x86/mm/ioremap.c:166 __ioremap_caller ...
        Modules linked in:
        CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.20.0 #48
        Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.0.0 02/06/2015
        EIP: __ioremap_caller.constprop.0+0x249/0x260
        Code: 90 0f b7 05 4e 38 40 de 09 45 e0 e9 09 ff ff ff 90 8d 45 ec c6 05 ...
        EAX: 00000029 EBX: 00000000 ECX: de59c228 EDX: 00000001
        ESI: 3f250fff EDI: 00000000 EBP: de3edf20 ESP: de3edee0
        DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068 EFLAGS: 00200296
        CR0: 80050033 CR2: ffd17000 CR3: 1e58c000 CR4: 00040690
        Call Trace:
         ioremap_cache+0xd/0x10
         ? old_map_region+0x72/0x9d
         old_map_region+0x72/0x9d
         efi_map_region+0x8/0xa
         efi_enter_virtual_mode+0x260/0x43b
         start_kernel+0x329/0x3aa
         i386_start_kernel+0xa7/0xab
         startup_32_smp+0x164/0x168
        ---[ end trace e15ccf6b9f356833 ]---
      
      Let's work around this by disregarding the memory attributes table
      altogether on i386, which does not result in a loss of functionality
      or protection, given that we never consumed the contents.
      
      Fixes: 3a6b6c6f ("efi: Make EFI_MEMORY_ATTRIBUTES_TABLE ... ")
      Tested-by: NArvind Sankar <nivedita@alum.mit.edu>
      Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Signed-off-by: NIngo Molnar <mingo@kernel.org>
      Link: https://lore.kernel.org/r/20200304165917.5893-1-ardb@kernel.org
      Link: https://lore.kernel.org/r/20200308080859.21568-21-ardb@kernel.org
      dd09fad9
  22. 03 3月, 2020 1 次提交
  23. 29 2月, 2020 3 次提交
  24. 26 2月, 2020 1 次提交
  25. 24 2月, 2020 10 次提交