05 Jun, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation version 2 this program is distributed
    in the hope that it will be useful but without any warranty without
    even the implied warranty of merchantability or fitness for a
    particular purpose see the gnu general public license for more
    details

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 97 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Alexios Zavras
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190529141901.025053186@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

31 May, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version this program is distributed in the
    hope that it will be useful but without any warranty without even
    the implied warranty of merchantability or fitness for a particular
    purpose see the gnu general public license for more details you
    should have received a copy of the gnu general public license along
    with this program if not write to the free software foundation inc
    59 temple place suite 330 boston ma 02111 1307 usa

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 1334 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Richard Fontana
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190527070033.113240726@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

21 May, 2019

1 commit


08 May, 2019

1 commit

  • There is a potential execution path in which variable *err*
    is compared against UBI_IO_BITFLIPS without being properly
    initialized previously.

    Fix this by initializing variable *err* to 0.

    Addresses-Coverity-ID: 1477298 "(Uninitialized scalar variable")
    Fixes: 663586c0a892 ("ubi: Expose the bitrot interface")
    Signed-off-by: Gustavo A. R. Silva
    Signed-off-by: Richard Weinberger

    Gustavo A. R. Silva
     

06 Mar, 2019

1 commit

  • This condition needs to be fipped around because "err" is uninitialized
    when "force" is set. The Smatch static analysis tool complains and
    UBsan will also complain at runtime.

    Fixes: 663586c0a892 ("ubi: Expose the bitrot interface")
    Signed-off-by: Dan Carpenter
    Reviewed-by: Nathan Chancellor
    Tested-by: Nathan Chancellor
    Signed-off-by: Richard Weinberger

    Dan Carpenter
     

24 Feb, 2019

2 commits

  • Using UBI_IOCRPEB and UBI_IOCSPEB userspace can force
    reading and scrubbing of PEBs.

    In case of bitflips UBI will automatically take action
    and move data to a different PEB.
    This interface allows a daemon to foster your NAND.

    Signed-off-by: Richard Weinberger

    Richard Weinberger
     
  • This function works like in_wl_tree() but checks whether an ubi_wl_entry
    is currently in the protection queue.
    We need this function to query the current state of an ubi_wl_entry.

    Signed-off-by: Richard Weinberger

    Richard Weinberger
     

14 Dec, 2018

2 commits

  • The UBI device reference is dropped but then the device is used as a
    parameter of ubi_err. The bug is introduced in changing ubi_err's
    behavior. The old ubi_err does not require a UBI device as its first
    parameter, but the new one does.

    Fixes: 32608703310 ("UBI: Extend UBI layer debug/messaging capabilities")
    Signed-off-by: Pan Bian
    Reviewed-by: Boris Brezillon
    Signed-off-by: Richard Weinberger

    Pan Bian
     
  • The MTD device reference is dropped via put_mtd_device, however its
    field ->index is read and passed to ubi_msg. To fix this, the patch
    moves the reference dropping after calling ubi_msg.

    Signed-off-by: Pan Bian
    Reviewed-by: Boris Brezillon
    Signed-off-by: Richard Weinberger

    Pan Bian
     

23 Oct, 2018

1 commit

  • In preparation to enabling -Wimplicit-fallthrough, mark switch cases
    where we are expecting to fall through.

    Addresses-Coverity-ID: 1373884 ("Missing break in switch")
    Addresses-Coverity-ID: 114869 ("Missing break in switch")
    Addresses-Coverity-ID: 114870 ("Missing break in switch")
    Signed-off-by: Gustavo A. R. Silva
    Signed-off-by: Richard Weinberger

    Gustavo A. R. Silva
     

15 Aug, 2018

