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
     

01 Oct, 2018

1 commit

  • As reported by nixiaoming, with some minor clarifications:

    1) memory leak in ramoops_register_dummy():
    dummy_data = kzalloc(sizeof(*dummy_data), GFP_KERNEL);
    but no kfree() if platform_device_register_data() fails.

    2) memory leak in ramoops_init():
    Missing platform_device_unregister(dummy) and kfree(dummy_data)
    if platform_driver_register(&ramoops_driver) fails.

    I've clarified the purpose of ramoops_register_dummy(), and added a
    common cleanup routine for all three failure paths to call.

    Reported-by: nixiaoming
    Cc: stable@vger.kernel.org
    Cc: Anton Vorontsov
    Cc: Colin Cross
    Cc: Tony Luck
    Cc: Joel Fernandes
    Cc: Geliang Tang
    Signed-off-by: Kees Cook

    Kees Cook
     

14 Sep, 2018

1 commit

  • 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

    Bin Yang
     

04 Aug, 2018

1 commit


14 Jun, 2018

1 commit

  • The pstore conversion to timespec64 introduces its own method of passing
    seconds into sscanf() and sprintf() type functions to work around the
    timespec64 definition on 64-bit systems that redefine it to 'timespec'.

    That hack is now finally getting removed, but that means we get a (harmless)
    warning once both patches are merged:

    fs/pstore/ram.c: In function 'ramoops_read_kmsg_hdr':
    fs/pstore/ram.c:39:29: error: format '%ld' expects argument of type 'long int *', but argument 3 has type 'time64_t *' {aka 'long long int *'} [-Werror=format=]
    #define RAMOOPS_KERNMSG_HDR "===="
    ^~~~~~
    fs/pstore/ram.c:167:21: note: in expansion of macro 'RAMOOPS_KERNMSG_HDR'

    This removes the pstore specific workaround and uses the same method that
    we have in place for all other functions that print a timespec64.

    Related to this, I found that the kasprintf() output contains an incorrect
    nanosecond values for any number starting with zeroes, and I adapt the
    format string accordingly.

    Link: https://lkml.org/lkml/2018/5/19/115
    Link: https://lkml.org/lkml/2018/5/16/1080
    Fixes: 0f0d83b99ef7 ("pstore: Convert internal records to timespec64")
    Acked-by: Kees Cook
    Signed-off-by: Arnd Bergmann

    Arnd Bergmann
     

06 Jun, 2018

