05 Oct, 2020

1 commit

  • Add additional hooks to test_firmware to pass in support
    for partial file read using request_firmware_into_buf():

    buf_size: size of buffer to request firmware into
    partial: indicates that a partial file request is being made
    file_offset: to indicate offset into file to request

    Also update firmware selftests to use the new partial read test API.

    Signed-off-by: Scott Branden
    Co-developed-by: Kees Cook
    Signed-off-by: Kees Cook
    Link: https://lore.kernel.org/r/20201002173828.2099543-17-keescook@chromium.org
    Signed-off-by: Greg Kroah-Hartman

    Scott Branden
     

11 Sep, 2020

1 commit

  • On non-EFI systems, it wasn't possible to test the platform firmware
    loader because it will have never set "checked_fw" during __init.
    Instead, allow the test code to override this check. Additionally split
    the declarations into a private symbol namespace so there is greater
    enforcement of the symbol visibility.

    Fixes: 548193cba2a7 ("test_firmware: add support for firmware_request_platform")
    Cc: stable@vger.kernel.org
    Signed-off-by: Kees Cook
    Acked-by: Ard Biesheuvel
    Link: https://lore.kernel.org/r/20200909225354.3118328-1-keescook@chromium.org
    Signed-off-by: Greg Kroah-Hartman

    Kees Cook
     

17 Apr, 2020

1 commit


20 Mar, 2020

1 commit


04 Sep, 2019

1 commit

  • Add test config into_buf to allow request_firmware_into_buf to be
    called instead of request_firmware/request_firmware_direct. The number
    of parameters differ calling request_firmware_into_buf and support
    has not been added to test such api in test_firmware until now.

    Signed-off-by: Scott Branden
    Acked-by: Luis Chamberlain
    Acked-by: Shuah Khan
    Link: https://lore.kernel.org/r/20190822184005.901-2-scott.branden@broadcom.com
    Signed-off-by: Greg Kroah-Hartman

    Scott Branden
     

25 Jul, 2019

1 commit

  • In test_firmware_init(), the buffer pointed to by the global pointer
    'test_fw_config' is allocated through kzalloc(). Then, the buffer is
    initialized in __test_firmware_config_init(). In the case that the
    initialization fails, the following execution in test_firmware_init() needs
    to be terminated with an error code returned to indicate this failure.
    However, the allocated buffer is not freed on this execution path, leading
    to a memory leak bug.

    To fix the above issue, free the allocated buffer before returning from
    test_firmware_init().

    Signed-off-by: Wenwen Wang
    Link: https://lore.kernel.org/r/1563084696-6865-1-git-send-email-wang6495@umn.edu
    Signed-off-by: Greg Kroah-Hartman

    Wenwen Wang
     

09 Jun, 2019

1 commit

  • Pull char/misc driver fixes from Greg KH:
    "Here are some small char and misc driver fixes for 5.2-rc4 to resolve
    a number of reported issues.

    The most "notable" one here is the kernel headers in proc^Wsysfs
    fixes. Those changes move the header file info into sysfs and fixes
    the build issues that you reported.

    Other than that, a bunch of small habanalabs driver fixes, some fpga
    driver fixes, and a few other tiny driver fixes.

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

    * tag 'char-misc-5.2-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc:
    habanalabs: Read upper bits of trace buffer from RWPHI
    habanalabs: Fix virtual address access via debugfs for 2MB pages
    fpga: zynqmp-fpga: Correctly handle error pointer
    habanalabs: fix bug in checking huge page optimization
    habanalabs: Avoid using a non-initialized MMU cache mutex
    habanalabs: fix debugfs code
    uapi/habanalabs: add opcode for enable/disable device debug mode
    habanalabs: halt debug engines on user process close
    test_firmware: Use correct snprintf() limit
    genwqe: Prevent an integer overflow in the ioctl
    parport: Fix mem leak in parport_register_dev_model
    fpga: dfl: expand minor range when registering chrdev region
    fpga: dfl: Add lockdep classes for pdata->lock
    fpga: dfl: afu: Pass the correct device to dma_mapping_error()
    fpga: stratix10-soc: fix use-after-free on s10_init()
    w1: ds2408: Fix typo after 49695ac46861 (reset on output_write retry with readback)
    kheaders: Do not regenerate archive if config is not changed
    kheaders: Move from proc to sysfs
    lkdtm/bugs: Adjust recursion test to avoid elision
    lkdtm/usercopy: Moves the KERNEL_DS test to non-canonical

    Linus Torvalds
     

25 May, 2019