3 commits

  • Now that we have the logic for skipping CRC check for static UBI volumes
    in the core, let's expose it to users.

    This makes use of a padding byte in the volume description data
    structure as a flag. This flag only tell for now whether we should skip
    the CRC check of a volume.

    This checks the UBI volume for which we are trying to skip the CRC check
    is static.

    Let's also make sure that the flags passed to verify_mkvol_req are
    valid.

    We voluntarily do not take into account the skip_check flag in
    vol_cdev_write() as we want to make sure what we wrote was correctly
    written.

    Suggested-by: Boris Brezillon
    Signed-off-by: Quentin Schulz
    Reviewed-by: Boris Brezillon
    Signed-off-by: Richard Weinberger

    Quentin Schulz
     
  • Some users of static UBI volumes implement their own integrity check,
    thus making the volume CRC check done at open time useless. For
    instance, this is the case when one use the ubiblock + dm-verity +
    squashfs combination, where dm-verity already checks integrity of the
    block device but this time at the block granularity instead of verifying
    the whole volume.

    Skipping this test drastically improves the boot-time.

    Suggested-by: Boris Brezillon
    Signed-off-by: Quentin Schulz
    Reviewed-by: Boris Brezillon
    Reviewed-by: Richard Weinberger
    Signed-off-by: Richard Weinberger

    Quentin Schulz
     
  • We cannot do it last, otherwithse it will be skipped for dynamic
    volumes.

    Reported-by: Lachmann, Juergen
    Fixes: 34653fd8c46e ("ubi: fastmap: Check each mapping only once")
    Signed-off-by: Richard Weinberger

    Richard Weinberger
     

13 Jun, 2018