2 commits

  • struct timespec is not y2038 safe. Transition vfs to use
    y2038 safe struct timespec64 instead.

    The change was made with the help of the following cocinelle
    script. This catches about 80% of the changes.
    All the header file and logic changes are included in the
    first 5 rules. The rest are trivial substitutions.
    I avoid changing any of the function signatures or any other
    filesystem specific data structures to keep the patch simple
    for review.

    The script can be a little shorter by combining different cases.
    But, this version was sufficient for my usecase.

    virtual patch

    @ depends on patch @
    identifier now;
    @@
    - struct timespec
    + struct timespec64
    current_time ( ... )
    {
    - struct timespec now = current_kernel_time();
    + struct timespec64 now = current_kernel_time64();
    ...
    - return timespec_trunc(
    + return timespec64_trunc(
    ... );
    }

    @ depends on patch @
    identifier xtime;
    @@
    struct \( iattr \| inode \| kstat \) {
    ...
    - struct timespec xtime;
    + struct timespec64 xtime;
    ...
    }

    @ depends on patch @
    identifier t;
    @@
    struct inode_operations {
    ...
    int (*update_time) (...,
    - struct timespec t,
    + struct timespec64 t,
    ...);
    ...
    }

    @ depends on patch @
    identifier t;
    identifier fn_update_time =~ "update_time$";
    @@
    fn_update_time (...,
    - struct timespec *t,
    + struct timespec64 *t,
    ...) { ... }

    @ depends on patch @
    identifier t;
    @@
    lease_get_mtime( ... ,
    - struct timespec *t
    + struct timespec64 *t
    ) { ... }

    @te depends on patch forall@
    identifier ts;
    local idexpression struct inode *inode_node;
    identifier i_xtime =~ "^i_[acm]time$";
    identifier ia_xtime =~ "^ia_[acm]time$";
    identifier fn_update_time =~ "update_time$";
    identifier fn;
    expression e, E3;
    local idexpression struct inode *node1;
    local idexpression struct inode *node2;
    local idexpression struct iattr *attr1;
    local idexpression struct iattr *attr2;
    local idexpression struct iattr attr;
    identifier i_xtime1 =~ "^i_[acm]time$";
    identifier i_xtime2 =~ "^i_[acm]time$";
    identifier ia_xtime1 =~ "^ia_[acm]time$";
    identifier ia_xtime2 =~ "^ia_[acm]time$";
    @@
    (
    (
    - struct timespec ts;
    + struct timespec64 ts;
    |
    - struct timespec ts = current_time(inode_node);
    + struct timespec64 ts = current_time(inode_node);
    )

    i_xtime, &ts)
    + timespec64_equal(&inode_node->i_xtime, &ts)
    |
    - timespec_equal(&ts, &inode_node->i_xtime)
    + timespec64_equal(&ts, &inode_node->i_xtime)
    |
    - timespec_compare(&inode_node->i_xtime, &ts)
    + timespec64_compare(&inode_node->i_xtime, &ts)
    |
    - timespec_compare(&ts, &inode_node->i_xtime)
    + timespec64_compare(&ts, &inode_node->i_xtime)
    |
    ts = current_time(e)
    |
    fn_update_time(..., &ts,...)
    |
    inode_node->i_xtime = ts
    |
    node1->i_xtime = ts
    |
    ts = inode_node->i_xtime
    |
    ia_xtime ...+> = ts
    |
    ts = attr1->ia_xtime
    |
    ts.tv_sec
    |
    ts.tv_nsec
    |
    btrfs_set_stack_timespec_sec(..., ts.tv_sec)
    |
    btrfs_set_stack_timespec_nsec(..., ts.tv_nsec)
    |
    - ts = timespec64_to_timespec(
    + ts =
    ...
    -)
    |
    - ts = ktime_to_timespec(
    + ts = ktime_to_timespec64(
    ...)
    |
    - ts = E3
    + ts = timespec_to_timespec64(E3)
    |
    - ktime_get_real_ts(&ts)
    + ktime_get_real_ts64(&ts)
    |
    fn(...,
    - ts
    + timespec64_to_timespec(ts)
    ,...)
    )
    ...+>
    (

    )
    |
    - timespec_equal(&node1->i_xtime1, &node2->i_xtime2)
    + timespec64_equal(&node1->i_xtime2, &node2->i_xtime2)
    |
    - timespec_equal(&node1->i_xtime1, &attr2->ia_xtime2)
    + timespec64_equal(&node1->i_xtime2, &attr2->ia_xtime2)
    |
    - timespec_compare(&node1->i_xtime1, &node2->i_xtime2)
    + timespec64_compare(&node1->i_xtime1, &node2->i_xtime2)
    |
    node1->i_xtime1 =
    - timespec_trunc(attr1->ia_xtime1,
    + timespec64_trunc(attr1->ia_xtime1,
    ...)
    |
    - attr1->ia_xtime1 = timespec_trunc(attr2->ia_xtime2,
    + attr1->ia_xtime1 = timespec64_trunc(attr2->ia_xtime2,
    ...)
    |
    - ktime_get_real_ts(&attr1->ia_xtime1)
    + ktime_get_real_ts64(&attr1->ia_xtime1)
    |
    - ktime_get_real_ts(&attr.ia_xtime1)
    + ktime_get_real_ts64(&attr.ia_xtime1)
    )

    @ depends on patch @
    struct inode *node;
    struct iattr *attr;
    identifier fn;
    identifier i_xtime =~ "^i_[acm]time$";
    identifier ia_xtime =~ "^ia_[acm]time$";
    expression e;
    @@
    (
    - fn(node->i_xtime);
    + fn(timespec64_to_timespec(node->i_xtime));
    |
    fn(...,
    - node->i_xtime);
    + timespec64_to_timespec(node->i_xtime));
    |
    - e = fn(attr->ia_xtime);
    + e = fn(timespec64_to_timespec(attr->ia_xtime));
    )

    @ depends on patch forall @
    struct inode *node;
    struct iattr *attr;
    identifier i_xtime =~ "^i_[acm]time$";
    identifier ia_xtime =~ "^ia_[acm]time$";
    identifier fn;
    @@
    {
    + struct timespec ts;
    i_xtime);
    fn (...,
    - &node->i_xtime,
    + &ts,
    ...);
    |
    + ts = timespec64_to_timespec(attr->ia_xtime);
    fn (...,
    - &attr->ia_xtime,
    + &ts,
    ...);
    )
    ...+>
    }

    @ depends on patch forall @
    struct inode *node;
    struct iattr *attr;
    struct kstat *stat;
    identifier ia_xtime =~ "^ia_[acm]time$";
    identifier i_xtime =~ "^i_[acm]time$";
    identifier xtime =~ "^[acm]time$";
    identifier fn, ret;
    @@
    {
    + struct timespec ts;
    i_xtime);
    ret = fn (...,
    - &node->i_xtime,
    + &ts,
    ...);
    |
    + ts = timespec64_to_timespec(node->i_xtime);
    ret = fn (...,
    - &node->i_xtime);
    + &ts);
    |
    + ts = timespec64_to_timespec(attr->ia_xtime);
    ret = fn (...,
    - &attr->ia_xtime,
    + &ts,
    ...);
    |
    + ts = timespec64_to_timespec(attr->ia_xtime);
    ret = fn (...,
    - &attr->ia_xtime);
    + &ts);
    |
    + ts = timespec64_to_timespec(stat->xtime);
    ret = fn (...,
    - &stat->xtime);
    + &ts);
    )
    ...+>
    }

    @ depends on patch @
    struct inode *node;
    struct inode *node2;
    identifier i_xtime1 =~ "^i_[acm]time$";
    identifier i_xtime2 =~ "^i_[acm]time$";
    identifier i_xtime3 =~ "^i_[acm]time$";
    struct iattr *attrp;
    struct iattr *attrp2;
    struct iattr attr ;
    identifier ia_xtime1 =~ "^ia_[acm]time$";
    identifier ia_xtime2 =~ "^ia_[acm]time$";
    struct kstat *stat;
    struct kstat stat1;
    struct timespec64 ts;
    identifier xtime =~ "^[acmb]time$";
    expression e;
    @@
    (
    ( node->i_xtime2 \| attrp->ia_xtime2 \| attr.ia_xtime2 \) = node->i_xtime1 ;
    |
    node->i_xtime2 = \( node2->i_xtime1 \| timespec64_trunc(...) \);
    |
    node->i_xtime2 = node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
    |
    node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
    |
    stat->xtime = node2->i_xtime1;
    |
    stat1.xtime = node2->i_xtime1;
    |
    ( node->i_xtime2 \| attrp->ia_xtime2 \) = attrp->ia_xtime1 ;
    |
    ( attrp->ia_xtime1 \| attr.ia_xtime1 \) = attrp2->ia_xtime2;
    |
    - e = node->i_xtime1;
    + e = timespec64_to_timespec( node->i_xtime1 );
    |
    - e = attrp->ia_xtime1;
    + e = timespec64_to_timespec( attrp->ia_xtime1 );
    |
    node->i_xtime1 = current_time(...);
    |
    node->i_xtime2 = node->i_xtime1 = node->i_xtime3 =
    - e;
    + timespec_to_timespec64(e);
    |
    node->i_xtime1 = node->i_xtime3 =
    - e;
    + timespec_to_timespec64(e);
    |
    - node->i_xtime1 = e;
    + node->i_xtime1 = timespec_to_timespec64(e);
    )

    Signed-off-by: Deepa Dinamani
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:
    Cc:

    Deepa Dinamani
     
  • This prepares pstore for converting the VFS layer to timespec64.

    Signed-off-by: Kees Cook
    Signed-off-by: Deepa Dinamani

    Kees Cook
     

