24 Aug, 2020

1 commit

  • Replace the existing /* fall through */ comments and its variants with
    the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary
    fall-through markings when it is the case.

    [1] https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

    Signed-off-by: Gustavo A. R. Silva

    Gustavo A. R. Silva
     

07 Jul, 2020

1 commit

  • When building a kernel with CONFIG_PSTORE=y and CONFIG_CRYPTO not set,
    a build error happens:

    ld: fs/pstore/platform.o: in function `pstore_dump':
    platform.c:(.text+0x3f9): undefined reference to `crypto_comp_compress'
    ld: fs/pstore/platform.o: in function `pstore_get_backend_records':
    platform.c:(.text+0x784): undefined reference to `crypto_comp_decompress'

    This because some pstore code uses crypto_comp_(de)compress regardless
    of the CONFIG_CRYPTO status. Fix it by wrapping the (de)compress usage
    by IS_ENABLED(CONFIG_PSTORE_COMPRESS)

    Signed-off-by: Matteo Croce
    Link: https://lore.kernel.org/lkml/20200706234045.9516-1-mcroce@linux.microsoft.com
    Fixes: cb3bee0369bc ("pstore: Use crypto compress API")
    Cc: stable@vger.kernel.org
    Signed-off-by: Kees Cook

    Matteo Croce
     

02 Jun, 2020

1 commit


01 Jun, 2020

4 commits

  • In order to use arbitrary block devices as a pstore backend, provide a
    new module param named "best_effort", which will allow using any block
    device, even if it has not provided a panic_write callback.

    Link: https://lore.kernel.org/lkml/20200511233229.27745-12-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • Add support for non-block devices (e.g. MTD). A non-block driver calls
    pstore_blk_register_device() to register iself.

    In addition, pstore/zone is updated to handle non-block devices,
    where an erase must be done before a write. Without this, there is no
    way to remove records stored to an MTD.

    Signed-off-by: WeiXiong Liao
    Link: https://lore.kernel.org/lkml/20200511233229.27745-10-keescook@chromium.org/
    Co-developed-by: Kees Cook
    Signed-off-by: Kees Cook

    WeiXiong Liao
     
  • In order to configure itself, the MTD backend needs to be able to query
    the current pstore configuration. Introduce pstore_blk_get_config() for
    this purpose.

    Signed-off-by: WeiXiong Liao
    Link: https://lore.kernel.org/lkml/20200511233229.27745-9-keescook@chromium.org/
    Co-developed-by: Kees Cook
    Signed-off-by: Kees Cook

    WeiXiong Liao
     
  • One requirement to support MTD devices in pstore/zone is having a
    way to declare certain regions as broken. Add this support to
    pstore/zone.

    The MTD driver should return -ENOMSG when encountering a bad region,
    which tells pstore/zone to skip and try the next one.

    Signed-off-by: WeiXiong Liao
    Link: https://lore.kernel.org/lkml/20200511233229.27745-8-keescook@chromium.org/
    Co-developed-by: Colin Ian King
    Signed-off-by: Colin Ian King
    Link: //lore.kernel.org/lkml/20200512173801.222666-1-colin.king@canonical.com
    Signed-off-by: Kees Cook

    WeiXiong Liao
     

31 May, 2020

