19 Aug, 2020

1 commit

  • commit fd49e03280e596e54edb93a91bc96170f8e97e4a upstream.

    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
    Signed-off-by: Greg Kroah-Hartman

    Matteo Croce
     

17 Apr, 2020

2 commits

  • commit 6c871b7314dde9ab64f20de8f5aa3d01be4518e8 upstream.

    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
    Signed-off-by: Greg Kroah-Hartman

    Vasily Averin
     
  • [ Upstream commit 8a57d6d4ddfa41c49014e20493152c41a38fcbf8 ]

    There is a potential mem leak when pstore_init_fs failed,
    since the pstore compression maybe unlikey to initialized
    successfully. We must clean up the allocation once this
    unlikey issue happens.

    Signed-off-by: chenqiwu
    Link: https://lore.kernel.org/r/1581068800-13817-1-git-send-email-qiwuchen55@gmail.com
    Signed-off-by: Kees Cook
    Signed-off-by: Sasha Levin

    chenqiwu
     

15 Jan, 2020

1 commit

  • commit e163fdb3f7f8c62dccf194f3f37a7bcb3c333aa8 upstream.

    In my attempt to fix a memory leak, I introduced a double-free in the
    pstore error path. Instead of trying to manage the allocation lifetime
    between persistent_ram_new() and its callers, adjust the logic so
    persistent_ram_new() always takes a kstrdup() copy, and leaves the
    caller's allocation lifetime up to the caller. Therefore callers are
    _always_ responsible for freeing their label. Before, it only needed
    freeing when the prz itself failed to allocate, and not in any of the
    other prz failure cases, which callers would have no visibility into,
    which is the root design problem that lead to both the leak and now
    double-free bugs.

    Reported-by: Cengiz Can
    Link: https://lore.kernel.org/lkml/d4ec59002ede4aaf9928c7f7526da87c@kernel.wtf
    Fixes: 8df955a32a73 ("pstore/ram: Fix error-path memory leak in persistent_ram_new() callers")
    Cc: stable@vger.kernel.org
    Signed-off-by: Kees Cook
    Signed-off-by: Greg Kroah-Hartman

    Kees Cook
     

09 Jan, 2020

2 commits

  • commit 8df955a32a73315055e0cd187cbb1cea5820394b upstream.

    For callers that allocated a label for persistent_ram_new(), if the call
    fails, they must clean up the allocation.

    Suggested-by: Navid Emamdoost
    Fixes: 1227daa43bce ("pstore/ram: Clarify resource reservation labels")
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/lkml/20191211191353.14385-1-navid.emamdoost@gmail.com
    Signed-off-by: Kees Cook
    Signed-off-by: Greg Kroah-Hartman

    Kees Cook
     
  • commit 9e5f1c19800b808a37fb9815a26d382132c26c3d upstream.

    The ram_core.c routines treat przs as circular buffers. When writing a
    new crash dump, the old buffer needs to be cleared so that the new dump
    doesn't end up in the wrong place (i.e. at the end).

    The solution to this problem is to reset the circular buffer state before
    writing a new Oops dump.

    Signed-off-by: Aleksandr Yashkin
    Signed-off-by: Nikolay Merinov
    Signed-off-by: Ariel Gilman
    Link: https://lore.kernel.org/r/20191223133816.28155-1-n.merinov@inango-systems.com
    Fixes: 896fc1f0c4c6 ("pstore/ram: Switch to persistent_ram routines")
    Cc: stable@vger.kernel.org
    Signed-off-by: Kees Cook
    Signed-off-by: Greg Kroah-Hartman

    Aleksandr Yashkin
     

30 Aug, 2019

1 commit

  • Leaving granularity at 1ns because it is dependent on the specific
    attached backing pstore module. ramoops has microsecond resolution.

    Fix the readback of ramoops fractional timestamp microseconds,
    which has incorrectly been reporting the value as nanoseconds.

    Fixes: 3f8f80f0cfeb ("pstore/ram: Read and write to the 'compressed' flag of pstore").

    Signed-off-by: Deepa Dinamani
    Acked-by: Kees Cook
    Acked-by: Jeff Layton
    Cc: anton@enomsg.org
    Cc: ccross@android.com
    Cc: keescook@chromium.org
    Cc: tony.luck@intel.com

    Deepa Dinamani
     

09 Jul, 2019