07 Apr, 2018

1 commit

  • Commit 58eb5b670747 ("pstore: fix crypto dependencies") fixed up the crypto
    dependencies but missed the case when no compression is selected.

    With CONFIG_PSTORE=y, CONFIG_PSTORE_COMPRESS=n and CONFIG_CRYPTO=m we see
    the following link error:

    fs/pstore/platform.o: In function `pstore_register':
    (.text+0x1b1): undefined reference to `crypto_has_alg'
    (.text+0x205): undefined reference to `crypto_alloc_base'
    fs/pstore/platform.o: In function `pstore_unregister':
    (.text+0x3b0): undefined reference to `crypto_destroy_tfm'

    Fix this by checking at compile-time if CONFIG_PSTORE_COMPRESS is enabled.

    Fixes: 58eb5b670747 ("pstore: fix crypto dependencies")
    Signed-off-by: Tobias Regnery
    Acked-by: Arnd Bergmann
    Signed-off-by: Kees Cook

    Tobias Regnery
     

16 Mar, 2018

1 commit

  • The new crypto API use causes some problems with Kconfig dependencies,
    including this link error:

    fs/pstore/platform.o: In function `pstore_register':
    platform.c:(.text+0x248): undefined reference to `crypto_has_alg'
    platform.c:(.text+0x2a0): undefined reference to `crypto_alloc_base'
    fs/pstore/platform.o: In function `pstore_unregister':
    platform.c:(.text+0x498): undefined reference to `crypto_destroy_tfm'
    crypto/lz4hc.o: In function `lz4hc_sdecompress':
    lz4hc.c:(.text+0x1a): undefined reference to `LZ4_decompress_safe'
    crypto/lz4hc.o: In function `lz4hc_decompress_crypto':
    lz4hc.c:(.text+0x5a): undefined reference to `LZ4_decompress_safe'
    crypto/lz4hc.o: In function `lz4hc_scompress':
    lz4hc.c:(.text+0xaa): undefined reference to `LZ4_compress_HC'
    crypto/lz4hc.o: In function `lz4hc_mod_init':
    lz4hc.c:(.init.text+0xf): undefined reference to `crypto_register_alg'
    lz4hc.c:(.init.text+0x1f): undefined reference to `crypto_register_scomp'
    lz4hc.c:(.init.text+0x2f): undefined reference to `crypto_unregister_alg'

    The problem is that with CONFIG_CRYPTO=m, we must not 'select CRYPTO_LZ4'
    from a bool symbol, or call crypto API functions from a built-in
    module.

    This turns the sub-options into 'tristate' ones so the dependencies
    are honored, and makes the pstore itself select the crypto core
    if necessary.

    Fixes: cb3bee0369bc ("pstore: Use crypto compress API")
    Signed-off-by: Arnd Bergmann
    Signed-off-by: Kees Cook

    Arnd Bergmann
     

