05 Sep, 2022

1 commit

  • commit 874b301985ef2f89b8b592ad255e03fb6fbfe605 upstream.

    CRYPTO_LIB_CHACHA_GENERIC doesn't need to select XOR_BLOCKS. It perhaps
    was thought that it's needed for __crypto_xor, but that's not the case.

    Enabling XOR_BLOCKS is problematic because the XOR_BLOCKS code runs a
    benchmark when it is initialized. That causes a boot time regression on
    systems that didn't have it enabled before.

    Therefore, remove this unnecessary and problematic selection.

    Fixes: e56e18985596 ("lib/crypto: add prompts back to crypto libraries")
    Cc: stable@vger.kernel.org
    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Eric Biggers
     

31 Aug, 2022

1 commit

  • [ Upstream commit 6bae8ceb90ba76cdba39496db936164fa672b9be ]

    While reading rs->interval and rs->burst, they can be changed
    concurrently via sysctl (e.g. net_ratelimit_state). Thus, we
    need to add READ_ONCE() to their readers.

    Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
    Signed-off-by: Kuniyuki Iwashima
    Signed-off-by: David S. Miller
    Signed-off-by: Sasha Levin

    Kuniyuki Iwashima
     

25 Aug, 2022

1 commit

  • [ Upstream commit 0cc011c576aaa4de505046f7a6c90933d7c749a9 ]

    In some circumstances, attempts are made to add entries to or to remove
    entries from an uninitialized list. A prime example is
    amdgpu_bo_vm_destroy(): It is indirectly called from
    ttm_bo_init_reserved() if that function fails, and tries to remove an
    entry from a list. However, that list is only initialized in
    amdgpu_bo_create_vm() after the call to ttm_bo_init_reserved() returned
    success. This results in crashes such as

    BUG: kernel NULL pointer dereference, address: 0000000000000000
    #PF: supervisor read access in kernel mode
    #PF: error_code(0x0000) - not-present page
    PGD 0 P4D 0
    Oops: 0000 [#1] PREEMPT SMP NOPTI
    CPU: 1 PID: 1479 Comm: chrome Not tainted 5.10.110-15768-g29a72e65dae5
    Hardware name: Google Grunt/Grunt, BIOS Google_Grunt.11031.149.0 07/15/2020
    RIP: 0010:__list_del_entry_valid+0x26/0x7d
    ...
    Call Trace:
    amdgpu_bo_vm_destroy+0x48/0x8b
    ttm_bo_init_reserved+0x1d7/0x1e0
    amdgpu_bo_create+0x212/0x476
    ? amdgpu_bo_user_destroy+0x23/0x23
    ? kmem_cache_alloc+0x60/0x271
    amdgpu_bo_create_vm+0x40/0x7d
    amdgpu_vm_pt_create+0xe8/0x24b
    ...

    Check if the list's prev and next pointers are NULL to catch such problems.

    Link: https://lkml.kernel.org/r/20220531222951.92073-1-linux@roeck-us.net
    Signed-off-by: Guenter Roeck
    Cc: Steven Rostedt
    Signed-off-by: Andrew Morton
    Signed-off-by: Sasha Levin

    Guenter Roeck
     

17 Aug, 2022

8 commits

  • commit d6c14da474bf260d73953fbf7992c98d9112aec7 upstream.

    Using 3 blocks here doesn't give us much more than using 2, and it
    causes a stack frame size warning on certain compiler/config/arch
    combinations:

    lib/crypto/blake2s-selftest.c: In function 'blake2s_selftest':
    >> lib/crypto/blake2s-selftest.c:632:1: warning: the frame size of 1088 bytes is larger than 1024 bytes [-Wframe-larger-than=]
    632 | }
    | ^

    So this patch just reduces the block from 3 to 2, which makes the
    warning go away.

    Reported-by: kernel test robot
    Link: https://lore.kernel.org/linux-crypto/202206200851.gE3MHCgd-lkp@intel.com
    Fixes: 2d16803c562e ("crypto: blake2s - remove shash module")
    Signed-off-by: Jason A. Donenfeld
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Jason A. Donenfeld
     
  • [ Upstream commit 2d16803c562ecc644803d42ba98a8e0aef9c014e ]

    BLAKE2s has no currently known use as an shash. Just remove all of this
    unnecessary plumbing. Removing this shash was something we talked about
    back when we were making BLAKE2s a built-in, but I simply never got
    around to doing it. So this completes that project.

    Importantly, this fixs a bug in which the lib code depends on
    crypto_simd_disabled_for_test, causing linker errors.

    Also add more alignment tests to the selftests and compare SIMD and
    non-SIMD compression functions, to make up for what we lose from
    testmgr.c.

    Reported-by: gaochao
    Cc: Eric Biggers
    Cc: Ard Biesheuvel
    Cc: stable@vger.kernel.org
    Fixes: 6048fdcc5f26 ("lib/crypto: blake2s: include as built-in")
    Signed-off-by: Jason A. Donenfeld
    Signed-off-by: Herbert Xu
    Signed-off-by: Sasha Levin

    Jason A. Donenfeld
     
  • [ Upstream commit bd27acaac24e4b252ee28dddcabaee80456d0faf ]

    Currently instrumentation_end() won't be called if printk_ratelimit()
    returned false.

    Link: https://lkml.kernel.org/r/a636d8e0-ad32-5888-acac-671f7f553bb3@I-love.SAKURA.ne.jp
    Fixes: 126f21f0e8d46e2c ("lib/smp_processor_id: Move it into noinstr section")
    Signed-off-by: Tetsuo Handa
    Cc: Thomas Gleixner
    Cc: Alexandre Chartre
    Cc: Peter Zijlstra
    Signed-off-by: Andrew Morton
    Signed-off-by: Sasha Levin

    Tetsuo Handa
     
  • [ Upstream commit 55eb9a6c8bf3e2099863118ef53e02d9f44f85a8 ]

    The test_klp_callbacks_busy module conditionally blocks a future
    livepatch transition by busy waiting inside its workqueue function,
    busymod_work_func(). After scheduling this work, a test livepatch is
    loaded, introducing the transition under test.

    Both events are marked in the kernel log for later verification, but
    there is no synchronization to ensure that busymod_work_func() logs its
    function entry message before subsequent selftest commands log their own
    messages. This can lead to a rare test failure due to unexpected
    ordering like:

    # --- expected
    # +++ result
    # @@ -1,7 +1,7 @@
    # % modprobe test_klp_callbacks_busy block_transition=Y
    # test_klp_callbacks_busy: test_klp_callbacks_busy_init
    # -test_klp_callbacks_busy: busymod_work_func enter
    # % modprobe test_klp_callbacks_demo
    # +test_klp_callbacks_busy: busymod_work_func enter
    # livepatch: enabling patch 'test_klp_callbacks_demo'
    # livepatch: 'test_klp_callbacks_demo': initializing patching transition
    # test_klp_callbacks_demo: pre_patch_callback: vmlinux

    Force the module init function to wait until busymod_work_func() has
    started (and logged its message), before exiting to the next selftest
    steps.

    Fixes: 547840bd5ae5 ("selftests/livepatch: simplify test-klp-callbacks busy target tests")
    Signed-off-by: Joe Lawrence
    Reviewed-by: Petr Mladek
    Signed-off-by: Petr Mladek
    Link: https://lore.kernel.org/r/20220602203233.979681-1-joe.lawrence@redhat.com
    Signed-off-by: Sasha Levin

    Joe Lawrence
     
  • [ Upstream commit ed913b055a74b723976f8e885a3395162a0371e6 ]

    If make_device_exclusive_range() fails or returns pages marked for
    exclusive access less than required, remaining fields of pages will left
    uninitialized. So dmirror_atomic_map() will access those yet
    uninitialized fields of pages. To fix it, do dmirror_atomic_map() iff all
    pages are marked for exclusive access (we will break if mapped is less
    than required anyway) so we won't access those uninitialized fields of
    pages.

    Link: https://lkml.kernel.org/r/20220609130835.35110-1-linmiaohe@huawei.com
    Fixes: b659baea7546 ("mm: selftests for exclusive device memory")
    Signed-off-by: Miaohe Lin
    Cc: Jerome Glisse
    Cc: Alistair Popple
    Cc: Jason Gunthorpe
    Cc: Ralph Campbell
    Signed-off-by: Andrew Morton
    Signed-off-by: Sasha Levin

    Miaohe Lin
     
  • [ Upstream commit 9676feccacdb0571791c88b23e3b7ac4e7c9c457 ]

    The prototype of .features is netdev_features_t, it should use
    NETIF_F_LLTX and NETIF_F_HW_VLAN_STAG_TX, not NETIF_F_LLTX_BIT
    and NETIF_F_HW_VLAN_STAG_TX_BIT.

    Fixes: cf204a718357 ("bpf, testing: Introduce 'gso_linear_no_head_frag' skb_segment test")
    Signed-off-by: Jian Shen
    Acked-by: John Fastabend
    Link: https://lore.kernel.org/r/20220622135002.8263-1-shenjian15@huawei.com
    Signed-off-by: Alexei Starovoitov
    Signed-off-by: Sasha Levin

    Jian Shen
     
  • [ Upstream commit aaf50b1969d7933a51ea421b11432a7fb90974e3 ]

    GCC 12 continues to get smarter about array accesses. The KASAN tests
    are expecting to explicitly test out-of-bounds conditions at run-time,
    so hide the variable from GCC, to avoid warnings like:

    ../lib/test_kasan.c: In function 'ksize_uaf':
    ../lib/test_kasan.c:790:61: warning: array subscript 120 is outside array bounds of 'void[120]' [-Warray-bounds]
    790 | KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)ptr)[size]);
    | ~~~~~~~~~~~~~~~~~~~~~~^~~~~~
    ../lib/test_kasan.c:97:9: note: in definition of macro 'KUNIT_EXPECT_KASAN_FAIL'
    97 | expression; \
    | ^~~~~~~~~~

    Cc: Andrey Ryabinin
    Cc: Alexander Potapenko
    Cc: Andrey Konovalov
    Cc: Dmitry Vyukov
    Cc: Vincenzo Frascino
    Cc: kasan-dev@googlegroups.com
    Signed-off-by: Kees Cook
    Link: https://lore.kernel.org/r/20220608214024.1068451-1-keescook@chromium.org
    Signed-off-by: Sasha Levin

    Kees Cook
     
  • commit c3497fd009ef2c59eea60d21c3ac22de3585ed7d upstream.

    Unlike other copying operations on ITER_PIPE, copy_mc_to_iter() can
    result in a short copy. In that case we need to trim the unused
    buffers, as well as the length of partially filled one - it's not
    enough to set ->head, ->iov_offset and ->count to reflect how
    much had we copied. Not hard to fix, fortunately...

    I'd put a helper (pipe_discard_from(pipe, head)) into pipe_fs_i.h,
    rather than iov_iter.c - it has nothing to do with iov_iter and
    having it will allow us to avoid an ugly kludge in fs/splice.c.
    We could put it into lib/iov_iter.c for now and move it later,
    but I don't see the point going that way...

    Cc: stable@kernel.org # 4.19+
    Fixes: ca146f6f091e "lib/iov_iter: Fix pipe handling in _copy_to_iter_mcsafe()"
    Reviewed-by: Jeff Layton
    Reviewed-by: Christian Brauner (Microsoft)
    Signed-off-by: Al Viro
    Signed-off-by: Greg Kroah-Hartman

    Al Viro
     