3 commits

  • The pstore_mkfile() function is passed a pointer to a struct
    pstore_record. On success it consumes this 'record' pointer and
    references it from the created inode.

    On failure, however, it may or may not free the record. There are even
    two different code paths which return -ENOMEM -- one of which does and
    the other doesn't free the record.

    Make the behaviour deterministic by never consuming and freeing the
    record when returning failure, allowing the caller to do the cleanup
    consistently.

    Signed-off-by: Norbert Manthey
    Link: https://lore.kernel.org/r/1562331960-26198-1-git-send-email-nmanthey@amazon.de
    Fixes: 83f70f0769ddd ("pstore: Do not duplicate record metadata")
    Fixes: 1dfff7dd67d1a ("pstore: Pass record contents instead of copying")
    Cc: stable@vger.kernel.org
    [kees: also move "private" allocation location, rename inode cleanup label]
    Signed-off-by: Kees Cook

    Norbert Manthey
     
  • When calling debugfs functions, there is no need to ever check the
    return value. The function can work or not, but the code logic should
    never do something different based on this.

    Cc: Kees Cook
    Cc: Anton Vorontsov
    Cc: Colin Cross
    Cc: Tony Luck
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Greg Kroah-Hartman
    Signed-off-by: Kees Cook

    Greg Kroah-Hartman
     
  • When you try to run an upstream kernel on an old ARM-based Chromebook
    you'll find that console-ramoops doesn't work.

    Old ARM-based Chromebooks, before
    ("ramoops: support upstream {console,pmsg,ftrace}-size properties")
    used to create a "ramoops" node at the top level that looked like:

    / {
    ramoops {
    compatible = "ramoops";
    reg = ;
    record-size = ;
    dump-oops;
    };
    };

    ...and these Chromebooks assumed that the downstream kernel would make
    console_size / pmsg_size match the record size. The above ramoops
    node was added by the firmware so it's not easy to make any changes.

    Let's match the expected behavior, but only for those using the old
    backward-compatible way of working where ramoops is right under the
    root node.

    NOTE: if there are some out-of-tree devices that had ramoops at the
    top level, left everything but the record size as 0, and somehow
    doesn't want this behavior, we can try to add more conditions here.

    Signed-off-by: Douglas Anderson
    Signed-off-by: Kees Cook

    Douglas Anderson
     

09 Jun, 2019

1 commit

  • Pull yet more SPDX updates from Greg KH:
    "Another round of SPDX header file fixes for 5.2-rc4

    These are all more "GPL-2.0-or-later" or "GPL-2.0-only" tags being
    added, based on the text in the files. We are slowly chipping away at
    the 700+ different ways people tried to write the license text. All of
    these were reviewed on the spdx mailing list by a number of different
    people.

    We now have over 60% of the kernel files covered with SPDX tags:
    $ ./scripts/spdxcheck.py -v 2>&1 | grep Files
    Files checked: 64533
    Files with SPDX: 40392
    Files with errors: 0

    I think the majority of the "easy" fixups are now done, it's now the
    start of the longer-tail of crazy variants to wade through"

    * tag 'spdx-5.2-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (159 commits)
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 450
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 449
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 448
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 446
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 445
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 444
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 443
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 442
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 441
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 440
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 438
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 437
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 436
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 435
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 434
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 433
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 432
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 431
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 430
    treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 429
    ...

    Linus Torvalds
     

06 Jun, 2019

1 commit


05 Jun, 2019

3 commits

  • 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 version 2 as
    published by the free software foundation 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 51 franklin st fifth floor boston ma 02110
    1301 usa

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

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

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

    Thomas Gleixner
     
  • 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 version 2 as
    published by the free software foundation 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-only

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

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

    Thomas Gleixner
     
  • Based on 1 normalized pattern(s):

    this software is licensed under the terms of the gnu general public
    license version 2 as published by the free software foundation and
    may be copied distributed and modified under those terms 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 285 file(s).

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

    Thomas Gleixner
     

31 May, 2019