10 Mar, 2018

1 commit

  • In the pstore compression part, we use zlib/lzo/lz4/lz4hc/842
    compression algorithm API to implement pstore compression backends. But
    there are many repeat codes in these implementations. This patch uses
    crypto compress API to simplify these codes.

    1) rewrite allocate_buf_for_compression, free_buf_for_compression,
    pstore_compress, pstore_decompress functions using crypto compress API.
    2) drop compress, decompress, allocate, free functions in pstore_zbackend,
    and add zbufsize function to get each different compress buffer size.
    3) use late_initcall to call ramoops_init later, to make sure the crypto
    subsystem has already initialized.
    4) use 'unsigned int' type instead of 'size_t' in pstore_compress,
    pstore_decompress functions' length arguments.
    5) rename 'zlib' to 'deflate' to follow the crypto API's name convention.

    Signed-off-by: Geliang Tang
    [kees: tweaked error messages on allocation failures and Kconfig help]
    Signed-off-by: Kees Cook

    Geliang Tang
     

08 Mar, 2018

2 commits

  • Instead of using a stack VLA for the parity workspace, preallocate a
    memory region. The preallocation is done to keep from needing to perform
    allocations during crash dump writing, etc. This also fixes a missed
    release of librs on free.

    Signed-off-by: Kees Cook

    Kees Cook
     
  • To allow for easier build test coverage and run-time testing, this allows
    multiple compression algorithms to be built into pstore. Still only one
    is supported to operate at a time (which can be selected at build time
    or at boot time, similar to how LSMs are selected).

    Signed-off-by: Kees Cook

    Kees Cook
     

07 Mar, 2018

2 commits


29 Nov, 2017

1 commit

  • Preempt counter APIs have been split out, currently, hardirq.h just
    includes irq_enter/exit APIs which are not used by pstore at all.

    So, remove the unused hardirq.h.

    Signed-off-by: Yang Shi
    Cc: Kees Cook
    Cc: Anton Vorontsov
    Cc: Colin Cross
    Cc: Tony Luck
    Signed-off-by: Kees Cook

    Yang Shi
     

