Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
  1. Mar 22, 2022
  2. Mar 21, 2022
    • Kees Cook's avatar
      lib: stackinit: Convert to KUnit · 02788ebc
      Kees Cook authored
      
      Convert stackinit unit tests to KUnit, for better integration
      into the kernel self test framework. Includes a rename of
      test_stackinit.c to stackinit_kunit.c, and CONFIG_TEST_STACKINIT to
      CONFIG_STACKINIT_KUNIT_TEST.
      
      Adjust expected test results based on which stack initialization method
      was chosen:
      
       $ CMD="./tools/testing/kunit/kunit.py run stackinit --raw_output \
              --arch=x86_64 --kconfig_add"
      
       $ $CMD | grep stackinit:
       # stackinit: pass:36 fail:0 skip:29 total:65
      
       $ $CMD CONFIG_GCC_PLUGIN_STRUCTLEAK_USER=y | grep stackinit:
       # stackinit: pass:37 fail:0 skip:28 total:65
      
       $ $CMD CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF=y | grep stackinit:
       # stackinit: pass:55 fail:0 skip:10 total:65
      
       $ $CMD CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL=y | grep stackinit:
       # stackinit: pass:62 fail:0 skip:3 total:65
      
       $ $CMD CONFIG_INIT_STACK_ALL_PATTERN=y --make_option LLVM=1 | grep stackinit:
       # stackinit: pass:60 fail:0 skip:5 total:65
      
       $ $CMD CONFIG_INIT_STACK_ALL_ZERO=y --make_option LLVM=1 | grep stackinit:
       # stackinit: pass:60 fail:0 skip:5 total:65
      
      Temporarily remove the userspace-build mode, which will be restored in a
      later patch.
      
      Expand the size of the pre-case switch variable so it doesn't get
      accidentally cleared.
      
      Cc: David Gow <davidgow@google.com>
      Cc: Daniel Latypov <dlatypov@google.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      ---
      v1: https://lore.kernel.org/lkml/20220224055145.1853657-1-keescook@chromium.org
      v2:
       - split "userspace KUnit stub" into separate header and patch (Daniel)
       - Improve commit log and comments (David)
       - Provide mapping of expected XFAIL tests to CONFIGs (David)
      02788ebc
  3. Mar 12, 2022
    • Jason A. Donenfeld's avatar
      random: replace custom notifier chain with standard one · 5acd3548
      Jason A. Donenfeld authored
      
      We previously rolled our own randomness readiness notifier, which only
      has two users in the whole kernel. Replace this with a more standard
      atomic notifier block that serves the same purpose with less code. Also
      unexport the symbols, because no modules use it, only unconditional
      builtins. The only drawback is that it's possible for a notification
      handler returning the "stop" code to prevent further processing, but
      given that there are only two users, and that we're unexporting this
      anyway, that doesn't seem like a significant drawback for the
      simplification we receive here.
      
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Theodore Ts'o <tytso@mit.edu>
      Reviewed-by: default avatarDominik Brodowski <linux@dominikbrodowski.net>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      5acd3548
  4. Mar 08, 2022
    • Paul Menzel's avatar
      lib/raid6: Include <asm/ppc-opcode.h> for VPERMXOR · 5b401e4e
      Paul Menzel authored
      
      On Ubuntu 21.10 (ppc64le) building raid6test with gcc (Ubuntu
      11.2.0-7ubuntu2) 11.2.0 fails with the error below.
      
          gcc -I.. -I ../../../include -g -O2                       \
                   -I../../../arch/powerpc/include -DCONFIG_ALTIVEC \
                   -c -o vpermxor1.o vpermxor1.c
          vpermxor1.c: In function ‘raid6_vpermxor1_gen_syndrome_real’:
          vpermxor1.c:64:29: error: expected string literal before ‘VPERMXOR’
             64 |   asm(VPERMXOR(%0,%1,%2,%3):"=v"(wq0):"v"(gf_high), "v"(gf_low), "v"(wq0));
                |       ^~~~~~~~
          make: *** [Makefile:58: vpermxor1.o] Error 1
      
      So, include the header asm/ppc-opcode.h defining this macro also when
      not building the Linux kernel but only this too.
      
      Cc: Matt Brown <matthew.brown.dev@gmail.com>
      Signed-off-by: default avatarPaul Menzel <pmenzel@molgen.mpg.de>
      Signed-off-by: default avatarSong Liu <song@kernel.org>
      5b401e4e
    • Paul Menzel's avatar
      lib/raid6/test/Makefile: Use $(pound) instead of \# for Make 4.3 · 633174a7
      Paul Menzel authored
      Buidling raid6test on Ubuntu 21.10 (ppc64le) with GNU Make 4.3 shows the
      errors below:
      
          $ cd lib/raid6/test/
          $ make
          <stdin>:1:1: error: stray ‘\’ in program
          <stdin>:1:2: error: stray ‘#’ in program
          <stdin>:1:11: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ \
              before ‘<’ token
      
          [...]
      
      The errors come from the HAS_ALTIVEC test, which fails, and the POWER
      optimized versions are not built. That’s also reason nobody noticed on the
      other architectures.
      
      GNU Make 4.3 does not remove the backslash anymore. From the 4.3 release
      announcment:
      
      > * WARNING: Backward-incompatibility!
      >   Number signs (#) appearing inside a macro reference or function invocation
      >   no longer introduce comments and should not be escaped with backslashes:
      >   thus a call such as:
      >     foo := $(shell echo '#')
      >   is legal.  Previously the number sign needed to be escaped, for example:
      >     foo := $(shell echo '\#')
      >   Now this latter will resolve to "\#".  If you want to write makefiles
      >   portable to both versions, assign the number sign to a variable:
      >     H := \#
      >     foo := $(shell echo '$H')
      >   This was claimed to be fixed in 3.81, but wasn't, for some reason.
      >   To detect this change search for 'nocomment' in the .FEATURES variable.
      
      So, do the same as commit 9564a8cf ("Kbuild: fix # escaping in .cmd
      files for future Make") and commit 929bef46 ("bpf: Use $(pound) instead
      of \# in Makefiles") and define and use a $(pound) variable.
      
      Reference for the change in make:
      https://git.savannah.gnu.org/cgit/make.git/commit/?id=c6966b323811c37acedff05b57
      
      
      
      Cc: Matt Brown <matthew.brown.dev@gmail.com>
      Signed-off-by: default avatarPaul Menzel <pmenzel@molgen.mpg.de>
      Signed-off-by: default avatarSong Liu <song@kernel.org>
      633174a7
    • Dirk Müller's avatar
      lib/raid6/test: fix multiple definition linking error · a5359ddd
      Dirk Müller authored
      
      GCC 10+ defaults to -fno-common, which enforces proper declaration of
      external references using "extern". without this change a link would
      fail with:
      
        lib/raid6/test/algos.c:28: multiple definition of `raid6_call';
        lib/raid6/test/test.c:22: first defined here
      
      the pq.h header that is included already includes an extern declaration
      so we can just remove the redundant one here.
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarDirk Müller <dmueller@suse.de>
      Reviewed-by: default avatarPaul Menzel <pmenzel@molgen.mpg.de>
      Signed-off-by: default avatarSong Liu <song@kernel.org>
      a5359ddd
  5. Mar 03, 2022
  6. Mar 02, 2022
  7. Feb 27, 2022
  8. Feb 26, 2022
  9. Feb 24, 2022
  10. Feb 21, 2022
  11. Feb 16, 2022
    • Kees Cook's avatar
      overflow: Provide constant expression struct_size · 230f6fa2
      Kees Cook authored
      
      There have been cases where struct_size() (or flex_array_size()) needs
      to be calculated for an initializer, which requires it be a constant
      expression. This is possible when the "count" argument is a constant
      expression, so provide this ability for the helpers.
      
      Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Reviewed-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
      Tested-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
      Link: https://lore.kernel.org/lkml/20220210010407.GA701603@embeddedor
      230f6fa2
    • Kees Cook's avatar
      overflow: Implement size_t saturating arithmetic helpers · e1be43d9
      Kees Cook authored
      
      In order to perform more open-coded replacements of common allocation
      size arithmetic, the kernel needs saturating (SIZE_MAX) helpers for
      multiplication, addition, and subtraction. For example, it is common in
      allocators, especially on realloc, to add to an existing size:
      
          p = krealloc(map->patch,
                       sizeof(struct reg_sequence) * (map->patch_regs + num_regs),
                       GFP_KERNEL);
      
      There is no existing saturating replacement for this calculation, and
      just leaving the addition open coded inside array_size() could
      potentially overflow as well. For example, an overflow in an expression
      for a size_t argument might wrap to zero:
      
          array_size(anything, something_at_size_max + 1) == 0
      
      Introduce size_mul(), size_add(), and size_sub() helpers that
      implicitly promote arguments to size_t and saturated calculations for
      use in allocations. With these helpers it is also possible to redefine
      array_size(), array3_size(), flex_array_size(), and struct_size() in
      terms of the new helpers.
      
      As with the check_*_overflow() helpers, the new helpers use __must_check,
      though what is really desired is a way to make sure that assignment is
      only to a size_t lvalue. Without this, it's still possible to introduce
      overflow/underflow via type conversion (i.e. from size_t to int).
      Enforcing this will currently need to be left to static analysis or
      future use of -Wconversion.
      
      Additionally update the overflow unit tests to force runtime evaluation
      for the pathological cases.
      
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Jason Gunthorpe <jgg@ziepe.ca>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Leon Romanovsky <leon@kernel.org>
      Cc: Keith Busch <kbusch@kernel.org>
      Cc: Len Baker <len.baker@gmx.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      e1be43d9
  12. Feb 10, 2022
  13. Feb 09, 2022
  14. Feb 08, 2022
  15. Feb 04, 2022
    • Jason A. Donenfeld's avatar
      lib/crypto: blake2s: avoid indirect calls to compression function for Clang CFI · d2a02e3c
      Jason A. Donenfeld authored
      blake2s_compress_generic is weakly aliased by blake2s_compress. The
      current harness for function selection uses a function pointer, which is
      ordinarily inlined and resolved at compile time. But when Clang's CFI is
      enabled, CFI still triggers when making an indirect call via a weak
      symbol. This seems like a bug in Clang's CFI, as though it's bucketing
      weak symbols and strong symbols differently. It also only seems to
      trigger when "full LTO" mode is used, rather than "thin LTO".
      
      [    0.000000][    T0] Kernel panic - not syncing: CFI failure (target: blake2s_compress_generic+0x0/0x1444)
      [    0.000000][    T0] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.16.0-mainline-06981-g076c855b846e #1
      [    0.000000][    T0] Hardware name: MT6873 (DT)
      [    0.000000][    T0] Call trace:
      [    0.000000][    T0]  dump_backtrace+0xfc/0x1dc
      [    0.000000][    T0]  dump_stack_lvl+0xa8/0x11c
      [    0.000000][    T0]  panic+0x194/0x464
      [    0.000000][  ...
      d2a02e3c
  16. Jan 30, 2022
  17. Jan 28, 2022
  18. Jan 27, 2022
  19. Jan 22, 2022
    • Marco Elver's avatar
      lib/stackdepot: always do filter_irq_stacks() in stack_depot_save() · e9400660
      Marco Elver authored
      The non-interrupt portion of interrupt stack traces before interrupt
      entry is usually arbitrary.  Therefore, saving stack traces of
      interrupts (that include entries before interrupt entry) to stack depot
      leads to unbounded stackdepot growth.
      
      As such, use of filter_irq_stacks() is a requirement to ensure
      stackdepot can efficiently deduplicate interrupt stacks.
      
      Looking through all current users of stack_depot_save(), none (except
      KASAN) pass the stack trace through filter_irq_stacks() before passing
      it on to stack_depot_save().
      
      Rather than adding filter_irq_stacks() to all current users of
      stack_depot_save(), it became clear that stack_depot_save() should
      simply do filter_irq_stacks().
      
      Link: https://lkml.kernel.org/r/20211130095727.2378739-1-elver@google.com
      
      
      Signed-off-by: default avatarMarco Elver <elver@google.com>
      Reviewed-by: default avatarAlexander Potapenko <glider@google.com>
      Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
      Reviewed-by: default avatarAndrey Konovalov <andreyknvl@gmail.com>
      Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
      Cc: Dmitry Vyukov <dvyukov@google.com>
      Cc: Vijayanand Jitta <vjitta@codeaurora.org>
      Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
      Cc: Imran Khan <imran.f.khan@oracle.com>
      Cc: Chris Wilson <chris@chris-wilson.co.uk>
      Cc: Jani Nikula <jani.nikula@intel.com>
      Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      e9400660
    • Vlastimil Babka's avatar
      lib/stackdepot: allow optional init and stack_table allocation by kvmalloc() · 2dba5eb1
      Vlastimil Babka authored
      Currently, enabling CONFIG_STACKDEPOT means its stack_table will be
      allocated from memblock, even if stack depot ends up not actually used.
      The default size of stack_table is 4MB on 32-bit, 8MB on 64-bit.
      
      This is fine for use-cases such as KASAN which is also a config option
      and has overhead on its own.  But it's an issue for functionality that
      has to be actually enabled on boot (page_owner) or depends on hardware
      (GPU drivers) and thus the memory might be wasted.  This was raised as
      an issue [1] when attempting to add stackdepot support for SLUB's debug
      object tracking functionality.  It's common to build kernels with
      CONFIG_SLUB_DEBUG and enable slub_debug on boot only when needed, or
      create only specific kmem caches with debugging for testing purposes.
      
      It would thus be more efficient if stackdepot's table was allocated only
      when actually going to be used.  This patch thus makes the allocation
      (and whole stack_depot_init() ca...
      2dba5eb1
    • Luis Chamberlain's avatar
      test_sysctl: simplify subdirectory registration with register_sysctl() · 04bc883c
      Luis Chamberlain authored
      There is no need to user boiler plate code to specify a set of base
      directories we're going to stuff sysctls under.  Simplify this by using
      register_sysctl() and specifying the directory path directly.
      
      // pycocci sysctl-subdir-register-sysctl-simplify.cocci lib/test_sysctl.c
      
      @c1@
      expression E1;
      identifier subdir, sysctls;
      @@
      
      static struct ctl_table subdir[] = {
      	{
      		.procname = E1,
      		.maxlen = 0,
      		.mode = 0555,
      		.child = sysctls,
      	},
      	{ }
      };
      
      @c2@
      identifier c1.subdir;
      
      expression E2;
      identifier base;
      @@
      
      static struct ctl_table base[] = {
      	{
      		.procname = E2,
      		.maxlen = 0,
      		.mode = 0555,
      		.child = subdir,
      	},
      	{ }
      };
      
      @c3@
      identifier c2.base;
      identifier header;
      @@
      
      header = register_sysctl_table(base);
      
      @r1 depends on c1 && c2 && c3@
      expression c1.E1;
      identifier c1.subdir, c1.sysctls;
      @@
      
      -static struct ctl_table subdir[] = {
      -	{
      -		.procname = E1,
      -		.maxlen = 0,
      -		.mode = 0555,
      -		.child = sysctls,
      -	},
      -	{ }
      -};
      
      @r2 depends on c1 && c2 && c3@
      identifier c1.subdir;
      
      expression c2.E2;
      identifier c2.base;
      @@
      -static struct ctl_table base[] = {
      -	{
      -		.procname = E2,
      -		.maxlen = 0,
      -		.mode = 0555,
      -		.child = subdir,
      -	},
      -	{ }
      -};
      
      @initialize:python@
      @@
      
      def make_my_fresh_expression(s1, s2):
        return '"' + s1.strip('"') + "/" + s2.strip('"') + '"'
      
      @r3 depends on c1 && c2 && c3@
      expression c1.E1;
      identifier c1.sysctls;
      expression c2.E2;
      identifier c2.base;
      identifier c3.header;
      fresh identifier E3 = script:python(E2, E1) { make_my_fresh_expression(E2, E1) };
      @@
      
      header =
      -register_sysctl_table(base);
      +register_sysctl(E3, sysctls);
      
      Generated-by: Coccinelle SmPL
      Link: https://lkml.kernel.org/r/20211123202422.819032-6-mcgrof@kernel.org
      
      
      Signed-off-by: default avatarLuis Chamberlain <mcgrof@kernel.org>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Amir Goldstein <amir73il@gmail.com>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Antti Palosaari <crope@iki.fi>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Benjamin LaHaise <bcrl@kvack.org>
      Cc: Clemens Ladisch <clemens@ladisch.de>
      Cc: David Airlie <airlied@linux.ie>
      Cc: "Eric W. Biederman" <ebiederm@xmission.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Iurii Zaikin <yzaikin@google.com>
      Cc: Jani Nikula <jani.nikula@linux.intel.com>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Joel Becker <jlbec@evilplan.org>
      Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
      Cc: Joseph Qi <joseph.qi@linux.alibaba.com>
      Cc: Julia Lawall <julia.lawall@inria.fr>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Lukas Middendorf <kernel@tuxforce.de>
      Cc: Mark Fasheh <mark@fasheh.com>
      Cc: Paul Turner <pjt@google.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Phillip Potter <phil@philpotter.co.uk>
      Cc: Qing Wang <wangqing@vivo.com>
      Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
      Cc: Sebastian Reichel <sre@kernel.org>
      Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
      Cc: Stephen Kitt <steve@sk2.org>
      Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Cc: Xiaoming Ni <nixiaoming@huawei.com>
      Cc: Douglas Gilbert <dgilbert@interlog.com>
      Cc: James E.J. Bottomley <jejb@linux.ibm.com>
      Cc: Jani Nikula <jani.nikula@intel.com>
      Cc: John Ogness <john.ogness@linutronix.de>
      Cc: Martin K. Petersen <martin.petersen@oracle.com>
      Cc: "Rafael J. Wysocki" <rafael@kernel.org>
      Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
      Cc: Suren Baghdasaryan <surenb@google.com>
      Cc: "Theodore Ts'o" <tytso@mit.edu>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      04bc883c
  20. Jan 20, 2022