1. 22 4月, 2022 1 次提交
  2. 22 10月, 2021 1 次提交
  3. 05 10月, 2021 3 次提交
  4. 29 7月, 2021 1 次提交
    • A
      firmware_loader: fix use-after-free in firmware_fallback_sysfs · 75d95e2e
      Anirudh Rayabharam 提交于
      This use-after-free happens when a fw_priv object has been freed but
      hasn't been removed from the pending list (pending_fw_head). The next
      time fw_load_sysfs_fallback tries to insert into the list, it ends up
      accessing the pending_list member of the previously freed fw_priv.
      
      The root cause here is that all code paths that abort the fw load
      don't delete it from the pending list. For example:
      
              _request_firmware()
                -> fw_abort_batch_reqs()
                    -> fw_state_aborted()
      
      To fix this, delete the fw_priv from the list in __fw_set_state() if
      the new state is DONE or ABORTED. This way, all aborts will remove
      the fw_priv from the list. Accordingly, remove calls to list_del_init
      that were being made before calling fw_state_(aborted|done).
      
      Also, in fw_load_sysfs_fallback, don't add the fw_priv to the pending
      list if it is already aborted. Instead, just jump out and return early.
      
      Fixes: bcfbd352 ("firmware: fix a double abort case with fw_load_sysfs_fallback")
      Cc: stable <stable@vger.kernel.org>
      Reported-by: syzbot+de271708674e2093097b@syzkaller.appspotmail.com
      Tested-by: syzbot+de271708674e2093097b@syzkaller.appspotmail.com
      Reviewed-by: NShuah Khan <skhan@linuxfoundation.org>
      Acked-by: NLuis Chamberlain <mcgrof@kernel.org>
      Signed-off-by: NAnirudh Rayabharam <mail@anirudhrb.com>
      Link: https://lore.kernel.org/r/20210728085107.4141-3-mail@anirudhrb.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      75d95e2e
  5. 21 7月, 2021 1 次提交
    • Z
      firmware: fix theoretical UAF race with firmware cache and resume · 3ecc8cb7
      Zhen Lei 提交于
      This race was discovered when I carefully analyzed the code to locate
      another firmware-related UAF issue. It can be triggered only when the
      firmware load operation is executed during suspend. This possibility is
      almost impossible because there are few firmware load and suspend actions
      in the actual environment.
      
      		CPU0			CPU1
      __device_uncache_fw_images():		assign_fw():
      					fw_cache_piggyback_on_request()
      					<----- P0
      	spin_lock(&fwc->name_lock);
      	...
      	list_del(&fce->list);
      	spin_unlock(&fwc->name_lock);
      
      	uncache_firmware(fce->name);
      					<----- P1
      					kref_get(&fw_priv->ref);
      
      If CPU1 is interrupted at position P0, the new 'fce' has been added to the
      list fwc->fw_names by the fw_cache_piggyback_on_request(). In this case,
      CPU0 executes __device_uncache_fw_images() and will be able to see it when
      it traverses list fwc->fw_names. Before CPU1 executes kref_get() at P1, if
      CPU0 further executes uncache_firmware(), the count of fw_priv->ref may
      decrease to 0, causing fw_priv to be released in advance.
      
      Move kref_get() to the lock protection range of fwc->name_lock to fix it.
      
      Fixes: ac39b3ea ("firmware loader: let caching firmware piggyback on loading firmware")
      Acked-by: NLuis Chamberlain <mcgrof@kernel.org>
      Signed-off-by: NZhen Lei <thunder.leizhen@huawei.com>
      Link: https://lore.kernel.org/r/20210719064531.3733-2-thunder.leizhen@huawei.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3ecc8cb7
  6. 07 5月, 2021 1 次提交
    • R
      init/initramfs.c: do unpacking asynchronously · e7cb072e
      Rasmus Villemoes 提交于
      Patch series "background initramfs unpacking, and CONFIG_MODPROBE_PATH", v3.
      
      These two patches are independent, but better-together.
      
      The second is a rather trivial patch that simply allows the developer to
      change "/sbin/modprobe" to something else - e.g.  the empty string, so
      that all request_module() during early boot return -ENOENT early, without
      even spawning a usermode helper, needlessly synchronizing with the
      initramfs unpacking.
      
      The first patch delegates decompressing the initramfs to a worker thread,
      allowing do_initcalls() in main.c to proceed to the device_ and late_
      initcalls without waiting for that decompression (and populating of
      rootfs) to finish.  Obviously, some of those later calls may rely on the
      initramfs being available, so I've added synchronization points in the
      firmware loader and usermodehelper paths - there might be other places
      that would need this, but so far no one has been able to think of any
      places I have missed.
      
      There's not much to win if most of the functionality needed during boot is
      only available as modules.  But systems with a custom-made .config and
      initramfs can boot faster, partly due to utilizing more than one cpu
      earlier, partly by avoiding known-futile modprobe calls (which would still
      trigger synchronization with the initramfs unpacking, thus eliminating
      most of the first benefit).
      
      This patch (of 2):
      
      Most of the boot process doesn't actually need anything from the
      initramfs, until of course PID1 is to be executed.  So instead of doing
      the decompressing and populating of the initramfs synchronously in
      populate_rootfs() itself, push that off to a worker thread.
      
      This is primarily motivated by an embedded ppc target, where unpacking
      even the rather modest sized initramfs takes 0.6 seconds, which is long
      enough that the external watchdog becomes unhappy that it doesn't get
      attention soon enough.  By doing the initramfs decompression in a worker
      thread, we get to do the device_initcalls and hence start petting the
      watchdog much sooner.
      
      Normal desktops might benefit as well.  On my mostly stock Ubuntu kernel,
      my initramfs is a 26M xz-compressed blob, decompressing to around 126M.
      That takes almost two seconds:
      
      [    0.201454] Trying to unpack rootfs image as initramfs...
      [    1.976633] Freeing initrd memory: 29416K
      
      Before this patch, these lines occur consecutively in dmesg.  With this
      patch, the timestamps on these two lines is roughly the same as above, but
      with 172 lines inbetween - so more than one cpu has been kept busy doing
      work that would otherwise only happen after the populate_rootfs()
      finished.
      
      Should one of the initcalls done after rootfs_initcall time (i.e., device_
      and late_ initcalls) need something from the initramfs (say, a kernel
      module or a firmware blob), it will simply wait for the initramfs
      unpacking to be done before proceeding, which should in theory make this
      completely safe.
      
      But if some driver pokes around in the filesystem directly and not via one
      of the official kernel interfaces (i.e.  request_firmware*(),
      call_usermodehelper*) that theory may not hold - also, I certainly might
      have missed a spot when sprinkling wait_for_initramfs().  So there is an
      escape hatch in the form of an initramfs_async= command line parameter.
      
      Link: https://lkml.kernel.org/r/20210313212528.2956377-1-linux@rasmusvillemoes.dk
      Link: https://lkml.kernel.org/r/20210313212528.2956377-2-linux@rasmusvillemoes.dkSigned-off-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Reviewed-by: NLuis Chamberlain <mcgrof@kernel.org>
      Cc: Jessica Yu <jeyu@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Jonathan Corbet <corbet@lwn.net>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Takashi Iwai <tiwai@suse.de>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      e7cb072e
  7. 05 10月, 2020 7 次提交
  8. 28 8月, 2020 1 次提交
  9. 03 7月, 2020 1 次提交
  10. 27 5月, 2020 1 次提交
  11. 17 4月, 2020 1 次提交
  12. 20 3月, 2020 1 次提交
    • H
      firmware: Add new platform fallback mechanism and firmware_request_platform() · e4c2c0ff
      Hans de Goede 提交于
      In some cases the platform's main firmware (e.g. the UEFI fw) may contain
      an embedded copy of device firmware which needs to be (re)loaded into the
      peripheral. Normally such firmware would be part of linux-firmware, but in
      some cases this is not feasible, for 2 reasons:
      
      1) The firmware is customized for a specific use-case of the chipset / use
      with a specific hardware model, so we cannot have a single firmware file
      for the chipset. E.g. touchscreen controller firmwares are compiled
      specifically for the hardware model they are used with, as they are
      calibrated for a specific model digitizer.
      
      2) Despite repeated attempts we have failed to get permission to
      redistribute the firmware. This is especially a problem with customized
      firmwares, these get created by the chip vendor for a specific ODM and the
      copyright may partially belong with the ODM, so the chip vendor cannot
      give a blanket permission to distribute these.
      
      This commit adds a new platform fallback mechanism to the firmware loader
      which will try to lookup a device fw copy embedded in the platform's main
      firmware if direct filesystem lookup fails.
      
      Drivers which need such embedded fw copies can enable this fallback
      mechanism by using the new firmware_request_platform() function.
      
      Note that for now this is only supported on EFI platforms and even on
      these platforms firmware_fallback_platform() only works if
      CONFIG_EFI_EMBEDDED_FIRMWARE is enabled (this gets selected by drivers
      which need this), in all other cases firmware_fallback_platform() simply
      always returns -ENOENT.
      Reported-by: NDave Olsthoorn <dave@bewaar.me>
      Suggested-by: NPeter Jones <pjones@redhat.com>
      Acked-by: NLuis Chamberlain <mcgrof@kernel.org>
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Link: https://lore.kernel.org/r/20200115163554.101315-5-hdegoede@redhat.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e4c2c0ff
  13. 11 2月, 2020 1 次提交
    • T
      firmware_loader: load files from the mount namespace of init · 901cff7c
      Topi Miettinen 提交于
      I have an experimental setup where almost every possible system
      service (even early startup ones) runs in separate namespace, using a
      dedicated, minimal file system. In process of minimizing the contents
      of the file systems with regards to modules and firmware files, I
      noticed that in my system, the firmware files are loaded from three
      different mount namespaces, those of systemd-udevd, init and
      systemd-networkd. The logic of the source namespace is not very clear,
      it seems to depend on the driver, but the namespace of the current
      process is used.
      
      So, this patch tries to make things a bit clearer and changes the
      loading of firmware files only from the mount namespace of init. This
      may also improve security, though I think that using firmware files as
      attack vector could be too impractical anyway.
      
      Later, it might make sense to make the mount namespace configurable,
      for example with a new file in /proc/sys/kernel/firmware_config/. That
      would allow a dedicated file system only for firmware files and those
      need not be present anywhere else. This configurability would make
      more sense if made also for kernel modules and /sbin/modprobe. Modules
      are already loaded from init namespace (usermodehelper uses kthreadd
      namespace) except when directly loaded by systemd-udevd.
      
      Instead of using the mount namespace of the current process to load
      firmware files, use the mount namespace of init process.
      
      Link: https://lore.kernel.org/lkml/bb46ebae-4746-90d9-ec5b-fce4c9328c86@gmail.com/
      Link: https://lore.kernel.org/lkml/0e3f7653-c59d-9341-9db2-c88f5b988c68@gmail.com/Signed-off-by: NTopi Miettinen <toiwoton@gmail.com>
      Link: https://lore.kernel.org/r/20200123125839.37168-1-toiwoton@gmail.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      901cff7c
  14. 24 1月, 2020 1 次提交
  15. 14 11月, 2019 1 次提交
  16. 04 11月, 2019 1 次提交
  17. 11 10月, 2019 1 次提交
  18. 18 6月, 2019 2 次提交
    • T
      firmware: Add support for loading compressed files · 82fd7a81
      Takashi Iwai 提交于
      This patch adds the support for loading compressed firmware files.
      The primary motivation is to reduce the storage size; e.g. currently
      the files in /lib/firmware on my machine counts up to 419MB, while
      they can be reduced to 130MB by file compression.
      
      The patch introduces a new kconfig option CONFIG_FW_LOADER_COMPRESS.
      Even with this option set, the firmware loader still tries to load the
      original firmware file as-is at first, but then falls back to the file
      with ".xz" extension when it's not found, and the decompressed file
      content is returned to the caller of request_firmware().  So, no
      change is needed for the rest.
      
      Currently only XZ format is supported.  A caveat is that the kernel XZ
      helper code supports only CRC32 (or none) integrity check type, so
      you'll have to compress the files via xz -C crc32 option.
      
      Since we can't determine the expanded size immediately from an XZ
      file, the patch re-uses the paged buffer that was used for the
      user-mode fallback; it puts the decompressed content page, which are
      vmapped at the end.  The paged buffer code is conditionally built with
      a new Kconfig that is selected automatically.
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      82fd7a81
    • T
      firmware: Factor out the paged buffer handling code · 5342e709
      Takashi Iwai 提交于
      This is merely a preparation for the upcoming compressed firmware
      support and no functional changes.  It moves the code to handle the
      paged buffer allocation and mapping out of fallback.c into the main
      code, so that they can be used commonly.
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5342e709
  19. 11 6月, 2019 3 次提交
  20. 26 2月, 2019 1 次提交
  21. 30 9月, 2018 1 次提交
  22. 12 9月, 2018 1 次提交
    • R
      firmware: Fix security issue with request_firmware_into_buf() · 422b3db2
      Rishabh Bhatnagar 提交于
      When calling request_firmware_into_buf() with the FW_OPT_NOCACHE flag
      it is expected that firmware is loaded into buffer from memory.
      But inside alloc_lookup_fw_priv every new firmware that is loaded is
      added to the firmware cache (fwc) list head. So if any driver requests
      a firmware that is already loaded the code iterates over the above
      mentioned list and it can end up giving a pointer to other device driver's
      firmware buffer.
      Also the existing copy may either be modified by drivers, remote processors
      or even freed. This causes a potential security issue with batched requests
      when using request_firmware_into_buf.
      
      Fix alloc_lookup_fw_priv to not add to the fwc head list if FW_OPT_NOCACHE
      is set, and also don't do the lookup in the list.
      
      Fixes: 0e742e92 ("firmware: provide infrastructure to make fw caching optional")
      [mcgrof: broken since feature introduction on v4.8]
      
      Cc: stable@vger.kernel.org # v4.8+
      Signed-off-by: NVikram Mulukutla <markivx@codeaurora.org>
      Signed-off-by: NRishabh Bhatnagar <rishabhb@codeaurora.org>
      Signed-off-by: NLuis Chamberlain <mcgrof@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      422b3db2
  23. 14 5月, 2018 4 次提交
  24. 23 3月, 2018 1 次提交
  25. 20 3月, 2018 2 次提交