1. 03 6月, 2017 5 次提交
  2. 27 1月, 2017 1 次提交
    • L
      firmware: fix NULL pointer dereference in __fw_load_abort() · 191e885a
      Luis R. Rodriguez 提交于
      Since commit 5d47ec02 ("firmware: Correct handling of
      fw_state_wait() return value") fw_load_abort() could be called twice and
      lead us to a kernel crash. This happens only when the firmware fallback
      mechanism (regular or custom) is used. The fallback mechanism exposes a
      sysfs interface for userspace to upload a file and notify the kernel
      when the file is loaded and ready, or to cancel an upload by echo'ing -1
      into on the loading file:
      
      echo -n "-1" > /sys/$DEVPATH/loading
      
      This will call fw_load_abort(). Some distributions actually have a udev
      rule in place to *always* immediately cancel all firmware fallback
      mechanism requests (Debian), they have:
      
        $ cat /lib/udev/rules.d/50-firmware.rules
        # stub for immediately telling the kernel that userspace firmware loading
        # failed; necessary to avoid long timeouts with CONFIG_FW_LOADER_USER_HELPER=y
        SUBSYSTEM=="firmware", ACTION=="add", ATTR{loading}="-1
      
      Distributions with this udev rule would run into this crash only if the
      fallback mechanism is used. Since most distributions disable by default
      using the fallback mechanism (CONFIG_FW_LOADER_USER_HELPER_FALLBACK),
      this would typicaly mean only 2 drivers which *require* the fallback
      mechanism could typically incur a crash: drivers/firmware/dell_rbu.c and
      the drivers/leds/leds-lp55xx-common.c driver. Distributions enabling
      CONFIG_FW_LOADER_USER_HELPER_FALLBACK by default are obviously more
      exposed to this crash.
      
      The crash happens because after commit 5b029624 ("firmware: do not
      use fw_lock for fw_state protection") and subsequent fix commit
      5d47ec02 ("firmware: Correct handling of fw_state_wait() return
      value") a race can happen between this cancelation and the firmware
      fw_state_wait_timeout() being woken up after a state change with which
      fw_load_abort() as that calls swake_up(). Upon error
      fw_state_wait_timeout() will also again call fw_load_abort() and trigger
      a null reference.
      
      At first glance we could just fix this with a !buf check on
      fw_load_abort() before accessing buf->fw_st, however there is a logical
      issue in having a state machine used for the fallback mechanism and
      preventing access from it once we abort as its inside the buf
      (buf->fw_st).
      
      The firmware_class.c code is setting the buf to NULL to annotate an
      abort has occurred. Replace this mechanism by simply using the state
      check instead. All the other code in place already uses similar checks
      for aborting as well so no further changes are needed.
      
      An oops can be reproduced with the new fw_fallback.sh fallback mechanism
      cancellation test. Either cancelling the fallback mechanism or the
      custom fallback mechanism triggers a crash.
      
      mcgrof@piggy ~/linux-next/tools/testing/selftests/firmware
      (git::20170111-fw-fixes)$ sudo ./fw_fallback.sh
      
      ./fw_fallback.sh: timeout works
      ./fw_fallback.sh: firmware comparison works
      ./fw_fallback.sh: fallback mechanism works
      
      [ this then sits here when it is trying the cancellation test ]
      
      Kernel log:
      
      test_firmware: loading 'nope-test-firmware.bin'
      misc test_firmware: Direct firmware load for nope-test-firmware.bin failed with error -2
      misc test_firmware: Falling back to user helper
      BUG: unable to handle kernel NULL pointer dereference at 0000000000000038
      IP: _request_firmware+0xa27/0xad0
      PGD 0
      
      Oops: 0000 [#1] SMP
      Modules linked in: test_firmware(E) ... etc ...
      CPU: 1 PID: 1396 Comm: fw_fallback.sh Tainted: G        W E   4.10.0-rc3-next-20170111+ #30
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.10.1-0-g8891697-prebuilt.qemu-project.org 04/01/2014
      task: ffff9740b27f4340 task.stack: ffffbb15c0bc8000
      RIP: 0010:_request_firmware+0xa27/0xad0
      RSP: 0018:ffffbb15c0bcbd10 EFLAGS: 00010246
      RAX: 00000000fffffffe RBX: ffff9740afe5aa80 RCX: 0000000000000000
      RDX: ffff9740b27f4340 RSI: 0000000000000283 RDI: 0000000000000000
      RBP: ffffbb15c0bcbd90 R08: ffffbb15c0bcbcd8 R09: 0000000000000000
      R10: 0000000894a0d4b1 R11: 000000000000008c R12: ffffffffc0312480
      R13: 0000000000000005 R14: ffff9740b1c32400 R15: 00000000000003e8
      FS:  00007f8604422700(0000) GS:ffff9740bfc80000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 0000000000000038 CR3: 000000012164c000 CR4: 00000000000006e0
      Call Trace:
       request_firmware+0x37/0x50
       trigger_request_store+0x79/0xd0 [test_firmware]
       dev_attr_store+0x18/0x30
       sysfs_kf_write+0x37/0x40
       kernfs_fop_write+0x110/0x1a0
       __vfs_write+0x37/0x160
       ? _cond_resched+0x1a/0x50
       vfs_write+0xb5/0x1a0
       SyS_write+0x55/0xc0
       ? trace_do_page_fault+0x37/0xd0
       entry_SYSCALL_64_fastpath+0x1e/0xad
      RIP: 0033:0x7f8603f49620
      RSP: 002b:00007fff6287b788 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
      RAX: ffffffffffffffda RBX: 000055c307b110a0 RCX: 00007f8603f49620
      RDX: 0000000000000016 RSI: 000055c3084d8a90 RDI: 0000000000000001
      RBP: 0000000000000016 R08: 000000000000c0ff R09: 000055c3084d6336
      R10: 000055c307b108b0 R11: 0000000000000246 R12: 000055c307b13c80
      R13: 000055c3084d6320 R14: 0000000000000000 R15: 00007fff6287b950
      Code: 9f 64 84 e8 9c 61 fe ff b8 f4 ff ff ff e9 6b f9 ff
      ff 48 c7 c7 40 6b 8d 84 89 45 a8 e8 43 84 18 00 49 8b be 00 03 00 00 8b
      45 a8 <83> 7f 38 02 74 08 e8 6e ec ff ff 8b 45 a8 49 c7 86 00 03 00 00
      RIP: _request_firmware+0xa27/0xad0 RSP: ffffbb15c0bcbd10
      CR2: 0000000000000038
      ---[ end trace 6d94ac339c133e6f ]---
      
      Fixes: 5d47ec02 ("firmware: Correct handling of fw_state_wait() return value")
      Reported-and-Tested-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Reported-and-Tested-by: NPatrick Bruenn <p.bruenn@beckhoff.com>
      Reported-by: NChris Wilson <chris@chris-wilson.co.uk>
      CC: <stable@vger.kernel.org>    [3.10+]
      Signed-off-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      191e885a
  3. 09 12月, 2016 1 次提交
  4. 02 12月, 2016 1 次提交
  5. 30 11月, 2016 6 次提交
    • D
      firmware: move fw_state_is_done() into UHM section · fab82cb3
      Daniel Wagner 提交于
      fw_state_is_done() is only used for UHM so moved into that section.
      
      Cc: Ming Lei <ming.lei@canonical.com>
      Signed-off-by: NDaniel Wagner <daniel.wagner@bmw-carit.de>
      Acked-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fab82cb3
    • D
      firmware: do not use fw_lock for fw_state protection · 5b029624
      Daniel Wagner 提交于
      fw_lock is to use to protect 'corner cases' inside firmware_class. It
      is not exactly clear what those corner cases are nor what it exactly
      protects. fw_state can be used without needing the fw_lock to protect
      its state transition and wake ups.
      
      fw_state is holds the state in status and the completion is used to
      wake up all waiters (in this case that is the user land helper so only
      one). This operation has to be 'atomic' to avoid races.  We can do this
      by using swait which takes care we don't miss any wake up.
      
      We use also swait instead of wait because don't need all the additional
      features wait provides.
      
      Note there some more cleanups possible after with this change. For
      example for !CONFIG_FW_LOADER_USER_HELPER we don't check for the state
      anymore.  Let's to this in the next patch instead mingling to many
      changes into this one. And yes you get a gcc warning "‘__fw_state_check’
      defined but not used [-Wunused-function] code." for the time beeing.
      
      Cc: Ming Lei <ming.lei@canonical.com>
      Signed-off-by: NDaniel Wagner <daniel.wagner@bmw-carit.de>
      Acked-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5b029624
    • D
      firmware: drop bit ops in favor of simple state machine · 0430cafc
      Daniel Wagner 提交于
      We track the state of the firmware loading with bit ops.  Since the
      state machine has only a few states and they are all mutual exclusive
      there are only a few simple state transition we can model this simplify.
      
      	   UNKNOWN -> LOADING -> DONE | ABORTED
      
      Because we don't use any bit ops on fw_state::status anymore we are able
      to change the data type to enum fw_status and update the function
      arguments accordingly.
      
      READ_ONCE() and WRITE_ONCE() are propably not needed because there are a
      lot of load and stores around fw_st->status. But let's make it explicit
      and not be sorry later.
      
      Cc: Ming Lei <ming.lei@canonical.com>
      Signed-off-by: NDaniel Wagner <daniel.wagner@bmw-carit.de>
      Acked-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0430cafc
    • D
      firmware: refactor loading status · f52cc379
      Daniel Wagner 提交于
      The firmware loader tracks the current state of the loading process
      via unsigned long status and a completion in struct
      firmware_buf. Instead of open code tracking the state, introduce data
      structure which encapsulate the state tracking and synchronization.
      
      While at it also separate UHM states from direct loading states, e.g.
      the loading_timeout is only defined when CONFIG_FW_LOADER_USER_HELPER.
      
      Cc: Ming Lei <ming.lei@canonical.com>
      Signed-off-by: NDaniel Wagner <daniel.wagner@bmw-carit.de>
      Acked-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f52cc379
    • Y
      firmware: fix usermode helper fallback loading · 2e700f8d
      Yves-Alexis Perez 提交于
      When you use the firmware usermode helper fallback with a timeout value set to a
      value greater than INT_MAX (2147483647) a cast overflow issue causes the
      timeout value to go negative and breaks all usermode helper loading. This
      regression was introduced through commit 68ff2a00 ("firmware_loader:
      handle timeout via wait_for_completion_interruptible_timeout()") on kernel
      v4.0.
      
      The firmware_class drivers relies on the firmware usermode helper
      fallback as a mechanism to look for firmware if the direct filesystem
      search failed only if:
      
        a) You've enabled CONFIG_FW_LOADER_USER_HELPER_FALLBACK (not many distros):
      
        Then all of these callers will rely on the fallback mechanism in case
        the firmware is not found through an initial direct filesystem lookup:
      
        o request_firmware()
        o request_firmware_into_buf()
        o request_firmware_nowait()
      
        b) If you've only enabled CONFIG_FW_LOADER_USER_HELPER (most distros):
      
        Then only callers using request_firmware_nowait() with the second
        argument set to false, this explicitly is requesting the UMH firmware
        fallback to be relied on in case the first filesystem lookup fails.
      
        Using Coccinelle SmPL grammar we have identified only two drivers
        explicitly requesting the UMH firmware fallback mechanism:
      
        - drivers/firmware/dell_rbu.c
        - drivers/leds/leds-lp55xx-common.c
      
      Since most distributions only enable CONFIG_FW_LOADER_USER_HELPER the
      biggest impact of this regression are users of the dell_rbu and
      leds-lp55xx-common device driver which required the UMH to find their
      respective needed firmwares.
      
      The default timeout for the UMH is set to 60 seconds always, as of
      commit 68ff2a00 ("firmware_loader: handle timeout via
      wait_for_completion_interruptible_timeout()") the timeout was bumped
      to MAX_JIFFY_OFFSET ((LONG_MAX >> 1)-1). Additionally the MAX_JIFFY_OFFSET
      value was also used if the timeout was configured by a user to 0.
      
      The following works:
      
      echo 2147483647 > /sys/class/firmware/timeout
      
      But both of the following set the timeout to MAX_JIFFY_OFFSET even if
      we display 0 back to userspace:
      
      echo 2147483648 > /sys/class/firmware/timeout
      cat /sys/class/firmware/timeout
      0
      
      echo 0> /sys/class/firmware/timeout
      cat /sys/class/firmware/timeout
      0
      
      A max value of INT_MAX (2147483647) seconds is therefore implicit due to the
      another cast with simple_strtol().
      
      This fixes the secondary cast (the first one is simple_strtol() but its an
      issue only by forcing an implicit limit) by re-using the timeout variable and
      only setting retval in appropriate cases.
      
      Lastly worth noting systemd had ripped out the UMH firmware fallback
      mechanism from udev since udev 2014 via commit be2ea723b1d023b3d
      ("udev: remove userspace firmware loading support"), so as of systemd v217.
      Signed-off-by: NYves-Alexis Perez <corsac@corsac.net>
      Fixes: 68ff2a00 "firmware_loader: handle timeout via wait_for_completion_interruptible_timeout()"
      Cc: Luis R. Rodriguez <mcgrof@kernel.org>
      Cc: Ming Lei <ming.lei@canonical.com>
      Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: stable@vger.kernel.org
      Acked-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      Reviewed-by: NBjorn Andersson <bjorn.andersson@linaro.org>
      [mcgrof@kernel.org: gave commit log a whole lot of love]
      Signed-off-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2e700f8d
    • G
      driver core: firmware_class: convert to use class_groups · 3f214cff
      Greg Kroah-Hartman 提交于
      Convert the firmware core to use class_groups instead of class_attrs as
      that's the correct way to handle lists of class attribute files.
      
      Cc: Ming Lei <ming.lei@canonical.com>
      Acked-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3f214cff
  6. 03 8月, 2016 3 次提交
    • S
      firmware: support loading into a pre-allocated buffer · a098ecd2
      Stephen Boyd 提交于
      Some systems are memory constrained but they need to load very large
      firmwares.  The firmware subsystem allows drivers to request this
      firmware be loaded from the filesystem, but this requires that the
      entire firmware be loaded into kernel memory first before it's provided
      to the driver.  This can lead to a situation where we map the firmware
      twice, once to load the firmware into kernel memory and once to copy the
      firmware into the final resting place.
      
      This creates needless memory pressure and delays loading because we have
      to copy from kernel memory to somewhere else.  Let's add a
      request_firmware_into_buf() API that allows drivers to request firmware
      be loaded directly into a pre-allocated buffer.  This skips the
      intermediate step of allocating a buffer in kernel memory to hold the
      firmware image while it's read from the filesystem.  It also requires
      that drivers know how much memory they'll require before requesting the
      firmware and negates any benefits of firmware caching because the
      firmware layer doesn't manage the buffer lifetime.
      
      For a 16MB buffer, about half the time is spent performing a memcpy from
      the buffer to the final resting place.  I see loading times go from
      0.081171 seconds to 0.047696 seconds after applying this patch.  Plus
      the vmalloc pressure is reduced.
      
      This is based on a patch from Vikram Mulukutla on codeaurora.org:
        https://www.codeaurora.org/cgit/quic/la/kernel/msm-3.18/commit/drivers/base/firmware_class.c?h=rel/msm-3.18&id=0a328c5f6cd999f5c591f172216835636f39bcb5
      
      Link: http://lkml.kernel.org/r/20160607164741.31849-4-stephen.boyd@linaro.orgSigned-off-by: NStephen Boyd <stephen.boyd@linaro.org>
      Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
      Cc: Vikram Mulukutla <markivx@codeaurora.org>
      Cc: Mark Brown <broonie@kernel.org>
      Cc: Ming Lei <ming.lei@canonical.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      a098ecd2
    • V
      firmware: provide infrastructure to make fw caching optional · 0e742e92
      Vikram Mulukutla 提交于
      Some low memory systems with complex peripherals cannot afford to have
      the relatively large firmware images taking up valuable memory during
      suspend and resume.  Change the internal implementation of
      firmware_class to disallow caching based on a configurable option.  In
      the near future, variants of request_firmware will take advantage of
      this feature.
      
      Link: http://lkml.kernel.org/r/20160607164741.31849-3-stephen.boyd@linaro.org
      [stephen.boyd@linaro.org: Drop firmware_desc design and use flags]
      Signed-off-by: NVikram Mulukutla <markivx@codeaurora.org>
      Signed-off-by: NStephen Boyd <stephen.boyd@linaro.org>
      Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
      Cc: Mark Brown <broonie@kernel.org>
      Cc: Ming Lei <ming.lei@canonical.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      0e742e92
    • S
      firmware: consolidate kmap/read/write logic · 9ccf9811
      Stephen Boyd 提交于
      Some systems are memory constrained but they need to load very large
      firmwares.  The firmware subsystem allows drivers to request this
      firmware be loaded from the filesystem, but this requires that the
      entire firmware be loaded into kernel memory first before it's provided
      to the driver.  This can lead to a situation where we map the firmware
      twice, once to load the firmware into kernel memory and once to copy the
      firmware into the final resting place.
      
      This design creates needless memory pressure and delays loading because
      we have to copy from kernel memory to somewhere else.  This patch sets
      adds support to the request firmware API to load the firmware directly
      into a pre-allocated buffer, skipping the intermediate copying step and
      alleviating memory pressure during firmware loading.  The drawback is
      that we can't use the firmware caching feature because the memory for
      the firmware cache is not managed by the firmware layer.
      
      This patch (of 3):
      
      We use similar structured code to read and write the kmapped firmware
      pages.  The only difference is read copies from the kmap region and
      write copies to it.  Consolidate this into one function to reduce
      duplication.
      
      Link: http://lkml.kernel.org/r/20160607164741.31849-2-stephen.boyd@linaro.orgSigned-off-by: NStephen Boyd <stephen.boyd@linaro.org>
      Cc: Vikram Mulukutla <markivx@codeaurora.org>
      Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
      Cc: Mark Brown <broonie@kernel.org>
      Cc: Ming Lei <ming.lei@canonical.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      9ccf9811
  7. 29 2月, 2016 1 次提交
    • L
      firmware: change kernel read fail to dev_dbg() · 8e516aa5
      Luis R. Rodriguez 提交于
      When we now use the new kernel_read_file_from_path() we
      are reporting a failure when we iterate over all the paths
      possible for firmware. Before using kernel_read_file_from_path()
      we only reported a failure once we confirmed a file existed
      with filp_open() but failed with fw_read_file_contents().
      
      With kernel_read_file_from_path() both are done for us and
      we obviously are now reporting too much information given that
      some optional paths will always fail and clutter the logs.
      
      fw_get_filesystem_firmware() already has a check for failure
      and uses an internal flag, FW_OPT_NO_WARN, but this does not
      let us capture other unxpected errors. This enables that
      as changed by Neil via commit:
      
      "firmware: Be a bit more verbose about direct firmware loading failure"
      Reported-by: NHeiner Kallweit <hkallweit1@gmail.com>
      Cc: Neil Horman <nhorman@tuxdriver.com>
      Cc: Heiner Kallweit <hkallweit1@gmail.com>
      Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
      Cc: Kees Cook <keescook@chromium.org>
      Signed-off-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      Acked-by: NKees Cook <keescook@chromium.org>
      Acked-by: NMing Lei <ming.lei@canonical.com>
      Signed-off-by: NJames Morris <james.l.morris@oracle.com>
      8e516aa5
  8. 21 2月, 2016 1 次提交
    • M
      firmware: replace call to fw_read_file_contents() with kernel version · e40ba6d5
      Mimi Zohar 提交于
      Replace the fw_read_file_contents with kernel_file_read_from_path().
      
      Although none of the upstreamed LSMs define a kernel_fw_from_file hook,
      IMA is called by the security function to prevent unsigned firmware from
      being loaded and to measure/appraise signed firmware, based on policy.
      
      Instead of reading the firmware twice, once for measuring/appraising the
      firmware and again for reading the firmware contents into memory, the
      kernel_post_read_file() security hook calculates the file hash based on
      the in memory file buffer.  The firmware is read once.
      
      This patch removes the LSM kernel_fw_from_file() hook and security call.
      
      Changelog v4+:
      - revert dropped buf->size assignment - reported by Sergey Senozhatsky
      v3:
      - remove kernel_fw_from_file hook
      - use kernel_file_read_from_path() - requested by Luis
      v2:
      - reordered and squashed firmware patches
      - fix MAX firmware size (Kees Cook)
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Acked-by: NKees Cook <keescook@chromium.org>
      Acked-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      e40ba6d5
  9. 19 2月, 2016 3 次提交
  10. 09 2月, 2016 2 次提交
  11. 08 1月, 2016 1 次提交
    • B
      firmware: actually return NULL on failed request_firmware_nowait() · 715780ae
      Brian Norris 提交于
      The kerneldoc for request_firmware_nowait() says that it may call the
      provided cont() callback with @fw == NULL, if the firmware request
      fails. However, this is not the case when called with an empty string
      (""). This case is short-circuited by the 'name[0] == '\0'' check
      introduced in commit 471b095d ("firmware_class: make sure fw requests
      contain a name"), so _request_firmware() never gets to set the fw to
      NULL.
      
      Noticed while using the new 'trigger_async_request' testing hook:
      
          # printf '\x00' > /sys/devices/virtual/misc/test_firmware/trigger_async_request
          [10553.726178] test_firmware: loading ''
          [10553.729859] test_firmware: loaded: 995209091
          # printf '\x00' > /sys/devices/virtual/misc/test_firmware/trigger_async_request
          [10733.676184] test_firmware: loading ''
          [10733.679855] Unable to handle kernel NULL pointer dereference at virtual address 00000004
          [10733.687951] pgd = ec188000
          [10733.690655] [00000004] *pgd=00000000
          [10733.694240] Internal error: Oops: 5 [#1] SMP ARM
          [10733.698847] Modules linked in: btmrvl_sdio btmrvl bluetooth sbs_battery nf_conntrack_ipv6 nf_defrag_ipv6 ip6table_filter ip6_tables asix usbnet mwifiex_sdio mwifiex cfg80211 jitterentropy_rng drbg joydev snd_seq_midi snd_seq_midi_event snd_rawmidi snd_seq snd_seq_device ppp_async ppp_generic slhc tun
          [10733.725670] CPU: 0 PID: 6600 Comm: bash Not tainted 4.4.0-rc4-00351-g63d0877 #178
          [10733.733137] Hardware name: Rockchip (Device Tree)
          [10733.737831] task: ed24f6c0 ti: ee322000 task.ti: ee322000
          [10733.743222] PC is at do_raw_spin_lock+0x18/0x1a0
          [10733.747831] LR is at _raw_spin_lock+0x18/0x1c
          [10733.752180] pc : [<c00653a0>]    lr : [<c054c204>]    psr: a00d0013
          [10733.752180] sp : ee323df8  ip : ee323e20  fp : ee323e1c
          [10733.763634] r10: 00000051  r9 : b6f18000  r8 : ee323f80
          [10733.768847] r7 : c089cebc  r6 : 00000001  r5 : 00000000  r4 : ec0e6000
          [10733.775360] r3 : dead4ead  r2 : c06bd140  r1 : eef913b4  r0 : 00000000
          [10733.781874] Flags: NzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
          [10733.788995] Control: 10c5387d  Table: 2c18806a  DAC: 00000051
          [10733.794728] Process bash (pid: 6600, stack limit = 0xee322218)
          [10733.800549] Stack: (0xee323df8 to 0xee324000)
          [10733.804896] 3de0:                                                       ec0e6000 00000000
          [10733.813059] 3e00: 00000001 c089cebc ee323f80 b6f18000 ee323e2c ee323e20 c054c204 c0065394
          [10733.821221] 3e20: ee323e44 ee323e30 c02fec60 c054c1f8 ec0e7ec0 ec3fcfc0 ee323e5c ee323e48
          [10733.829384] 3e40: c02fed08 c02fec48 c07dbf74 eeb05a00 ee323e8c ee323e60 c0253828 c02fecac
          [10733.837547] 3e60: 00000001 c0116950 ee323eac ee323e78 00000001 ec3fce00 ed2d9700 ed2d970c
          [10733.845710] 3e80: ee323e9c ee323e90 c02e873c c02537d4 ee323eac ee323ea0 c017bd40 c02e8720
          [10733.853873] 3ea0: ee323ee4 ee323eb0 c017b250 c017bd00 00000000 00000000 f3e47a54 ec128b00
          [10733.862035] 3ec0: c017b10c ee323f80 00000001 c000f504 ee322000 00000000 ee323f4c ee323ee8
          [10733.870197] 3ee0: c011b71c c017b118 ee323fb0 c011bc90 becfa8d9 00000001 ec128b00 00000001
          [10733.878359] 3f00: b6f18000 ee323f80 ee323f4c ee323f18 c011bc90 c0063950 ee323f3c ee323f28
          [10733.886522] 3f20: c0063950 c0549138 00000001 ec128b00 00000001 ec128b00 b6f18000 ee323f80
          [10733.894684] 3f40: ee323f7c ee323f50 c011bed8 c011b6ec c0135fb8 c0135f24 ec128b00 ec128b00
          [10733.902847] 3f60: 00000001 b6f18000 c000f504 ee322000 ee323fa4 ee323f80 c011c664 c011be24
          [10733.911009] 3f80: 00000000 00000000 00000001 b6f18000 b6e79be0 00000004 00000000 ee323fa8
          [10733.919172] 3fa0: c000f340 c011c618 00000001 b6f18000 00000001 b6f18000 00000001 00000000
          [10733.927334] 3fc0: 00000001 b6f18000 b6e79be0 00000004 00000001 00000001 8068a3f1 b6e79c84
          [10733.935496] 3fe0: 00000000 becfa7dc b6de194d b6e20246 400d0030 00000001 7a4536e8 49bda390
          [10733.943664] [<c00653a0>] (do_raw_spin_lock) from [<c054c204>] (_raw_spin_lock+0x18/0x1c)
          [10733.951743] [<c054c204>] (_raw_spin_lock) from [<c02fec60>] (fw_free_buf+0x24/0x64)
          [10733.959388] [<c02fec60>] (fw_free_buf) from [<c02fed08>] (release_firmware+0x68/0x74)
          [10733.967207] [<c02fed08>] (release_firmware) from [<c0253828>] (trigger_async_request_store+0x60/0x124)
          [10733.976501] [<c0253828>] (trigger_async_request_store) from [<c02e873c>] (dev_attr_store+0x28/0x34)
          [10733.985533] [<c02e873c>] (dev_attr_store) from [<c017bd40>] (sysfs_kf_write+0x4c/0x58)
          [10733.993437] [<c017bd40>] (sysfs_kf_write) from [<c017b250>] (kernfs_fop_write+0x144/0x1a8)
          [10734.001689] [<c017b250>] (kernfs_fop_write) from [<c011b71c>] (__vfs_write+0x3c/0xe4)
      
      After this patch:
      
          # printf '\x00' > /sys/devices/virtual/misc/test_firmware/trigger_async_request
          [   32.126322] test_firmware: loading ''
          [   32.129995] test_firmware: failed to async load firmware
          -bash: printf: write error: No such device
      
      Fixes: 471b095d ("firmware_class: make sure fw requests contain a name")
      Signed-off-by: NBrian Norris <computersforpeace@gmail.com>
      Acked-by: NMing Lei <ming.lei@canonical.com>
      Acked-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: NShuah Khan <shuahkh@osg.samsung.com>
      715780ae
  12. 06 8月, 2015 1 次提交
  13. 10 7月, 2015 1 次提交
  14. 01 6月, 2015 1 次提交
  15. 25 5月, 2015 4 次提交
    • L
      firmware: use const for remaining firmware names · e0fd9b1d
      Luis R. Rodriguez 提交于
      We currently use flexible arrays with a char at the
      end for the remaining internal firmware name uses.
      There are two limitations with the way we use this.
      Since we're using a flexible array for a string on the
      struct if we wanted to use two strings it means we'd
      have a disjoint means of handling the strings, one
      using the flexible array, and another a char * pointer.
      We're also currently not using 'const' for the string.
      
      We wish to later extend some firmware data structures
      with other string/char pointers, but we also want to be
      very pedantic about const usage. Since we're going to
      change things to use 'const' we might as well also address
      unified way to use multiple strings on the structs.
      
      Replace the flexible array practice for strings with
      kstrdup_const() and kfree_const(), this will avoid
      allocations when the vmlinux .rodata is used, and just
      allocate a new proper string for us when needed. This
      also means we can simplify the struct allocations by
      removing the string length from the allocation size
      computation, which would otherwise get even more
      complicated when supporting multiple strings.
      
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Rusty Russell <rusty@rustcorp.com.au>
      Cc: David Howells <dhowells@redhat.com>
      Cc: Ming Lei <ming.lei@canonical.com>
      Cc: Seth Forshee <seth.forshee@canonical.com>
      Cc: Kyle McMartin <kyle@kernel.org>
      Signed-off-by: NLuis R. Rodriguez <mcgrof@suse.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e0fd9b1d
    • L
      firmware: fix possible use after free on name on asynchronous request · f9692b26
      Luis R. Rodriguez 提交于
      Asynchronous firmware loading copies the pointer to the
      name passed as an argument only to be scheduled later and
      used. This behaviour works well for synchronous calling
      but in asynchronous mode there's a chance the caller could
      immediately free the passed string after making the
      asynchronous call. This could trigger a use after free
      having the kernel look on disk for arbitrary file names.
      
      In order to force-test the issue you can use a test-driver
      designed to illustrate this issue on github [0], use the
      next-20150505-fix-use-after-free branch.
      
      With this patch applied you get:
      
      [  283.512445] firmware name: test_module_stuff.bin
      [  287.514020] firmware name: test_module_stuff.bin
      [  287.532489] firmware found
      
      Without this patch applied you can end up with something such as:
      
      [  135.624216] firmware name: \xffffff80BJ
      [  135.624249] platform fake-dev.0: Direct firmware load for \xffffff80Bi failed with error -2
      [  135.624252] No firmware found
      [  135.624252] firmware found
      
      Unfortunatley in the worst and most common case however you
      can typically crash your system with a page fault by trying to
      free something which you cannot, and/or a NULL pointer
      dereference [1].
      
      The fix and issue using schedule_work() for asynchronous
      runs is generalized in the following SmPL grammar patch,
      when applied to next-20150505 only the firmware_class
      code is affected. This grammar patch can and should further
      be generalized to vet for for other kernel asynchronous
      mechanisms.
      
      @ calls_schedule_work @
      type T;
      T *priv_work;
      identifier func, work_func;
      identifier work;
      identifier priv_name, name;
      expression gfp;
      @@
      
       func(..., const char *name, ...)
       {
       	...
       	priv_work = kzalloc(sizeof(T), gfp);
       	...
      -	priv_work->priv_name = name;
      +	priv_work->priv_name = kstrdup_const(name, gfp);
      	...
      (... when any
       	if (...)
       	{
       		...
      + 		kfree_const(priv_work->priv_name);
       		kfree(priv_work);
      		...
       	}
      ) ... when any
       	INIT_WORK(&priv_work->work, work_func);
       	...
       	schedule_work(&priv_work->work);
       	...
       }
      
      @ the_work_func depends on calls_schedule_work @
      type calls_schedule_work.T;
      T *priv_work;
      identifier calls_schedule_work.work_func;
      identifier calls_schedule_work.priv_name;
      identifier calls_schedule_work.work;
      identifier some_work;
      @@
      
       work_func(...)
       {
       	...
       	priv_work = container_of(some_work, T, work);
       	...
      +	kfree_const(priv_work->priv_name);
       	kfree(priv_work);
       	...
       }
      
      [0] https://github.com/mcgrof/fake-firmware-test.git
      [1] The following kernel ring buffer splat:
      
      firmware name: test_module_stuff.bin
      firmware name:
      firmware found
      general protection fault: 0000 [#1] SMP
      Modules linked in: test(O) <...etc-it-does-not-matter>
       drm sr_mod cdrom xhci_pci xhci_hcd rtsx_pci mfd_core video button sg
      CPU: 3 PID: 87 Comm: kworker/3:2 Tainted: G           O    4.0.0-00010-g22b5bb0-dirty #176
      Hardware name: LENOVO 20AW000LUS/20AW000LUS, BIOS GLET43WW (1.18 ) 12/04/2013
      Workqueue: events request_firmware_work_func
      task: ffff8800c7f8e290 ti: ffff8800c7f94000 task.ti: ffff8800c7f94000
      RIP: 0010:[<ffffffff814a586c>]  [<ffffffff814a586c>] fw_free_buf+0xc/0x40
      RSP: 0000:ffff8800c7f97d78  EFLAGS: 00010286
      RAX: ffffffff81ae3700 RBX: ffffffff816d1181 RCX: 0000000000000006
      RDX: 0001ee850ff68500 RSI: 0000000000000246 RDI: c35d5f415e415d41
      RBP: ffff8800c7f97d88 R08: 000000000000000a R09: 0000000000000000
      R10: 0000000000000358 R11: ffff8800c7f97a7e R12: ffff8800c7ec1e80
      R13: ffff88021e2d4cc0 R14: ffff88021e2dff00 R15: 00000000000000c0
      FS:  0000000000000000(0000) GS:ffff88021e2c0000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00000000034b8cd8 CR3: 000000021073c000 CR4: 00000000001407e0
      Stack:
       ffffffff816d1181 ffff8800c7ec1e80 ffff8800c7f97da8 ffffffff814a58f8
       000000000000000a ffffffff816d1181 ffff8800c7f97dc8 ffffffffa047002c
       ffff88021e2dff00 ffff8802116ac1c0 ffff8800c7f97df8 ffffffff814a65fe
      Call Trace:
       [<ffffffff816d1181>] ? __schedule+0x361/0x940
       [<ffffffff814a58f8>] release_firmware+0x58/0x80
       [<ffffffff816d1181>] ? __schedule+0x361/0x940
       [<ffffffffa047002c>] test_mod_cb+0x2c/0x43 [test]
       [<ffffffff814a65fe>] request_firmware_work_func+0x5e/0x80
       [<ffffffff816d1181>] ? __schedule+0x361/0x940
       [<ffffffff8108d23a>] process_one_work+0x14a/0x3f0
       [<ffffffff8108d911>] worker_thread+0x121/0x460
       [<ffffffff8108d7f0>] ? rescuer_thread+0x310/0x310
       [<ffffffff810928f9>] kthread+0xc9/0xe0
       [<ffffffff81092830>] ? kthread_create_on_node+0x180/0x180
       [<ffffffff816d52d8>] ret_from_fork+0x58/0x90
       [<ffffffff81092830>] ? kthread_create_on_node+0x180/0x180
      Code: c7 c6 dd ad a3 81 48 c7 c7 20 97 ce 81 31 c0 e8 0b b2 ed ff e9 78 ff ff ff 66 0f 1f 44 00 00 0f 1f 44 00 00 55 48 89 e5 41 54 53 <4c> 8b 67 38 48 89 fb 4c 89 e7 e8 85 f7 22 00 f0 83 2b 01 74 0f
      RIP  [<ffffffff814a586c>] fw_free_buf+0xc/0x40
       RSP <ffff8800c7f97d78>
      ---[ end trace 4e62c56a58d0eac1 ]---
      BUG: unable to handle kernel paging request at ffffffffffffffd8
      IP: [<ffffffff81093ee0>] kthread_data+0x10/0x20
      PGD 1c13067 PUD 1c15067 PMD 0
      Oops: 0000 [#2] SMP
      Modules linked in: test(O) <...etc-it-does-not-matter>
       drm sr_mod cdrom xhci_pci xhci_hcd rtsx_pci mfd_core video button sg
      CPU: 3 PID: 87 Comm: kworker/3:2 Tainted: G      D    O    4.0.0-00010-g22b5bb0-dirty #176
      Hardware name: LENOVO 20AW000LUS/20AW000LUS, BIOS GLET43WW (1.18 ) 12/04/2013
      task: ffff8800c7f8e290 ti: ffff8800c7f94000 task.ti: ffff8800c7f94000
      RIP: 0010:[<ffffffff81092ee0>]  [<ffffffff81092ee0>] kthread_data+0x10/0x20
      RSP: 0018:ffff8800c7f97b18  EFLAGS: 00010096
      RAX: 0000000000000000 RBX: 0000000000000003 RCX: 000000000000000d
      RDX: 0000000000000003 RSI: 0000000000000003 RDI: ffff8800c7f8e290
      RBP: ffff8800c7f97b18 R08: 000000000000bc00 R09: 0000000000007e76
      R10: 0000000000000001 R11: 000000000000002f R12: ffff8800c7f8e290
      R13: 00000000000154c0 R14: 0000000000000003 R15: 0000000000000000
      FS:  0000000000000000(0000) GS:ffff88021e2c0000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 0000000000000028 CR3: 0000000210675000 CR4: 00000000001407e0
      Stack:
       ffff8800c7f97b38 ffffffff8108dcd5 ffff8800c7f97b38 ffff88021e2d54c0
       ffff8800c7f97b88 ffffffff816d1500 ffff880213d42368 ffff8800c7f8e290
       ffff8800c7f97b88 ffff8800c7f97fd8 ffff8800c7f8e710 0000000000000246
      Call Trace:
       [<ffffffff8108dcd5>] wq_worker_sleeping+0x15/0xa0
       [<ffffffff816d1500>] __schedule+0x6e0/0x940
       [<ffffffff816d1797>] schedule+0x37/0x90
       [<ffffffff810779bc>] do_exit+0x6bc/0xb40
       [<ffffffff8101898f>] oops_end+0x9f/0xe0
       [<ffffffff81018efb>] die+0x4b/0x70
       [<ffffffff81015622>] do_general_protection+0xe2/0x170
       [<ffffffff816d74e8>] general_protection+0x28/0x30
       [<ffffffff816d1181>] ? __schedule+0x361/0x940
       [<ffffffff814a586c>] ? fw_free_buf+0xc/0x40
       [<ffffffff816d1181>] ? __schedule+0x361/0x940
       [<ffffffff814a58f8>] release_firmware+0x58/0x80
       [<ffffffff816d1181>] ? __schedule+0x361/0x940
       [<ffffffffa047002c>] test_mod_cb+0x2c/0x43 [test]
       [<ffffffff814a65fe>] request_firmware_work_func+0x5e/0x80
       [<ffffffff816d1181>] ? __schedule+0x361/0x940
       [<ffffffff8108d23a>] process_one_work+0x14a/0x3f0
       [<ffffffff8108d911>] worker_thread+0x121/0x460
       [<ffffffff8108d7f0>] ? rescuer_thread+0x310/0x310
       [<ffffffff810928f9>] kthread+0xc9/0xe0
       [<ffffffff81092830>] ? kthread_create_on_node+0x180/0x180
       [<ffffffff816d52d8>] ret_from_fork+0x58/0x90
       [<ffffffff81092830>] ? kthread_create_on_node+0x180/0x180
      Code: 00 48 89 e5 5d 48 8b 40 c8 48 c1 e8 02 83 e0 01 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 8b 87 30 05 00 00 55 48 89 e5 <48> 8b 40 d8 5d c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00
      RIP  [<ffffffff81092ee0>] kthread_data+0x10/0x20
       RSP <ffff8800c7f97b18>
      CR2: ffffffffffffffd8
      ---[ end trace 4e62c56a58d0eac2 ]---
      Fixing recursive fault but reboot is needed!
      
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Rusty Russell <rusty@rustcorp.com.au>
      Cc: David Howells <dhowells@redhat.com>
      Cc: Ming Lei <ming.lei@canonical.com>
      Cc: Seth Forshee <seth.forshee@canonical.com>
      Cc: Kyle McMartin <kyle@kernel.org>
      Generated-by: Coccinelle SmPL
      Signed-off-by: NLuis R. Rodriguez <mcgrof@suse.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f9692b26
    • L
      firmware: check for file truncation on direct firmware loading · 1ba4de17
      Luis R. Rodriguez 提交于
      When direct firmware loading is used we iterate over a list
      of possible firmware paths and concatenate the desired firmware
      name with each path and look for the file there. Should the
      passed firmware name be too long we end up truncating the
      file we want to look for, the search however is still done.
      Add a check for truncation instead of looking for a
      truncated firmware filename.
      
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Ming Lei <ming.lei@canonical.com>
      Cc: Rusty Russell <rusty@rustcorp.com.au>
      Cc: David Howells <dhowells@redhat.com>
      Cc: Kyle McMartin <kyle@kernel.org>
      Signed-off-by: NLuis R. Rodriguez <mcgrof@suse.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1ba4de17
    • L
      firmware: fix __getname() missing failure check · f5727b05
      Luis R. Rodriguez 提交于
      The request_firmware*() APIs uses __getname() to iterate
      over the list of paths possible for firmware to be found,
      the code however never checked for failure on __getname().
      Although *very unlikely*, this can still happen. Add the
      missing check.
      
      There is still no checks on the concatenation of the path
      and filename passed, that requires a bit more work and
      subsequent patches address this. The commit that introduced
      this is abb139e7 ("firmware: teach the kernel to load
      firmware files directly from the filesystem").
      
      mcgrof@ergon ~/linux (git::firmware-fixes) $ git describe --contains abb139e7
      v3.7-rc1~120
      
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Ming Lei <ming.lei@canonical.com>
      Cc: Rusty Russell <rusty@rustcorp.com.au>
      Cc: David Howells <dhowells@redhat.com>
      Cc: Kyle McMartin <kyle@kernel.org>
      Signed-off-by: NLuis R. Rodriguez <mcgrof@suse.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f5727b05
  16. 25 3月, 2015 3 次提交
  17. 12 2月, 2015 1 次提交
  18. 04 2月, 2015 3 次提交
  19. 27 11月, 2014 1 次提交