22 Nov, 2017

1 commit

  • This changes all DEFINE_TIMER() callbacks to use a struct timer_list
    pointer instead of unsigned long. Since the data argument has already been
    removed, none of these callbacks are using their argument currently, so
    this renames the argument to "unused".

    Done using the following semantic patch:

    @match_define_timer@
    declarer name DEFINE_TIMER;
    identifier _timer, _callback;
    @@

    DEFINE_TIMER(_timer, _callback);

    @change_callback depends on match_define_timer@
    identifier match_define_timer._callback;
    type _origtype;
    identifier _origarg;
    @@

    void
    -_callback(_origtype _origarg)
    +_callback(struct timer_list *unused)
    { ... }

    Signed-off-by: Kees Cook

    Kees Cook
     

18 Nov, 2017

1 commit

  • Pull misc vfs updates from Al Viro:
    "Assorted stuff, really no common topic here"

    * 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    vfs: grab the lock instead of blocking in __fd_install during resizing
    vfs: stop clearing close on exec when closing a fd
    include/linux/fs.h: fix comment about struct address_space
    fs: make fiemap work from compat_ioctl
    coda: fix 'kernel memory exposure attempt' in fsync
    pstore: remove unneeded unlikely()
    vfs: remove unneeded unlikely()
    stubs for mount_bdev() and kill_block_super() in !CONFIG_BLOCK case
    make vfs_ustat() static
    do_handle_open() should be static
    elf_fdpic: fix unused variable warning
    fold destroy_super() into __put_super()
    new helper: destroy_unused_super()
    fix address space warnings in ipc/
    acct.h: get rid of detritus

    Linus Torvalds
     

14 Nov, 2017

1 commit

  • Pull timer updates from Thomas Gleixner:
    "Yet another big pile of changes:

    - More year 2038 work from Arnd slowly reaching the point where we
    need to think about the syscalls themself.

    - A new timer function which allows to conditionally (re)arm a timer
    only when it's either not running or the new expiry time is sooner
    than the armed expiry time. This allows to use a single timer for
    multiple timeout requirements w/o caring about the first expiry
    time at the call site.

    - A new NMI safe accessor to clock real time for the printk timestamp
    work. Can be used by tracing, perf as well if required.

    - A large number of timer setup conversions from Kees which got
    collected here because either maintainers requested so or they
    simply got ignored. As Kees pointed out already there are a few
    trivial merge conflicts and some redundant commits which was
    unavoidable due to the size of this conversion effort.

    - Avoid a redundant iteration in the timer wheel softirq processing.

    - Provide a mechanism to treat RTC implementations depending on their
    hardware properties, i.e. don't inflict the write at the 0.5
    seconds boundary which originates from the PC CMOS RTC to all RTCs.
    No functional change as drivers need to be updated separately.

    - The usual small updates to core code clocksource drivers. Nothing
    really exciting"

    * 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (111 commits)
    timers: Add a function to start/reduce a timer
    pstore: Use ktime_get_real_fast_ns() instead of __getnstimeofday()
    timer: Prepare to change all DEFINE_TIMER() callbacks
    netfilter: ipvs: Convert timers to use timer_setup()
    scsi: qla2xxx: Convert timers to use timer_setup()
    block/aoe: discover_timer: Convert timers to use timer_setup()
    ide: Convert timers to use timer_setup()
    drbd: Convert timers to use timer_setup()
    mailbox: Convert timers to use timer_setup()
    crypto: Convert timers to use timer_setup()
    drivers/pcmcia: omap1: Fix error in automated timer conversion
    ARM: footbridge: Fix typo in timer conversion
    drivers/sgi-xp: Convert timers to use timer_setup()
    drivers/pcmcia: Convert timers to use timer_setup()
    drivers/memstick: Convert timers to use timer_setup()
    drivers/macintosh: Convert timers to use timer_setup()
    hwrng/xgene-rng: Convert timers to use timer_setup()
    auxdisplay: Convert timers to use timer_setup()
    sparc/led: Convert timers to use timer_setup()
    mips: ip22/32: Convert timers to use timer_setup()
    ...

    Linus Torvalds
     

12 Nov, 2017

