09 Jan, 2017

1 commit

  • commit 2e700f8d85975f516ccaad821278c1fe66b2cc98 upstream.

    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 68ff2a00dbf5 ("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 68ff2a00dbf5 ("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: Yves-Alexis Perez
    Fixes: 68ff2a00dbf5 "firmware_loader: handle timeout via wait_for_completion_interruptible_timeout()"
    Cc: Luis R. Rodriguez
    Cc: Ming Lei
    Cc: Bjorn Andersson
    Cc: Greg Kroah-Hartman
    Acked-by: Luis R. Rodriguez
    Reviewed-by: Bjorn Andersson
    [mcgrof@kernel.org: gave commit log a whole lot of love]
    Signed-off-by: Luis R. Rodriguez
    Signed-off-by: Greg Kroah-Hartman
    Signed-off-by: Greg Kroah-Hartman

    Yves-Alexis Perez
     

03 Aug, 2016

3 commits

  • 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.org
    Signed-off-by: Stephen Boyd
    Cc: Mimi Zohar
    Cc: Vikram Mulukutla
    Cc: Mark Brown
    Cc: Ming Lei
    Cc: Greg Kroah-Hartman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Stephen Boyd
     
  • 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: Vikram Mulukutla
    Signed-off-by: Stephen Boyd
    Cc: Mimi Zohar
    Cc: Mark Brown
    Cc: Ming Lei
    Cc: Greg Kroah-Hartman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Vikram Mulukutla
     
  • 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.org
    Signed-off-by: Stephen Boyd
    Cc: Vikram Mulukutla
    Cc: Mimi Zohar
    Cc: Mark Brown
    Cc: Ming Lei
    Cc: Greg Kroah-Hartman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Stephen Boyd
     

18 Mar, 2016

1 commit

  • Pull char/misc updates from Greg KH:
    "Here is the big char/misc driver update for 4.6-rc1.

    The majority of the patches here is hwtracing and some new mic
    drivers, but there's a lot of other driver updates as well. Full
    details in the shortlog.

    All have been in linux-next for a while with no reported issues"

    * tag 'char-misc-4.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (238 commits)
    goldfish: Fix build error of missing ioremap on UM
    nvmem: mediatek: Fix later provider initialization
    nvmem: imx-ocotp: Fix return value of imx_ocotp_read
    nvmem: Fix dependencies for !HAS_IOMEM archs
    char: genrtc: replace blacklist with whitelist
    drivers/hwtracing: make coresight-etm-perf.c explicitly non-modular
    drivers: char: mem: fix IS_ERROR_VALUE usage
    char: xillybus: Fix internal data structure initialization
    pch_phub: return -ENODATA if ROM can't be mapped
    Drivers: hv: vmbus: Support kexec on ws2012 r2 and above
    Drivers: hv: vmbus: Support handling messages on multiple CPUs
    Drivers: hv: utils: Remove util transport handler from list if registration fails
    Drivers: hv: util: Pass the channel information during the init call
    Drivers: hv: vmbus: avoid unneeded compiler optimizations in vmbus_wait_for_unload()
    Drivers: hv: vmbus: remove code duplication in message handling
    Drivers: hv: vmbus: avoid wait_for_completion() on crash
    Drivers: hv: vmbus: don't loose HVMSG_TIMER_EXPIRED messages
    misc: at24: replace memory_accessor with nvmem_device_read
    eeprom: 93xx46: extend driver to plug into the NVMEM framework
    eeprom: at25: extend driver to plug into the NVMEM framework
    ...

    Linus Torvalds
     

29 Feb, 2016

1 commit

  • 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: Heiner Kallweit
    Cc: Neil Horman
    Cc: Heiner Kallweit
    Cc: Mimi Zohar
    Cc: Kees Cook
    Signed-off-by: Luis R. Rodriguez
    Acked-by: Kees Cook
    Acked-by: Ming Lei
    Signed-off-by: James Morris

    Luis R. Rodriguez
     

21 Feb, 2016

1 commit

  • 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: Mimi Zohar
    Acked-by: Kees Cook
    Acked-by: Luis R. Rodriguez

    Mimi Zohar
     

19 Feb, 2016

3 commits

  • This makes the error and success paths more readable while trying to
    load firmware from the filesystem.

    Signed-off-by: Kees Cook
    Cc: Josh Boyer
    Cc: David Howells
    Acked-by: Luis R. Rodriguez
    Signed-off-by: Mimi Zohar

    Kees Cook
     
  • This will be re-used later through a new extensible interface.

    Reviewed-by: Josh Boyer
    Signed-off-by: Luis R. Rodriguez
    Signed-off-by: Mimi Zohar
    Acked-by: Kees Cook

    Luis R. Rodriguez
     
  • Simplify a few of the *generic* shared dev_warn() and dev_dbg()
    print messages for three reasons:

    0) Historically firmware_class code was added to help
    get device driver firmware binaries but these days
    request_firmware*() helpers are being repurposed for
    general *system data* needed by the kernel.

    1) This will also help generalize shared code as much as possible
    later in the future in consideration for a new extensible firmware
    API which will enable to separate usermode helper code out as much
    as possible.

    2) Kees Cook pointed out the the prints already have the device
    associated as dev_*() helpers are used, that should help identify
    the user and case in which the helpers are used. That should provide
    enough context and simplifies the messages further.

    v4: generalize debug/warn messages even further as suggested by
    Kees Cook.

    Cc: Rusty Russell
    Cc: Andrew Morton
    Cc: Greg Kroah-Hartman
    Cc: David Howells
    Cc: Kees Cook
    Cc: Casey Schaufler
    Cc: Ming Lei
    Cc: Takashi Iwai
    Cc: Vojtěch Pavlík
    Cc: Kyle McMartin
    Cc: Matthew Garrett
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Luis R. Rodriguez
    Signed-off-by: Mimi Zohar
    Acked-by: Kees Cook
    Signed-off-by: Greg Kroah-Hartman

    Luis R. Rodriguez
     

