1. 09 7月, 2019 1 次提交
    • D
      pstore/ram: Improve backward compatibility with older Chromebooks · 1614e921
      Douglas Anderson 提交于
      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 <https://crrev.com/c/439792>
      ("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: NDouglas Anderson <dianders@chromium.org>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      1614e921
  2. 05 6月, 2019 1 次提交
  3. 31 5月, 2019 1 次提交
    • K
      pstore/ram: Run without kernel crash dump region · 8880fa32
      Kees Cook 提交于
      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 89d328f6
      ("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: NYaro Slav <yaro330@gmail.com>
      Fixes: 89d328f6 ("pstore/ram: Correctly calculate usable PRZ bytes")
      Cc: stable@vger.kernel.org
      Signed-off-by: NKees Cook <keescook@chromium.org>
      8880fa32
  4. 13 2月, 2019 4 次提交
  5. 22 1月, 2019 1 次提交
  6. 21 1月, 2019 1 次提交
  7. 18 1月, 2019 1 次提交
    • S
      pstore/ram: Fix console ramoops to show the previous boot logs · 6a4c9ab1
      Sai Prakash Ranjan 提交于
      commit b05c9506 ("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: b05c9506 ("pstore/ram: Simplify ramoops_get_next_prz() arguments")
      Signed-off-by: NSai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
      Acked-by: NJoel Fernandes (Google) <joel@joelfernandes.org>
      [kees: dropped local variable usage]
      Signed-off-by: NKees Cook <keescook@chromium.org>
      6a4c9ab1
  8. 04 12月, 2018 6 次提交
    • K
      pstore/ram: Avoid NULL deref in ftrace merging failure path · 8665569e
      Kees Cook 提交于
      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.htmlReported-by: NDan Carpenter <dan.carpenter@oracle.com>
      Fixes: 2fbea82b ("pstore: Merge per-CPU ftrace records into one")
      Cc: "Joel Fernandes (Google)" <joel@joelfernandes.org>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      8665569e
    • K
      pstore: Convert buf_lock to semaphore · ea84b580
      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:
      |[<ffffffff99d60512>] 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: NSebastian Andrzej Siewior <bigeasy@linutronix.de>
      Fixes: 21b3ddd3 ("efi: Don't use spinlocks for efi vars")
      Signed-off-by: NKees Cook <keescook@chromium.org>
      ea84b580
    • J
      pstore/ram: Simplify ramoops_get_next_prz() arguments · b05c9506
      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: NJoel Fernandes (Google) <joel@joelfernandes.org>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      b05c9506
    • J
      pstore: Map PSTORE_TYPE_* to strings · f0f23e54
      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: NJoel Fernandes (Google) <joel@joelfernandes.org>
      Co-developed-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      f0f23e54
    • K
      pstore/ram: Report backend assignments with finer granularity · dc80b1ea
      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: NKees Cook <keescook@chromium.org>
      dc80b1ea
    • P
      pstore: Avoid duplicate call of persistent_ram_zap() · 7684bd33
      Peng Wang 提交于
      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: NPeng Wang <wangpeng15@xiaomi.com>
      [kees: minor tweak to exit path and commit log]
      Signed-off-by: NKees Cook <keescook@chromium.org>
      7684bd33
  9. 30 11月, 2018 1 次提交
    • K
      pstore/ram: Correctly calculate usable PRZ bytes · 89d328f6
      Kees Cook 提交于
      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 70ad35db ("pstore: Convert console
      write to use ->write_buf")
      Reported-by: NJoel Fernandes <joel@joelfernandes.org>
      Fixes: b0aad7a9 ("pstore: Add compression support to pstore")
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Reviewed-by: NJoel Fernandes (Google) <joel@joelfernandes.org>
      89d328f6
  10. 22 10月, 2018 2 次提交
  11. 01 10月, 2018 1 次提交
    • K
      pstore/ram: Fix failure-path memory leak in ramoops_init · bac6f6cd
      Kees Cook 提交于
      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: Nnixiaoming <nixiaoming@huawei.com>
      Cc: stable@vger.kernel.org
      Cc: Anton Vorontsov <anton@enomsg.org>
      Cc: Colin Cross <ccross@android.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Joel Fernandes <joelaf@google.com>
      Cc: Geliang Tang <geliangtang@gmail.com>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      bac6f6cd
  12. 14 6月, 2018 1 次提交
    • A
      pstore: Remove bogus format string definition · e264abea
      Arnd Bergmann 提交于
      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: NKees Cook <keescook@chromium.org>
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      e264abea
  13. 06 6月, 2018 1 次提交
  14. 10 3月, 2018 1 次提交
    • G
      pstore: Use crypto compress API · cb3bee03
      Geliang Tang 提交于
      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: NGeliang Tang <geliangtang@gmail.com>
      [kees: tweaked error messages on allocation failures and Kconfig help]
      Signed-off-by: NKees Cook <keescook@chromium.org>
      cb3bee03
  15. 01 6月, 2017 1 次提交
  16. 20 4月, 2017 1 次提交
    • D
      Annotate hardware config module parameters in fs/pstore/ · b90fe0c4
      David Howells 提交于
      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: NAlan Cox <gnomes@lxorguk.ukuu.org.uk>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Acked-by: NKees Cook <keescook@chromium.org>
      cc: Anton Vorontsov <anton@enomsg.org>
      cc: Colin Cross <ccross@android.com>
      cc: Tony Luck <tony.luck@intel.com>
      b90fe0c4
  17. 08 3月, 2017 5 次提交
  18. 14 2月, 2017 1 次提交
  19. 10 2月, 2017 1 次提交
  20. 16 11月, 2016 7 次提交
  21. 12 11月, 2016 1 次提交