26 Jan, 2019

1 commit

  • [ Upstream commit 30696378f68a9e3dad6bfe55938b112e72af00c2 ]

    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
    Signed-off-by: Sasha Levin

    Joel Fernandes (Google)
     

23 Jan, 2019

1 commit

  • commit 5631e8576a3caf606cdc375f97425a67983b420c upstream.

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

    Kees Cook
     

17 Dec, 2018

1 commit

  • [ Upstream commit 89d328f637b9904b6d4c9af73c8a608b8dd4d6f8 ]

    The actual number of bytes stored in a PRZ is smaller than the
    bytes requested by platform data, since there is a header on each
    PRZ. Additionally, if ECC is enabled, there are trailing bytes used
    as well. Normally this mismatch doesn't matter since PRZs are circular
    buffers and the leading "overflow" bytes are just thrown away. However, in
    the case of a compressed record, this rather badly corrupts the results.

    This corruption was visible with "ramoops.mem_size=204800 ramoops.ecc=1".
    Any stored crashes would not be uncompressable (producing a pstorefs
    "dmesg-*.enc.z" file), and triggering errors at boot:

    [ 2.790759] pstore: crypto_comp_decompress failed, ret = -22!

    Backporting this depends on commit 70ad35db3321 ("pstore: Convert console
    write to use ->write_buf")

    Reported-by: Joel Fernandes
    Fixes: b0aad7a99c1d ("pstore: Add compression support to pstore")
    Signed-off-by: Kees Cook
    Reviewed-by: Joel Fernandes (Google)
    Signed-off-by: Sasha Levin

    Kees Cook
     

26 Sep, 2018

1 commit

  • commit 831b624df1b420c8f9281ed1307a8db23afb72df upstream.

    persistent_ram_vmap() returns the page start vaddr.
    persistent_ram_iomap() supports non-page-aligned mapping.

    persistent_ram_buffer_map() always adds offset-in-page to the vaddr
    returned from these two functions, which causes incorrect mapping of
    non-page-aligned persistent ram buffer.

    By default ftrace_size is 4096 and max_ftrace_cnt is nr_cpu_ids. Without
    this patch, the zone_sz in ramoops_init_przs() is 4096/nr_cpu_ids which
    might not be page aligned. If the offset-in-page > 2048, the vaddr will be
    in next page. If the next page is not mapped, it will cause kernel panic:

    [ 0.074231] BUG: unable to handle kernel paging request at ffffa19e0081b000
    ...
    [ 0.075000] RIP: 0010:persistent_ram_new+0x1f8/0x39f
    ...
    [ 0.075000] Call Trace:
    [ 0.075000] ramoops_init_przs.part.10.constprop.15+0x105/0x260
    [ 0.075000] ramoops_probe+0x232/0x3a0
    [ 0.075000] platform_drv_probe+0x3e/0xa0
    [ 0.075000] driver_probe_device+0x2cd/0x400
    [ 0.075000] __driver_attach+0xe4/0x110
    [ 0.075000] ? driver_probe_device+0x400/0x400
    [ 0.075000] bus_for_each_dev+0x70/0xa0
    [ 0.075000] driver_attach+0x1e/0x20
    [ 0.075000] bus_add_driver+0x159/0x230
    [ 0.075000] ? do_early_param+0x95/0x95
    [ 0.075000] driver_register+0x70/0xc0
    [ 0.075000] ? init_pstore_fs+0x4d/0x4d
    [ 0.075000] __platform_driver_register+0x36/0x40
    [ 0.075000] ramoops_init+0x12f/0x131
    [ 0.075000] do_one_initcall+0x4d/0x12c
    [ 0.075000] ? do_early_param+0x95/0x95
    [ 0.075000] kernel_init_freeable+0x19b/0x222
    [ 0.075000] ? rest_init+0xbb/0xbb
    [ 0.075000] kernel_init+0xe/0xfc
    [ 0.075000] ret_from_fork+0x3a/0x50

    Signed-off-by: Bin Yang
    [kees: add comments describing the mapping differences, updated commit log]
    Fixes: 24c3d2f342ed ("staging: android: persistent_ram: Make it possible to use memory outside of bootmem")
    Cc: stable@vger.kernel.org
    Signed-off-by: Kees Cook
    Signed-off-by: Greg Kroah-Hartman

    Bin Yang
     

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
     

18 Aug, 2017

2 commits

  • This reverts commit 68c4a4f8abc60c9440ede9cd123d48b78325f7a3, with
    various conflict clean-ups.

    The capability check required too much privilege compared to simple DAC
    controls. A system builder was forced to have crash handler processes
    run with CAP_SYSLOG which would give it the ability to read (and wipe)
    the _current_ dmesg, which is much more access than being given access
    only to the historical log stored in pstorefs.

    With the prior commit to make the root directory 0750, the files are
    protected by default but a system builder can now opt to give access
    to a specific group (via chgrp on the pstorefs root directory) without
    being forced to also give away CAP_SYSLOG.

    Suggested-by: Nick Kralevich
    Signed-off-by: Kees Cook
    Reviewed-by: Petr Mladek
    Reviewed-by: Sergey Senozhatsky

    Kees Cook
     
  • Currently only DMESG and CONSOLE record types are protected, and it isn't
    obvious that they are using a capability check. Instead switch to explicit
    root directory mode of 0750 to keep files private by default. This will
    allow the removal of the capability check, which was non-obvious and
    forces a process to have possibly too much privilege when simple post-boot
    chgrp for readers would be possible without it.

    Signed-off-by: Kees Cook
    Reviewed-by: Sergey Senozhatsky

    Kees Cook
     

16 Jul, 2017

1 commit

  • Pull ->s_options removal from Al Viro:
    "Preparations for fsmount/fsopen stuff (coming next cycle). Everything
    gets moved to explicit ->show_options(), killing ->s_options off +
    some cosmetic bits around fs/namespace.c and friends. Basically, the
    stuff needed to work with fsmount series with minimum of conflicts
    with other work.

    It's not strictly required for this merge window, but it would reduce
    the PITA during the coming cycle, so it would be nice to have those
    bits and pieces out of the way"

    * 'work.mount' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    isofs: Fix isofs_show_options()
    VFS: Kill off s_options and helpers
    orangefs: Implement show_options
    9p: Implement show_options
    isofs: Implement show_options
    afs: Implement show_options
    affs: Implement show_options
    befs: Implement show_options
    spufs: Implement show_options
    bpf: Implement show_options
    ramfs: Implement show_options
    pstore: Implement show_options
    omfs: Implement show_options
    hugetlbfs: Implement show_options
    VFS: Don't use save/replace_mount_options if not using generic_show_options
    VFS: Provide empty name qstr
    VFS: Make get_filesystem() return the affected filesystem
    VFS: Clean up whitespace in fs/namespace.c and fs/super.c
    Provide a function to create a NUL-terminated string from unterminated data

    Linus Torvalds
     

06 Jul, 2017

1 commit

  • Implement the show_options superblock op for pstore as part of a bid to get
    rid of s_options and generic_show_options() to make it easier to implement
    a context-based mount where the mount options can be passed individually
    over a file descriptor.

    Signed-off-by: David Howells
    cc: Kees Cook
    cc: Anton Vorontsov
    cc: Colin Cross
    cc: Tony Luck
    Signed-off-by: Al Viro

    David Howells
     

28 Jun, 2017

1 commit


01 Jun, 2017

6 commits

  • The format string for record->id (u64) was using %lld instead of %llu.

    Signed-off-by: Kees Cook

    Kees Cook
     
  • The current time will be initially available in the record->time field
    for all pstore_read() and pstore_write() calls. Backends can either
    update the field during read(), or use the field during write() instead
    of fetching time themselves.

    Signed-off-by: Kees Cook

    Kees Cook
     
  • In preparation for setting timestamps in the pstore core, create a common
    initializer routine, instead of using static initializers.

    Signed-off-by: Kees Cook

    Kees Cook
     
  • If a backend does not correctly iterate through its records, pstore will
    get stuck loading entries. Detect this with a large record count, and
    announce if we ever hit the limit. This will let future backend reading
    bugs less annoying to debug. Additionally adjust the error about
    pstore_mkfile() failing.

    Signed-off-by: Kees Cook

    Kees Cook
     
  • When the "if (record->size
    Signed-off-by: Kees Cook
    Cc: stable@vger.kernel.org

    Douglas Anderson
     
  • commit 9abdcccc3d5f ("pstore: Extract common arguments into structure")
    moved record decompression to function. decompress_record() gets
    called without checking type and compressed flag. Warning will be
    reported if data is uncompressed. Pstore type PSTORE_TYPE_PPC_OPAL,
    PSTORE_TYPE_PPC_COMMON doesn't contain compressed data and warning get
    printed part of dmesg.

    Partial dmesg log:
    [ 35.848914] pstore: ignored compressed record type 6
    [ 35.848927] pstore: ignored compressed record type 8

    Above warning should not get printed as it is known that data won't be
    compressed for above type and it is valid condition.

    This patch returns if data is not compressed and print warning only if
    data is compressed and type is not PSTORE_TYPE_DMESG.

    Reported-by: Anton Blanchard
    Signed-off-by: Ankit Kumar
    Reviewed-by: Mahesh Salgaonkar
    Signed-off-by: Kees Cook
    Fixes: 9abdcccc3d5f ("pstore: Extract common arguments into structure")
    Cc: stable@vger.kernel.org

    Ankit Kumar
     

11 May, 2017

1 commit

  • Pull hw lockdown support from David Howells:
    "Annotation of module parameters that configure hardware resources
    including ioports, iomem addresses, irq lines and dma channels.

    This allows a future patch to prohibit the use of such module
    parameters to prevent that hardware from being abused to gain access
    to the running kernel image as part of locking the kernel down under
    UEFI secure boot conditions.

    Annotations are made by changing:

    module_param(n, t, p)
    module_param_named(n, v, t, p)
    module_param_array(n, t, m, p)

    to:

    module_param_hw(n, t, hwtype, p)
    module_param_hw_named(n, v, t, hwtype, p)
    module_param_hw_array(n, t, hwtype, m, p)

    where the module parameter refers to a hardware setting

    hwtype specifies the type of the resource being configured. This can
    be one of:

    ioport Module parameter configures an I/O port
    iomem Module parameter configures an I/O mem address
    ioport_or_iomem Module parameter could be either (runtime set)
    irq Module parameter configures an I/O port
    dma Module parameter configures a DMA channel
    dma_addr Module parameter configures a DMA buffer address
    other Module parameter configures some other value

    Note that the hwtype is compile checked, but not currently stored (the
    lockdown code probably won't require it). It is, however, there for
    future use.

    A bonus is that the hwtype can also be used for grepping.

    The intention is for the kernel to ignore or reject attempts to set
    annotated module parameters if lockdown is enabled. This applies to
    options passed on the boot command line, passed to insmod/modprobe or
    direct twiddling in /sys/module/ parameter files.

    The module initialisation then needs to handle the parameter not being
    set, by (1) giving an error, (2) probing for a value or (3) using a
    reasonable default.

    What I can't do is just reject a module out of hand because it may
    take a hardware setting in the module parameters. Some important
    modules, some ipmi stuff for instance, both probe for hardware and
    allow hardware to be manually specified; if the driver is aborts with
    any error, you don't get any ipmi hardware.

    Further, trying to do this entirely in the module initialisation code
    doesn't protect against sysfs twiddling.

    [!] Note that in and of itself, this series of patches should have no
    effect on the the size of the kernel or code execution - that is
    left to a patch in the next series to effect. It does mark
    annotated kernel parameters with a KERNEL_PARAM_FL_HWPARAM flag in
    an already existing field"

    * tag 'hwparam-20170420' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs: (38 commits)
    Annotate hardware config module parameters in sound/pci/
    Annotate hardware config module parameters in sound/oss/
    Annotate hardware config module parameters in sound/isa/
    Annotate hardware config module parameters in sound/drivers/
    Annotate hardware config module parameters in fs/pstore/
    Annotate hardware config module parameters in drivers/watchdog/
    Annotate hardware config module parameters in drivers/video/
    Annotate hardware config module parameters in drivers/tty/
    Annotate hardware config module parameters in drivers/staging/vme/
    Annotate hardware config module parameters in drivers/staging/speakup/
    Annotate hardware config module parameters in drivers/staging/media/
    Annotate hardware config module parameters in drivers/scsi/
    Annotate hardware config module parameters in drivers/pcmcia/
    Annotate hardware config module parameters in drivers/pci/hotplug/
    Annotate hardware config module parameters in drivers/parport/
    Annotate hardware config module parameters in drivers/net/wireless/
    Annotate hardware config module parameters in drivers/net/wan/
    Annotate hardware config module parameters in drivers/net/irda/
    Annotate hardware config module parameters in drivers/net/hamradio/
    Annotate hardware config module parameters in drivers/net/ethernet/
    ...

    Linus Torvalds
     

28 Apr, 2017

2 commits

  • Lockdep complains about a possible deadlock between mount and unlink
    (which is technically impossible), but fixing this improves possible
    future multiple-backend support, and keeps locking in the right order.

    The lockdep warning could be triggered by unlinking a file in the
    pstore filesystem:

    -> #1 (&sb->s_type->i_mutex_key#14){++++++}:
    lock_acquire+0xc9/0x220
    down_write+0x3f/0x70
    pstore_mkfile+0x1f4/0x460
    pstore_get_records+0x17a/0x320
    pstore_fill_super+0xa4/0xc0
    mount_single+0x89/0xb0
    pstore_mount+0x13/0x20
    mount_fs+0xf/0x90
    vfs_kern_mount+0x66/0x170
    do_mount+0x190/0xd50
    SyS_mount+0x90/0xd0
    entry_SYSCALL_64_fastpath+0x1c/0xb1

    -> #0 (&psinfo->read_mutex){+.+.+.}:
    __lock_acquire+0x1ac0/0x1bb0
    lock_acquire+0xc9/0x220
    __mutex_lock+0x6e/0x990
    mutex_lock_nested+0x16/0x20
    pstore_unlink+0x3f/0xa0
    vfs_unlink+0xb5/0x190
    do_unlinkat+0x24c/0x2a0
    SyS_unlinkat+0x16/0x30
    entry_SYSCALL_64_fastpath+0x1c/0xb1

    Possible unsafe locking scenario:

    CPU0 CPU1
    ---- ----
    lock(&sb->s_type->i_mutex_key#14);
    lock(&psinfo->read_mutex);
    lock(&sb->s_type->i_mutex_key#14);
    lock(&psinfo->read_mutex);

    Reported-by: Marta Lofstedt
    Reported-by: Chris Wilson
    Signed-off-by: Kees Cook
    Acked-by: Namhyung Kim

    Kees Cook
     
  • Since the vmalloc code has been removed from write_pmsg() in the commit
    "5bf6d1b pstore/pmsg: drop bounce buffer", remove the unused header
    vmalloc.h.

    Signed-off-by: Geliang Tang
    Signed-off-by: Kees Cook

    Geliang Tang
     

20 Apr, 2017

1 commit

  • When the kernel is running in secure boot mode, we lock down the kernel to
    prevent userspace from modifying the running kernel image. Whilst this
    includes prohibiting access to things like /dev/mem, it must also prevent
    access by means of configuring driver modules in such a way as to cause a
    device to access or modify the kernel image.

    To this end, annotate module_param* statements that refer to hardware
    configuration and indicate for future reference what type of parameter they
    specify. The parameter parser in the core sees this information and can
    skip such parameters with an error message if the kernel is locked down.
    The module initialisation then runs as normal, but just sees whatever the
    default values for those parameters is.

    Note that we do still need to do the module initialisation because some
    drivers have viable defaults set in case parameters aren't specified and
    some drivers support automatic configuration (e.g. PNP or PCI) in addition
    to manually coded parameters.

    This patch annotates drivers in fs/pstore/.

    Suggested-by: Alan Cox
    Signed-off-by: David Howells
    Acked-by: Kees Cook
    cc: Anton Vorontsov
    cc: Colin Cross
    cc: Tony Luck

    David Howells
     

08 Mar, 2017

19 commits


25 Feb, 2017

1 commit

  • Update fs/pstore and fs/squashfs to use the updated functions from the
    new LZ4 module.

    Link: http://lkml.kernel.org/r/1486321748-19085-5-git-send-email-4sschmid@informatik.uni-hamburg.de
    Signed-off-by: Sven Schmidt
    Cc: Bongkyu Kim
    Cc: Rui Salvaterra
    Cc: Sergey Senozhatsky
    Cc: Greg Kroah-Hartman
    Cc: Herbert Xu
    Cc: David S. Miller
    Cc: Anton Vorontsov
    Cc: Colin Cross
    Cc: Kees Cook
    Cc: Tony Luck
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sven Schmidt