1 commit

  • The limit here is supposed to be how much of the page is left, but it's
    just using PAGE_SIZE as the limit.

    The other thing to remember is that snprintf() returns the number of
    bytes which would have been copied if we had had enough room. So that
    means that if we run out of space then this code would end up passing a
    negative value as the limit and the kernel would print an error message.
    I have change the code to use scnprintf() which returns the number of
    bytes that were successfully printed (not counting the NUL terminator).

    Fixes: c92316bf8e94 ("test_firmware: add batched firmware tests")
    Signed-off-by: Dan Carpenter
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Dan Carpenter
     

21 May, 2019

1 commit

  • Add SPDX license identifiers to all files which:

    - Have no license information of any form

    - Have MODULE_LICENCE("GPL*") inside which was used in the initial
    scan/conversion to ignore the file

    These files fall under the project license, GPL v2 only. The resulting SPDX
    license identifier is:

    GPL-2.0-only

    Signed-off-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

08 Mar, 2019

1 commit

  • The test_fw_config->reqs allocation succeeded so these addresses can't
    be NULL.

    Also on the second error path, we forgot to set "rc = -ENOMEM;".

    Link: http://lkml.kernel.org/r/20190221183700.GA1737@kadam
    Signed-off-by: Dan Carpenter
    Reviewed-by: Andrew Morton
    Cc: "Luis R. Rodriguez"
    Cc: Randy Dunlap
    Cc: Greg Kroah-Hartman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dan Carpenter
     

12 Nov, 2018

1 commit

  • In the case where eq->fw->size > PAGE_SIZE the error return rc
    is being set to EINVAL however this is being overwritten to
    rc = req->fw->size because the error exit path via label 'out' is
    not being taken. Fix this by adding the jump to the error exit
    path 'out'.

    Detected by CoverityScan, CID#1453465 ("Unused value")

    Fixes: c92316bf8e94 ("test_firmware: add batched firmware tests")
    Signed-off-by: Colin Ian King
    Signed-off-by: Greg Kroah-Hartman

    Colin Ian King
     

13 Jun, 2018

