Skip to content
Snippets Groups Projects
  1. Jul 10, 2022
    • Linus Torvalds's avatar
      ida: don't use BUG_ON() for debugging · fc82bbf4
      Linus Torvalds authored
      
      This is another old BUG_ON() that just shouldn't exist (see also commit
      a382f8fe: "signal handling: don't use BUG_ON() for debugging").
      
      In fact, as Matthew Wilcox points out, this condition shouldn't really
      even result in a warning, since a negative id allocation result is just
      a normal allocation failure:
      
        "I wonder if we should even warn here -- sure, the caller is trying to
         free something that wasn't allocated, but we don't warn for
         kfree(NULL)"
      
      and goes on to point out how that current error check is only causing
      people to unnecessarily do their own index range checking before freeing
      it.
      
      This was noted by Itay Iellin, because the bluetooth HCI socket cookie
      code does *not* do that range checking, and ends up just freeing the
      error case too, triggering the BUG_ON().
      
      The HCI code requires CAP_NET_RAW, and seems to just result in an ugly
      splat, but there really is no reason to BUG_ON() here, and we have
      generally striven for allocation models where it's always ok to just do
      
          free(alloc());
      
      even if the allocation were to fail for some random reason (usually
      obviously that "random" reason being some resource limit).
      
      Fixes: 88eca020 ("ida: simplified functions for id allocation")
      Reported-by: default avatarItay Iellin <ieitayie@gmail.com>
      Suggested-by: default avatarMatthew Wilcox <willy@infradead.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      fc82bbf4
  2. Jul 03, 2022
    • Linus Torvalds's avatar
      lockref: remove unused 'lockref_get_or_lock()' function · b8d5109f
      Linus Torvalds authored
      
      Looking at the conditional lock acquire functions in the kernel due to
      the new sparse support (see commit 4a557a5d "sparse: introduce
      conditional lock acquire function attribute"), it became obvious that
      the lockref code has a couple of them, but they don't match the usual
      naming convention for the other ones, and their return value logic is
      also reversed.
      
      In the other very similar places, the naming pattern is '*_and_lock()'
      (eg 'atomic_put_and_lock()' and 'refcount_dec_and_lock()'), and the
      function returns true when the lock is taken.
      
      The lockref code is superficially very similar to the refcount code,
      only with the special "atomic wrt the embedded lock" semantics.  But
      instead of the '*_and_lock()' naming it uses '*_or_lock()'.
      
      And instead of returning true in case it took the lock, it returns true
      if it *didn't* take the lock.
      
      Now, arguably the reflock code is quite logical: it really is a "either
      decrement _or_ lock" kind of situation - and the return value is about
      whether the operation succeeded without any special care needed.
      
      So despite the similarities, the differences do make some sense, and
      maybe it's not worth trying to unify the different conditional locking
      primitives in this area.
      
      But while looking at this all, it did become obvious that the
      'lockref_get_or_lock()' function hasn't actually had any users for
      almost a decade.
      
      The only user it ever had was the shortlived 'd_rcu_to_refcount()'
      function, and it got removed and replaced with 'lockref_get_not_dead()'
      back in 2013 in commits 0d98439e ("vfs: use lockred 'dead' flag to
      mark unrecoverably dead dentries") and e5c832d5 ("vfs: fix dentry
      RCU to refcounting possibly sleeping dput()")
      
      In fact, that single use was removed less than a week after the whole
      function was introduced in commit b3abd802 ("lockref: add
      'lockref_get_or_lock() helper") so this function has been around for a
      decade, but only had a user for six days.
      
      Let's just put this mis-designed and unused function out of its misery.
      
      We can think about the naming and semantic oddities of the remaining
      'lockref_put_or_lock()' later, but at least that function has users.
      
      And while the naming is different and the return value doesn't match,
      that function matches the whole '{atomic,refcount}_dec_and_test()'
      pattern much better (ie the magic happens when the count goes down to
      zero, not when it is incremented from zero).
      
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      b8d5109f
  3. Jun 25, 2022
  4. Jun 12, 2022
    • Jason A. Donenfeld's avatar
      crypto: memneq - move into lib/ · abfed87e
      Jason A. Donenfeld authored
      
      This is used by code that doesn't need CONFIG_CRYPTO, so move this into
      lib/ with a Kconfig option so that it can be selected by whatever needs
      it.
      
      This fixes a linker error Zheng pointed out when
      CRYPTO_MANAGER_DISABLE_TESTS!=y and CRYPTO=m:
      
        lib/crypto/curve25519-selftest.o: In function `curve25519_selftest':
        curve25519-selftest.c:(.init.text+0x60): undefined reference to `__crypto_memneq'
        curve25519-selftest.c:(.init.text+0xec): undefined reference to `__crypto_memneq'
        curve25519-selftest.c:(.init.text+0x114): undefined reference to `__crypto_memneq'
        curve25519-selftest.c:(.init.text+0x154): undefined reference to `__crypto_memneq'
      
      Reported-by: default avatarZheng Bin <zhengbin13@huawei.com>
      Cc: Eric Biggers <ebiggers@kernel.org>
      Cc: stable@vger.kernel.org
      Fixes: aa127963 ("crypto: lib/curve25519 - re-add selftests")
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      Reviewed-by: default avatarEric Biggers <ebiggers@google.com>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      abfed87e
  5. Jun 11, 2022
    • Linus Torvalds's avatar
      iov_iter: fix build issue due to possible type mis-match · 1c27f1fc
      Linus Torvalds authored
      
      Commit 6c776766 ("iov_iter: Fix iter_xarray_get_pages{,_alloc}()")
      introduced a problem on some 32-bit architectures (at least arm, xtensa,
      csky,sparc and mips), that have a 'size_t' that is 'unsigned int'.
      
      The reason is that we now do
      
          min(nr * PAGE_SIZE - offset, maxsize);
      
      where 'nr' and 'offset' and both 'unsigned int', and PAGE_SIZE is
      'unsigned long'.  As a result, the normal C type rules means that the
      first argument to 'min()' ends up being 'unsigned long'.
      
      In contrast, 'maxsize' is of type 'size_t'.
      
      Now, 'size_t' and 'unsigned long' are always the same physical type in
      the kernel, so you'd think this doesn't matter, and from an actual
      arithmetic standpoint it doesn't.
      
      But on 32-bit architectures 'size_t' is commonly 'unsigned int', even if
      it could also be 'unsigned long'.  In that situation, both are unsigned
      32-bit types, but they are not the *same* type.
      
      And as a result 'min()' will complain about the distinct types (ignore
      the "pointer types" part of the error message: that's an artifact of the
      way we have made 'min()' check types for being the same):
      
        lib/iov_iter.c: In function 'iter_xarray_get_pages':
        include/linux/minmax.h:20:35: error: comparison of distinct pointer types lacks a cast [-Werror]
           20 |         (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
              |                                   ^~
        lib/iov_iter.c:1464:16: note: in expansion of macro 'min'
         1464 |         return min(nr * PAGE_SIZE - offset, maxsize);
              |                ^~~
      
      This was not visible on 64-bit architectures (where we always define
      'size_t' to be 'unsigned long').
      
      Force these cases to use 'min_t(size_t, x, y)' to make the type explicit
      and avoid the issue.
      
      [ Nit-picky note: technically 'size_t' doesn't have to match 'unsigned
        long' arithmetically. We've certainly historically seen environments
        with 16-bit address spaces and 32-bit 'unsigned long'.
      
        Similarly, even in 64-bit modern environments, 'size_t' could be its
        own type distinct from 'unsigned long', even if it were arithmetically
        identical.
      
        So the above type commentary is only really descriptive of the kernel
        environment, not some kind of universal truth for the kinds of wild
        and crazy situations that are allowed by the C standard ]
      
      Reported-by: default avatarSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Link: https://lore.kernel.org/all/YqRyL2sIqQNDfky2@debian/
      
      
      Cc: Jeff Layton <jlayton@kernel.org>
      Cc: David Howells <dhowells@redhat.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      1c27f1fc
  6. Jun 10, 2022
    • David Howells's avatar
      iov_iter: Fix iter_xarray_get_pages{,_alloc}() · 6c776766
      David Howells authored and Al Viro's avatar Al Viro committed
      
      The maths at the end of iter_xarray_get_pages() to calculate the actual
      size doesn't work under some circumstances, such as when it's been asked to
      extract a partial single page.  Various terms of the equation cancel out
      and you end up with actual == offset.  The same issue exists in
      iter_xarray_get_pages_alloc().
      
      Fix these to just use min() to select the lesser amount from between the
      amount of page content transcribed into the buffer, minus the offset, and
      the size limit specified.
      
      This doesn't appear to have caused a problem yet upstream because network
      filesystems aren't getting the pages from an xarray iterator, but rather
      passing it directly to the socket, which just iterates over it.  Cachefiles
      *does* do DIO from one to/from ext4/xfs/btrfs/etc. but it always asks for
      whole pages to be written or read.
      
      Fixes: 7ff50620 ("iov_iter: Add ITER_XARRAY")
      Reported-by: default avatarJeff Layton <jlayton@kernel.org>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Alexander Viro <viro@zeniv.linux.org.uk>
      cc: Dominique Martinet <asmadeus@codewreck.org>
      cc: Mike Marshall <hubcap@omnibond.com>
      cc: Gao Xiang <xiang@kernel.org>
      cc: linux-afs@lists.infradead.org
      cc: v9fs-developer@lists.sourceforge.net
      cc: devel@lists.orangefs.org
      cc: linux-erofs@lists.ozlabs.org
      cc: linux-cachefs@redhat.com
      cc: linux-fsdevel@vger.kernel.org
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      6c776766
    • Jason A. Donenfeld's avatar
      random: remove rng_has_arch_random() · e052a478
      Jason A. Donenfeld authored
      
      With arch randomness being used by every distro and enabled in
      defconfigs, the distinction between rng_has_arch_random() and
      rng_is_initialized() is now rather small. In fact, the places where they
      differ are now places where paranoid users and system builders really
      don't want arch randomness to be used, in which case we should respect
      that choice, or places where arch randomness is known to be broken, in
      which case that choice is all the more important. So this commit just
      removes the function and its one user.
      
      Reviewed-by: Petr Mladek <pmladek@suse.com> # for vsprintf.c
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      e052a478
  7. Jun 09, 2022
  8. Jun 07, 2022
  9. Jun 06, 2022
  10. Jun 03, 2022
    • Kees Cook's avatar
      nodemask: Fix return values to be unsigned · 0dfe5407
      Kees Cook authored
      
      The nodemask routines had mixed return values that provided potentially
      signed return values that could never happen. This was leading to the
      compiler getting confusing about the range of possible return values
      (it was thinking things could be negative where they could not be). Fix
      all the nodemask routines that should be returning unsigned
      (or bool) values. Silences:
      
       mm/swapfile.c: In function ‘setup_swap_info’:
       mm/swapfile.c:2291:47: error: array subscript -1 is below array bounds of ‘struct plist_node[]’ [-Werror=array-bounds]
        2291 |                                 p->avail_lists[i].prio = 1;
             |                                 ~~~~~~~~~~~~~~^~~
       In file included from mm/swapfile.c:16:
       ./include/linux/swap.h:292:27: note: while referencing ‘avail_lists’
         292 |         struct plist_node avail_lists[]; /*
             |                           ^~~~~~~~~~~
      
      Reported-by: default avatarChristophe de Dinechin <dinechin@redhat.com>
      Link: https://lore.kernel.org/lkml/20220414150855.2407137-3-dinechin@redhat.com/
      
      
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: Yury Norov <yury.norov@gmail.com>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Zhen Lei <thunder.leizhen@huawei.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarYury Norov <yury.norov@gmail.com>
      0dfe5407
    • Kees Cook's avatar
      bitmap: Fix return values to be unsigned · 005f1700
      Kees Cook authored
      
      Both nodemask and bitmap routines had mixed return values that provided
      potentially signed return values that could never happen. This was
      leading to the compiler getting confusing about the range of possible
      return values (it was thinking things could be negative where they could
      not be). In preparation for fixing nodemask, fix all the bitmap routines
      that should be returning unsigned (or bool) values.
      
      Cc: Yury Norov <yury.norov@gmail.com>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Christophe de Dinechin <dinechin@redhat.com>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Zhen Lei <thunder.leizhen@huawei.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarYury Norov <yury.norov@gmail.com>
      005f1700
    • Yury Norov's avatar
      lib/bitmap: add test for bitmap_{from,to}_arr64 · 2c523550
      Yury Norov authored
      
      Test newly added bitmap_{from,to}_arr64() functions similarly to
      already existing bitmap_{from,to}_arr32() tests.
      
      CC: Alexander Gordeev <agordeev@linux.ibm.com>
      CC: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      CC: Christian Borntraeger <borntraeger@linux.ibm.com>
      CC: Claudio Imbrenda <imbrenda@linux.ibm.com>
      CC: David Hildenbrand <david@redhat.com>
      CC: Heiko Carstens <hca@linux.ibm.com>
      CC: Janosch Frank <frankja@linux.ibm.com>
      CC: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      CC: Sven Schnelle <svens@linux.ibm.com>
      CC: Vasily Gorbik <gor@linux.ibm.com>
      Signed-off-by: default avatarYury Norov <yury.norov@gmail.com>
      2c523550
    • Yury Norov's avatar
      lib: add bitmap_{from,to}_arr64 · 0a97953f
      Yury Norov authored
      
      Manipulating 64-bit arrays with bitmap functions is potentially dangerous
      because on 32-bit BE machines the order of halfwords doesn't match.
      Another issue is that compiler may throw a warning about out-of-boundary
      access.
      
      This patch adds bitmap_{from,to}_arr64 functions in addition to existing
      bitmap_{from,to}_arr32.
      
      CC: Alexander Gordeev <agordeev@linux.ibm.com>
      CC: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      CC: Christian Borntraeger <borntraeger@linux.ibm.com>
      CC: Claudio Imbrenda <imbrenda@linux.ibm.com>
      CC: David Hildenbrand <david@redhat.com>
      CC: Heiko Carstens <hca@linux.ibm.com>
      CC: Janosch Frank <frankja@linux.ibm.com>
      CC: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      CC: Sven Schnelle <svens@linux.ibm.com>
      CC: Vasily Gorbik <gor@linux.ibm.com>
      Signed-off-by: default avatarYury Norov <yury.norov@gmail.com>
      0a97953f
    • Mauro Carvalho Chehab's avatar
      lib/bitmap.c make bitmap_print_bitmask_to_buf parseable · 430cd4a2
      Mauro Carvalho Chehab authored
      The documentation of such function is not on a proper ReST format,
      as reported by Sphinx:
      
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:532: WARNING: Unexpected indentation.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:526: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:532: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:532: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:533: WARNING: Block quote ends without a blank line; unexpected unindent.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:536: WARNING: Definition list ends without a blank line; unexpected unindent.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:542: WARNING: Unexpected indentation.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:536: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:536: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:543: WARNING: Block quote ends without a blank line; unexpected unindent.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:552: WARNING: Unexpected indentation.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:545: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:545: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:552: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:552: WARNING: Inline emphasis start-string without end-string.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:554: WARNING: Block quote ends without a blank line; unexpected unindent.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:556: WARNING: Definition list ends without a blank line; unexpected unindent.
          Documentation/core-api/kernel-api:81: ./lib/bitmap.c:580: WARNING: Unexpected indentation.
      
      So, the produced output at:
      
      	https://www.kernel.org/doc/html/latest/core-api/kernel-api.html?#c.bitmap_print_bitmask_to_buf
      
      
      
      is broken. Fix it by adding spaces and marking the literal blocks.
      
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
      Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
      Signed-off-by: default avatarYury Norov <yury.norov@gmail.com>
      430cd4a2
  11. Jun 02, 2022
    • Stephen Brennan's avatar
      assoc_array: Fix BUG_ON during garbage collect · d1dc8776
      Stephen Brennan authored
      A rare BUG_ON triggered in assoc_array_gc:
      
          [3430308.818153] kernel BUG at lib/assoc_array.c:1609!
      
      Which corresponded to the statement currently at line 1593 upstream:
      
          BUG_ON(assoc_array_ptr_is_meta(p));
      
      Using the data from the core dump, I was able to generate a userspace
      reproducer[1] and determine the cause of the bug.
      
      [1]: https://github.com/brenns10/kernel_stuff/tree/master/assoc_array_gc
      
      
      
      After running the iterator on the entire branch, an internal tree node
      looked like the following:
      
          NODE (nr_leaves_on_branch: 3)
            SLOT [0] NODE (2 leaves)
            SLOT [1] NODE (1 leaf)
            SLOT [2..f] NODE (empty)
      
      In the userspace reproducer, the pr_devel output when compressing this
      node was:
      
          -- compress node 0x5607cc089380 --
          free=0, leaves=0
          [0] retain node 2/1 [nx 0]
          [1] fold node 1/1 [nx 0]
          [2] fold node 0/1 [nx 2]
          [3] fold node 0/2 [nx 2]
          [4] fold node 0/3 [nx 2]
          [5] fold node 0/4 [nx 2]
          [6] fold node 0/5 [nx 2]
          [7] fold node 0/6 [nx 2]
          [8] fold node 0/7 [nx 2]
          [9] fold node 0/8 [nx 2]
          [10] fold node 0/9 [nx 2]
          [11] fold node 0/10 [nx 2]
          [12] fold node 0/11 [nx 2]
          [13] fold node 0/12 [nx 2]
          [14] fold node 0/13 [nx 2]
          [15] fold node 0/14 [nx 2]
          after: 3
      
      At slot 0, an internal node with 2 leaves could not be folded into the
      node, because there was only one available slot (slot 0). Thus, the
      internal node was retained. At slot 1, the node had one leaf, and was
      able to be folded in successfully. The remaining nodes had no leaves,
      and so were removed. By the end of the compression stage, there were 14
      free slots, and only 3 leaf nodes. The tree was ascended and then its
      parent node was compressed. When this node was seen, it could not be
      folded, due to the internal node it contained.
      
      The invariant for compression in this function is: whenever
      nr_leaves_on_branch < ASSOC_ARRAY_FAN_OUT, the node should contain all
      leaf nodes. The compression step currently cannot guarantee this, given
      the corner case shown above.
      
      To fix this issue, retry compression whenever we have retained a node,
      and yet nr_leaves_on_branch < ASSOC_ARRAY_FAN_OUT. This second
      compression will then allow the node in slot 1 to be folded in,
      satisfying the invariant. Below is the output of the reproducer once the
      fix is applied:
      
          -- compress node 0x560e9c562380 --
          free=0, leaves=0
          [0] retain node 2/1 [nx 0]
          [1] fold node 1/1 [nx 0]
          [2] fold node 0/1 [nx 2]
          [3] fold node 0/2 [nx 2]
          [4] fold node 0/3 [nx 2]
          [5] fold node 0/4 [nx 2]
          [6] fold node 0/5 [nx 2]
          [7] fold node 0/6 [nx 2]
          [8] fold node 0/7 [nx 2]
          [9] fold node 0/8 [nx 2]
          [10] fold node 0/9 [nx 2]
          [11] fold node 0/10 [nx 2]
          [12] fold node 0/11 [nx 2]
          [13] fold node 0/12 [nx 2]
          [14] fold node 0/13 [nx 2]
          [15] fold node 0/14 [nx 2]
          internal nodes remain despite enough space, retrying
          -- compress node 0x560e9c562380 --
          free=14, leaves=1
          [0] fold node 2/15 [nx 0]
          after: 3
      
      Changes
      =======
      DH:
       - Use false instead of 0.
       - Reorder the inserted lines in a couple of places to put retained before
         next_slot.
      
      ver #2)
       - Fix typo in pr_devel, correct comparison to "<="
      
      Fixes: 3cb98950 ("Add a generic associative array implementation.")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarStephen Brennan <stephen.s.brennan@oracle.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      cc: Andrew Morton <akpm@linux-foundation.org>
      cc: keyrings@vger.kernel.org
      Link: https://lore.kernel.org/r/20220511225517.407935-1-stephen.s.brennan@oracle.com/ # v1
      Link: https://lore.kernel.org/r/20220512215045.489140-1-stephen.s.brennan@oracle.com/
      
       # v2
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      d1dc8776
  12. May 28, 2022
    • Jason A. Donenfeld's avatar
      Revert "crypto: poly1305 - cleanup stray CRYPTO_LIB_POLY1305_RSIZE" · ca7984df
      Jason A. Donenfeld authored
      
      This reverts commit 8bdc2a19.
      
      It got merged a bit prematurely and shortly after the kernel test robot
      and Sudip pointed out build failures:
      
        arm: imx_v6_v7_defconfig and multi_v7_defconfig
        mips: decstation_64_defconfig, decstation_defconfig, decstation_r4k_defconfig
      
        In file included from crypto/chacha20poly1305.c:13:
        include/crypto/poly1305.h:56:46: error: 'CONFIG_CRYPTO_LIB_POLY1305_RSIZE' undeclared here (not in a function); did you mean 'CONFIG_CRYPTO_POLY1305_MODULE'?
           56 |                 struct poly1305_key opaque_r[CONFIG_CRYPTO_LIB_POLY1305_RSIZE];
              |                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      We could attempt to fix this by listing the dependencies piecemeal, but
      it's not as obvious as it looks: drivers like caam use this macro in
      headers even if there's no .o compiled in that makes use of it.  So
      actually fixing this might require a bit more of a comprehensive
      approach, rather than whack-a-mole with hunting down which drivers use
      which headers which use this macro.
      
      Therefore, this commit just reverts the change, and maybe the problem
      can be visited on the next rainy day.
      
      Reported-by: default avatarSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Fixes: 8bdc2a19 ("crypto: poly1305 - cleanup stray CRYPTO_LIB_POLY1305_RSIZE")
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      ca7984df
  13. May 27, 2022
  14. May 26, 2022
    • Uroš Bizjak's avatar
      locking/lockref: Use try_cmpxchg64 in CMPXCHG_LOOP macro · 3378323b
      Uroš Bizjak authored
      
      Use try_cmpxchg64 instead of cmpxchg64 in CMPXCHG_LOOP macro.
      x86 CMPXCHG instruction returns success in ZF flag, so this
      change saves a compare after cmpxchg (and related move instruction
      in front of cmpxchg). The main loop of lockref_get improves from:
      
        13:	48 89 c1             	mov    %rax,%rcx
        16:	48 c1 f9 20          	sar    $0x20,%rcx
        1a:	83 c1 01             	add    $0x1,%ecx
        1d:	48 89 ce             	mov    %rcx,%rsi
        20:	89 c1                	mov    %eax,%ecx
        22:	48 89 d0             	mov    %rdx,%rax
        25:	48 c1 e6 20          	shl    $0x20,%rsi
        29:	48 09 f1             	or     %rsi,%rcx
        2c:	f0 48 0f b1 4d 00    	lock cmpxchg %rcx,0x0(%rbp)
        32:	48 39 d0             	cmp    %rdx,%rax
        35:	75 17                	jne    4e <lockref_get+0x4e>
      
      to:
      
        13:	48 89 ca             	mov    %rcx,%rdx
        16:	48 c1 fa 20          	sar    $0x20,%rdx
        1a:	83 c2 01             	add    $0x1,%edx
        1d:	48 89 d6             	mov    %rdx,%rsi
        20:	89 ca                	mov    %ecx,%edx
        22:	48 c1 e6 20          	shl    $0x20,%rsi
        26:	48 09 f2             	or     %rsi,%rdx
        29:	f0 48 0f b1 55 00    	lock cmpxchg %rdx,0x0(%rbp)
        2f:	75 02                	jne    33 <lockref_get+0x33>
      
      [ Michael Ellerman and Mark Rutland confirm that code generation on
        powerpc and arm64 respectively is also ok, even though they do not
        have a native arch_try_cmpxchg() implementation, and rely on the
        default fallback case    - Linus ]
      
      Signed-off-by: default avatarUros Bizjak <ubizjak@gmail.com>
      Tested-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Tested-by: default avatarMark Rutland <mark.rutland@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Waiman.Long@hp.com
      Cc: paulmck@linux.vnet.ibm.com
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      3378323b
  15. May 22, 2022
  16. May 19, 2022
  17. May 18, 2022
    • Jason A. Donenfeld's avatar
      random: remove ratelimiting for in-kernel unseeded randomness · cc1e127b
      Jason A. Donenfeld authored
      
      The CONFIG_WARN_ALL_UNSEEDED_RANDOM debug option controls whether the
      kernel warns about all unseeded randomness or just the first instance.
      There's some complicated rate limiting and comparison to the previous
      caller, such that even with CONFIG_WARN_ALL_UNSEEDED_RANDOM enabled,
      developers still don't see all the messages or even an accurate count of
      how many were missed. This is the result of basically parallel
      mechanisms aimed at accomplishing more or less the same thing, added at
      different points in random.c history, which sort of compete with the
      first-instance-only limiting we have now.
      
      It turns out, however, that nobody cares about the first unseeded
      randomness instance of in-kernel users. The same first user has been
      there for ages now, and nobody is doing anything about it. It isn't even
      clear that anybody _can_ do anything about it. Most places that can do
      something about it have switched over to using get_random_bytes_wait()
      or wait_for_random_bytes(), which is the right thing to do, but there is
      still much code that needs randomness sometimes during init, and as a
      geeneral rule, if you're not using one of the _wait functions or the
      readiness notifier callback, you're bound to be doing it wrong just
      based on that fact alone.
      
      So warning about this same first user that can't easily change is simply
      not an effective mechanism for anything at all. Users can't do anything
      about it, as the Kconfig text points out -- the problem isn't in
      userspace code -- and kernel developers don't or more often can't react
      to it.
      
      Instead, show the warning for all instances when CONFIG_WARN_ALL_UNSEEDED_RANDOM
      is set, so that developers can debug things need be, or if it isn't set,
      don't show a warning at all.
      
      At the same time, CONFIG_WARN_ALL_UNSEEDED_RANDOM now implies setting
      random.ratelimit_disable=1 on by default, since if you care about one
      you probably care about the other too. And we can clean up usage around
      the related urandom_warning ratelimiter as well (whose behavior isn't
      changing), so that it properly counts missed messages after the 10
      message threshold is reached.
      
      Cc: Theodore Ts'o <tytso@mit.edu>
      Cc: Dominik Brodowski <linux@dominikbrodowski.net>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      cc1e127b
    • Jason A. Donenfeld's avatar
      random32: use real rng for non-deterministic randomness · d4150779
      Jason A. Donenfeld authored
      random32.c has two random number generators in it: one that is meant to
      be used deterministically, with some predefined seed, and one that does
      the same exact thing as random.c, except does it poorly. The first one
      has some use cases. The second one no longer does and can be replaced
      with calls to random.c's proper random number generator.
      
      The relatively recent siphash-based bad random32.c code was added in
      response to concerns that the prior random32.c was too deterministic.
      Out of fears that random.c was (at the time) too slow, this code was
      anonymously contributed. Then out of that emerged a kind of shadow
      entropy gathering system, with its own tentacles throughout various net
      code, added willy nilly.
      
      Stop👏making👏bespoke👏random👏number👏generators👏
      
      .
      
      Fortunately, recent advances in random.c mean that we can stop playing
      with this sketchiness, and just use get_random_u32(), which is now fast
      enough. In micro benchmarks using RDPMC, I'm seeing the same median
      cycle count between the two functions, with the mean being _slightly_
      higher due to batches refilling (which we can optimize further need be).
      However, when doing *real* benchmarks of the net functions that actually
      use these random numbers, the mean cycles actually *decreased* slightly
      (with the median still staying the same), likely because the additional
      prandom code means icache misses and complexity, whereas random.c is
      generally already being used by something else nearby.
      
      The biggest benefit of this is that there are many users of prandom who
      probably should be using cryptographically secure random numbers. This
      makes all of those accidental cases become secure by just flipping a
      switch. Later on, we can do a tree-wide cleanup to remove the static
      inline wrapper functions that this commit adds.
      
      There are also some low-ish hanging fruits for making this even faster
      in the future: a get_random_u16() function for use in the networking
      stack will give a 2x performance boost there, using SIMD for ChaCha20
      will let us compute 4 or 8 or 16 blocks of output in parallel, instead
      of just one, giving us large buffers for cheap, and introducing a
      get_random_*_bh() function that assumes irqs are already disabled will
      shave off a few cycles for ordinary calls. These are things we can chip
      away at down the road.
      
      Acked-by: default avatarJakub Kicinski <kuba@kernel.org>
      Acked-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      d4150779
    • Jason A. Donenfeld's avatar
      siphash: use one source of truth for siphash permutations · e73aaae2
      Jason A. Donenfeld authored
      
      The SipHash family of permutations is currently used in three places:
      
      - siphash.c itself, used in the ordinary way it was intended.
      - random32.c, in a construction from an anonymous contributor.
      - random.c, as part of its fast_mix function.
      
      Each one of these places reinvents the wheel with the same C code, same
      rotation constants, and same symmetry-breaking constants.
      
      This commit tidies things up a bit by placing macros for the
      permutations and constants into siphash.h, where each of the three .c
      users can access them. It also leaves a note dissuading more users of
      them from emerging.
      
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      e73aaae2
    • Al Viro's avatar
      percpu_ref_init(): clean ->percpu_count_ref on failure · a9171431
      Al Viro authored
      
      That way percpu_ref_exit() is safe after failing percpu_ref_init().
      At least one user (cgroup_create()) had a double-free that way;
      there might be other similar bugs.  Easier to fix in percpu_ref_init(),
      rather than playing whack-a-mole in sloppy users...
      
      Usual symptoms look like a messed refcounting in one of subsystems
      that use percpu allocations (might be percpu-refcount, might be
      something else).  Having refcounts for two different objects share
      memory is Not Nice(tm)...
      
      Reported-by: default avatar <syzbot+5b1e53987f858500ec00@syzkaller.appspotmail.com>
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      a9171431
  18. May 17, 2022
  19. May 16, 2022
  20. May 13, 2022
  21. May 12, 2022
    • Daniel Latypov's avatar
      kunit: bail out of test filtering logic quicker if OOM · a02353f4
      Daniel Latypov authored
      When filtering what tests to run (suites and/or cases) via
      kunit.filter_glob (e.g. kunit.py run <glob>), we allocate copies of
      suites.
      
      These allocations can fail, and we largely don't handle that.
      Note: realistically, this probably doesn't matter much.
      We're not allocating much memory and this happens early in boot, so if
      we can't do that, then there's likely far bigger problems.
      
      This patch makes us immediately bail out from the top-level function
      (kunit_filter_suites) with -ENOMEM if any of the underlying kmalloc()
      calls return NULL.
      
      Implementation note: we used to return NULL pointers from some functions
      to indicate either that all suites/tests were filtered out or there was
      an error allocating the new array.
      
      We'll log a short error in this case and not run any tests or print a
      TAP header. From a kunit.py user's perspective, they'll get a message
      about missing/invalid TAP output and have to dig into the test.log to
      see it. Since hitting this error seems so unlikely, it's probably fine
      to not invent a way to plumb this error message more visibly.
      
      See also: https://lore.kernel.org/linux-kselftest/20220329103919.2376818-1-lv.ruyi@zte.com.cn/
      
      
      
      Signed-off-by: default avatarDaniel Latypov <dlatypov@google.com>
      Reported-by: default avatarZeal Robot <zealci@zte.com.cn>
      Reported-by: default avatarLv Ruyi <lv.ruyi@zte.com.cn>
      Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      a02353f4
    • Daniel Latypov's avatar
      lib/Kconfig.debug: change KUnit tests to default to KUNIT_ALL_TESTS · dcbb2ee2
      Daniel Latypov authored
      
      This is in line with Documentation/dev-tools/kunit/style.rst.
      Some of these tests predate that so they don't follow this convention.
      
      With this and commit b0841b51 ("kunit: arch/um/configs: Enable
      KUNIT_ALL_TESTS by default"), kunit.py will now run these tests by
      default. This hopefully makes it easier to run and maintain the tests.
      If any of these were to start failing, people would notice much quicker.
      
      Note: this commit doesn't update LINEAR_RANGES_TEST since that would
      select its dependency (LINEAR_RANGES). We don't want KUNIT_ALL_TESTS
      to enable anything other than test kconfigs.
      
      Signed-off-by: default avatarDaniel Latypov <dlatypov@google.com>
      Reviewed-by: default avatarDavid Gow <davidgow@google.com>
      Reviewed-by: default avatarNico Pache <npache@redhat.com>
      Acked-by: default avatarNico Pache <npache@redhat.com>
      Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      dcbb2ee2
    • David Gow's avatar
      kunit: Rework kunit_resource allocation policy · ad69172e
      David Gow authored
      
      KUnit's test-managed resources can be created in two ways:
      - Using the kunit_add_resource() family of functions, which accept a
        struct kunit_resource pointer, typically allocated statically or on
        the stack during the test.
      - Using the kunit_alloc_resource() family of functions, which allocate a
        struct kunit_resource using kzalloc() behind the scenes.
      
      Both of these families of functions accept a 'free' function to be
      called when the resource is finally disposed of.
      
      At present, KUnit will kfree() the resource if this 'free' function is
      specified, and will not if it is NULL. However, this can lead
      kunit_alloc_resource() to leak memory (if no 'free' function is passed
      in), or kunit_add_resource() to incorrectly kfree() memory which was
      allocated by some other means (on the stack, as part of a larger
      allocation, etc), if a 'free' function is provided.
      
      Instead, always kfree() if the resource was allocated with
      kunit_alloc_resource(), and never kfree() if it was passed into
      kunit_add_resource() by the user. (If the user of kunit_add_resource()
      wishes the resource be kfree()ed, they can call kfree() on the resource
      from within the 'free' function.
      
      This is implemented by adding a 'should_free' member to
      struct kunit_resource and setting it appropriately. To facilitate this,
      the various resource add/alloc functions have been refactored somewhat,
      making them all call a __kunit_add_resource() helper after setting the
      'should_free' member appropriately. In the process, all other functions
      have been made static inline functions.
      
      Signed-off-by: default avatarDavid Gow <davidgow@google.com>
      Tested-by: default avatarDaniel Latypov <dlatypov@google.com>
      Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      ad69172e
Loading