09 Feb, 2016

2 commits

  • No need to use use continuous memory, it may be fail
    when memory deeply fragmented.

    Signed-off-by: Chen Feng
    Signed-off-by: Xia Qing
    Signed-off-by: Greg Kroah-Hartman

    Chen Feng
     
  • Simplify a few of the *generic* shared dev_warn() and dev_dbg()
    print messages for three reasons:

    0) Historically firmware_class code was added to help
    get device driver firmware binaries but these days
    request_firmware*() helpers are being repurposed for
    general *system data* needed by the kernel.

    1) This will also help generalize shared code as much as possible
    later in the future in consideration for a new extensible firmware
    API which will enable to separate usermode helper code out as much
    as possible.

    2) Kees Cook pointed out the the prints already have the device
    associated as dev_*() helpers are used, that should help identify
    the user and case in which the helpers are used. That should provide
    enough context and simplifies the messages further.

    v4: generalize debug/warn messages even further as suggested by
    Kees Cook.

    Cc: Rusty Russell
    Cc: Andrew Morton
    Cc: David Howells
    Cc: Casey Schaufler
    Cc: Ming Lei
    Cc: Takashi Iwai
    Cc: Vojtěch Pavlík
    Cc: Kyle McMartin
    Cc: Matthew Garrett
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Luis R. Rodriguez
    Signed-off-by: Mimi Zohar
    Acked-by: Kees Cook
    Signed-off-by: Greg Kroah-Hartman

    Luis R. Rodriguez
     

08 Jan, 2016

