commit a1a1b79c5ddb99186f1778d00551eebe18961479
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date:   Mon Jun 6 08:19:47 2022 +0200

    Linux 4.9.317
    
    Link: https://lore.kernel.org/r/20220603173812.524184588@linuxfoundation.org
    Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
    Tested-by: Guenter Roeck <linux@roeck-us.net>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 8fea6446ef7dd0e3a714ab0c477c0e9de900a48c
Author: Liu Jian <liujian56@huawei.com>
Date:   Sat Apr 16 18:57:59 2022 +0800

    bpf: Enlarge offset check value to INT_MAX in bpf_skb_{load,store}_bytes
    
    commit 45969b4152c1752089351cd6836a42a566d49bcf upstream.
    
    The data length of skb frags + frag_list may be greater than 0xffff, and
    skb_header_pointer can not handle negative offset. So, here INT_MAX is used
    to check the validity of offset. Add the same change to the related function
    skb_store_bytes.
    
    Fixes: 05c74e5e53f6 ("bpf: add bpf_skb_load_bytes helper")
    Signed-off-by: Liu Jian <liujian56@huawei.com>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Acked-by: Song Liu <songliubraving@fb.com>
    Link: https://lore.kernel.org/bpf/20220416105801.88708-2-liujian56@huawei.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit fea1d0940301378206955264a01778700fc9c16f
Author: Chuck Lever <chuck.lever@oracle.com>
Date:   Sat May 21 19:06:13 2022 -0400

    NFSD: Fix possible sleep during nfsd4_release_lockowner()
    
    commit ce3c4ad7f4ce5db7b4f08a1e237d8dd94b39180b upstream.
    
    nfsd4_release_lockowner() holds clp->cl_lock when it calls
    check_for_locks(). However, check_for_locks() calls nfsd_file_get()
    / nfsd_file_put() to access the backing inode's flc_posix list, and
    nfsd_file_put() can sleep if the inode was recently removed.
    
    Let's instead rely on the stateowner's reference count to gate
    whether the release is permitted. This should be a reliable
    indication of locks-in-use since file lock operations and
    ->lm_get_owner take appropriate references, which are released
    appropriately when file locks are removed.
    
    Reported-by: Dai Ngo <dai.ngo@oracle.com>
    Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 0b6f6940a2bd40a3a0796e93c28689033437948b
Author: Xiu Jianfeng <xiujianfeng@huawei.com>
Date:   Fri Mar 18 14:02:01 2022 +0800

    tpm: ibmvtpm: Correct the return value in tpm_ibmvtpm_probe()
    
    commit d0dc1a7100f19121f6e7450f9cdda11926aa3838 upstream.
    
    Currently it returns zero when CRQ response timed out, it should return
    an error code instead.
    
    Fixes: d8d74ea3c002 ("tpm: ibmvtpm: Wait for buffer to be set before proceeding")
    Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
    Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
    Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
    Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 27798cca4e54fe9c390396c4cc655480f827bbd5
Author: Sarthak Kukreti <sarthakkukreti@google.com>
Date:   Tue May 31 15:56:40 2022 -0400

    dm verity: set DM_TARGET_IMMUTABLE feature flag
    
    commit 4caae58406f8ceb741603eee460d79bacca9b1b5 upstream.
    
    The device-mapper framework provides a mechanism to mark targets as
    immutable (and hence fail table reloads that try to change the target
    type). Add the DM_TARGET_IMMUTABLE flag to the dm-verity target's
    feature flags to prevent switching the verity target with a different
    target type.
    
    Fixes: a4ffc152198e ("dm: add verity target")
    Cc: stable@vger.kernel.org
    Signed-off-by: Sarthak Kukreti <sarthakkukreti@google.com>
    Reviewed-by: Kees Cook <keescook@chromium.org>
    Signed-off-by: Mike Snitzer <snitzer@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 6adce527fe86f0156ea853742c951c01b1f0d6fc
Author: Mikulas Patocka <mpatocka@redhat.com>
Date:   Sun Apr 24 16:43:00 2022 -0400

    dm stats: add cond_resched when looping over entries
    
    commit bfe2b0146c4d0230b68f5c71a64380ff8d361f8b upstream.
    
    dm-stats can be used with a very large number of entries (it is only
    limited by 1/4 of total system memory), so add rescheduling points to
    the loops that iterate over the entries.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
    Signed-off-by: Mike Snitzer <snitzer@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 49e2a292b3d63d1971f80a929fc806702074559a