2 commits

  • The ram pstore backend has always had the crash dumper frontend enabled
    unconditionally. However, it was possible to effectively disable it
    by setting a record_size=0. All the machinery would run (storing dumps
    to the temporary crash buffer), but 0 bytes would ultimately get stored
    due to there being no przs allocated for dumps. Commit 89d328f637b9
    ("pstore/ram: Correctly calculate usable PRZ bytes"), however, assumed
    that there would always be at least one allocated dprz for calculating
    the size of the temporary crash buffer. This was, of course, not the
    case when record_size=0, and would lead to a NULL deref trying to find
    the dprz buffer size:

    BUG: unable to handle kernel NULL pointer dereference at (null)
    ...
    IP: ramoops_probe+0x285/0x37e (fs/pstore/ram.c:808)

    cxt->pstore.bufsize = cxt->dprzs[0]->buffer_size;

    Instead, we need to only enable the frontends based on the success of the
    prz initialization and only take the needed actions when those zones are
    available. (This also fixes a possible error in detecting if the ftrace
    frontend should be enabled.)

    Reported-and-tested-by: Yaro Slav
    Fixes: 89d328f637b9 ("pstore/ram: Correctly calculate usable PRZ bytes")
    Cc: stable@vger.kernel.org
    Signed-off-by: Kees Cook

    Kees Cook
     
  • Set tfm to NULL on free_buf_for_compression() after crypto_free_comp().

    This avoid a use-after-free when allocate_buf_for_compression()
    and free_buf_for_compression() are called twice. Although
    free_buf_for_compression() freed the tfm, allocate_buf_for_compression()
    won't reinitialize the tfm since the tfm pointer is not NULL.

    Fixes: 95047b0519c1 ("pstore: Refactor compression initialization")
    Signed-off-by: Pi-Hsun Shih
    Cc: stable@vger.kernel.org
    Signed-off-by: Kees Cook

    Pi-Hsun Shih
     

21 May, 2019

1 commit


09 Apr, 2019

1 commit

  • %pF and %pf are functionally equivalent to %pS and %ps conversion
    specifiers. The former are deprecated, therefore switch the current users
    to use the preferred variant.

    The changes have been produced by the following command:

    git grep -l '%p[fF]' | grep -v '^\(tools\|Documentation\)/' | \
    while read i; do perl -i -pe 's/%pf/%ps/g; s/%pF/%pS/g;' $i; done

    And verifying the result.

    Link: http://lkml.kernel.org/r/20190325193229.23390-1-sakari.ailus@linux.intel.com
    Cc: Andy Shevchenko
    Cc: linux-arm-kernel@lists.infradead.org
    Cc: sparclinux@vger.kernel.org
    Cc: linux-um@lists.infradead.org
    Cc: xen-devel@lists.xenproject.org
    Cc: linux-acpi@vger.kernel.org
    Cc: linux-pm@vger.kernel.org
    Cc: drbd-dev@lists.linbit.com
    Cc: linux-block@vger.kernel.org
    Cc: linux-mmc@vger.kernel.org
    Cc: linux-nvdimm@lists.01.org
    Cc: linux-pci@vger.kernel.org
    Cc: linux-scsi@vger.kernel.org
    Cc: linux-btrfs@vger.kernel.org
    Cc: linux-f2fs-devel@lists.sourceforge.net
    Cc: linux-mm@kvack.org
    Cc: ceph-devel@vger.kernel.org
    Cc: netdev@vger.kernel.org
    Signed-off-by: Sakari Ailus
    Acked-by: David Sterba (for btrfs)
    Acked-by: Mike Rapoport (for mm/memblock.c)
    Acked-by: Bjorn Helgaas (for drivers/pci)
    Acked-by: Rafael J. Wysocki
    Signed-off-by: Petr Mladek

    Sakari Ailus
     

13 Feb, 2019

4 commits


22 Jan, 2019

1 commit

  • In ramoops_register_dummy() dummy_data is allocated via kzalloc()
    then it will always occupy the heap space after register platform
    device via platform_device_register_data(), but it will not be
    used any more. So let's free it for system usage, replace it with
    stack memory is better due to small size.

    Signed-off-by: Yue Hu
    [kees: add required memset and adjust sizeof() argument]
    Signed-off-by: Kees Cook

    Yue Hu
     

21 Jan, 2019

1 commit

  • Yue Hu noticed that when parsing device tree the allocated platform data
    was never freed. Since it's not used beyond the function scope, this
    switches to using a stack variable instead.

    Reported-by: Yue Hu
    Fixes: 35da60941e44 ("pstore/ram: add Device Tree bindings")
    Cc: stable@vger.kernel.org
    Signed-off-by: Kees Cook

    Kees Cook
     

18 Jan, 2019