1 commit

  • The vzalloc() function has no 2-factor argument form, so multiplication
    factors need to be wrapped in array_size(). This patch replaces cases of:

    vzalloc(a * b)

    with:
    vzalloc(array_size(a, b))

    as well as handling cases of:

    vzalloc(a * b * c)

    with:

    vzalloc(array3_size(a, b, c))

    This does, however, attempt to ignore constant size factors like:

    vzalloc(4 * 1024)

    though any constants defined via macros get caught up in the conversion.

    Any factors with a sizeof() of "unsigned char", "char", and "u8" were
    dropped, since they're redundant.

    The Coccinelle script used for this was:

    // Fix redundant parens around sizeof().
    @@
    type TYPE;
    expression THING, E;
    @@

    (
    vzalloc(
    - (sizeof(TYPE)) * E
    + sizeof(TYPE) * E
    , ...)
    |
    vzalloc(
    - (sizeof(THING)) * E
    + sizeof(THING) * E
    , ...)
    )

    // Drop single-byte sizes and redundant parens.
    @@
    expression COUNT;
    typedef u8;
    typedef __u8;
    @@

    (
    vzalloc(
    - sizeof(u8) * (COUNT)
    + COUNT
    , ...)
    |
    vzalloc(
    - sizeof(__u8) * (COUNT)
    + COUNT
    , ...)
    |
    vzalloc(
    - sizeof(char) * (COUNT)
    + COUNT
    , ...)
    |
    vzalloc(
    - sizeof(unsigned char) * (COUNT)
    + COUNT
    , ...)
    |
    vzalloc(
    - sizeof(u8) * COUNT
    + COUNT
    , ...)
    |
    vzalloc(
    - sizeof(__u8) * COUNT
    + COUNT
    , ...)
    |
    vzalloc(
    - sizeof(char) * COUNT
    + COUNT
    , ...)
    |
    vzalloc(
    - sizeof(unsigned char) * COUNT
    + COUNT
    , ...)
    )

    // 2-factor product with sizeof(type/expression) and identifier or constant.
    @@
    type TYPE;
    expression THING;
    identifier COUNT_ID;
    constant COUNT_CONST;
    @@

    (
    vzalloc(
    - sizeof(TYPE) * (COUNT_ID)
    + array_size(COUNT_ID, sizeof(TYPE))
    , ...)
    |
    vzalloc(
    - sizeof(TYPE) * COUNT_ID
    + array_size(COUNT_ID, sizeof(TYPE))
    , ...)
    |
    vzalloc(
    - sizeof(TYPE) * (COUNT_CONST)
    + array_size(COUNT_CONST, sizeof(TYPE))
    , ...)
    |
    vzalloc(
    - sizeof(TYPE) * COUNT_CONST
    + array_size(COUNT_CONST, sizeof(TYPE))
    , ...)
    |
    vzalloc(
    - sizeof(THING) * (COUNT_ID)
    + array_size(COUNT_ID, sizeof(THING))
    , ...)
    |
    vzalloc(
    - sizeof(THING) * COUNT_ID
    + array_size(COUNT_ID, sizeof(THING))
    , ...)
    |
    vzalloc(
    - sizeof(THING) * (COUNT_CONST)
    + array_size(COUNT_CONST, sizeof(THING))
    , ...)
    |
    vzalloc(
    - sizeof(THING) * COUNT_CONST
    + array_size(COUNT_CONST, sizeof(THING))
    , ...)
    )

    // 2-factor product, only identifiers.
    @@
    identifier SIZE, COUNT;
    @@

    vzalloc(
    - SIZE * COUNT
    + array_size(COUNT, SIZE)
    , ...)

    // 3-factor product with 1 sizeof(type) or sizeof(expression), with
    // redundant parens removed.
    @@
    expression THING;
    identifier STRIDE, COUNT;
    type TYPE;
    @@

    (
    vzalloc(
    - sizeof(TYPE) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    vzalloc(
    - sizeof(TYPE) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    vzalloc(
    - sizeof(TYPE) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    vzalloc(
    - sizeof(TYPE) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    vzalloc(
    - sizeof(THING) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    vzalloc(
    - sizeof(THING) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    vzalloc(
    - sizeof(THING) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    vzalloc(
    - sizeof(THING) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    )

    // 3-factor product with 2 sizeof(variable), with redundant parens removed.
    @@
    expression THING1, THING2;
    identifier COUNT;
    type TYPE1, TYPE2;
    @@

    (
    vzalloc(
    - sizeof(TYPE1) * sizeof(TYPE2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    vzalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    vzalloc(
    - sizeof(THING1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    vzalloc(
    - sizeof(THING1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    vzalloc(
    - sizeof(TYPE1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    |
    vzalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    )

    // 3-factor product, only identifiers, with redundant parens removed.
    @@
    identifier STRIDE, SIZE, COUNT;
    @@

    (
    vzalloc(
    - (COUNT) * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    vzalloc(
    - COUNT * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    vzalloc(
    - COUNT * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    vzalloc(
    - (COUNT) * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    vzalloc(
    - COUNT * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    vzalloc(
    - (COUNT) * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    vzalloc(
    - (COUNT) * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    vzalloc(
    - COUNT * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    )

    // Any remaining multi-factor products, first at least 3-factor products
    // when they're not all constants...
    @@
    expression E1, E2, E3;
    constant C1, C2, C3;
    @@

    (
    vzalloc(C1 * C2 * C3, ...)
    |
    vzalloc(
    - E1 * E2 * E3
    + array3_size(E1, E2, E3)
    , ...)
    )

    // And then all remaining 2 factors products when they're not all constants.
    @@
    expression E1, E2;
    constant C1, C2;
    @@

    (
    vzalloc(C1 * C2, ...)
    |
    vzalloc(
    - E1 * E2
    + array_size(E1, E2)
    , ...)
    )

    Signed-off-by: Kees Cook

    Kees Cook
     

06 Apr, 2018

1 commit

  • Currently #includes for no obvious
    reason. It looks like it's only a convenience, so remove kmemleak.h
    from slab.h and add to any users of kmemleak_* that
    don't already #include it. Also remove from source
    files that do not use it.

    This is tested on i386 allmodconfig and x86_64 allmodconfig. It would
    be good to run it through the 0day bot for other $ARCHes. I have
    neither the horsepower nor the storage space for the other $ARCHes.

    Update: This patch has been extensively build-tested by both the 0day
    bot & kisskb/ozlabs build farms. Both of them reported 2 build failures
    for which patches are included here (in v2).

    [ slab.h is the second most used header file after module.h; kernel.h is
    right there with slab.h. There could be some minor error in the
    counting due to some #includes having comments after them and I didn't
    combine all of those. ]

    [akpm@linux-foundation.org: security/keys/big_key.c needs vmalloc.h, per sfr]
    Link: http://lkml.kernel.org/r/e4309f98-3749-93e1-4bb7-d9501a39d015@infradead.org
    Link: http://kisskb.ellerman.id.au/kisskb/head/13396/
    Signed-off-by: Randy Dunlap
    Reviewed-by: Ingo Molnar
    Reported-by: Michael Ellerman [2 build failures]
    Reported-by: Fengguang Wu [2 build failures]
    Reviewed-by: Andrew Morton
    Cc: Wei Yongjun
    Cc: Luis R. Rodriguez
    Cc: Greg Kroah-Hartman
    Cc: Mimi Zohar
    Cc: John Johansen
    Cc: Stephen Rothwell
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Randy Dunlap
     

22 Jan, 2018

2 commits


09 Jan, 2018

1 commit

  • Convert DEVICE_ATTR uses to DEVICE_ATTR_RW where possible.

    Done with perl script:

    $ git grep -w --name-only DEVICE_ATTR | \
    xargs perl -i -e 'local $/; while (<>) { s/\bDEVICE_ATTR\s*\(\s*(\w+)\s*,\s*\(?(\s*S_IRUGO\s*\|\s*S_IWUSR|\s*S_IWUSR\s*\|\s*S_IRUGO\s*|\s*0644\s*)\)?\s*,\s*\1_show\s*,\s*\1_store\s*\)/DEVICE_ATTR_RW(\1)/g; print;}'

    Signed-off-by: Joe Perches
    Acked-by: Felipe Balbi
    Acked-by: Andy Shevchenko
    Acked-by: Bartlomiej Zolnierkiewicz
    Acked-by: Zhang Rui
    Acked-by: Jarkko Nikula
    Acked-by: Jani Nikula
    Signed-off-by: Greg Kroah-Hartman

    Joe Perches
     

11 Aug, 2017

1 commit

  • The firmware API has a feature to enable batching requests for the same fil
    e under one worker, so only one lookup is done. This only triggers if we so
    happen to schedule two lookups for same file around the same time, or if
    release_firmware() has not been called for a successful firmware call. This
    can happen for instance if you happen to have multiple devices and one
    device driver for certain drivers where the stars line up scheduling
    wise.

    This adds a new sync and async test trigger. Instead of adding a new
    trigger for each new test type we make the tests a bit configurable so that
    we could configure the tests in userspace and just kick a test through a
    few basic triggers. With this, for instance the two types of sync requests:

    o request_firmware() and
    o request_firmware_direct()

    can be modified with a knob. Likewise the two type of async requests:

    o request_firmware_nowait(uevent=true) and
    o request_firmware_nowait(uevent=false)

    can be configured with another knob. The call request_firmware_into_buf()
    has no users... yet.

    The old tests are left in place as-is given they serve a few other purposes
    which we are currently not interested in also testing yet. This will change
    later as we will be able to just consolidate all tests under a few basic
    triggers with just one general configuration setup.

    We perform two types of tests, one for where the file is present and one
    for where the file is not present. All test tests go tested and they now
    pass for the following 3 kernel builds possible for the firmware API:

    0. Most distro setup:
    CONFIG_FW_LOADER_USER_HELPER_FALLBACK=n
    CONFIG_FW_LOADER_USER_HELPER=y
    1. Android:
    CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
    CONFIG_FW_LOADER_USER_HELPER=y
    2. Rare build:
    CONFIG_FW_LOADER_USER_HELPER_FALLBACK=n
    CONFIG_FW_LOADER_USER_HELPER=n

    Signed-off-by: Luis R. Rodriguez
    Signed-off-by: Greg Kroah-Hartman

    Luis R. Rodriguez
     

25 Jan, 2017

3 commits


08 Jan, 2016

3 commits

  • We might want to test for bugs like that found in commit f9692b2699bd
    ("firmware: fix possible use after free on name on asynchronous
    request"), where the asynchronous request API had race conditions.

    Let's add a simple file that will launch the async request, then wait
    until it's complete and report the status. It's not a true async test
    (we're using a mutex + wait_for_completion(), so we can't get more than
    one going at the same time), but it does help make sure the basic API is
    sane, and it can catch some class of bugs.

    Signed-off-by: Brian Norris
    Cc: Luis R. Rodriguez
    Acked-by: Kees Cook
    Signed-off-by: Shuah Khan

    Brian Norris
     
  • We're essentially just doing an open-coded kstrndup(). The only
    differences are with what happens after the first '\0' character, but
    request_firmware() doesn't care about that.

    Suggested-by: Kees Cook
    Signed-off-by: Brian Norris
    Signed-off-by: Shuah Khan

    Brian Norris
     
  • request_firmware() failures currently won't get reported at all (the
    error code is discarded). What's more, we get confusing messages, like:

    # echo -n notafile > /sys/devices/virtual/misc/test_firmware/trigger_request
    [ 8280.311856] test_firmware: loading 'notafile'
    [ 8280.317042] test_firmware: load of 'notafile' failed: -2
    [ 8280.322445] test_firmware: loaded: 0
    # echo $?
    0

    Report the failures via write() errors, and don't say we "loaded"
    anything.

    Signed-off-by: Brian Norris
    Acked-by: Kees Cook
    Signed-off-by: Shuah Khan

    Brian Norris
     

18 Jul, 2014

1 commit

  • This provides a simple interface to trigger the firmware_class loader
    to test built-in, filesystem, and user helper modes. Additionally adds
    tests via the new interface to the selftests tree.

    Signed-off-by: Kees Cook
    Signed-off-by: Greg Kroah-Hartman

    Kees Cook