Author: Mikulas Patocka <mpatocka@redhat.com>
Date:   Mon Apr 25 08:53:29 2022 -0400

    dm crypt: make printing of the key constant-time
    
    commit 567dd8f34560fa221a6343729474536aa7ede4fd upstream.
    
    The device mapper dm-crypt target is using scnprintf("%02x", cc->key[i]) to
    report the current key to userspace. However, this is not a constant-time
    operation and it may leak information about the key via timing, via cache
    access patterns or via the branch predictor.
    
    Change dm-crypt's key printing to use "%c" instead of "%02x". Also
    introduce hex2asc() that carefully avoids any branching or memory
    accesses when converting a number in the range 0 ... 15 to an ascii
    character.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
    Tested-by: Milan Broz <gmazyland@gmail.com>
    Signed-off-by: Mike Snitzer <snitzer@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 41f6ea5b9aaa28b740d47ffe995a5013211fdbb0
Author: Kees Cook <keescook@chromium.org>
Date:   Mon Jan 31 16:09:47 2022 -0800

    exec: Force single empty string when argv is empty
    
    commit dcd46d897adb70d63e025f175a00a89797d31a43 upstream.
    
    Quoting[1] Ariadne Conill:
    
    "In several other operating systems, it is a hard requirement that the
    second argument to execve(2) be the name of a program, thus prohibiting
    a scenario where argc < 1. POSIX 2017 also recommends this behaviour,
    but it is not an explicit requirement[2]:
    
        The argument arg0 should point to a filename string that is
        associated with the process being started by one of the exec
        functions.
    ...
    Interestingly, Michael Kerrisk opened an issue about this in 2008[3],
    but there was no consensus to support fixing this issue then.
    Hopefully now that CVE-2021-4034 shows practical exploitative use[4]
    of this bug in a shellcode, we can reconsider.
    
    This issue is being tracked in the KSPP issue tracker[5]."
    
    While the initial code searches[6][7] turned up what appeared to be
    mostly corner case tests, trying to that just reject argv == NULL
    (or an immediately terminated pointer list) quickly started tripping[8]
    existing userspace programs.
    
    The next best approach is forcing a single empty string into argv and
    adjusting argc to match. The number of programs depending on argc == 0
    seems a smaller set than those calling execve with a NULL argv.
    
    Account for the additional stack space in bprm_stack_limits(). Inject an
    empty string when argc == 0 (and set argc = 1). Warn about the case so
    userspace has some notice about the change:
    
        process './argc0' launched './argc0' with NULL argv: empty string added
    
    Additionally WARN() and reject NULL argv usage for kernel threads.
    
    [1] https://lore.kernel.org/lkml/20220127000724.15106-1-ariadne@dereferenced.org/
    [2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html
    [3] https://bugzilla.kernel.org/show_bug.cgi?id=8408
    [4] https://www.qualys.com/2022/01/25/cve-2021-4034/pwnkit.txt
    [5] https://github.com/KSPP/linux/issues/176
    [6] https://codesearch.debian.net/search?q=execve%5C+*%5C%28%5B%5E%2C%5D%2B%2C+*NULL&literal=0
    [7] https://codesearch.debian.net/search?q=execlp%3F%5Cs*%5C%28%5B%5E%2C%5D%2B%2C%5Cs*NULL&literal=0
    [8] https://lore.kernel.org/lkml/20220131144352.GE16385@xsang-OptiPlex-9020/
    
    Reported-by: Ariadne Conill <ariadne@dereferenced.org>
    Reported-by: Michael Kerrisk <mtk.manpages@gmail.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Christian Brauner <brauner@kernel.org>
    Cc: Rich Felker <dalias@libc.org>
    Cc: Eric Biederman <ebiederm@xmission.com>
    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Cc: linux-fsdevel@vger.kernel.org
    Cc: stable@vger.kernel.org
    Signed-off-by: Kees Cook <keescook@chromium.org>
    Acked-by: Christian Brauner <brauner@kernel.org>
    Acked-by: Ariadne Conill <ariadne@dereferenced.org>
    Acked-by: Andy Lutomirski <luto@kernel.org>
    Link: https://lore.kernel.org/r/20220201000947.2453721-1-keescook@chromium.org
    [vegard: fixed conflicts due to missing
     886d7de631da71e30909980fdbf318f7caade262^- and
     3950e975431bc914f7e81b8f2a2dbdf2064acb0f^- and
     655c16a8ce9c15842547f40ce23fd148aeccc074]
    Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit d59073bedb7cf752b8cd4027dd0f67cf7ac4330f
Author: Haimin Zhang <tcs.kernel@gmail.com>
Date:   Wed Feb 16 16:40:38 2022 +0800

    block-map: add __GFP_ZERO flag for alloc_page in function bio_copy_kern
    
    commit cc8f7fe1f5eab010191aa4570f27641876fa1267 upstream.
    
    Add __GFP_ZERO flag for alloc_page in function bio_copy_kern to initialize
    the buffer of a bio.
    
    Signed-off-by: Haimin Zhang <tcs.kernel@gmail.com>
    Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Link: https://lore.kernel.org/r/20220216084038.15635-1-tcs.kernel@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>
    [DP: Backported to 4.19: Manually added __GFP_ZERO flag]
    Signed-off-by: Dragos-Marian Panait <dragos.panait@windriver.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 2441cedd2941c43c670252cc1761c6dc299b699f
Author: Gustavo A. R. Silva <gustavoars@kernel.org>
Date:   Wed Apr 27 17:47:14 2022 -0500

    drm/i915: Fix -Wstringop-overflow warning in call to intel_read_wm_latency()
    
    commit 336feb502a715909a8136eb6a62a83d7268a353b upstream.
    
    Fix the following -Wstringop-overflow warnings when building with GCC-11:
    
    drivers/gpu/drm/i915/intel_pm.c:3106:9: warning: ‘intel_read_wm_latency’ accessing 16 bytes in a region of size 10 [-Wstringop-overflow=]
     3106 |         intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency);
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    drivers/gpu/drm/i915/intel_pm.c:3106:9: note: referencing argument 2 of type ‘u16 *’ {aka ‘short unsigned int *’}
    drivers/gpu/drm/i915/intel_pm.c:2861:13: note: in a call to function ‘intel_read_wm_latency’
     2861 | static void intel_read_wm_latency(struct drm_i915_private *dev_priv,
          |             ^~~~~~~~~~~~~~~~~~~~~
    
    by removing the over-specified array size from the argument declarations.
    
    It seems that this code is actually safe because the size of the
    array depends on the hardware generation, and the function checks
    for that.
    
    Notice that wm can be an array of 5 elements:
    drivers/gpu/drm/i915/intel_pm.c:3109:   intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency);
    
    or an array of 8 elements:
    drivers/gpu/drm/i915/intel_pm.c:3131:   intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency);
    
    and the compiler legitimately complains about that.
    
    This helps with the ongoing efforts to globally enable
    -Wstringop-overflow.
    
    Link: https://github.com/KSPP/linux/issues/181
    Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit 54187b6c98a795d0bd14e9bcc8a3ef7fd89dfdc9