1 commit

  • commit b05c950698fe ("pstore/ram: Simplify ramoops_get_next_prz()
    arguments") changed update assignment in getting next persistent ram zone
    by adding a check for record type. But the check always returns true since
    the record type is assigned 0. And this breaks console ramoops by showing
    current console log instead of previous log on warm reset and hard reset
    (actually hard reset should not be showing any logs).

    Fix this by having persistent ram zone type check instead of record type
    check. Tested this on SDM845 MTP and dragonboard 410c.

    Reproducing this issue is simple as below:

    1. Trigger hard reset and mount pstore. Will see console-ramoops
    record in the mounted location which is the current log.

    2. Trigger warm reset and mount pstore. Will see the current
    console-ramoops record instead of previous record.

    Fixes: b05c950698fe ("pstore/ram: Simplify ramoops_get_next_prz() arguments")
    Signed-off-by: Sai Prakash Ranjan
    Acked-by: Joel Fernandes (Google)
    [kees: dropped local variable usage]
    Signed-off-by: Kees Cook

    Sai Prakash Ranjan
     

04 Jan, 2019

1 commit

  • Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
    of the user address range verification function since we got rid of the
    old racy i386-only code to walk page tables by hand.

    It existed because the original 80386 would not honor the write protect
    bit when in kernel mode, so you had to do COW by hand before doing any
    user access. But we haven't supported that in a long time, and these
    days the 'type' argument is a purely historical artifact.

    A discussion about extending 'user_access_begin()' to do the range
    checking resulted this patch, because there is no way we're going to
    move the old VERIFY_xyz interface to that model. And it's best done at
    the end of the merge window when I've done most of my merges, so let's
    just get this done once and for all.

    This patch was mostly done with a sed-script, with manual fix-ups for
    the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.

    There were a couple of notable cases:

    - csky still had the old "verify_area()" name as an alias.

    - the iter_iov code had magical hardcoded knowledge of the actual
    values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
    really used it)

    - microblaze used the type argument for a debug printout

    but other than those oddities this should be a total no-op patch.

    I tried to fix up all architectures, did fairly extensive grepping for
    access_ok() uses, and the changes are trivial, but I may have missed
    something. Any missed conversion should be trivially fixable, though.

    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

04 Dec, 2018