1 commit

  • 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 471b095dfe0d ("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 : [] lr : [] 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] [] (do_raw_spin_lock) from [] (_raw_spin_lock+0x18/0x1c)
    [10733.951743] [] (_raw_spin_lock) from [] (fw_free_buf+0x24/0x64)
    [10733.959388] [] (fw_free_buf) from [] (release_firmware+0x68/0x74)
    [10733.967207] [] (release_firmware) from [] (trigger_async_request_store+0x60/0x124)
    [10733.976501] [] (trigger_async_request_store) from [] (dev_attr_store+0x28/0x34)
    [10733.985533] [] (dev_attr_store) from [] (sysfs_kf_write+0x4c/0x58)
    [10733.993437] [] (sysfs_kf_write) from [] (kernfs_fop_write+0x144/0x1a8)
    [10734.001689] [] (kernfs_fop_write) from [] (__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: 471b095dfe0d ("firmware_class: make sure fw requests contain a name")
    Signed-off-by: Brian Norris
    Acked-by: Ming Lei
    Acked-by: Kees Cook
    Signed-off-by: Shuah Khan

    Brian Norris
     

06 Aug, 2015

1 commit


10 Jul, 2015

1 commit

  • The firmware class uevent function accessed the "fw_priv->buf" buffer
    without the proper locking and testing for NULL. This is an old bug
    (looks like it goes back to 2012 and commit 1244691c73b2: "firmware
    loader: introduce firmware_buf"), but for some reason it's triggering
    only now in 4.2-rc1.

    Shuah Khan is trying to bisect what it is that causes this to trigger
    more easily, but in the meantime let's just fix the bug since others are
    hitting it too (at least Ingo reports having seen it as well).

    Reported-and-tested-by: Shuah Khan
    Acked-by: Ming Lei
    Cc: Greg Kroah-Hartman
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

01 Jun, 2015

1 commit


25 May, 2015

4 commits

  • 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
    Cc: Rusty Russell
    Cc: David Howells
    Cc: Ming Lei
    Cc: Seth Forshee
    Cc: Kyle McMartin
    Signed-off-by: Luis R. Rodriguez
    Signed-off-by: Greg Kroah-Hartman

    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)
    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:[] [] 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:
    [] ? __schedule+0x361/0x940
    [] release_firmware+0x58/0x80
    [] ? __schedule+0x361/0x940
    [] test_mod_cb+0x2c/0x43 [test]
    [] request_firmware_work_func+0x5e/0x80
    [] ? __schedule+0x361/0x940
    [] process_one_work+0x14a/0x3f0
    [] worker_thread+0x121/0x460
    [] ? rescuer_thread+0x310/0x310
    [] kthread+0xc9/0xe0
    [] ? kthread_create_on_node+0x180/0x180
    [] ret_from_fork+0x58/0x90
    [] ? 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 8b 67 38 48 89 fb 4c 89 e7 e8 85 f7 22 00 f0 83 2b 01 74 0f
    RIP [] fw_free_buf+0xc/0x40
    RSP
    ---[ end trace 4e62c56a58d0eac1 ]---
    BUG: unable to handle kernel paging request at ffffffffffffffd8
    IP: [] kthread_data+0x10/0x20
    PGD 1c13067 PUD 1c15067 PMD 0
    Oops: 0000 [#2] SMP
    Modules linked in: test(O)
    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:[] [] 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:
    [] wq_worker_sleeping+0x15/0xa0
    [] __schedule+0x6e0/0x940
    [] schedule+0x37/0x90
    [] do_exit+0x6bc/0xb40
    [] oops_end+0x9f/0xe0
    [] die+0x4b/0x70
    [] do_general_protection+0xe2/0x170
    [] general_protection+0x28/0x30
    [] ? __schedule+0x361/0x940
    [] ? fw_free_buf+0xc/0x40
    [] ? __schedule+0x361/0x940
    [] release_firmware+0x58/0x80
    [] ? __schedule+0x361/0x940
    [] test_mod_cb+0x2c/0x43 [test]
    [] request_firmware_work_func+0x5e/0x80
    [] ? __schedule+0x361/0x940
    [] process_one_work+0x14a/0x3f0
    [] worker_thread+0x121/0x460
    [] ? rescuer_thread+0x310/0x310
    [] kthread+0xc9/0xe0
    [] ? kthread_create_on_node+0x180/0x180
    [] ret_from_fork+0x58/0x90
    [] ? 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 8b 40 d8 5d c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00
    RIP [] kthread_data+0x10/0x20
    RSP
    CR2: ffffffffffffffd8
    ---[ end trace 4e62c56a58d0eac2 ]---
    Fixing recursive fault but reboot is needed!

    Cc: Linus Torvalds
    Cc: Rusty Russell
    Cc: David Howells
    Cc: Ming Lei
    Cc: Seth Forshee
    Cc: Kyle McMartin
    Generated-by: Coccinelle SmPL
    Signed-off-by: Luis R. Rodriguez
    Signed-off-by: Greg Kroah-Hartman

    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
    Cc: Ming Lei
    Cc: Rusty Russell
    Cc: David Howells
    Cc: Kyle McMartin
    Signed-off-by: Luis R. Rodriguez
    Signed-off-by: Greg Kroah-Hartman

    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
    Cc: Ming Lei
    Cc: Rusty Russell
    Cc: David Howells
    Cc: Kyle McMartin
    Signed-off-by: Luis R. Rodriguez
    Signed-off-by: Greg Kroah-Hartman

    Luis R. Rodriguez
     

25 Mar, 2015

3 commits


16 Feb, 2015

1 commit

  • Pull driver core patches from Greg KH:
    "Really tiny set of patches for this kernel. Nothing major, all
    described in the shortlog and have been in linux-next for a while"

    * tag 'driver-core-3.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core:
    sysfs: fix warning when creating a sysfs group without attributes
    firmware_loader: handle timeout via wait_for_completion_interruptible_timeout()
    firmware_loader: abort request if wait_for_completion is interrupted
    firmware: Correct function name in comment
    device: Change dev_ logging functions to return void
    device: Fix dev_dbg_once macro

    Linus Torvalds
     

12 Feb, 2015

1 commit

  • This patch reduces the kernel size by removing error messages that duplicate
    the normal OOM message.

    A simplified version of the semantic patch that finds this problem is as
    follows: (http://coccinelle.lip6.fr)

    @@
    identifier f,print,l;
    expression e;
    constant char[] c;
    @@

    e = \(kzalloc\|kmalloc\|devm_kzalloc\|devm_kmalloc\)(...);
    if (e == NULL) {
    }

    Signed-off-by: Quentin Lambert
    Acked-by: Nishanth Menon
    Signed-off-by: Rafael J. Wysocki

    Quentin Lambert
     

04 Feb, 2015

3 commits


27 Nov, 2014

2 commits

  • The vunmap() function performes also input parameter validation. Thus the test
    around the call is not needed.

    This issue was detected by using the Coccinelle software.

    Signed-off-by: Markus Elfring
    Signed-off-by: Greg Kroah-Hartman

    Markus Elfring
     
  • When using request_firmware_nowait() with FW_ACTION_NOHOTPLUG param to
    expose user helper interface, if the user do not react immediately, after
    120 seconds there will be a hung task warning message dumped as below:

    [ 3000.784235] INFO: task kworker/0:0:8259 blocked for more than 120 seconds.
    [ 3000.791281] Tainted: G E 3.16.0-rc1-yocto-standard #41
    [ 3000.798082] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
    [ 3000.806072] kworker/0:0 D cd0075c8 0 8259 2 0x00000000
    [ 3000.812765] Workqueue: events request_firmware_work_func
    [ 3000.818253] cd375e18 00000046 0000000e cd0075c8 000000f0 cd40ea00 cd375fec 1b883e89
    [ 3000.826374] 0000026b cd40ea00 80000000 00000001 cd0075c8 00000000 cd375de4 c119917f
    [ 3000.834492] cd563360 cd375df4 c119a0ab cd563360 00000000 cd375e24 c119a1d6 00000000
    [ 3000.842616] Call Trace:
    [ 3000.845252] [] ? kernfs_next_descendant_post+0x3f/0x50
    [ 3000.851543] [] ? kernfs_activate+0x6b/0xc0
    [ 3000.856790] [] ? kernfs_add_one+0xd6/0x130
    [ 3000.862047] [] schedule+0x22/0x60
    [ 3000.866548] [] schedule_timeout+0x175/0x1d0
    [ 3000.871887] [] ? __kernfs_create_file+0x71/0xa0
    [ 3000.877574] [] ? sysfs_add_file_mode_ns+0xaa/0x180
    [ 3000.883533] [] wait_for_completion+0x6f/0xb0
    [ 3000.888961] [] ? wake_up_process+0x40/0x40
    [ 3000.894219] [] _request_firmware+0x750/0x9f0
    [ 3000.899666] [] ? n_tty_receive_buf2+0x1f/0x30
    [ 3000.905200] [] request_firmware_work_func+0x22/0x50
    [ 3000.911235] [] process_one_work+0x122/0x380
    [ 3000.916571] [] worker_thread+0xf9/0x470
    [ 3000.921555] [] ? create_and_start_worker+0x50/0x50
    [ 3000.927497] [] ? create_and_start_worker+0x50/0x50
    [ 3000.933448] [] kthread+0x9f/0xc0
    [ 3000.937850] [] ret_from_kernel_thread+0x20/0x30
    [ 3000.943548] [] ? kthread_worker_fn+0x100/0x100

    This patch change the wait_for_completion() function call to
    wait_for_completion_interruptible() function call for solving the issue.

    Cc: Matt Fleming
    Signed-off-by: Kweh, Hock Leong
    Acked-by: Ming Lei
    Acked-by: Greg Kroah-Hartman
    Signed-off-by: Greg Kroah-Hartman

    Kweh, Hock Leong
     

24 Sep, 2014

1 commit

  • An empty firmware request name will trigger warnings when building
    device names. Make sure this is caught earlier and rejected.

    The warning was visible via the test_firmware.ko module interface:

    echo -ne "\x00" > /sys/devices/virtual/misc/test_firmware/trigger_request

    Reported-by: Sasha Levin
    Signed-off-by: Kees Cook
    Cc: stable@vger.kernel.org
    Tested-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Kees Cook
     

06 Aug, 2014

1 commit

  • Pull security subsystem updates from James Morris:
    "In this release:

    - PKCS#7 parser for the key management subsystem from David Howells
    - appoint Kees Cook as seccomp maintainer
    - bugfixes and general maintenance across the subsystem"

    * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (94 commits)
    X.509: Need to export x509_request_asymmetric_key()
    netlabel: shorter names for the NetLabel catmap funcs/structs
    netlabel: fix the catmap walking functions
    netlabel: fix the horribly broken catmap functions
    netlabel: fix a problem when setting bits below the previously lowest bit
    PKCS#7: X.509 certificate issuer and subject are mandatory fields in the ASN.1
    tpm: simplify code by using %*phN specifier
    tpm: Provide a generic means to override the chip returned timeouts
    tpm: missing tpm_chip_put in tpm_get_random()
    tpm: Properly clean sysfs entries in error path
    tpm: Add missing tpm_do_selftest to ST33 I2C driver
    PKCS#7: Use x509_request_asymmetric_key()
    Revert "selinux: fix the default socket labeling in sock_graft()"
    X.509: x509_request_asymmetric_keys() doesn't need string length arguments
    PKCS#7: fix sparse non static symbol warning
    KEYS: revert encrypted key change
    ima: add support for measuring and appraising firmware
    firmware_class: perform new LSM checks
    security: introduce kernel_fw_from_file hook
    PKCS#7: Missing inclusion of linux/err.h
    ...

    Linus Torvalds
     

26 Jul, 2014

1 commit

  • This attaches LSM hooks to the existing firmware loading interfaces:
    filesystem-found firmware and demand-loaded blobs. On errors, loads
    are aborted and the failure code is returned to userspace.

    Signed-off-by: Kees Cook
    Reviewed-by: Takashi Iwai
    Acked-by: Greg Kroah-Hartman

    Kees Cook
     

24 Jul, 2014

1 commit


09 Jul, 2014

4 commits

  • Now that the udev firmware loader is optional request_firmware()
    will not provide any information on the kernel ring buffer if
    direct firmware loading failed and udev firmware loading is disabled.
    If no information is needed request_firmware_direct() should be used
    for optional firmware, at which point drivers can take on the onus
    over informing of any failures, if udev firmware loading is disabled
    though we should at the very least provide some sort of information
    as when the udev loader was enabled by default back in the days.

    With this change with a simple firmware load test module [0]:

    Example output without FW_LOADER_USER_HELPER_FALLBACK

    platform fake-dev.0: Direct firmware load for fake.bin failed
    with error -2

    Example with FW_LOADER_USER_HELPER_FALLBACK

    platform fake-dev.0: Direct firmware load for fake.bin failed with error -2
    platform fake-dev.0: Falling back to user helper

    Without this change without FW_LOADER_USER_HELPER_FALLBACK we
    get no output logged upon failure.

    Cc: Tom Gundersen
    Cc: Ming Lei
    Cc: Abhay Salunke
    Cc: Stefan Roese
    Cc: Arnd Bergmann
    Cc: Kay Sievers
    Signed-off-by: Luis R. Rodriguez
    Reviewed-by: Takashi Iwai
    Signed-off-by: Greg Kroah-Hartman

    Luis R. Rodriguez
     
  • use mm.h definition

    Cc: Ming Lei
    Signed-off-by: Fabian Frederick
    Signed-off-by: Greg Kroah-Hartman

    Fabian Frederick
     
  • There is no need to read attr because inode structure contains size
    of the file. Use i_size_read() instead.

    Signed-off-by: Dmitry Kasatkin
    Acked-by: Ming Lei
    Signed-off-by: Greg Kroah-Hartman

    Dmitry Kasatkin
     
  • [The patch was originally proposed by Tom Gundersen, and rewritten
    afterwards by me; most of changelogs below borrowed from Tom's
    original patch -- tiwai]

    Currently (at least) the dell-rbu driver selects FW_LOADER_USER_HELPER,
    which means that distros can't really stop loading firmware through
    udev without breaking other users (though some have).

    Ideally we would remove/disable the udev firmware helper in both the
    kernel and in udev, but if we were to disable it in udev and not the
    kernel, the result would be (seemingly) hung kernels as no one would
    be around to cancel firmware requests.

    This patch allows udev firmware loading to be disabled while still
    allowing non-udev firmware loading, as done by the dell-rbu driver, to
    continue working. This is achieved by only using the fallback
    mechanism when the uevent is suppressed.

    The patch renames the user-selectable Kconfig from FW_LOADER_USER_HELPER
    to FW_LOADER_USER_HELPER_FALLBACK, and the former is reverse-selected
    by the latter or the drivers that need userhelper like dell-rbu.

    Also, the "default y" is removed together with this change, since it's
    been deprecated in udev upstream, thus rather better to disable it
    nowadays.

    Tested with
    FW_LOADER_USER_HELPER=n
    LATTICE_ECP3_CONFIG=y
    DELL_RBU=y
    and udev without the firmware loading support, but I don't have the
    hardware to test the lattice/dell drivers, so additional testing would
    be appreciated.

    Reviewed-by: Tom Gundersen
    Cc: Ming Lei
    Cc: Abhay Salunke
    Cc: Stefan Roese
    Cc: Arnd Bergmann
    Cc: Kay Sievers
    Tested-by: Balaji Singh
    Signed-off-by: Takashi Iwai
    Signed-off-by: Greg Kroah-Hartman

    Takashi Iwai
     

03 Mar, 2014

1 commit


26 Feb, 2014

1 commit

  • During restore, pm_notifier chain are called with
    PM_RESTORE_PREPARE. The firmware_class driver handler
    fw_pm_notify does not have a handler for this. As a result,
    it keeps a reader on the kmod.c umhelper_sem. During
    freeze_processes, the call to __usermodehelper_disable tries to
    take a write lock on this semaphore and hangs waiting.

    Signed-off-by: Sebastian Capella
    Acked-by: Ming Lei
    Cc: All applicable
    Signed-off-by: Rafael J. Wysocki

    Sebastian Capella