Author: Stephen Brennan <stephen.s.brennan@oracle.com>
Date:   Thu May 19 09:50:30 2022 +0100

    assoc_array: Fix BUG_ON during garbage collect
    
    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 "<="
    
    Fixes: 3cb989501c26 ("Add a generic associative array implementation.")
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
    Signed-off-by: David 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: Jarkko Sakkinen <jarkko@kernel.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

commit d570f31cc50ef23c76300fe848e8ff4299a7aba8
Author: Piyush Malgujar <pmalgujar@marvell.com>
Date:   Wed May 11 06:36:59 2022 -0700

    drivers: i2c: thunderx: Allow driver to work with ACPI defined TWSI controllers
    
    [ Upstream commit 03a35bc856ddc09f2cc1f4701adecfbf3b464cb3 ]
    
    Due to i2c->adap.dev.fwnode not being set, ACPI_COMPANION() wasn't properly
    found for TWSI controllers.
    
    Signed-off-by: Szymon Balcerak <sbalcerak@marvell.com>
    Signed-off-by: Piyush Malgujar <pmalgujar@marvell.com>
    Signed-off-by: Wolfram Sang <wsa@kernel.org>
    Signed-off-by: Sasha Levin <sashal@kernel.org>

commit 8c73e7c18e093c63bc0dbca2cca81e832f3b9fbc
Author: Thomas Bartschies <thomas.bartschies@cvk.de>
Date:   Wed May 18 08:32:18 2022 +0200

    net: af_key: check encryption module availability consistency
    
    [ Upstream commit 015c44d7bff3f44d569716117becd570c179ca32 ]
    
    Since the recent introduction supporting the SM3 and SM4 hash algos for IPsec, the kernel
    produces invalid pfkey acquire messages, when these encryption modules are disabled. This
    happens because the availability of the algos wasn't checked in all necessary functions.
    This patch adds these checks.
    
    Signed-off-by: Thomas Bartschies <thomas.bartschies@cvk.de>
    Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
    Signed-off-by: Sasha Levin <sashal@kernel.org>