13 commits

  • Given corruption in the ftrace records, it might be possible to allocate
    tmp_prz without assigning prz to it, but still marking it as needing to
    be freed, which would cause at least a NULL dereference.

    smatch warnings:
    fs/pstore/ram.c:340 ramoops_pstore_read() error: we previously assumed 'prz' could be null (see line 255)

    https://lists.01.org/pipermail/kbuild-all/2018-December/055528.html

    Reported-by: Dan Carpenter
    Fixes: 2fbea82bbb89 ("pstore: Merge per-CPU ftrace records into one")
    Cc: "Joel Fernandes (Google)"
    Signed-off-by: Kees Cook

    Kees Cook
     
  • Instead of running with interrupts disabled, use a semaphore. This should
    make it easier for backends that may need to sleep (e.g. EFI) when
    performing a write:

    |BUG: sleeping function called from invalid context at kernel/sched/completion.c:99
    |in_atomic(): 1, irqs_disabled(): 1, pid: 2236, name: sig-xstate-bum
    |Preemption disabled at:
    |[] pstore_dump+0x72/0x330
    |CPU: 26 PID: 2236 Comm: sig-xstate-bum Tainted: G D 4.20.0-rc3 #45
    |Call Trace:
    | dump_stack+0x4f/0x6a
    | ___might_sleep.cold.91+0xd3/0xe4
    | __might_sleep+0x50/0x90
    | wait_for_completion+0x32/0x130
    | virt_efi_query_variable_info+0x14e/0x160
    | efi_query_variable_store+0x51/0x1a0
    | efivar_entry_set_safe+0xa3/0x1b0
    | efi_pstore_write+0x109/0x140
    | pstore_dump+0x11c/0x330
    | kmsg_dump+0xa4/0xd0
    | oops_exit+0x22/0x30
    ...

    Reported-by: Sebastian Andrzej Siewior
    Fixes: 21b3ddd39fee ("efi: Don't use spinlocks for efi vars")
    Signed-off-by: Kees Cook

    Kees Cook
     
  • Bool initializations should use true and false. Bool tests don't need
    comparisons.

    Signed-off-by: Thomas Meyer
    Signed-off-by: Kees Cook

    Thomas Meyer
     
  • The ramoops backend currently calls persistent_ram_save_old() even
    if a buffer is empty. While this appears to work, it is does not seem
    like the right thing to do and could lead to future bugs so lets avoid
    that. It also prevents misleading prints in the logs which claim the
    buffer is valid.

    I got something like:

    found existing buffer, size 0, start 0

    When I was expecting:

    no valid data in buffer (sig = ...)

    This bails out early (and reports with pr_debug()), since it's an
    acceptable state.

    Signed-off-by: Joel Fernandes (Google)
    Co-developed-by: Kees Cook
    Signed-off-by: Kees Cook

    Joel Fernandes (Google)
     
  • (1) remove type argument from ramoops_get_next_prz()

    Since we store the type of the prz when we initialize it, we no longer
    need to pass it again in ramoops_get_next_prz() since we can just use
    that to setup the pstore record. So lets remove it from the argument list.

    (2) remove max argument from ramoops_get_next_prz()

    Looking at the code flow, the 'max' checks are already being done on
    the prz passed to ramoops_get_next_prz(). Lets remove it to simplify
    this function and reduce its arguments.

    (3) further reduce ramoops_get_next_prz() arguments by passing record

    Both the id and type fields of a pstore_record are set by
    ramoops_get_next_prz(). So we can just pass a pointer to the pstore_record
    instead of passing individual elements. This results in cleaner more
    readable code and fewer lines.

    In addition lets also remove the 'update' argument since we can detect
    that. Changes are squashed into a single patch to reduce fixup conflicts.

    Signed-off-by: Joel Fernandes (Google)
    Signed-off-by: Kees Cook

    Joel Fernandes (Google)
     
  • In later patches we will need to map types to names, so create a
    constant table for that which can also be used in different parts of
    old and new code. This saves the type in the PRZ which will be useful
    in later patches.

    Instead of having an explicit PSTORE_TYPE_UNKNOWN, just use ..._MAX.

    This includes removing the now redundant filename templates which can use
    a single format string. Also, there's no reason to limit the "is it still
    compressed?" test to only PSTORE_TYPE_DMESG when building the pstorefs
    filename. Records are zero-initialized, so a backend would need to have
    explicitly set compressed=1.

    Signed-off-by: Joel Fernandes (Google)
    Co-developed-by: Kees Cook
    Signed-off-by: Kees Cook

    Joel Fernandes (Google)
     
  • This improves and updates some comments:
    - dump handler comment out of sync from calling convention
    - fix kern-doc typo

    and improves status output:
    - reminder that only kernel crash dumps are compressed
    - do not be silent about ECC infrastructure failures

    Signed-off-by: Kees Cook

    Kees Cook
     
  • The struct persistent_ram_zone wasn't well documented. This adds kern-doc
    for it.

    Signed-off-by: Kees Cook

    Kees Cook
     
  • In order to more easily perform automated regression testing, this
    adds pr_debug() calls to report each prz allocation which can then be
    verified against persistent storage. Specifically, seeing the dividing
    line between header, data, any ECC bytes. (And the general assignment
    output is updated to remove the bogus ECC blocksize which isn't actually
    recorded outside the prz instance.)

    Signed-off-by: Kees Cook

    Kees Cook
     
  • With both ram.c and ram_core.c built into ramoops.ko, it doesn't make
    sense to have differing pr_fmt prefixes. This fixes ram_core.c to use
    the module name (as ram.c already does). Additionally improves region
    reservation error to include the region name.

    Signed-off-by: Kees Cook

    Kees Cook
     
  • When initialing a prz, if invalid data is found (no PERSISTENT_RAM_SIG),
    the function call path looks like this:

    ramoops_init_prz ->
    persistent_ram_new -> persistent_ram_post_init -> persistent_ram_zap
    persistent_ram_zap

    As we can see, persistent_ram_zap() is called twice.
    We can avoid this by adding an option to persistent_ram_new(), and
    only call persistent_ram_zap() when it is needed.

    Signed-off-by: Peng Wang
    [kees: minor tweak to exit path and commit log]
    Signed-off-by: Kees Cook

    Peng Wang
     
  • Since the console writer does not use the preallocated crash dump buffer
    any more, there is no reason to perform locking around it.

    Fixes: 70ad35db3321 ("pstore: Convert console write to use ->write_buf")
    Signed-off-by: Kees Cook
    Reviewed-by: Joel Fernandes (Google)

    Kees Cook
     
  • The pre-allocated compression buffer used for crash dumping was also
    being used for decompression. This isn't technically safe, since it's
    possible the kernel may attempt a crashdump while pstore is populating the
    pstore filesystem (and performing decompression). Instead, just allocate
    a separate buffer for decompression. Correctness is preferred over
    performance here.

    Signed-off-by: Kees Cook

    Kees Cook