21 commits

  • Add details on using pstore/blk, the new backend of pstore to record
    dumps to block devices, in Documentation/admin-guide/pstore-blk.rst

    Signed-off-by: WeiXiong Liao
    Link: https://lore.kernel.org/lkml/20200511233229.27745-7-keescook@chromium.org/
    Signed-off-by: Kees Cook

    WeiXiong Liao
     
  • Support backend for ftrace. To enable ftrace backend, just make
    ftrace_size be greater than 0 and a multiple of 4096.

    Signed-off-by: WeiXiong Liao
    Link: https://lore.kernel.org/lkml/20200511233229.27745-6-keescook@chromium.org/
    Co-developed-by: Colin Ian King
    Signed-off-by: Colin Ian King
    Link: https://lore.kernel.org/lkml/20200512170719.221514-1-colin.king@canonical.com
    Signed-off-by: Kees Cook

    WeiXiong Liao
     
  • Support backend for console. To enable console backend, just make
    console_size be greater than 0 and a multiple of 4096.

    Signed-off-by: WeiXiong Liao
    Link: https://lore.kernel.org/lkml/20200511233229.27745-5-keescook@chromium.org/
    Signed-off-by: Kees Cook

    WeiXiong Liao
     
  • Add pmsg support to pstore/blk (through pstore/zone). To enable, pmsg_size
    must be greater than 0 and a multiple of 4096.

    Signed-off-by: WeiXiong Liao
    Link: https://lore.kernel.org/lkml/20200511233229.27745-4-keescook@chromium.org/
    Co-developed-by: Colin Ian King
    Signed-off-by: Colin Ian King
    Link: https://lore.kernel.org/lkml/20200512171932.222102-1-colin.king@canonical.com
    Co-developed-by: Kees Cook
    Signed-off-by: Kees Cook

    WeiXiong Liao
     
  • pstore/blk is similar to pstore/ram, but uses a block device as the
    storage rather than persistent ram.

    The pstore/blk backend solves two common use-cases that used to preclude
    using pstore/ram:
    - not all devices have a battery that could be used to persist
    regular RAM across power failures.
    - most embedded intelligent equipment have no persistent ram, which
    increases costs, instead preferring cheaper solutions, like block
    devices.

    pstore/blk provides separate configurations for the end user and for the
    block drivers. User configuration determines how pstore/blk operates, such
    as record sizes, max kmsg dump reasons, etc. These can be set by Kconfig
    and/or module parameters, but module parameter have priority over Kconfig.
    Driver configuration covers all the details about the target block device,
    such as total size of the device and how to perform read/write operations.
    These are provided by block drivers, calling pstore_register_blkdev(),
    including an optional panic_write callback used to bypass regular IO
    APIs in an effort to avoid potentially destabilized kernel code during
    a panic.

    Signed-off-by: WeiXiong Liao
    Link: https://lore.kernel.org/lkml/20200511233229.27745-3-keescook@chromium.org/
    Co-developed-by: Kees Cook
    Signed-off-by: Kees Cook

    WeiXiong Liao
     
  • Implement a common set of APIs needed to support pstore storage zones,
    based on how ramoops is designed. This will be used by pstore/blk with
    the intention of migrating pstore/ram in the future.

    Signed-off-by: WeiXiong Liao
    Link: https://lore.kernel.org/lkml/20200511233229.27745-2-keescook@chromium.org/
    Co-developed-by: Kees Cook
    Signed-off-by: Kees Cook

    WeiXiong Liao
     
  • Now that pstore_register() can correctly pass max_reason to the kmesg
    dump facility, introduce a new "max_reason" module parameter and
    "max-reason" Device Tree field.

    The "dump_oops" module parameter and "dump-oops" Device
    Tree field are now considered deprecated, but are now automatically
    converted to their corresponding max_reason values when present, though
    the new max_reason setting has precedence.

    For struct ramoops_platform_data, the "dump_oops" member is entirely
    replaced by a new "max_reason" member, with the only existing user
    updated in place.

    Additionally remove the "reason" filter logic from ramoops_pstore_write(),
    as that is not specifically needed anymore, though technically
    this is a change in behavior for any ramoops users also setting the
    printk.always_kmsg_dump boot param, which will cause ramoops to behave as
    if max_reason was set to KMSG_DUMP_MAX.

    Co-developed-by: Pavel Tatashin
    Signed-off-by: Pavel Tatashin
    Link: https://lore.kernel.org/lkml/20200515184434.8470-6-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • Add a new member to struct pstore_info for passing information about
    kmesg dump maximum reason. This allows a finer control of what kmesg
    dumps are sent to pstore storage backends.

    Those backends that do not explicitly set this field (keeping it equal to
    0), get the default behavior: store only Oopses and Panics, or everything
    if the printk.always_kmsg_dump boot param is set.

    Signed-off-by: Pavel Tatashin
    Link: https://lore.kernel.org/lkml/20200515184434.8470-5-keescook@chromium.org/
    Co-developed-by: Kees Cook
    Signed-off-by: Kees Cook

    Pavel Tatashin
     
  • The pstore subsystem already had a private version of this function.
    With the coming addition of the pstore/zone driver, this needs to be
    shared. As it really should live with printk, move it there instead.

    Link: https://lore.kernel.org/lkml/20200515184434.8470-4-keescook@chromium.org/
    Acked-by: Petr Mladek
    Acked-by: Sergey Senozhatsky
    Reviewed-by: Pavel Tatashin
    Signed-off-by: Kees Cook

    Kees Cook
     
  • To turn the KMSG_DUMP_* reasons into a more ordered list, collapse
    the redundant KMSG_DUMP_(RESTART|HALT|POWEROFF) reasons into
    KMSG_DUMP_SHUTDOWN. The current users already don't meaningfully
    distinguish between them, so there's no need to, as discussed here:
    https://lore.kernel.org/lkml/CA+CK2bAPv5u1ih5y9t5FUnTyximtFCtDYXJCpuyjOyHNOkRdqw@mail.gmail.com/

    Link: https://lore.kernel.org/lkml/20200515184434.8470-2-keescook@chromium.org/
    Reviewed-by: Pavel Tatashin
    Reviewed-by: Petr Mladek
    Acked-by: Michael Ellerman (powerpc)
    Signed-off-by: Kees Cook

    Kees Cook
     
  • Move the ftrace log merging logic out of pstore/ram into pstore/ftrace
    so other backends can use it, like pstore/zone.

    Link: https://lore.kernel.org/lkml/20200510202436.63222-7-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • This changes the ftrace record merging code to be agnostic of
    pstore/ram, as the first step to making it available as a generic
    routine for other backends to use, such as pstore/zone.

    Link: https://lore.kernel.org/lkml/20200510202436.63222-6-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • Refactor device tree size parsing routines to be able to pass a non-zero
    default value for providing a configurable default for the coming
    "max_reason" field. Also rename the helpers, since we're not always
    parsing a size -- we're parsing a u32 and making sure it's not greater
    than INT_MAX.

    Link: https://lore.kernel.org/lkml/20200506211523.15077-4-keescook@chromium.org/
    Link: https://lore.kernel.org/lkml/20200521205223.175957-1-tyhicks@linux.microsoft.com
    Signed-off-by: Kees Cook

    Kees Cook
     
  • A couple module parameters had 0600 permissions, but changing them would
    have no impact on ramoops, so switch these to 0400 to reflect reality.

    Link: https://lore.kernel.org/lkml/20200506211523.15077-7-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • It is easier to see how module params are used if they're near the
    variables they use.

    Link: https://lore.kernel.org/lkml/20200510202436.63222-4-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • If the pstore backend changes, there's no indication in the logs what
    the console is (it always says "pstore"). Instead, pass through the
    active backend's name. (Also adjust the selftest to match.)

    Link: https://lore.kernel.org/lkml/20200510202436.63222-5-keescook@chromium.org/
    Link: https://lore.kernel.org/lkml/20200526135429.GQ12456@shao2-debian
    Signed-off-by: Kees Cook

    Kees Cook
     
  • In order to more cleanly pass around backend names, make the "name" member
    const. This means the module param needs to be dynamic (technically, it
    was before, so this actually cleans up a minor memory leak if a backend
    was specified and then gets unloaded.)

    Link: https://lore.kernel.org/lkml/20200510202436.63222-3-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • The CON_ENABLED flag gets cleared during unregister_console(), so make
    sure we already reset the console flags before calling register_console(),
    otherwise unloading and reloading a pstore backend will not restart
    console logging.

    Signed-off-by: Kees Cook

    Kees Cook
     
  • If a backend was unloaded without having first removed all its
    associated records in pstorefs, subsequent removals would crash while
    attempting to call into the now missing backend. Add automatic removal
    from the tree in pstore_unregister(), so that no references to the
    backend remain.

    Reported-by: Luis Henriques
    Link: https://lore.kernel.org/lkml/87o8yrmv69.fsf@suse.com
    Link: https://lore.kernel.org/lkml/20200506152114.50375-11-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • The pstore.update_ms value was being disabled during pstore_unregister(),
    which would cause any prior value to go unnoticed on the next
    pstore_register(). Instead, just let del_timer() stop the timer, which
    was always sufficient. This additionally refactors the timer reset code
    and allows the timer to be enabled if the module parameter is changed
    away from the default.

    Link: https://lore.kernel.org/lkml/20200506152114.50375-10-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • Nothing was protecting changes to the pstorefs superblock. Add locking
    and refactor away is_pstore_mounted(), instead using a helper to add a
    way to safely lock the pstorefs root inode during filesystem changes.

    Link: https://lore.kernel.org/lkml/20200506152114.50375-9-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     