2 commits

  • The kzalloc() function has a 2-factor argument form, kcalloc(). This
    patch replaces cases of:

    kzalloc(a * b, gfp)

    with:
    kcalloc(a * b, gfp)

    as well as handling cases of:

    kzalloc(a * b * c, gfp)

    with:

    kzalloc(array3_size(a, b, c), gfp)

    as it's slightly less ugly than:

    kzalloc_array(array_size(a, b), c, gfp)

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

    kzalloc(4 * 1024, gfp)

    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;
    @@

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

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

    (
    kzalloc(
    - sizeof(u8) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(__u8) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(char) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(unsigned char) * (COUNT)
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(u8) * COUNT
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(__u8) * COUNT
    + COUNT
    , ...)
    |
    kzalloc(
    - sizeof(char) * COUNT
    + COUNT
    , ...)
    |
    kzalloc(
    - 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;
    @@

    (
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * (COUNT_ID)
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * COUNT_ID
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * (COUNT_CONST)
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * COUNT_CONST
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * (COUNT_ID)
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * COUNT_ID
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * (COUNT_CONST)
    + COUNT_CONST, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * COUNT_CONST
    + COUNT_CONST, sizeof(THING)
    , ...)
    )

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

    - kzalloc
    + kcalloc
    (
    - SIZE * COUNT
    + COUNT, SIZE
    , ...)

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

    (
    kzalloc(
    - sizeof(TYPE) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kzalloc(
    - sizeof(THING) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kzalloc(
    - sizeof(THING) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kzalloc(
    - sizeof(THING) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kzalloc(
    - 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;
    @@

    (
    kzalloc(
    - sizeof(TYPE1) * sizeof(TYPE2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kzalloc(
    - sizeof(THING1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kzalloc(
    - sizeof(THING1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kzalloc(
    - sizeof(TYPE1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    |
    kzalloc(
    - 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;
    @@

    (
    kzalloc(
    - (COUNT) * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - COUNT * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - COUNT * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - (COUNT) * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - COUNT * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - (COUNT) * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - (COUNT) * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kzalloc(
    - 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;
    @@

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

    // And then all remaining 2 factors products when they're not all constants,
    // keeping sizeof() as the second factor argument.
    @@
    expression THING, E1, E2;
    type TYPE;
    constant C1, C2, C3;
    @@

    (
    kzalloc(sizeof(THING) * C2, ...)
    |
    kzalloc(sizeof(TYPE) * C2, ...)
    |
    kzalloc(C1 * C2 * C3, ...)
    |
    kzalloc(C1 * C2, ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * (E2)
    + E2, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(TYPE) * E2
    + E2, sizeof(TYPE)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * (E2)
    + E2, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - sizeof(THING) * E2
    + E2, sizeof(THING)
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - (E1) * E2
    + E1, E2
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - (E1) * (E2)
    + E1, E2
    , ...)
    |
    - kzalloc
    + kcalloc
    (
    - E1 * E2
    + E1, E2
    , ...)
    )

    Signed-off-by: Kees Cook

    Kees Cook
     
  • The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
    patch replaces cases of:

    kmalloc(a * b, gfp)

    with:
    kmalloc_array(a * b, gfp)

    as well as handling cases of:

    kmalloc(a * b * c, gfp)

    with:

    kmalloc(array3_size(a, b, c), gfp)

    as it's slightly less ugly than:

    kmalloc_array(array_size(a, b), c, gfp)

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

    kmalloc(4 * 1024, gfp)

    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 tools/ directory was manually excluded, since it has its own
    implementation of kmalloc().

    The Coccinelle script used for this was:

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

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

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

    (
    kmalloc(
    - sizeof(u8) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(__u8) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(char) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(unsigned char) * (COUNT)
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(u8) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(__u8) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - sizeof(char) * COUNT
    + COUNT
    , ...)
    |
    kmalloc(
    - 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;
    @@

    (
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (COUNT_ID)
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * COUNT_ID
    + COUNT_ID, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (COUNT_CONST)
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * COUNT_CONST
    + COUNT_CONST, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (COUNT_ID)
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * COUNT_ID
    + COUNT_ID, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (COUNT_CONST)
    + COUNT_CONST, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * COUNT_CONST
    + COUNT_CONST, sizeof(THING)
    , ...)
    )

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

    - kmalloc
    + kmalloc_array
    (
    - SIZE * COUNT
    + COUNT, SIZE
    , ...)

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

    (
    kmalloc(
    - sizeof(TYPE) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE) * COUNT * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(TYPE))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * (COUNT) * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * (COUNT) * STRIDE
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - sizeof(THING) * COUNT * (STRIDE)
    + array3_size(COUNT, STRIDE, sizeof(THING))
    , ...)
    |
    kmalloc(
    - 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;
    @@

    (
    kmalloc(
    - sizeof(TYPE1) * sizeof(TYPE2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
    , ...)
    |
    kmalloc(
    - sizeof(THING1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - sizeof(THING1) * sizeof(THING2) * (COUNT)
    + array3_size(COUNT, sizeof(THING1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - sizeof(TYPE1) * sizeof(THING2) * COUNT
    + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
    , ...)
    |
    kmalloc(
    - 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;
    @@

    (
    kmalloc(
    - (COUNT) * STRIDE * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * (STRIDE) * SIZE
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - COUNT * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * STRIDE * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - (COUNT) * (STRIDE) * (SIZE)
    + array3_size(COUNT, STRIDE, SIZE)
    , ...)
    |
    kmalloc(
    - 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;
    @@

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

    // And then all remaining 2 factors products when they're not all constants,
    // keeping sizeof() as the second factor argument.
    @@
    expression THING, E1, E2;
    type TYPE;
    constant C1, C2, C3;
    @@

    (
    kmalloc(sizeof(THING) * C2, ...)
    |
    kmalloc(sizeof(TYPE) * C2, ...)
    |
    kmalloc(C1 * C2 * C3, ...)
    |
    kmalloc(C1 * C2, ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * (E2)
    + E2, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(TYPE) * E2
    + E2, sizeof(TYPE)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * (E2)
    + E2, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - sizeof(THING) * E2
    + E2, sizeof(THING)
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - (E1) * E2
    + E1, E2
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - (E1) * (E2)
    + E1, E2
    , ...)
    |
    - kmalloc
    + kmalloc_array
    (
    - E1 * E2
    + E1, E2
    , ...)
    )

    Signed-off-by: Kees Cook

    Kees Cook
     

07 Jun, 2018

5 commits

  • Update license template using SPDX. Move the global layout
    of UBI headers to dual license helping UBI to be the standard
    solution for raw NAND management.

    Signed-off-by: Lionel Debieve
    Acked-by: Thomas Gleixner
    Acked-by: Artem Bityutskiy
    Acked-by: Paul E. McKenney
    Signed-off-by: Richard Weinberger

    Lionel Debieve
     
  • Now we have the machinery to detect EBA mismatches on-the-fly
    by comparing the in-memory volume ID and LEB number with the found
    VID header.
    This helps to detect malfunction of Fastmap.

    Signed-off-by: Richard Weinberger

    Richard Weinberger
     
  • Maintain a bitmap to keep track of which LEB->PEB mapping
    was checked already.
    That way we have to read back VID headers only once.

    Signed-off-by: Richard Weinberger

    Richard Weinberger
     
  • Fastmap cannot track the LEB unmap operation, therefore it can
    happen that after an interrupted erasure the mapping still looks
    good from Fastmap's point of view, while reading from the PEB will
    cause an ECC error and confuses the upper layer.

    Instead of teaching users of UBI how to deal with that, we read back
    the VID header and check for errors. If the PEB is empty or shows ECC
    errors we fixup the mapping and schedule the PEB for erasure.

    Fixes: dbb7d2a88d2a ("UBI: Add fastmap core")
    Cc:
    Reported-by: martin bayern
    Signed-off-by: Richard Weinberger

    Richard Weinberger
     
  • Ben Hutchings pointed out that 29b7a6fa1ec0 ("ubi: fastmap: Don't flush
    fastmap work on detach") does not really fix the problem, it just
    reduces the risk to hit the race window where fastmap work races against
    free()'ing ubi->volumes[].

    The correct approach is making sure that no more fastmap work is in
    progress before we free ubi data structures.
    So we cancel fastmap work right after the ubi background thread is
    stopped.
    By setting ubi->thread_enabled to zero we make sure that no further work
    tries to wake the thread.

    Fixes: 29b7a6fa1ec0 ("ubi: fastmap: Don't flush fastmap work on detach")
    Fixes: 74cdaf24004a ("UBI: Fastmap: Fix memory leaks while closing the WL sub-system")
    Cc: stable@vger.kernel.org
    Cc: Ben Hutchings
    Cc: Martin Townsend

    Signed-off-by: Richard Weinberger

    Richard Weinberger
     

12 Apr, 2018

1 commit

  • Pull UBI and UBIFS updates from Richard Weinberger:
    "Minor bug fixes and improvements"

    * tag 'tags/upstream-4.17-rc1' of git://git.infradead.org/linux-ubifs:
    ubi: Reject MLC NAND
    ubifs: Remove useless parameter of lpt_heap_replace
    ubifs: Constify struct ubifs_lprops in scan_for_leb_for_idx
    ubifs: remove unnecessary assignment
    ubi: Fix error for write access
    ubi: fastmap: Don't flush fastmap work on detach
    ubifs: Check ubifs_wbuf_sync() return code

    Linus Torvalds
     

05 Apr, 2018

3 commits

  • While UBI and UBIFS seem to work at first sight with MLC NAND, you will
    most likely lose all your data upon a power-cut or due to read/write
    disturb.
    In order to protect users from bad surprises, refuse to attach to MLC
    NAND.

    Cc: stable@vger.kernel.org
    Signed-off-by: Richard Weinberger
    Acked-by: Boris Brezillon
    Acked-by: Artem Bityutskiy

    Richard Weinberger
     
  • When opening a device with write access, ubiblock_open returns an error
    code. Currently, this error code is -EPERM, but this is not the right
    value.

    The open function for other block devices returns -EROFS when opening
    read-only devices with FMODE_WRITE set. When used with dm-verity, the
    veritysetup userspace tool is expecting EROFS, and refuses to use the
    ubiblock device.

    Use -EROFS for ubiblock as well. As a result, veritysetup accepts the
    ubiblock device as valid.

    Cc: stable@vger.kernel.org
    Fixes: 9d54c8a33eec (UBI: R/O block driver on top of UBI volumes)
    Signed-off-by: Romain Izard
    Signed-off-by: Richard Weinberger

    Romain Izard
     
  • At this point UBI volumes have already been free()'ed and fastmap can no
    longer access these data structures.

    Reported-by: Martin Townsend
    Fixes: 74cdaf24004a ("UBI: Fastmap: Fix memory leaks while closing the WL sub-system")
    Cc: stable@vger.kernel.org
    Signed-off-by: Richard Weinberger

    Richard Weinberger
     

21 Mar, 2018

1 commit

  • MTD users are no longer checking erase_info->state to determine if the
    erase operation failed or succeeded. Moreover, mtd_erase_callback() is
    now a NOP.

    We can safely get rid of all mtd_erase_callback() calls and all
    erase_info->state assignments. While at it, get rid of the
    erase_info->state field, all MTD_ERASE_XXX definitions and the
    mtd_erase_callback() function.

    Signed-off-by: Boris Brezillon
    Reviewed-by: Richard Weinberger
    Reviewed-by: Miquel Raynal
    Acked-by: Bert Kenward
    ---
    Changes in v2:
    - Address a few coding style issues (reported by Miquel)
    - Remove comments that are no longer valid (reported by Miquel)

    Boris Brezillon
     

16 Mar, 2018

2 commits

  • ->fail_addr and ->addr can be updated no matter the result of
    parent->_erase(), we just need to remove the code doing the same thing
    in mtd_erase_callback() to avoid adjusting those fields twice.

    Note that this can be done because all MTD users have been converted to
    not pass an erase_info->callback() and are thus only taking the
    ->addr_fail and ->addr fields into account after part_erase() has
    returned.

    While we're at it, get rid of the erase_info->mtd field which was only
    needed to let mtd_erase_callback() get the partition device back.

    Signed-off-by: Boris Brezillon
    Reviewed-by: Richard Weinberger

    Boris Brezillon
     
  • None of the mtd->_erase() implementations work in an asynchronous manner,
    so let's simplify MTD users that call mtd_erase(). All they need to do
    is check the value returned by mtd_erase() and assume that != 0 means
    failure.

    Signed-off-by: Boris Brezillon
    Reviewed-by: Richard Weinberger

    Boris Brezillon
     

18 Jan, 2018

9 commits

  • This fixes a race with idr_alloc where gd->first_minor can be set to the
    same value for two simultaneous calls to ubiblock_create. Each instance
    calls device_add_disk with the same first_minor. device_add_disk calls
    bdi_register_owner which generates several warnings.

    WARNING: CPU: 1 PID: 179 at kernel-source/fs/sysfs/dir.c:31
    sysfs_warn_dup+0x68/0x88
    sysfs: cannot create duplicate filename '/devices/virtual/bdi/252:2'

    WARNING: CPU: 1 PID: 179 at kernel-source/lib/kobject.c:240
    kobject_add_internal+0x1ec/0x2f8
    kobject_add_internal failed for 252:2 with -EEXIST, don't try to
    register things with the same name in the same directory

    WARNING: CPU: 1 PID: 179 at kernel-source/fs/sysfs/dir.c:31
    sysfs_warn_dup+0x68/0x88
    sysfs: cannot create duplicate filename '/dev/block/252:2'

    However, device_add_disk does not error out when bdi_register_owner
    returns an error. Control continues until reaching blk_register_queue.
    It then BUGs.

    kernel BUG at kernel-source/fs/sysfs/group.c:113!
    [] (internal_create_group) from []
    (sysfs_create_group+0x20/0x24)
    [] (sysfs_create_group) from []
    (blk_trace_init_sysfs+0x18/0x20)
    [] (blk_trace_init_sysfs) from []
    (blk_register_queue+0xd8/0x154)
    [] (blk_register_queue) from []
    (device_add_disk+0x194/0x44c)
    [] (device_add_disk) from []
    (ubiblock_create+0x284/0x2e0)
    [] (ubiblock_create) from []
    (vol_cdev_ioctl+0x450/0x554)
    [] (vol_cdev_ioctl) from [] (vfs_ioctl+0x30/0x44)
    [] (vfs_ioctl) from [] (do_vfs_ioctl+0xa0/0x790)
    [] (do_vfs_ioctl) from [] (SyS_ioctl+0x44/0x68)
    [] (SyS_ioctl) from [] (ret_fast_syscall+0x0/0x34)

    Locking idr_alloc/idr_remove removes the race and keeps gd->first_minor
    unique.

    Fixes: 2bf50d42f3a4 ("UBI: block: Dynamically allocate minor numbers")
    Cc: stable@vger.kernel.org
    Signed-off-by: Bradley Bolen
    Reviewed-by: Boris Brezillon
    Signed-off-by: Richard Weinberger

    Bradley Bolen
     
  • Fix to return error code -ENOMEM from the kmem_cache_alloc() error
    handling case instead of 0, as done elsewhere in this function.

    Fixes: f78e5623f45b ("ubi: fastmap: Erase outdated anchor PEBs during
    attach")
    Signed-off-by: Wei Yongjun
    Reviewed-by: Boris Brezillon
    Signed-off-by: Richard Weinberger

    Wei Yongjun
     
  • The function documentation of leb_write_trylock is copied from
    leb_write_lock. Replace the function name with the correct one.

    Signed-off-by: Sascha Hauer
    Signed-off-by: Richard Weinberger

    Sascha Hauer
     
  • Fix misspelling of 'available' in function name.

    Signed-off-by: Sascha Hauer
    Signed-off-by: Richard Weinberger

    Sascha Hauer
     
  • The fastmap update code might erase the current fastmap anchor PEB
    in case it doesn't find any new free PEB. When a power cut happens
    in this situation we must not have any outdated fastmap anchor PEB
    on the device, because that would be used to attach during next
    boot.
    The easiest way to make that sure is to erase all outdated fastmap
    anchor PEBs synchronously during attach.

    Signed-off-by: Sascha Hauer
    Reviewed-by: Richard Weinberger
    Fixes: dbb7d2a88d2a ("UBI: Add fastmap core")
    Cc:
    Signed-off-by: Richard Weinberger

    Sascha Hauer
     
  • The pointer p is being initialized with one value and a few lines
    later being set to a newer replacement value. Clean up the code by
    using the latter assignment to p as the initial value. Cleans up
    clang warning:

    drivers/mtd/ubi/fastmap.c:217:19: warning: Value stored to 'p'
    during its initialization is never read

    Signed-off-by: Colin Ian King
    Reviewed-by: Boris Brezillon
    Signed-off-by: Richard Weinberger

    Colin Ian King
     
  • Memory allocated by kmem_cache_alloc() should not be deallocated with
    kfree(). Use kmem_cache_free() instead.

    Signed-off-by: Pan Bian
    Reviewed-by: Boris Brezillon
    Signed-off-by: Richard Weinberger

    Pan Bian
     
  • Similar to commit 714fb87e8bc0 ("ubi: Fix race condition between ubi
    device creation and udev"), we should make the volume active before
    registering it.

    Signed-off-by: Clay McClure
    Cc:
    Signed-off-by: Richard Weinberger

    Clay McClure
     
  • If the user has not set max_beb_per1024 using either the cmdline or
    Kconfig options for doing so, use the MTD function 'max_bad_blocks' to
    compute the UBI bad_peb_limit.

    Signed-off-by: Jeff Westfahl
    Signed-off-by: Zach Brown
    Acked-by: Boris Brezillon
    Acked-by: Richard Weinberger
    Signed-off-by: Richard Weinberger

    Jeff Westfahl
     

16 Nov, 2017

1 commit

  • Pull module updates from Jessica Yu:
    "Summary of modules changes for the 4.15 merge window:

    - treewide module_param_call() cleanup, fix up set/get function
    prototype mismatches, from Kees Cook

    - minor code cleanups"

    * tag 'modules-for-v4.15' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux:
    module: Do not paper over type mismatches in module_param_call()
    treewide: Fix function prototypes for module_param_call()
    module: Prepare to convert all module_param_call() prototypes
    kernel/module: Delete an error message for a failed memory allocation in add_module_usage()

    Linus Torvalds
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

31 Oct, 2017

1 commit

  • Several function prototypes for the set/get functions defined by
    module_param_call() have a slightly wrong argument types. This fixes
    those in an effort to clean up the calls when running under type-enforced
    compiler instrumentation for CFI. This is the result of running the
    following semantic patch:

    @match_module_param_call_function@
    declarer name module_param_call;
    identifier _name, _set_func, _get_func;
    expression _arg, _mode;
    @@

    module_param_call(_name, _set_func, _get_func, _arg, _mode);

    @fix_set_prototype
    depends on match_module_param_call_function@
    identifier match_module_param_call_function._set_func;
    identifier _val, _param;
    type _val_type, _param_type;
    @@

    int _set_func(
    -_val_type _val
    +const char * _val
    ,
    -_param_type _param
    +const struct kernel_param * _param
    ) { ... }

    @fix_get_prototype
    depends on match_module_param_call_function@
    identifier match_module_param_call_function._get_func;
    identifier _val, _param;
    type _val_type, _param_type;
    @@

    int _get_func(
    -_val_type _val
    +char * _val
    ,
    -_param_type _param
    +const struct kernel_param * _param
    ) { ... }

    Two additional by-hand changes are included for places where the above
    Coccinelle script didn't notice them:

    drivers/platform/x86/thinkpad_acpi.c
    fs/lockd/svc.c

    Signed-off-by: Kees Cook
    Signed-off-by: Jessica Yu

    Kees Cook
     

14 Sep, 2017

1 commit