1 commit

  • __getnstimeofday() is a rather odd interface, with a number of quirks:

    - The caller may come from NMI context, but the implementation is not NMI safe,
    one way to get there from NMI is

    NMI handler:
    something bad
    panic()
    kmsg_dump()
    pstore_dump()
    pstore_record_init()
    __getnstimeofday()

    - The calling conventions are different from any other timekeeping functions,
    to deal with returning an error code during suspended timekeeping.

    Address the above issues by using a completely different method to get the
    time: ktime_get_real_fast_ns() is NMI safe and has a reasonable behavior
    when timekeeping is suspended: it returns the time at which it got
    suspended. As Thomas Gleixner explained, this is safe, as
    ktime_get_real_fast_ns() does not call into the clocksource driver that
    might be suspended.

    The result can easily be transformed into a timespec structure. Since
    ktime_get_real_fast_ns() was not exported to modules, add the export.

    The pstore behavior for the suspended case changes slightly, as it now
    stores the timestamp at which timekeeping was suspended instead of storing
    a zero timestamp.

    This change is not addressing y2038-safety, that's subject to a more
    complex follow up patch.

    Signed-off-by: Arnd Bergmann
    Signed-off-by: Thomas Gleixner
    Acked-by: Kees Cook
    Cc: Tony Luck
    Cc: Anton Vorontsov
    Cc: Stephen Boyd
    Cc: John Stultz
    Cc: Colin Cross
    Link: https://lkml.kernel.org/r/20171110152530.1926955-1-arnd@arndb.de

    Arnd Bergmann
     

06 Nov, 2017

1 commit


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
     

05 Oct, 2017

1 commit

  • Drop the arguments from the macro and adjust all callers with the
    following script:

    perl -pi -e 's/DEFINE_TIMER\((.*), 0, 0\);/DEFINE_TIMER($1);/g;' \
    $(git grep DEFINE_TIMER | cut -d: -f1 | sort -u | grep -v timer.h)

    Signed-off-by: Kees Cook
    Acked-by: Geert Uytterhoeven # for m68k parts
    Acked-by: Guenter Roeck # for watchdog parts
    Acked-by: David S. Miller # for networking parts
    Acked-by: Greg Kroah-Hartman
    Acked-by: Kalle Valo # for wireless parts
    Acked-by: Arnd Bergmann
    Cc: linux-mips@linux-mips.org
    Cc: Petr Mladek
    Cc: Benjamin Herrenschmidt
    Cc: Lai Jiangshan
    Cc: Sebastian Reichel
    Cc: Kalle Valo
    Cc: Paul Mackerras
    Cc: Pavel Machek
    Cc: linux1394-devel@lists.sourceforge.net
    Cc: Chris Metcalf
    Cc: linux-s390@vger.kernel.org
    Cc: linux-wireless@vger.kernel.org
    Cc: "James E.J. Bottomley"
    Cc: Wim Van Sebroeck
    Cc: Michael Ellerman
    Cc: Ursula Braun
    Cc: Viresh Kumar
    Cc: Harish Patil
    Cc: Stephen Boyd
    Cc: Michael Reed
    Cc: Manish Chopra
    Cc: Len Brown
    Cc: Arnd Bergmann
    Cc: linux-pm@vger.kernel.org
    Cc: Heiko Carstens
    Cc: Tejun Heo
    Cc: Julian Wiedmann
    Cc: John Stultz
    Cc: Mark Gross
    Cc: linux-watchdog@vger.kernel.org
    Cc: linux-scsi@vger.kernel.org
    Cc: "Martin K. Petersen"
    Cc: Greg Kroah-Hartman
    Cc: "Rafael J. Wysocki"
    Cc: Oleg Nesterov
    Cc: Ralf Baechle
    Cc: Stefan Richter
    Cc: Guenter Roeck
    Cc: netdev@vger.kernel.org
    Cc: Martin Schwidefsky
    Cc: Andrew Morton
    Cc: linuxppc-dev@lists.ozlabs.org
    Cc: Sudip Mukherjee
    Link: https://lkml.kernel.org/r/1507159627-127660-11-git-send-email-keescook@chromium.org
    Signed-off-by: Thomas Gleixner

    Kees Cook
     

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

1 commit

  • Nothing actually uses write_user_compat() currently, but there is no
    reason to reuse the dmesg buffer. Instead, just allocate a new record
    buffer, copy in from userspace, and pass it to write() as normal.

    Signed-off-by: Kees Cook

    Kees Cook