13 May, 2020

7 commits

  • The "unlink" handling should perform list removal (which can also make
    sure records don't get double-erased), and the "evict" handling should
    be responsible only for memory freeing.

    Link: https://lore.kernel.org/lkml/20200506152114.50375-8-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • The pstore backend lock wasn't being used during pstore_unregister().
    Add sanity check and locking.

    Link: https://lore.kernel.org/lkml/20200506152114.50375-7-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • The pstorefs internal list lock doesn't need to be a spinlock and will
    create problems when trying to access the list in the subsequent patch
    that will walk the pstorefs records during pstore_unregister(). Change
    this to a mutex to avoid may_sleep() warnings when unregistering devices.

    Link: https://lore.kernel.org/lkml/20200506152114.50375-6-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • The name "allpstore" doesn't carry much meaning, so rename it to what it
    actually is: the list of all records present in the filesystem. The lock
    is also renamed accordingly.

    Link: https://lore.kernel.org/lkml/20200506152114.50375-5-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • Currently pstore can only have a single backend attached at a time, and it
    tracks the active backend via "psinfo", under a lock. The locking for this
    does not need to be a spinlock, and in order to avoid may_sleep() issues
    during future changes to pstore_unregister(), switch to a mutex instead.

    Link: https://lore.kernel.org/lkml/20200506152114.50375-4-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • The name "pstore_lock" sounds very global, but it is only supposed to be
    used for managing changes to "psinfo", so rename it accordingly.

    Link: https://lore.kernel.org/lkml/20200506152114.50375-3-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     
  • There is no reason to be doing a module get/put in pstore_register(),
    since the module calling pstore_register() cannot be unloaded since it
    hasn't finished its initialization. Remove it so there is no confusion
    about how registration ordering works.

    Link: https://lore.kernel.org/lkml/20200506152114.50375-2-keescook@chromium.org/
    Signed-off-by: Kees Cook

    Kees Cook
     

23 Apr, 2020

1 commit


10 Mar, 2020

1 commit

  • The current codebase makes use of the zero-length array language
    extension to the C90 standard, but the preferred mechanism to declare
    variable-length types such as these ones is a flexible array member[1][2],
    introduced in C99:

    struct foo {
    int stuff;
    struct boo array[];
    };

    By making use of the mechanism above, we will get a compiler warning
    in case the flexible array does not occur last in the structure, which
    will help us prevent some kind of undefined behavior bugs from being
    inadvertently introduced[3] to the codebase from now on.

    Also, notice that, dynamic memory allocations won't be affected by
    this change:

    "Flexible array members have incomplete type, and so the sizeof operator
    may not be applied. As a quirk of the original implementation of
    zero-length arrays, sizeof evaluates to zero."[1]

    This issue was found with the help of Coccinelle.

    [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
    [2] https://github.com/KSPP/linux/issues/21
    [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")

    Signed-off-by: Gustavo A. R. Silva
    Link: https://lore.kernel.org/r/20200309202327.GA8813@embeddedor
    Signed-off-by: Kees Cook

    Gustavo A. R. Silva
     

28 Feb, 2020

1 commit

  • In Aug 2018 NeilBrown noticed
    commit 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface")
    "Some ->next functions do not increment *pos when they return NULL...
    Note that such ->next functions are buggy and should be fixed.
    A simple demonstration is

    dd if=/proc/swaps bs=1000 skip=1

    Choose any block size larger than the size of /proc/swaps. This will
    always show the whole last line of /proc/swaps"

    /proc/swaps output was fixed recently, however there are lot of other
    affected files, and one of them is related to pstore subsystem.

    If .next function does not change position index, following .show function
    will repeat output related to current position index.

    There are at least 2 related problems:
    - read after lseek beyond end of file, described above by NeilBrown
    "dd if= bs=1000 skip=1" will generate whole last list
    - read after lseek on in middle of last line will output expected rest of
    last line but then repeat whole last line once again.

    If .show() function generates multy-line output (like
    pstore_ftrace_seq_show() does ?) following bash script cycles endlessly

    $ q=;while read -r r;do echo "$((++q)) $r";done < AFFECTED_FILE

    Unfortunately I'm not familiar enough to pstore subsystem and was unable
    to find affected pstore-related file on my test node.

    If .next function does not change position index, following .show function
    will repeat output related to current position index.

    Cc: stable@vger.kernel.org
    Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code ...")
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=206283
    Signed-off-by: Vasily Averin
    Link: https://lore.kernel.org/r/4e49830d-4c88-0171-ee24-1ee540028dad@virtuozzo.com
    [kees: with robustness tweak from Joel Fernandes ]
    Signed-off-by: Kees Cook

    Vasily Averin
     

26 Feb, 2020

2 commits