Skip to content
Snippets Groups Projects
  1. Sep 04, 2024
  2. Sep 02, 2024
    • Marco Elver's avatar
      kfence: introduce burst mode · cc0a0f98
      Marco Elver authored
      Introduce burst mode, which can be configured with kfence.burst=$count,
      where the burst count denotes the additional successive slab allocations
      to be allocated through KFENCE for each sample interval.
      
      The idea is that this can give developers an additional knob to make
      KFENCE more aggressive when debugging specific issues of systems where
      either rebooting or recompiling the kernel with KASAN is not possible.
      
      Experiment: To assess the effectiveness of the new option, we randomly
      picked a recent out-of-bounds [1] and use-after-free bug [2], each with a
      reproducer provided by syzbot, that initially detected these bugs with
      KASAN.  We then tried to reproduce the bugs with KFENCE below.
      
      [1] Fixed by: 7c55b788 ("jfs: xattr: fix buffer overflow for invalid xattr")
          https://syzkaller.appspot.com/bug?id=9d1b59d4718239da6f6069d3891863c25f9f24a2
      [2] Fixed by: f8ad00f3 ("l2tp: fix possible UAF when cleaning up tunnels")
          https://syzkaller.appspot.com/bug?id=4f34adc84f4a3b080187c390eeef60611fd450e1
      
      The following KFENCE configs were compared. A pool size of 1023 objects
      was used for all configurations.
      
      	Baseline
      		kfence.sample_interval=100
      		kfence.skip_covered_thresh=75
      		kfence.burst=0
      
      	Aggressive
      		kfence.sample_interval=1
      		kfence.skip_covered_thresh=10
      		kfence.burst=0
      
      	AggressiveBurst
      		kfence.sample_interval=1
      		kfence.skip_covered_thresh=10
      		kfence.burst=1000
      
      Each reproducer was run 10 times (after a fresh reboot), with the
      following detection counts for each KFENCE config:
      
                          | Detection Count out of 10 |
                          |    OOB [1]  |    UAF [2]  |
        ------------------+-------------+-------------+
        Default           |     0/10    |     0/10    |
        Aggressive        |     0/10    |     0/10    |
        AggressiveBurst   |     8/10    |     8/10    |
      
      With the Default and even the Aggressive configs the results are
      unsurprising, given KFENCE has not been designed for deterministic bug
      detection of small test cases.
      
      However, when enabling burst mode with relatively large burst count,
      KFENCE can start to detect heap memory-safety bugs even in simpler test
      cases with high probability (in the above cases with ~80% probability).
      
      Link: https://lkml.kernel.org/r/20240805124203.2692278-1-elver@google.com
      
      
      Signed-off-by: default avatarMarco Elver <elver@google.com>
      Reviewed-by: default avatarAlexander Potapenko <glider@google.com>
      Cc: Andrey Konovalov <andreyknvl@gmail.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Jann Horn <jannh@google.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      cc0a0f98
  3. Aug 26, 2024
  4. Aug 09, 2024
  5. Jul 29, 2024
    • Stephen Boyd's avatar
      clk: Add test managed clk provider/consumer APIs · d690bd11
      Stephen Boyd authored
      
      Unit tests are more ergonomic and simpler to understand if they don't
      have to hoist a bunch of code into the test harness init and exit
      functions. Add some test managed wrappers for the clk APIs so that clk
      unit tests can write more code in the actual test and less code in the
      harness.
      
      Only add APIs that are used for now. More wrappers can be added in the
      future as necessary.
      
      Cc: Brendan Higgins <brendan.higgins@linux.dev>
      Cc: David Gow <davidgow@google.com>
      Cc: Rae Moar <rmoar@google.com>
      Signed-off-by: default avatarStephen Boyd <sboyd@kernel.org>
      Link: https://lore.kernel.org/r/20240718210513.3801024-7-sboyd@kernel.org
      d690bd11
    • Stephen Boyd's avatar
      platform: Add test managed platform_device/driver APIs · 5ac79730
      Stephen Boyd authored
      
      Introduce KUnit resource wrappers around platform_driver_register(),
      platform_device_alloc(), and platform_device_add() so that test authors
      can register platform drivers/devices from their tests and have the
      drivers/devices automatically be unregistered when the test is done.
      
      This makes test setup code simpler when a platform driver or platform
      device is needed. Add a few test cases at the same time to make sure the
      APIs work as intended.
      
      Cc: Brendan Higgins <brendan.higgins@linux.dev>
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Cc: Rae Moar <rmoar@google.com>
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: "Rafael J. Wysocki" <rafael@kernel.org>
      Signed-off-by: default avatarStephen Boyd <sboyd@kernel.org>
      Link: https://lore.kernel.org/r/20240718210513.3801024-6-sboyd@kernel.org
      5ac79730
    • Stephen Boyd's avatar
      of: Add test managed wrappers for of_overlay_apply()/of_node_put() · 6774e90f
      Stephen Boyd authored
      
      Add test managed wrappers for of_overlay_apply() that automatically
      removes the overlay when the test is finished. This API is intended for
      use by KUnit tests that test code which relies on 'struct device_node's
      and of_*() APIs.
      
      KUnit tests will call of_overlay_apply_kunit() to load an overlay that's
      been built into the kernel image. When the test is complete, the overlay
      will be removed.
      
      This has a few benefits:
      
       1) It keeps the tests hermetic because the overlay is removed when the
          test is complete. Tests won't even be aware that an overlay was
          loaded in another test.
      
       2) The overlay code can live right next to the unit test that loads it.
          The overlay and the unit test can be compiled into one kernel module
          if desired.
      
       3) We can test different device tree configurations by loading
          different overlays. The overlays can be written for a specific test,
          and there can be many of them loaded per-test without needing to jam
          all possible combinations into one DTB.
      
       4) It also allows KUnit to test device tree dependent code on any
          architecture, not just UML. This allows KUnit tests to test
          architecture specific device tree code.
      
      There are some potential pitfalls though. Test authors need to be
      careful to not overwrite properties in the live tree. The easiest way to
      do this is to add and remove nodes with a 'kunit-' prefix, almost
      guaranteeing that the same node won't be present in the tree loaded at
      boot.
      
      Suggested-by: default avatarRob Herring <robh@kernel.org>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Saravana Kannan <saravanak@google.com>
      Reviewed-by: default avatarRob Herring (Arm) <robh@kernel.org>
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Signed-off-by: default avatarStephen Boyd <sboyd@kernel.org>
      Link: https://lore.kernel.org/r/20240718210513.3801024-3-sboyd@kernel.org
      6774e90f
  6. Jul 11, 2024
  7. Jul 04, 2024
    • Ilya Leoshkevich's avatar
      kmsan: allow disabling KMSAN checks for the current task · ec3e837d
      Ilya Leoshkevich authored
      Like for KASAN, it's useful to temporarily disable KMSAN checks around,
      e.g., redzone accesses.  Introduce kmsan_disable_current() and
      kmsan_enable_current(), which are similar to their KASAN counterparts.
      
      Make them reentrant in order to handle memory allocations in interrupt
      context.  Repurpose the allow_reporting field for this.
      
      Link: https://lkml.kernel.org/r/20240621113706.315500-12-iii@linux.ibm.com
      
      
      Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
      Reviewed-by: default avatarAlexander Potapenko <glider@google.com>
      Cc: Alexander Gordeev <agordeev@linux.ibm.com>
      Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Heiko Carstens <hca@linux.ibm.com>
      Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>
      Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
      Cc: <kasan-dev@googlegroups.com>
      Cc: Marco Elver <elver@google.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: Roman Gushchin <roman.gushchin@linux.dev>
      Cc: Steven Rostedt (Google) <rostedt@goodmis.org>
      Cc: Sven Schnelle <svens@linux.ibm.com>
      Cc: Vasily Gorbik <gor@linux.ibm.com>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      ec3e837d
  8. Jul 01, 2024
  9. Jun 26, 2024
  10. May 11, 2024
  11. May 07, 2024
  12. May 06, 2024
  13. Mar 29, 2024
  14. Feb 22, 2024
  15. Feb 21, 2024
  16. Feb 12, 2024
  17. Feb 06, 2024
    • Kees Cook's avatar
      ubsan: Remove CONFIG_UBSAN_SANITIZE_ALL · 918327e9
      Kees Cook authored
      
      For simplicity in splitting out UBSan options into separate rules,
      remove CONFIG_UBSAN_SANITIZE_ALL, effectively defaulting to "y", which
      is how it is generally used anyway. (There are no ":= y" cases beyond
      where a specific file is enabled when a top-level ":= n" is in effect.)
      
      Cc: Andrey Konovalov <andreyknvl@gmail.com>
      Cc: Marco Elver <elver@google.com>
      Cc: linux-doc@vger.kernel.org
      Cc: linux-kbuild@vger.kernel.org
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      918327e9
  18. Jan 31, 2024
    • Benjamin Poirier's avatar
      selftests: Introduce Makefile variable to list shared bash scripts · 2a0683be
      Benjamin Poirier authored
      
      Some tests written in bash source other files in a parent directory. For
      example, drivers/net/bonding/dev_addr_lists.sh sources
      net/forwarding/lib.sh. If a subset of tests is exported and run outside the
      source tree (for example by using `make -C tools/testing/selftests gen_tar
      TARGETS="drivers/net/bonding"`), these other files must be made available
      as well.
      
      Commit ae108c48 ("selftests: net: Fix cross-tree inclusion of scripts")
      addressed this problem by symlinking and copying the sourced files but this
      only works for direct dependencies. Commit 25ae948b ("selftests/net:
      add lib.sh") changed net/forwarding/lib.sh to source net/lib.sh. As a
      result, that latter file must be included as well when the former is
      exported. This was not handled and was reverted in commit 2114e833
      ("selftests: forwarding: Avoid failures to source net/lib.sh"). In order to
      allow reinstating the inclusion of net/lib.sh from net/forwarding/lib.sh,
      add a mechanism to list dependent files in a new Makefile variable and
      export them. This allows sourcing those files using the same expression
      whether tests are run in-tree or exported.
      
      Dependencies are not resolved recursively so transitive dependencies must
      be listed in TEST_INCLUDES. For example, if net/forwarding/lib.sh sources
      net/lib.sh; the Makefile related to a test that sources
      net/forwarding/lib.sh from a parent directory must list:
      TEST_INCLUDES := \
      	../../../net/forwarding/lib.sh \
      	../../../net/lib.sh
      
      v2:
      Fix rst syntax in Documentation/dev-tools/kselftest.rst (Jakub Kicinski)
      
      v1 (from RFC):
      * changed TEST_INCLUDES to take relative paths, like other TEST_* variables
        (Vladimir Oltean)
      * preserved common "$(MAKE) OUTPUT=... -C ... target" ordering in Makefile
        (Petr Machata)
      
      Signed-off-by: default avatarBenjamin Poirier <bpoirier@nvidia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      2a0683be
  19. Jan 22, 2024
  20. Jan 05, 2024
  21. Jan 03, 2024
  22. Dec 29, 2023
  23. Dec 18, 2023
  24. Nov 17, 2023
  25. Nov 01, 2023
  26. Oct 18, 2023
  27. Oct 09, 2023
    • Marcos Paulo de Souza's avatar
      Documentation: kselftests: Remove references to bpf tests · 2531f374
      Marcos Paulo de Souza authored
      
      Currently the bpf selftests are skipped by default, so is someone would
      like to run the tests one would need to run:
        $ make TARGETS=bpf SKIP_TARGETS="" kselftest
      
      To overwrite the SKIP_TARGETS that defines bpf by default. Also,
      following the BPF instructions[1], to run the bpf selftests one would
      need to enter in the tools/testing/selftests/bpf/ directory, and then
      run make, which is not the standard way to run selftests per it's
      documentation.
      
      For the reasons above stop mentioning bpf in the kselftests as examples
      of how to run a test suite.
      
      [1]: Documentation/bpf/bpf_devel_QA.rst
      
      Signed-off-by: default avatarMarcos Paulo de Souza <mpdesouza@suse.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      2531f374
  28. Sep 06, 2023
    • Qing Zhang's avatar
      LoongArch: Add KASAN (Kernel Address Sanitizer) support · 5aa4ac64
      Qing Zhang authored
      
      1/8 of kernel addresses reserved for shadow memory. But for LoongArch,
      There are a lot of holes between different segments and valid address
      space (256T available) is insufficient to map all these segments to kasan
      shadow memory with the common formula provided by kasan core, saying
      (addr >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET
      
      So LoongArch has a arch-specific mapping formula, different segments are
      mapped individually, and only limited space lengths of these specific
      segments are mapped to shadow.
      
      At early boot stage the whole shadow region populated with just one
      physical page (kasan_early_shadow_page). Later, this page is reused as
      readonly zero shadow for some memory that kasan currently don't track.
      After mapping the physical memory, pages for shadow memory are allocated
      and mapped.
      
      Functions like memset()/memcpy()/memmove() do a lot of memory accesses.
      If bad pointer passed to one of these function it is important to be
      caught. Compiler's instrumentation cannot do this since these functions
      are written in assembly.
      
      KASan replaces memory functions with manually instrumented variants.
      Original functions declared as weak symbols so strong definitions in
      mm/kasan/kasan.c could replace them. Original functions have aliases
      with '__' prefix in names, so we could call non-instrumented variant
      if needed.
      
      Signed-off-by: default avatarQing Zhang <zhangqing@loongson.cn>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      5aa4ac64
  29. Jul 26, 2023
  30. Jun 23, 2023
  31. Jun 19, 2023
  32. Jun 12, 2023
  33. Jun 06, 2023
Loading