12 Jul, 2022

1 commit

  • commit fc82bbf4dede758007763867d0282353c06d1121 upstream.

    This is another old BUG_ON() that just shouldn't exist (see also commit
    a382f8fee42c: "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: 88eca0207cf1 ("ida: simplified functions for id allocation")
    Reported-by: Itay Iellin
    Suggested-by: Matthew Wilcox
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Linus Torvalds
     

22 Jun, 2022

1 commit

  • commit abfed87e2a12bd246047d78c01d81eb9529f1d06 upstream.

    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: Zheng Bin
    Cc: Eric Biggers
    Cc: stable@vger.kernel.org
    Fixes: aa127963f1ca ("crypto: lib/curve25519 - re-add selftests")
    Signed-off-by: Jason A. Donenfeld
    Reviewed-by: Eric Biggers
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Jason A. Donenfeld
     

15 Jun, 2022

4 commits

  • commit 1c27f1fc1549f0e470429f5497a76ad28a37f21a upstream.

    Commit 6c77676645ad ("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: Sudip Mukherjee
    Link: https://lore.kernel.org/all/YqRyL2sIqQNDfky2@debian/
    Cc: Jeff Layton
    Cc: David Howells
    Cc: Al Viro
    Signed-off-by: Linus Torvalds
    Cc: Guenter Roeck
    Signed-off-by: Greg Kroah-Hartman

    Linus Torvalds
     
  • [ Upstream commit 0dfe54071d7c828a02917b595456bfde1afdddc9 ]

    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: Christophe de Dinechin
    Link: https://lore.kernel.org/lkml/20220414150855.2407137-3-dinechin@redhat.com/
    Cc: Alexey Dobriyan
    Cc: Yury Norov
    Cc: Andy Shevchenko
    Cc: Rasmus Villemoes
    Cc: Andrew Morton
    Cc: Zhen Lei
    Signed-off-by: Kees Cook
    Signed-off-by: Yury Norov
    Signed-off-by: Sasha Levin

    Kees Cook
     
  • [ Upstream commit 6c77676645ad42993e0a8bdb8dafa517851a352a ]

    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: 7ff5062079ef ("iov_iter: Add ITER_XARRAY")
    Reported-by: Jeff Layton
    Signed-off-by: David Howells
    cc: Alexander Viro
    cc: Dominique Martinet
    cc: Mike Marshall
    cc: Gao Xiang
    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: Al Viro
    Signed-off-by: Sasha Levin

    David Howells
     
  • [ Upstream commit 6014a23638cdee63a71ef13c51d7c563eb5829ee ]

    Since the APIs defined in the bootconfig.o are not individually used,
    it is meaningless to build it as library by lib-y. Use obj-y for that.

    Link: https://lkml.kernel.org/r/164921225875.1090670.15565363126983098971.stgit@devnote2

    Cc: Padmanabha Srinivasaiah
    Cc: Jonathan Corbet
    Cc: Randy Dunlap
    Cc: Nick Desaulniers
    Cc: Sami Tolvanen
    Cc: Nathan Chancellor
    Cc: Linux Kbuild mailing list
    Reported-by: Masahiro Yamada
    Signed-off-by: Masami Hiramatsu
    Signed-off-by: Steven Rostedt (Google)
    Signed-off-by: Sasha Levin

    Masami Hiramatsu
     

09 Jun, 2022

2 commits

  • commit 37dc573c0a547e1aed0c9abb480fab797bd3833f upstream.

    list_is_head() was added recently[1], and didn't have a KUnit test. The
    implementation is trivial, so it's not a particularly exciting test, but
    it'd be nice to get back to full coverage of the list functions.

    [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/list.h?id=0425473037db40d9e322631f2d4dc6ef51f97e88

    Signed-off-by: David Gow
    Acked-by: Daniel Latypov
    Acked-by: Brendan Higgins
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Shuah Khan
    Signed-off-by: Greg Kroah-Hartman

    David Gow
     
  • [ Upstream commit 38289a26e1b8a37755f3e07056ca416c1ee2a2e8 ]

    Commit 6d2426b2f258 ("kunit: Support skipped tests") switched to using
    `enum kunit_status` to track the result of running a test/suite since we
    now have more than just pass/fail.

    This callsite wasn't updated, silently converting to enum to a bool and
    then back.

    Fixes: 6d2426b2f258 ("kunit: Support skipped tests")
    Signed-off-by: Daniel Latypov
    Reviewed-by: Brendan Higgins
    Signed-off-by: Shuah Khan
    Signed-off-by: Sasha Levin

    Daniel Latypov
     

06 Jun, 2022

3 commits

  • commit e56e18985596617ae426ed5997fb2e737cffb58b upstream.

    Commit 6048fdcc5f269 ("lib/crypto: blake2s: include as built-in") took
    away a number of prompt texts from other crypto libraries. This makes
    values flip from built-in to module when oldconfig runs, and causes
    problems when these crypto libs need to be built in for thingslike
    BIG_KEYS.

    Fixes: 6048fdcc5f269 ("lib/crypto: blake2s: include as built-in")
    Cc: Herbert Xu
    Cc: linux-crypto@vger.kernel.org
    Signed-off-by: Justin M. Forbes
    [Jason: - moved menu into submenu of lib/ instead of root menu
    - fixed chacha sub-dependencies for CONFIG_CRYPTO]
    Signed-off-by: Jason A. Donenfeld
    Signed-off-by: Greg Kroah-Hartman

    Justin M. Forbes
     
  • commit d1dc87763f406d4e67caf16dbe438a5647692395 upstream.

    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 "
    Signed-off-by: Stephen Brennan
    Signed-off-by: David Howells
    cc: Andrew Morton
    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: Jarkko Sakkinen
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Stephen Brennan
     
  • [ Upstream commit a91714312eb16f9ecd1f7f8b3efe1380075f28d4 ]

    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: syzbot+5b1e53987f858500ec00@syzkaller.appspotmail.com
    Signed-off-by: Al Viro
    Signed-off-by: Sasha Levin

    Al Viro
     

30 May, 2022

8 commits

  • commit cc1e127bfa95b5fb2f9307e7168bf8b2b45b4c5e upstream.

    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
    Cc: Dominik Brodowski
    Signed-off-by: Jason A. Donenfeld
    Signed-off-by: Greg Kroah-Hartman

    Jason A. Donenfeld
     
  • commit e73aaae2fa9024832e1f42e30c787c7baf61d014 upstream.

    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: Jason A. Donenfeld
    Signed-off-by: Greg Kroah-Hartman

    Jason A. Donenfeld
     
  • commit 5acd35487dc911541672b3ffc322851769c32a56 upstream.

    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
    Cc: Theodore Ts'o
    Reviewed-by: Dominik Brodowski
    [Jason: for stable, also backported to crypto/drbg.c, not unexporting.]
    Signed-off-by: Jason A. Donenfeld
    Signed-off-by: Greg Kroah-Hartman

    Jason A. Donenfeld
     
  • commit 14c174633f349cb41ea90c2c0aaddac157012f74 upstream.

    These explicit tracepoints aren't really used and show sign of aging.
    It's work to keep these up to date, and before I attempted to keep them
    up to date, they weren't up to date, which indicates that they're not
    really used. These days there are better ways of introspecting anyway.

    Cc: Theodore Ts'o
    Reviewed-by: Dominik Brodowski
    Reviewed-by: Eric Biggers
    Signed-off-by: Jason A. Donenfeld
    Signed-off-by: Greg Kroah-Hartman

    Jason A. Donenfeld
     
  • commit d2a02e3c8bb6b347818518edff5a4b40ff52d6d8 upstream.

    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][ T0] __cfi_check_fail+0x54/0x58
    [ 0.000000][ T0] __cfi_slowpath_diag+0x354/0x4b0
    [ 0.000000][ T0] blake2s_update+0x14c/0x178
    [ 0.000000][ T0] _extract_entropy+0xf4/0x29c
    [ 0.000000][ T0] crng_initialize_primary+0x24/0x94
    [ 0.000000][ T0] rand_initialize+0x2c/0x6c
    [ 0.000000][ T0] start_kernel+0x2f8/0x65c
    [ 0.000000][ T0] __primary_switched+0xc4/0x7be4
    [ 0.000000][ T0] Rebooting in 5 seconds..

    Nonetheless, the function pointer method isn't so terrific anyway, so
    this patch replaces it with a simple boolean, which also gets inlined
    away. This successfully works around the Clang bug.

    In general, I'm not too keen on all of the indirection involved here; it
    clearly does more harm than good. Hopefully the whole thing can get
    cleaned up down the road when lib/crypto is overhauled more
    comprehensively. But for now, we go with a simple bandaid.

    Fixes: 6048fdcc5f26 ("lib/crypto: blake2s: include as built-in")
    Link: https://github.com/ClangBuiltLinux/linux/issues/1567
    Reported-by: Miles Chen
    Tested-by: Miles Chen
    Tested-by: Nathan Chancellor
    Tested-by: John Stultz
    Acked-by: Nick Desaulniers
    Reviewed-by: Eric Biggers
    Signed-off-by: Jason A. Donenfeld
    Signed-off-by: Greg Kroah-Hartman

    Jason A. Donenfeld
     
  • commit 9a1536b093bb5bf60689021275fd24d513bb8db0 upstream.

    With SHA-1 no longer being used for anything performance oriented, and
    also soon to be phased out entirely, we can make up for the space added
    by unrolled BLAKE2s by simply re-rolling SHA-1. Since SHA-1 is so much
    more complex, re-rolling it more or less takes care of the code size
    added by BLAKE2s. And eventually, hopefully we'll see SHA-1 removed
    entirely from most small kernel builds.

    Cc: Herbert Xu
    Cc: Ard Biesheuvel
    Tested-by: Geert Uytterhoeven
    Signed-off-by: Jason A. Donenfeld
    Signed-off-by: Greg Kroah-Hartman

    Jason A. Donenfeld
     
  • commit d8d83d8ab0a453e17e68b3a3bed1f940c34b8646 upstream.

    Basically nobody should use blake2s in an HMAC construction; it already
    has a keyed variant. But unfortunately for historical reasons, Noise,
    used by WireGuard, uses HKDF quite strictly, which means we have to use
    this. Because this really shouldn't be used by others, this commit moves
    it into wireguard's noise.c locally, so that kernels that aren't using
    WireGuard don't get this superfluous code baked in. On m68k systems,
    this shaves off ~314 bytes.

    Cc: Herbert Xu
    Tested-by: Geert Uytterhoeven
    Acked-by: Ard Biesheuvel
    Signed-off-by: Jason A. Donenfeld
    Signed-off-by: Greg Kroah-Hartman

    Jason A. Donenfeld
     
  • commit 6048fdcc5f269c7f31d774c295ce59081b36e6f9 upstream.

    In preparation for using blake2s in the RNG, we change the way that it
    is wired-in to the build system. Instead of using ifdefs to select the
    right symbol, we use weak symbols. And because ARM doesn't need the
    generic implementation, we make the generic one default only if an arch
    library doesn't need it already, and then have arch libraries that do
    need it opt-in. So that the arch libraries can remain tristate rather
    than bool, we then split the shash part from the glue code.

    Acked-by: Herbert Xu
    Acked-by: Ard Biesheuvel
    Acked-by: Greg Kroah-Hartman
    Cc: Masahiro Yamada
    Cc: linux-kbuild@vger.kernel.org
    Cc: linux-crypto@vger.kernel.org
    Signed-off-by: Jason A. Donenfeld
    Signed-off-by: Greg Kroah-Hartman

    Jason A. Donenfeld
     

18 May, 2022

1 commit

  • [ Upstream commit ee1444b5e1df4155b591d0d9b1e72853a99ea861 ]

    The W=2 build pointed out that the code wasn't initializing all the
    variables in the dim_cq_moder declarations with the struct initializers.
    The net change here is zero since these structs were already static
    const globals and were initialized with zeros by the compiler, but
    removing compiler warnings has value in and of itself.

    lib/dim/net_dim.c: At top level:
    lib/dim/net_dim.c:54:9: warning: missing initializer for field ‘comps’ of ‘const struct dim_cq_moder’ [-Wmissing-field-initializers]
    54 | NET_DIM_RX_EQE_PROFILES,
    | ^~~~~~~~~~~~~~~~~~~~~~~
    In file included from lib/dim/net_dim.c:6:
    ./include/linux/dim.h:45:13: note: ‘comps’ declared here
    45 | u16 comps;
    | ^~~~~

    and repeats for the tx struct, and once you fix the comps entry then
    the cq_period_mode field needs the same treatment.

    Use the commonly accepted style to indicate to the compiler that we
    know what we're doing, and add a comma at the end of each struct
    initializer to clean up the issue, and use explicit initializers
    for the fields we are initializing which makes the compiler happy.

    While here and fixing these lines, clean up the code slightly with
    a fix for the super long lines by removing the word "_MODERATION" from a
    couple defines only used in this file.

    Fixes: f8be17b81d44 ("lib/dim: Fix -Wunused-const-variable warnings")
    Signed-off-by: Jesse Brandeburg
    Link: https://lore.kernel.org/r/20220507011038.14568-1-jesse.brandeburg@intel.com
    Signed-off-by: Jakub Kicinski
    Signed-off-by: Sasha Levin

    Jesse Brandeburg
     

09 May, 2022

2 commits

  • commit e4d8a29997731b3bb14059024b24df9f784288d0 upstream.

    If we pass too short string to "hex2bin" (and the string size without
    the terminating NUL character is even), "hex2bin" reads one byte after
    the terminating NUL character. This patch fixes it.

    Note that hex_to_bin returns -1 on error and hex2bin return -EINVAL on
    error - so we can't just return the variable "hi" or "lo" on error.
    This inconsistency may be fixed in the next merge window, but for the
    purpose of fixing this bug, we just preserve the existing behavior and
    return -1 and -EINVAL.

    Signed-off-by: Mikulas Patocka
    Reviewed-by: Andy Shevchenko
    Fixes: b78049831ffe ("lib: add error checking to hex2bin")
    Cc: stable@vger.kernel.org
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Mikulas Patocka
     
  • commit e5be15767e7e284351853cbaba80cde8620341fb upstream.

    The function hex2bin is used to load cryptographic keys into device
    mapper targets dm-crypt and dm-integrity. It should take constant time
    independent on the processed data, so that concurrently running
    unprivileged code can't infer any information about the keys via
    microarchitectural convert channels.

    This patch changes the function hex_to_bin so that it contains no
    branches and no memory accesses.

    Note that this shouldn't cause performance degradation because the size
    of the new function is the same as the size of the old function (on
    x86-64) - and the new function causes no branch misprediction penalties.

    I compile-tested this function with gcc on aarch64 alpha arm hppa hppa64
    i386 ia64 m68k mips32 mips64 powerpc powerpc64 riscv sh4 s390x sparc32
    sparc64 x86_64 and with clang on aarch64 arm hexagon i386 mips32 mips64
    powerpc powerpc64 s390x sparc32 sparc64 x86_64 to verify that there are
    no branches in the generated code.

    Signed-off-by: Mikulas Patocka
    Cc: stable@vger.kernel.org
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Mikulas Patocka
     

01 May, 2022

4 commits

  • commit 3337ab08d08b1a375f88471d9c8b1cac968cb054 upstream

    Introduce a new nofault flag to indicate to iov_iter_get_pages not to
    fault in user pages.

    This is implemented by passing the FOLL_NOFAULT flag to get_user_pages,
    which causes get_user_pages to fail when it would otherwise fault in a
    page. We'll use the ->nofault flag to prevent iomap_dio_rw from faulting
    in pages when page faults are not allowed.

    Signed-off-by: Andreas Gruenbacher
    Signed-off-by: Anand Jain
    Signed-off-by: Greg Kroah-Hartman

    Andreas Gruenbacher
     
  • commit cdd591fc86e38ad3899196066219fbbd845f3162 upstream

    Introduce a new fault_in_iov_iter_writeable helper for safely faulting
    in an iterator for writing. Uses get_user_pages() to fault in the pages
    without actually writing to them, which would be destructive.

    We'll use fault_in_iov_iter_writeable in gfs2 once we've determined that
    the iterator passed to .read_iter isn't in memory.

    Signed-off-by: Andreas Gruenbacher
    Signed-off-by: Anand Jain
    Signed-off-by: Greg Kroah-Hartman

    Andreas Gruenbacher
     
  • commit a6294593e8a1290091d0b078d5d33da5e0cd3dfe upstream

    Turn iov_iter_fault_in_readable into a function that returns the number
    of bytes not faulted in, similar to copy_to_user, instead of returning a
    non-zero value when any of the requested pages couldn't be faulted in.
    This supports the existing users that require all pages to be faulted in
    as well as new users that are happy if any pages can be faulted in.

    Rename iov_iter_fault_in_readable to fault_in_iov_iter_readable to make
    sure this change doesn't silently break things.

    Signed-off-by: Andreas Gruenbacher
    Signed-off-by: Anand Jain
    Signed-off-by: Greg Kroah-Hartman

    Andreas Gruenbacher
     
  • commit bb523b406c849eef8f265a07cd7f320f1f177743 upstream

    Turn fault_in_pages_{readable,writeable} into versions that return the
    number of bytes not faulted in, similar to copy_to_user, instead of
    returning a non-zero value when any of the requested pages couldn't be
    faulted in. This supports the existing users that require all pages to
    be faulted in as well as new users that are happy if any pages can be
    faulted in.

    Rename the functions to fault_in_{readable,writeable} to make sure
    this change doesn't silently break things.

    Neither of these functions is entirely trivial and it doesn't seem
    useful to inline them, so move them to mm/gup.c.

    Signed-off-by: Andreas Gruenbacher
    Signed-off-by: Anand Jain
    Signed-off-by: Greg Kroah-Hartman

    Andreas Gruenbacher
     

14 Apr, 2022

3 commits

  • commit f39f21b3ddc7fc0f87eb6dc75ddc81b5bbfb7672 upstream.

    filter_irq_stacks() has little to do with the stackdepot implementation,
    except that it is usually used by users (such as KASAN) of stackdepot to
    reduce the stack trace.

    However, filter_irq_stacks() itself is not useful without a stack trace
    as obtained by stack_trace_save() and friends.

    Therefore, move filter_irq_stacks() to kernel/stacktrace.c, so that new
    users of filter_irq_stacks() do not have to start depending on
    STACKDEPOT only for filter_irq_stacks().

    Link: https://lkml.kernel.org/r/20210923104803.2620285-1-elver@google.com
    Signed-off-by: Marco Elver
    Acked-by: Dmitry Vyukov
    Cc: Alexander Potapenko
    Cc: Jann Horn
    Cc: Aleksandr Nogikh
    Cc: Taras Madan
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Marco Elver
     
  • commit 69d0db01e210e07fe915e5da91b54a867cda040f upstream.

    The object-size sanitizer is redundant to -Warray-bounds, and
    inappropriately performs its checks at run-time when all information
    needed for the evaluation is available at compile-time, making it quite
    difficult to use:

    https://bugzilla.kernel.org/show_bug.cgi?id=214861

    With -Warray-bounds almost enabled globally, it doesn't make sense to
    keep this around.

    Link: https://lkml.kernel.org/r/20211203235346.110809-1-keescook@chromium.org
    Signed-off-by: Kees Cook
    Reviewed-by: Marco Elver
    Cc: Masahiro Yamada
    Cc: Michal Marek
    Cc: Nick Desaulniers
    Cc: Nathan Chancellor
    Cc: Andrey Ryabinin
    Cc: "Peter Zijlstra (Intel)"
    Cc: Stephen Rothwell
    Cc: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Cc: Tadeusz Struk
    Signed-off-by: Greg Kroah-Hartman

    Kees Cook
     
  • commit eafc0a02391b7b36617b36c97c4b5d6832cf5e24 upstream.

    When partialDecoding, it is EOF if we've either filled the output buffer
    or can't proceed with reading an offset for following match.

    In some extreme corner cases when compressed data is suitably corrupted,
    UAF will occur. As reported by KASAN [1], LZ4_decompress_safe_partial
    may lead to read out of bound problem during decoding. lz4 upstream has
    fixed it [2] and this issue has been disscussed here [3] before.

    current decompression routine was ported from lz4 v1.8.3, bumping
    lib/lz4 to v1.9.+ is certainly a huge work to be done later, so, we'd
    better fix it first.

    [1] https://lore.kernel.org/all/000000000000830d1205cf7f0477@google.com/
    [2] https://github.com/lz4/lz4/commit/c5d6f8a8be3927c0bec91bcc58667a6cfad244ad#
    [3] https://lore.kernel.org/all/CC666AE8-4CA4-4951-B6FB-A2EFDE3AC03B@fb.com/

    Link: https://lkml.kernel.org/r/20211111105048.2006070-1-guoxuenan@huawei.com
    Reported-by: syzbot+63d688f1d899c588fb71@syzkaller.appspotmail.com
    Signed-off-by: Guo Xuenan
    Reviewed-by: Nick Terrell
    Acked-by: Gao Xiang
    Cc: Yann Collet
    Cc: Chengyang Fan
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Guo Xuenan