Skip to content
Snippets Groups Projects
  1. Dec 14, 2024
    • Yang Erkun's avatar
      nfsd: fix nfs4_openowner leak when concurrent nfsd4_open occur · 2d505a80
      Yang Erkun authored
      
      commit 98100e88 upstream.
      
      The action force umount(umount -f) will attempt to kill all rpc_task even
      umount operation may ultimately fail if some files remain open.
      Consequently, if an action attempts to open a file, it can potentially
      send two rpc_task to nfs server.
      
                         NFS CLIENT
      thread1                             thread2
      open("file")
      ...
      nfs4_do_open
       _nfs4_do_open
        _nfs4_open_and_get_state
         _nfs4_proc_open
          nfs4_run_open_task
           /* rpc_task1 */
           rpc_run_task
           rpc_wait_for_completion_task
      
                                          umount -f
                                          nfs_umount_begin
                                           rpc_killall_tasks
                                            rpc_signal_task
           rpc_task1 been wakeup
           and return -512
       _nfs4_do_open // while loop
          ...
          nfs4_run_open_task
           /* rpc_task2 */
           rpc_run_task
           rpc_wait_for_completion_task
      
      While processing an open request, nfsd will first attempt to find or
      allocate an nfs4_openowner. If it finds an nfs4_openowner that is not
      marked as NFS4_OO_CONFIRMED, this nfs4_openowner will released. Since
      two rpc_task can attempt to open the same file simultaneously from the
      client to server, and because two instances of nfsd can run
      concurrently, this situation can lead to lots of memory leak.
      Additionally, when we echo 0 to /proc/fs/nfsd/threads, warning will be
      triggered.
      
                          NFS SERVER
      nfsd1                  nfsd2       echo 0 > /proc/fs/nfsd/threads
      
      nfsd4_open
       nfsd4_process_open1
        find_or_alloc_open_stateowner
         // alloc oo1, stateid1
                             nfsd4_open
                              nfsd4_process_open1
                              find_or_alloc_open_stateowner
                              // find oo1, without NFS4_OO_CONFIRMED
                               release_openowner
                                unhash_openowner_locked
                                list_del_init(&oo->oo_perclient)
                                // cannot find this oo
                                // from client, LEAK!!!
                               alloc_stateowner // alloc oo2
      
       nfsd4_process_open2
        init_open_stateid
        // associate oo1
        // with stateid1, stateid1 LEAK!!!
        nfs4_get_vfs_file
        // alloc nfsd_file1 and nfsd_file_mark1
        // all LEAK!!!
      
                               nfsd4_process_open2
                               ...
      
                                          write_threads
                                           ...
                                           nfsd_destroy_serv
                                            nfsd_shutdown_net
                                             nfs4_state_shutdown_net
                                              nfs4_state_destroy_net
                                               destroy_client
                                                __destroy_client
                                                // won't find oo1!!!
                                           nfsd_shutdown_generic
                                            nfsd_file_cache_shutdown
                                             kmem_cache_destroy
                                             for nfsd_file_slab
                                             and nfsd_file_mark_slab
                                             // bark since nfsd_file1
                                             // and nfsd_file_mark1
                                             // still alive
      
      =======================================================================
      BUG nfsd_file (Not tainted): Objects remaining in nfsd_file on
      __kmem_cache_shutdown()
      -----------------------------------------------------------------------
      
      Slab 0xffd4000004438a80 objects=34 used=1 fp=0xff11000110e2ad28
      flags=0x17ffffc0000240(workingset|head|node=0|zone=2|lastcpupid=0x1fffff)
      CPU: 4 UID: 0 PID: 757 Comm: sh Not tainted 6.12.0-rc6+ #19
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
      1.16.1-2.fc37 04/01/2014
      Call Trace:
       <TASK>
       dump_stack_lvl+0x53/0x70
       slab_err+0xb0/0xf0
       __kmem_cache_shutdown+0x15c/0x310
       kmem_cache_destroy+0x66/0x160
       nfsd_file_cache_shutdown+0xac/0x210 [nfsd]
       nfsd_destroy_serv+0x251/0x2a0 [nfsd]
       nfsd_svc+0x125/0x1e0 [nfsd]
       write_threads+0x16a/0x2a0 [nfsd]
       nfsctl_transaction_write+0x74/0xa0 [nfsd]
       vfs_write+0x1ae/0x6d0
       ksys_write+0xc1/0x160
       do_syscall_64+0x5f/0x170
       entry_SYSCALL_64_after_hwframe+0x76/0x7e
      
      Disabling lock debugging due to kernel taint
      Object 0xff11000110e2ac38 @offset=3128
      Allocated in nfsd_file_do_acquire+0x20f/0xa30 [nfsd] age=1635 cpu=3
      pid=800
       nfsd_file_do_acquire+0x20f/0xa30 [nfsd]
       nfsd_file_acquire_opened+0x5f/0x90 [nfsd]
       nfs4_get_vfs_file+0x4c9/0x570 [nfsd]
       nfsd4_process_open2+0x713/0x1070 [nfsd]
       nfsd4_open+0x74b/0x8b0 [nfsd]
       nfsd4_proc_compound+0x70b/0xc20 [nfsd]
       nfsd_dispatch+0x1b4/0x3a0 [nfsd]
       svc_process_common+0x5b8/0xc50 [sunrpc]
       svc_process+0x2ab/0x3b0 [sunrpc]
       svc_handle_xprt+0x681/0xa20 [sunrpc]
       nfsd+0x183/0x220 [nfsd]
       kthread+0x199/0x1e0
       ret_from_fork+0x31/0x60
       ret_from_fork_asm+0x1a/0x30
      
      Add nfs4_openowner_unhashed to help found unhashed nfs4_openowner, and
      break nfsd4_open process to fix this problem.
      
      Cc: stable@vger.kernel.org # v5.4+
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Signed-off-by: default avatarYang Erkun <yangerkun@huawei.com>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2d505a80
    • Yang Erkun's avatar
      nfsd: make sure exp active before svc_export_show · 7fd29d28
      Yang Erkun authored
      
      commit be8f982c upstream.
      
      The function `e_show` was called with protection from RCU. This only
      ensures that `exp` will not be freed. Therefore, the reference count for
      `exp` can drop to zero, which will trigger a refcount use-after-free
      warning when `exp_get` is called. To resolve this issue, use
      `cache_get_rcu` to ensure that `exp` remains active.
      
      ------------[ cut here ]------------
      refcount_t: addition on 0; use-after-free.
      WARNING: CPU: 3 PID: 819 at lib/refcount.c:25
      refcount_warn_saturate+0xb1/0x120
      CPU: 3 UID: 0 PID: 819 Comm: cat Not tainted 6.12.0-rc3+ #1
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
      1.16.1-2.fc37 04/01/2014
      RIP: 0010:refcount_warn_saturate+0xb1/0x120
      ...
      Call Trace:
       <TASK>
       e_show+0x20b/0x230 [nfsd]
       seq_read_iter+0x589/0x770
       seq_read+0x1e5/0x270
       vfs_read+0x125/0x530
       ksys_read+0xc1/0x160
       do_syscall_64+0x5f/0x170
       entry_SYSCALL_64_after_hwframe+0x76/0x7e
      
      Fixes: bf18f163 ("NFSD: Using exp_get for export getting")
      Cc: stable@vger.kernel.org # 4.20+
      Signed-off-by: default avatarYang Erkun <yangerkun@huawei.com>
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7fd29d28
    • Yuan Can's avatar
      dm thin: Add missing destroy_work_on_stack() · 1f53e840
      Yuan Can authored
      
      commit e74fa244 upstream.
      
      This commit add missed destroy_work_on_stack() operations for pw->worker in
      pool_work_wait().
      
      Fixes: e7a3e871 ("dm thin: cleanup noflush_work to use a proper completion")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarYuan Can <yuancan@huawei.com>
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1f53e840
    • Kishon Vijay Abraham I's avatar
      PCI: keystone: Add link up check to ks_pcie_other_map_bus() · c6ac663c
      Kishon Vijay Abraham I authored
      commit 9e9ec8d8 upstream.
      
      K2G forwards the error triggered by a link-down state (e.g., no connected
      endpoint device) on the system bus for PCI configuration transactions;
      these errors are reported as an SError at system level, which is fatal and
      hangs the system.
      
      So, apply fix similar to how it was done in the DesignWare Core driver
      commit 15b23906 ("PCI: dwc: Add link up check in dw_child_pcie_ops.map_bus()").
      
      Fixes: 10a797c6 ("PCI: dwc: keystone: Use pci_ops for config space accessors")
      Link: https://lore.kernel.org/r/20240524105714.191642-3-s-vadapalli@ti.com
      
      
      Signed-off-by: default avatarKishon Vijay Abraham I <kishon@ti.com>
      Signed-off-by: default avatarSiddharth Vadapalli <s-vadapalli@ti.com>
      [kwilczynski: commit log, added tag for stable releases]
      Signed-off-by: default avatarKrzysztof Wilczyński <kwilczynski@kernel.org>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c6ac663c
    • Frank Li's avatar
      i3c: master: Fix miss free init_dyn_addr at i3c_master_put_i3c_addrs() · 093ecc6d
      Frank Li authored
      
      commit 30829905 upstream.
      
      if (dev->boardinfo && dev->boardinfo->init_dyn_addr)
                                            ^^^ here check "init_dyn_addr"
      	i3c_bus_set_addr_slot_status(&master->bus, dev->info.dyn_addr, ...)
      						             ^^^^
      							free "dyn_addr"
      Fix copy/paste error "dyn_addr" by replacing it with "init_dyn_addr".
      
      Cc: stable@kernel.org
      Fixes: 3a379bbc ("i3c: Add core I3C infrastructure")
      Reviewed-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Signed-off-by: default avatarFrank Li <Frank.Li@nxp.com>
      Link: https://lore.kernel.org/r/20241001162608.224039-1-Frank.Li@nxp.com
      
      
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      093ecc6d
    • Peter Griffin's avatar
      scsi: ufs: exynos: Fix hibern8 notify callbacks · aa10c746
      Peter Griffin authored
      commit ceef938b upstream.
      
      v1 of the patch which introduced the ufshcd_vops_hibern8_notify()
      callback used a bool instead of an enum. In v2 this was updated to an
      enum based on the review feedback in [1].
      
      ufs-exynos hibernate calls have always been broken upstream as it
      follows the v1 bool implementation.
      
      Link: https://patchwork.kernel.org/project/linux-scsi/patch/001f01d23994$719997c0$54ccc740$@samsung.com/
      
       [1]
      Fixes: 55f4b1f7 ("scsi: ufs: ufs-exynos: Add UFS host support for Exynos SoCs")
      Signed-off-by: default avatarPeter Griffin <peter.griffin@linaro.org>
      Link: https://lore.kernel.org/r/20241031150033.3440894-13-peter.griffin@linaro.org
      
      
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarTudor Ambarus <tudor.ambarus@linaro.org>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      aa10c746
    • Alexandru Ardelean's avatar
      util_macros.h: fix/rework find_closest() macros · a1f2aff0
      Alexandru Ardelean authored
      commit bc73b418 upstream.
      
      A bug was found in the find_closest() (find_closest_descending() is also
      affected after some testing), where for certain values with small
      progressions, the rounding (done by averaging 2 values) causes an
      incorrect index to be returned.  The rounding issues occur for
      progressions of 1, 2 and 3.  It goes away when the progression/interval
      between two values is 4 or larger.
      
      It's particularly bad for progressions of 1.  For example if there's an
      array of 'a = { 1, 2, 3 }', using 'find_closest(2, a ...)' would return 0
      (the index of '1'), rather than returning 1 (the index of '2').  This
      means that for exact values (with a progression of 1), find_closest() will
      misbehave and return the index of the value smaller than the one we're
      searching for.
      
      For progressions of 2 and 3, the exact values are obtained correctly; but
      values aren't approximated correctly (as one would expect).  Starting with
      progressions of 4, all seems to be good (one gets what one would expect).
      
      While one could argue that 'find_closest()' should not be used for arrays
      with progressions of 1 (i.e. '{1, 2, 3, ...}', the macro should still
      behave correctly.
      
      The bug was found while testing the 'drivers/iio/adc/ad7606.c',
      specifically the oversampling feature.
      For reference, the oversampling values are listed as:
         static const unsigned int ad7606_oversampling_avail[7] = {
                1, 2, 4, 8, 16, 32, 64,
         };
      
      When doing:
        1. $ echo 1 > /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           $ cat /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           1  # this is fine
        2. $ echo 2 > /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           $ cat /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           1  # this is wrong; 2 should be returned here
        3. $ echo 3 > /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           $ cat /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           2  # this is fine
        4. $ echo 4 > /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           $ cat /sys/bus/iio/devices/iio\:device0/oversampling_ratio
           4  # this is fine
      And from here-on, the values are as correct (one gets what one would
      expect.)
      
      While writing a kunit test for this bug, a peculiar issue was found for the
      array in the 'drivers/hwmon/ina2xx.c' & 'drivers/iio/adc/ina2xx-adc.c'
      drivers. While running the kunit test (for 'ina226_avg_tab' from these
      drivers):
        * idx = find_closest([-1 to 2], ina226_avg_tab, ARRAY_SIZE(ina226_avg_tab));
          This returns idx == 0, so value.
        * idx = find_closest(3, ina226_avg_tab, ARRAY_SIZE(ina226_avg_tab));
          This returns idx == 0, value 1; and now one could argue whether 3 is
          closer to 4 or to 1. This quirk only appears for value '3' in this
          array, but it seems to be a another rounding issue.
        * And from 4 onwards the 'find_closest'() works fine (one gets what one
          would expect).
      
      This change reworks the find_closest() macros to also check the difference
      between the left and right elements when 'x'. If the distance to the right
      is smaller (than the distance to the left), the index is incremented by 1.
      This also makes redundant the need for using the DIV_ROUND_CLOSEST() macro.
      
      In order to accommodate for any mix of negative + positive values, the
      internal variables '__fc_x', '__fc_mid_x', '__fc_left' & '__fc_right' are
      forced to 'long' type. This also addresses any potential bugs/issues with
      'x' being of an unsigned type. In those situations any comparison between
      signed & unsigned would be promoted to a comparison between 2 unsigned
      numbers; this is especially annoying when '__fc_left' & '__fc_right'
      underflow.
      
      The find_closest_descending() macro was also reworked and duplicated from
      the find_closest(), and it is being iterated in reverse. The main reason
      for this is to get the same indices as 'find_closest()' (but in reverse).
      The comparison for '__fc_right < __fc_left' favors going the array in
      ascending order.
      For example for array '{ 1024, 512, 256, 128, 64, 16, 4, 1 }' and x = 3, we
      get:
          __fc_mid_x = 2
          __fc_left = -1
          __fc_right = -2
          Then '__fc_right < __fc_left' evaluates to true and '__fc_i++' becomes 7
          which is not quite incorrect, but 3 is closer to 4 than to 1.
      
      This change has been validated with the kunit from the next patch.
      
      Link: https://lkml.kernel.org/r/20241105145406.554365-1-aardelean@baylibre.com
      
      
      Fixes: 95d11952 ("util_macros.h: add find_closest() macro")
      Signed-off-by: default avatarAlexandru Ardelean <aardelean@baylibre.com>
      Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a1f2aff0
    • Zicheng Qu's avatar
      ad7780: fix division by zero in ad7780_write_raw() · afc1e3c0
      Zicheng Qu authored
      
      commit c174b53e upstream.
      
      In the ad7780_write_raw() , val2 can be zero, which might lead to a
      division by zero error in DIV_ROUND_CLOSEST(). The ad7780_write_raw()
      is based on iio_info's write_raw. While val is explicitly declared that
      can be zero (in read mode), val2 is not specified to be non-zero.
      
      Fixes: 9085daa4 ("staging: iio: ad7780: add gain & filter gpio support")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarZicheng Qu <quzicheng@huawei.com>
      Link: https://patch.msgid.link/20241028142027.1032332-1-quzicheng@huawei.com
      
      
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      afc1e3c0
    • Filipe Manana's avatar
      btrfs: ref-verify: fix use-after-free after invalid ref action · 6fd018aa
      Filipe Manana authored
      
      [ Upstream commit 7c4e39f9 ]
      
      At btrfs_ref_tree_mod() after we successfully inserted the new ref entry
      (local variable 'ref') into the respective block entry's rbtree (local
      variable 'be'), if we find an unexpected action of BTRFS_DROP_DELAYED_REF,
      we error out and free the ref entry without removing it from the block
      entry's rbtree. Then in the error path of btrfs_ref_tree_mod() we call
      btrfs_free_ref_cache(), which iterates over all block entries and then
      calls free_block_entry() for each one, and there we will trigger a
      use-after-free when we are called against the block entry to which we
      added the freed ref entry to its rbtree, since the rbtree still points
      to the block entry, as we didn't remove it from the rbtree before freeing
      it in the error path at btrfs_ref_tree_mod(). Fix this by removing the
      new ref entry from the rbtree before freeing it.
      
      Syzbot report this with the following stack traces:
      
         BTRFS error (device loop0 state EA):   Ref action 2, root 5, ref_root 0, parent 8564736, owner 0, offset 0, num_refs 18446744073709551615
            __btrfs_mod_ref+0x7dd/0xac0 fs/btrfs/extent-tree.c:2523
            update_ref_for_cow+0x9cd/0x11f0 fs/btrfs/ctree.c:512
            btrfs_force_cow_block+0x9f6/0x1da0 fs/btrfs/ctree.c:594
            btrfs_cow_block+0x35e/0xa40 fs/btrfs/ctree.c:754
            btrfs_search_slot+0xbdd/0x30d0 fs/btrfs/ctree.c:2116
            btrfs_insert_empty_items+0x9c/0x1a0 fs/btrfs/ctree.c:4314
            btrfs_insert_empty_item fs/btrfs/ctree.h:669 [inline]
            btrfs_insert_orphan_item+0x1f1/0x320 fs/btrfs/orphan.c:23
            btrfs_orphan_add+0x6d/0x1a0 fs/btrfs/inode.c:3482
            btrfs_unlink+0x267/0x350 fs/btrfs/inode.c:4293
            vfs_unlink+0x365/0x650 fs/namei.c:4469
            do_unlinkat+0x4ae/0x830 fs/namei.c:4533
            __do_sys_unlinkat fs/namei.c:4576 [inline]
            __se_sys_unlinkat fs/namei.c:4569 [inline]
            __x64_sys_unlinkat+0xcc/0xf0 fs/namei.c:4569
            do_syscall_x64 arch/x86/entry/common.c:52 [inline]
            do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
            entry_SYSCALL_64_after_hwframe+0x77/0x7f
         BTRFS error (device loop0 state EA):   Ref action 1, root 5, ref_root 5, parent 0, owner 260, offset 0, num_refs 1
            __btrfs_mod_ref+0x76b/0xac0 fs/btrfs/extent-tree.c:2521
            update_ref_for_cow+0x96a/0x11f0
            btrfs_force_cow_block+0x9f6/0x1da0 fs/btrfs/ctree.c:594
            btrfs_cow_block+0x35e/0xa40 fs/btrfs/ctree.c:754
            btrfs_search_slot+0xbdd/0x30d0 fs/btrfs/ctree.c:2116
            btrfs_lookup_inode+0xdc/0x480 fs/btrfs/inode-item.c:411
            __btrfs_update_delayed_inode+0x1e7/0xb90 fs/btrfs/delayed-inode.c:1030
            btrfs_update_delayed_inode fs/btrfs/delayed-inode.c:1114 [inline]
            __btrfs_commit_inode_delayed_items+0x2318/0x24a0 fs/btrfs/delayed-inode.c:1137
            __btrfs_run_delayed_items+0x213/0x490 fs/btrfs/delayed-inode.c:1171
            btrfs_commit_transaction+0x8a8/0x3740 fs/btrfs/transaction.c:2313
            prepare_to_relocate+0x3c4/0x4c0 fs/btrfs/relocation.c:3586
            relocate_block_group+0x16c/0xd40 fs/btrfs/relocation.c:3611
            btrfs_relocate_block_group+0x77d/0xd90 fs/btrfs/relocation.c:4081
            btrfs_relocate_chunk+0x12c/0x3b0 fs/btrfs/volumes.c:3377
            __btrfs_balance+0x1b0f/0x26b0 fs/btrfs/volumes.c:4161
            btrfs_balance+0xbdc/0x10c0 fs/btrfs/volumes.c:4538
         BTRFS error (device loop0 state EA):   Ref action 2, root 5, ref_root 0, parent 8564736, owner 0, offset 0, num_refs 18446744073709551615
            __btrfs_mod_ref+0x7dd/0xac0 fs/btrfs/extent-tree.c:2523
            update_ref_for_cow+0x9cd/0x11f0 fs/btrfs/ctree.c:512
            btrfs_force_cow_block+0x9f6/0x1da0 fs/btrfs/ctree.c:594
            btrfs_cow_block+0x35e/0xa40 fs/btrfs/ctree.c:754
            btrfs_search_slot+0xbdd/0x30d0 fs/btrfs/ctree.c:2116
            btrfs_lookup_inode+0xdc/0x480 fs/btrfs/inode-item.c:411
            __btrfs_update_delayed_inode+0x1e7/0xb90 fs/btrfs/delayed-inode.c:1030
            btrfs_update_delayed_inode fs/btrfs/delayed-inode.c:1114 [inline]
            __btrfs_commit_inode_delayed_items+0x2318/0x24a0 fs/btrfs/delayed-inode.c:1137
            __btrfs_run_delayed_items+0x213/0x490 fs/btrfs/delayed-inode.c:1171
            btrfs_commit_transaction+0x8a8/0x3740 fs/btrfs/transaction.c:2313
            prepare_to_relocate+0x3c4/0x4c0 fs/btrfs/relocation.c:3586
            relocate_block_group+0x16c/0xd40 fs/btrfs/relocation.c:3611
            btrfs_relocate_block_group+0x77d/0xd90 fs/btrfs/relocation.c:4081
            btrfs_relocate_chunk+0x12c/0x3b0 fs/btrfs/volumes.c:3377
            __btrfs_balance+0x1b0f/0x26b0 fs/btrfs/volumes.c:4161
            btrfs_balance+0xbdc/0x10c0 fs/btrfs/volumes.c:4538
         ==================================================================
         BUG: KASAN: slab-use-after-free in rb_first+0x69/0x70 lib/rbtree.c:473
         Read of size 8 at addr ffff888042d1af38 by task syz.0.0/5329
      
         CPU: 0 UID: 0 PID: 5329 Comm: syz.0.0 Not tainted 6.12.0-rc7-syzkaller #0
         Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
         Call Trace:
          <TASK>
          __dump_stack lib/dump_stack.c:94 [inline]
          dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
          print_address_description mm/kasan/report.c:377 [inline]
          print_report+0x169/0x550 mm/kasan/report.c:488
          kasan_report+0x143/0x180 mm/kasan/report.c:601
          rb_first+0x69/0x70 lib/rbtree.c:473
          free_block_entry+0x78/0x230 fs/btrfs/ref-verify.c:248
          btrfs_free_ref_cache+0xa3/0x100 fs/btrfs/ref-verify.c:917
          btrfs_ref_tree_mod+0x139f/0x15e0 fs/btrfs/ref-verify.c:898
          btrfs_free_extent+0x33c/0x380 fs/btrfs/extent-tree.c:3544
          __btrfs_mod_ref+0x7dd/0xac0 fs/btrfs/extent-tree.c:2523
          update_ref_for_cow+0x9cd/0x11f0 fs/btrfs/ctree.c:512
          btrfs_force_cow_block+0x9f6/0x1da0 fs/btrfs/ctree.c:594
          btrfs_cow_block+0x35e/0xa40 fs/btrfs/ctree.c:754
          btrfs_search_slot+0xbdd/0x30d0 fs/btrfs/ctree.c:2116
          btrfs_lookup_inode+0xdc/0x480 fs/btrfs/inode-item.c:411
          __btrfs_update_delayed_inode+0x1e7/0xb90 fs/btrfs/delayed-inode.c:1030
          btrfs_update_delayed_inode fs/btrfs/delayed-inode.c:1114 [inline]
          __btrfs_commit_inode_delayed_items+0x2318/0x24a0 fs/btrfs/delayed-inode.c:1137
          __btrfs_run_delayed_items+0x213/0x490 fs/btrfs/delayed-inode.c:1171
          btrfs_commit_transaction+0x8a8/0x3740 fs/btrfs/transaction.c:2313
          prepare_to_relocate+0x3c4/0x4c0 fs/btrfs/relocation.c:3586
          relocate_block_group+0x16c/0xd40 fs/btrfs/relocation.c:3611
          btrfs_relocate_block_group+0x77d/0xd90 fs/btrfs/relocation.c:4081
          btrfs_relocate_chunk+0x12c/0x3b0 fs/btrfs/volumes.c:3377
          __btrfs_balance+0x1b0f/0x26b0 fs/btrfs/volumes.c:4161
          btrfs_balance+0xbdc/0x10c0 fs/btrfs/volumes.c:4538
          btrfs_ioctl_balance+0x493/0x7c0 fs/btrfs/ioctl.c:3673
          vfs_ioctl fs/ioctl.c:51 [inline]
          __do_sys_ioctl fs/ioctl.c:907 [inline]
          __se_sys_ioctl+0xf9/0x170 fs/ioctl.c:893
          do_syscall_x64 arch/x86/entry/common.c:52 [inline]
          do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
          entry_SYSCALL_64_after_hwframe+0x77/0x7f
         RIP: 0033:0x7f996df7e719
         RSP: 002b:00007f996ede7038 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
         RAX: ffffffffffffffda RBX: 00007f996e135f80 RCX: 00007f996df7e719
         RDX: 0000000020000180 RSI: 00000000c4009420 RDI: 0000000000000004
         RBP: 00007f996dff139e R08: 0000000000000000 R09: 0000000000000000
         R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
         R13: 0000000000000000 R14: 00007f996e135f80 R15: 00007fff79f32e68
          </TASK>
      
         Allocated by task 5329:
          kasan_save_stack mm/kasan/common.c:47 [inline]
          kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
          poison_kmalloc_redzone mm/kasan/common.c:377 [inline]
          __kasan_kmalloc+0x98/0xb0 mm/kasan/common.c:394
          kasan_kmalloc include/linux/kasan.h:257 [inline]
          __kmalloc_cache_noprof+0x19c/0x2c0 mm/slub.c:4295
          kmalloc_noprof include/linux/slab.h:878 [inline]
          kzalloc_noprof include/linux/slab.h:1014 [inline]
          btrfs_ref_tree_mod+0x264/0x15e0 fs/btrfs/ref-verify.c:701
          btrfs_free_extent+0x33c/0x380 fs/btrfs/extent-tree.c:3544
          __btrfs_mod_ref+0x7dd/0xac0 fs/btrfs/extent-tree.c:2523
          update_ref_for_cow+0x9cd/0x11f0 fs/btrfs/ctree.c:512
          btrfs_force_cow_block+0x9f6/0x1da0 fs/btrfs/ctree.c:594
          btrfs_cow_block+0x35e/0xa40 fs/btrfs/ctree.c:754
          btrfs_search_slot+0xbdd/0x30d0 fs/btrfs/ctree.c:2116
          btrfs_lookup_inode+0xdc/0x480 fs/btrfs/inode-item.c:411
          __btrfs_update_delayed_inode+0x1e7/0xb90 fs/btrfs/delayed-inode.c:1030
          btrfs_update_delayed_inode fs/btrfs/delayed-inode.c:1114 [inline]
          __btrfs_commit_inode_delayed_items+0x2318/0x24a0 fs/btrfs/delayed-inode.c:1137
          __btrfs_run_delayed_items+0x213/0x490 fs/btrfs/delayed-inode.c:1171
          btrfs_commit_transaction+0x8a8/0x3740 fs/btrfs/transaction.c:2313
          prepare_to_relocate+0x3c4/0x4c0 fs/btrfs/relocation.c:3586
          relocate_block_group+0x16c/0xd40 fs/btrfs/relocation.c:3611
          btrfs_relocate_block_group+0x77d/0xd90 fs/btrfs/relocation.c:4081
          btrfs_relocate_chunk+0x12c/0x3b0 fs/btrfs/volumes.c:3377
          __btrfs_balance+0x1b0f/0x26b0 fs/btrfs/volumes.c:4161
          btrfs_balance+0xbdc/0x10c0 fs/btrfs/volumes.c:4538
          btrfs_ioctl_balance+0x493/0x7c0 fs/btrfs/ioctl.c:3673
          vfs_ioctl fs/ioctl.c:51 [inline]
          __do_sys_ioctl fs/ioctl.c:907 [inline]
          __se_sys_ioctl+0xf9/0x170 fs/ioctl.c:893
          do_syscall_x64 arch/x86/entry/common.c:52 [inline]
          do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
          entry_SYSCALL_64_after_hwframe+0x77/0x7f
      
         Freed by task 5329:
          kasan_save_stack mm/kasan/common.c:47 [inline]
          kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
          kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:579
          poison_slab_object mm/kasan/common.c:247 [inline]
          __kasan_slab_free+0x59/0x70 mm/kasan/common.c:264
          kasan_slab_free include/linux/kasan.h:230 [inline]
          slab_free_hook mm/slub.c:2342 [inline]
          slab_free mm/slub.c:4579 [inline]
          kfree+0x1a0/0x440 mm/slub.c:4727
          btrfs_ref_tree_mod+0x136c/0x15e0
          btrfs_free_extent+0x33c/0x380 fs/btrfs/extent-tree.c:3544
          __btrfs_mod_ref+0x7dd/0xac0 fs/btrfs/extent-tree.c:2523
          update_ref_for_cow+0x9cd/0x11f0 fs/btrfs/ctree.c:512
          btrfs_force_cow_block+0x9f6/0x1da0 fs/btrfs/ctree.c:594
          btrfs_cow_block+0x35e/0xa40 fs/btrfs/ctree.c:754
          btrfs_search_slot+0xbdd/0x30d0 fs/btrfs/ctree.c:2116
          btrfs_lookup_inode+0xdc/0x480 fs/btrfs/inode-item.c:411
          __btrfs_update_delayed_inode+0x1e7/0xb90 fs/btrfs/delayed-inode.c:1030
          btrfs_update_delayed_inode fs/btrfs/delayed-inode.c:1114 [inline]
          __btrfs_commit_inode_delayed_items+0x2318/0x24a0 fs/btrfs/delayed-inode.c:1137
          __btrfs_run_delayed_items+0x213/0x490 fs/btrfs/delayed-inode.c:1171
          btrfs_commit_transaction+0x8a8/0x3740 fs/btrfs/transaction.c:2313
          prepare_to_relocate+0x3c4/0x4c0 fs/btrfs/relocation.c:3586
          relocate_block_group+0x16c/0xd40 fs/btrfs/relocation.c:3611
          btrfs_relocate_block_group+0x77d/0xd90 fs/btrfs/relocation.c:4081
          btrfs_relocate_chunk+0x12c/0x3b0 fs/btrfs/volumes.c:3377
          __btrfs_balance+0x1b0f/0x26b0 fs/btrfs/volumes.c:4161
          btrfs_balance+0xbdc/0x10c0 fs/btrfs/volumes.c:4538
          btrfs_ioctl_balance+0x493/0x7c0 fs/btrfs/ioctl.c:3673
          vfs_ioctl fs/ioctl.c:51 [inline]
          __do_sys_ioctl fs/ioctl.c:907 [inline]
          __se_sys_ioctl+0xf9/0x170 fs/ioctl.c:893
          do_syscall_x64 arch/x86/entry/common.c:52 [inline]
          do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
          entry_SYSCALL_64_after_hwframe+0x77/0x7f
      
         The buggy address belongs to the object at ffff888042d1af00
          which belongs to the cache kmalloc-64 of size 64
         The buggy address is located 56 bytes inside of
          freed 64-byte region [ffff888042d1af00, ffff888042d1af40)
      
         The buggy address belongs to the physical page:
         page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x42d1a
         anon flags: 0x4fff00000000000(node=1|zone=1|lastcpupid=0x7ff)
         page_type: f5(slab)
         raw: 04fff00000000000 ffff88801ac418c0 0000000000000000 dead000000000001
         raw: 0000000000000000 0000000000200020 00000001f5000000 0000000000000000
         page dumped because: kasan: bad access detected
         page_owner tracks the page as allocated
         page last allocated via order 0, migratetype Unmovable, gfp_mask 0x52c40(GFP_NOFS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 5055, tgid 5055 (dhcpcd-run-hook), ts 40377240074, free_ts 40376848335
          set_page_owner include/linux/page_owner.h:32 [inline]
          post_alloc_hook+0x1f3/0x230 mm/page_alloc.c:1541
          prep_new_page mm/page_alloc.c:1549 [inline]
          get_page_from_freelist+0x3649/0x3790 mm/page_alloc.c:3459
          __alloc_pages_noprof+0x292/0x710 mm/page_alloc.c:4735
          alloc_pages_mpol_noprof+0x3e8/0x680 mm/mempolicy.c:2265
          alloc_slab_page+0x6a/0x140 mm/slub.c:2412
          allocate_slab+0x5a/0x2f0 mm/slub.c:2578
          new_slab mm/slub.c:2631 [inline]
          ___slab_alloc+0xcd1/0x14b0 mm/slub.c:3818
          __slab_alloc+0x58/0xa0 mm/slub.c:3908
          __slab_alloc_node mm/slub.c:3961 [inline]
          slab_alloc_node mm/slub.c:4122 [inline]
          __do_kmalloc_node mm/slub.c:4263 [inline]
          __kmalloc_noprof+0x25a/0x400 mm/slub.c:4276
          kmalloc_noprof include/linux/slab.h:882 [inline]
          kzalloc_noprof include/linux/slab.h:1014 [inline]
          tomoyo_encode2 security/tomoyo/realpath.c:45 [inline]
          tomoyo_encode+0x26f/0x540 security/tomoyo/realpath.c:80
          tomoyo_realpath_from_path+0x59e/0x5e0 security/tomoyo/realpath.c:283
          tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
          tomoyo_check_open_permission+0x255/0x500 security/tomoyo/file.c:771
          security_file_open+0x777/0x990 security/security.c:3109
          do_dentry_open+0x369/0x1460 fs/open.c:945
          vfs_open+0x3e/0x330 fs/open.c:1088
          do_open fs/namei.c:3774 [inline]
          path_openat+0x2c84/0x3590 fs/namei.c:3933
         page last free pid 5055 tgid 5055 stack trace:
          reset_page_owner include/linux/page_owner.h:25 [inline]
          free_pages_prepare mm/page_alloc.c:1112 [inline]
          free_unref_page+0xcfb/0xf20 mm/page_alloc.c:2642
          free_pipe_info+0x300/0x390 fs/pipe.c:860
          put_pipe_info fs/pipe.c:719 [inline]
          pipe_release+0x245/0x320 fs/pipe.c:742
          __fput+0x23f/0x880 fs/file_table.c:431
          __do_sys_close fs/open.c:1567 [inline]
          __se_sys_close fs/open.c:1552 [inline]
          __x64_sys_close+0x7f/0x110 fs/open.c:1552
          do_syscall_x64 arch/x86/entry/common.c:52 [inline]
          do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
          entry_SYSCALL_64_after_hwframe+0x77/0x7f
      
         Memory state around the buggy address:
          ffff888042d1ae00: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
          ffff888042d1ae80: 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc
         >ffff888042d1af00: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
                                                 ^
          ffff888042d1af80: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
          ffff888042d1b000: 00 00 00 00 00 fc fc 00 00 00 00 00 fc fc 00 00
      
      Reported-by: default avatar <syzbot+7325f164162e200000c1@syzkaller.appspotmail.com>
      Link: https://lore.kernel.org/linux-btrfs/673723eb.050a0220.1324f8.00a8.GAE@google.com/T/#u
      
      
      Fixes: fd708b81 ("Btrfs: add a extent ref verify tool")
      CC: stable@vger.kernel.org # 4.19+
      Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
      Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6fd018aa
    • Ojaswin Mujoo's avatar
      quota: flush quota_release_work upon quota writeback · 6f3821ac
      Ojaswin Mujoo authored
      
      [ Upstream commit ac6f4202 ]
      
      One of the paths quota writeback is called from is:
      
      freeze_super()
        sync_filesystem()
          ext4_sync_fs()
            dquot_writeback_dquots()
      
      Since we currently don't always flush the quota_release_work queue in
      this path, we can end up with the following race:
      
       1. dquot are added to releasing_dquots list during regular operations.
       2. FS Freeze starts, however, this does not flush the quota_release_work queue.
       3. Freeze completes.
       4. Kernel eventually tries to flush the workqueue while FS is frozen which
          hits a WARN_ON since transaction gets started during frozen state:
      
        ext4_journal_check_start+0x28/0x110 [ext4] (unreliable)
        __ext4_journal_start_sb+0x64/0x1c0 [ext4]
        ext4_release_dquot+0x90/0x1d0 [ext4]
        quota_release_workfn+0x43c/0x4d0
      
      Which is the following line:
      
        WARN_ON(sb->s_writers.frozen == SB_FREEZE_COMPLETE);
      
      Which ultimately results in generic/390 failing due to dmesg
      noise. This was detected on powerpc machine 15 cores.
      
      To avoid this, make sure to flush the workqueue during
      dquot_writeback_dquots() so we dont have any pending workitems after
      freeze.
      
      Reported-by: default avatarDisha Goel <disgoel@linux.ibm.com>
      CC: stable@vger.kernel.org
      Fixes: dabc8b20 ("quota: fix dqput() to follow the guarantees dquot_srcu should provide")
      Reviewed-by: default avatarBaokun Li <libaokun1@huawei.com>
      Signed-off-by: default avatarOjaswin Mujoo <ojaswin@linux.ibm.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Link: https://patch.msgid.link/20241121123855.645335-2-ojaswin@linux.ibm.com
      
      
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6f3821ac
    • Gustavo A. R. Silva's avatar
      octeontx2-pf: Fix out-of-bounds read in otx2_get_fecparam() · 366e55e9
      Gustavo A. R. Silva authored
      
      commit 93efb0c6 upstream.
      
      Code at line 967 implies that rsp->fwdata.supported_fec may be up to 4:
      
       967: if (rsp->fwdata.supported_fec <= FEC_MAX_INDEX)
      
      If rsp->fwdata.supported_fec evaluates to 4, then there is an
      out-of-bounds read at line 971 because fec is an array with
      a maximum of 4 elements:
      
       954         const int fec[] = {
       955                 ETHTOOL_FEC_OFF,
       956                 ETHTOOL_FEC_BASER,
       957                 ETHTOOL_FEC_RS,
       958                 ETHTOOL_FEC_BASER | ETHTOOL_FEC_RS};
       959 #define FEC_MAX_INDEX 4
      
       971: fecparam->fec = fec[rsp->fwdata.supported_fec];
      
      Fix this by properly indexing fec[] with rsp->fwdata.supported_fec - 1.
      In this case the proper indexes 0 to 3 are used when
      rsp->fwdata.supported_fec evaluates to a range of 1 to 4, correspondingly.
      
      Fixes: d0cf9503 ("octeontx2-pf: ethtool fec mode support")
      Addresses-Coverity-ID: 1501722 ("Out-of-bounds read")
      Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      366e55e9
    • Shengjiu Wang's avatar
      ASoC: fsl_micfil: fix the naming style for mask definition · 442dadf3
      Shengjiu Wang authored
      
      commit 101b096b upstream.
      
      Remove the _SHIFT for the mask definition.
      
      Fixes: 17f2142b ("ASoC: fsl_micfil: use GENMASK to define register bit fields")
      Signed-off-by: default avatarShengjiu Wang <shengjiu.wang@nxp.com>
      Acked-by: default avatarSascha Hauer <s.hauer@pengutronix.de>
      Link: https://lore.kernel.org/r/1651736047-28809-1-git-send-email-shengjiu.wang@nxp.com
      
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      442dadf3
    • Dan Carpenter's avatar
      sh: intc: Fix use-after-free bug in register_intc_controller() · 971b4893
      Dan Carpenter authored
      
      [ Upstream commit 63e72e55 ]
      
      In the error handling for this function, d is freed without ever
      removing it from intc_list which would lead to a use after free.
      To fix this, let's only add it to the list after everything has
      succeeded.
      
      Fixes: 2dcec7a9 ("sh: intc: set_irq_wake() support")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Reviewed-by: default avatarJohn Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
      Signed-off-by: default avatarJohn Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      971b4893
    • Liu Jian's avatar
      sunrpc: clear XPRT_SOCK_UPD_TIMEOUT when reset transport · 86a1f9fa
      Liu Jian authored
      
      [ Upstream commit 4db9ad82 ]
      
      Since transport->sock has been set to NULL during reset transport,
      XPRT_SOCK_UPD_TIMEOUT also needs to be cleared. Otherwise, the
      xs_tcp_set_socket_timeouts() may be triggered in xs_tcp_send_request()
      to dereference the transport->sock that has been set to NULL.
      
      Fixes: 7196dbb0 ("SUNRPC: Allow changing of the TCP timeout parameters on the fly")
      Signed-off-by: default avatarLi Lingfeng <lilingfeng3@huawei.com>
      Signed-off-by: default avatarLiu Jian <liujian56@huawei.com>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      86a1f9fa
    • Trond Myklebust's avatar
      SUNRPC: Replace internal use of SOCKWQ_ASYNC_NOSPACE · 8c06a00a
      Trond Myklebust authored
      
      [ Upstream commit 2790a624 ]
      
      The socket's SOCKWQ_ASYNC_NOSPACE can be cleared by various actors in
      the socket layer, so replace it with our own flag in the transport
      sock_state field.
      
      Reported-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Stable-dep-of: 4db9ad82 ("sunrpc: clear XPRT_SOCK_UPD_TIMEOUT when reset transport")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8c06a00a
    • Thiago Rafael Becker's avatar
      sunrpc: remove unnecessary test in rpc_task_set_client() · a4b153bd
      Thiago Rafael Becker authored
      
      [ Upstream commit 023859ce ]
      
      In rpc_task_set_client(), testing for a NULL clnt is not necessary, as
      clnt should always be a valid pointer to a rpc_client.
      
      Signed-off-by: default avatarThiago Rafael Becker <trbecker@gmail.com>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Stable-dep-of: 4db9ad82 ("sunrpc: clear XPRT_SOCK_UPD_TIMEOUT when reset transport")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      a4b153bd
    • Trond Myklebust's avatar
      SUNRPC: Convert rpc_client refcount to use refcount_t · 3ccfa826
      Trond Myklebust authored
      
      [ Upstream commit 71d3d0eb ]
      
      There are now tools in the refcount library that allow us to convert the
      client shutdown code.
      
      Reported-by: default avatarXiyu Yang <xiyuyang19@fudan.edu.cn>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
      Stable-dep-of: 4db9ad82 ("sunrpc: clear XPRT_SOCK_UPD_TIMEOUT when reset transport")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3ccfa826
    • Calum Mackay's avatar
      SUNRPC: correct error code comment in xs_tcp_setup_socket() · e2730edf
      Calum Mackay authored
      
      [ Upstream commit 8c71139d ]
      
      This comment was introduced by commit 6ea44adc
      ("SUNRPC: ensure correct error is reported by xs_tcp_setup_socket()").
      
      I believe EIO was a typo at the time: it should have been EAGAIN.
      
      Subsequently, commit 0445f92c ("SUNRPC: Fix disconnection races")
      changed that to ENOTCONN.
      
      Rather than trying to keep the comment here in sync with the code in
      xprt_force_disconnect(), make the point in a non-specific way.
      
      Fixes: 6ea44adc ("SUNRPC: ensure correct error is reported by xs_tcp_setup_socket()")
      Signed-off-by: default avatarCalum Mackay <calum.mackay@oracle.com>
      Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
      Stable-dep-of: 4db9ad82 ("sunrpc: clear XPRT_SOCK_UPD_TIMEOUT when reset transport")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e2730edf
    • Li Lingfeng's avatar
      nfs: ignore SB_RDONLY when mounting nfs · f69fb61c
      Li Lingfeng authored
      [ Upstream commit 52cb7f8f ]
      
      When exporting only one file system with fsid=0 on the server side, the
      client alternately uses the ro/rw mount options to perform the mount
      operation, and a new vfsmount is generated each time.
      
      It can be reproduced as follows:
      [root@localhost ~]# mount /dev/sda /mnt2
      [root@localhost ~]# echo "/mnt2 *(rw,no_root_squash,fsid=0)" >/etc/exports
      [root@localhost ~]# systemctl restart nfs-server
      [root@localhost ~]# mount -t nfs -o ro,vers=4 127.0.0.1:/ /mnt/sdaa
      [root@localhost ~]# mount -t nfs -o rw,vers=4 127.0.0.1:/ /mnt/sdaa
      [root@localhost ~]# mount -t nfs -o ro,vers=4 127.0.0.1:/ /mnt/sdaa
      [root@localhost ~]# mount -t nfs -o rw,vers=4 127.0.0.1:/ /mnt/sdaa
      [root@localhost ~]# mount | grep nfs4
      127.0.0.1:/ on /mnt/sdaa type nfs4 (ro,relatime,vers=4.2,rsize=1048576,...
      127.0.0.1:/ on /mnt/sdaa type nfs4 (rw,relatime,vers=4.2,rsize=1048576,...
      127.0.0.1:/ on /mnt/sdaa type nfs4 (ro,relatime,vers=4.2,rsize=1048576,...
      127.0.0.1:/ on /mnt/sdaa type nfs4 (rw,relatime,vers=4.2,rsize=1048576,...
      [root@localhost ~]#
      
      We expected that after mounting with the ro option, using the rw option to
      mount again would return EBUSY, but the actual situation was not the case.
      
      As shown above, when mounting for the first time, a superblock with the ro
      flag will be generated, and at the same time, in do_new_mount_fc -->
      do_add_mount, it detects that the superblock corresponding to the current
      target directory is inconsistent with the currently generated one
      (path->mnt->mnt_sb != newmnt->mnt.mnt_sb), and a new vfsmount will be
      generated.
      
      When mounting with the rw option for the second time, since no matching
      superblock can be found in the fs_supers list, a new superblock with the
      rw flag will be generated again. The superblock in use (ro) is different
      from the newly generated superblock (rw), and a new vfsmount will be
      generated again.
      
      When mounting with the ro option for the third time, the superblock (ro)
      is found in fs_supers, the superblock in use (rw) is different from the
      found superblock (ro), and a new vfsmount will be generated again.
      
      We can switch between ro/rw through remount, and only one superblock needs
      to be generated, thus avoiding the problem of repeated generation of
      vfsmount caused by switching superblocks.
      
      Furthermore, This can also resolve the issue described in the link.
      
      Fixes: 275a5d24 ("NFS: Error when mounting the same filesystem with different options")
      Link: https://lore.kernel.org/all/20240604112636.236517-3-lilingfeng@huaweicloud.com/
      
      
      Signed-off-by: default avatarLi Lingfeng <lilingfeng3@huawei.com>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f69fb61c
    • Masahiro Yamada's avatar
      modpost: remove incorrect code in do_eisa_entry() · bd4624d7
      Masahiro Yamada authored
      
      [ Upstream commit 0c3e0913 ]
      
      This function contains multiple bugs after the following commits:
      
       - ac551828 ("modpost: i2c aliases need no trailing wildcard")
       - 6543becf ("mod/file2alias: make modalias generation safe for cross compiling")
      
      Commit ac551828 inserted the following code to do_eisa_entry():
      
          else
                  strcat(alias, "*");
      
      This is incorrect because 'alias' is uninitialized. If it is not
      NULL-terminated, strcat() could cause a buffer overrun.
      
      Even if 'alias' happens to be zero-filled, it would output:
      
          MODULE_ALIAS("*");
      
      This would match anything. As a result, the module could be loaded by
      any unrelated uevent from an unrelated subsystem.
      
      Commit ac551828 introduced another bug.            
      
      Prior to that commit, the conditional check was:
      
          if (eisa->sig[0])
      
      This checked if the first character of eisa_device_id::sig was not '\0'.
      
      However, commit ac551828 changed it as follows:
      
          if (sig[0])
      
      sig[0] is NOT the first character of the eisa_device_id::sig. The
      type of 'sig' is 'char (*)[8]', meaning that the type of 'sig[0]' is
      'char [8]' instead of 'char'. 'sig[0]' and 'symval' refer to the same
      address, which never becomes NULL.
      
      The correct conversion would have been:
      
          if ((*sig)[0])
      
      However, this if-conditional was meaningless because the earlier change
      in commit ac551828 was incorrect.
      
      This commit removes the entire incorrect code, which should never have
      been executed.
      
      Fixes: ac551828 ("modpost: i2c aliases need no trailing wildcard")
      Fixes: 6543becf ("mod/file2alias: make modalias generation safe for cross compiling")
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      bd4624d7
    • Maxime Chevallier's avatar
      rtc: ab-eoz9: don't fail temperature reads on undervoltage notification · b0660da6
      Maxime Chevallier authored
      
      [ Upstream commit e0779a0d ]
      
      The undervoltage flags reported by the RTC are useful to know if the
      time and date are reliable after a reboot. Although the threshold VLOW1
      indicates that the thermometer has been shutdown and time compensation
      is off, it doesn't mean that the temperature readout is currently
      impossible.
      
      As the system is running, the RTC voltage is now fully established and
      we can read the temperature.
      
      Fixes: 67075b63 ("rtc: add AB-RTCMC-32.768kHz-EOZ9 RTC support")
      Signed-off-by: default avatarMaxime Chevallier <maxime.chevallier@bootlin.com>
      Link: https://lore.kernel.org/r/20241122101031.68916-3-maxime.chevallier@bootlin.com
      
      
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b0660da6
    • Alex Zenla's avatar
      9p/xen: fix release of IRQ · 7f5a2ed5
      Alex Zenla authored
      
      [ Upstream commit e43c608f ]
      
      Kernel logs indicate an IRQ was double-freed.
      
      Pass correct device ID during IRQ release.
      
      Fixes: 71ebd719 ("xen/9pfs: connect to the backend")
      Signed-off-by: default avatarAlex Zenla <alex@edera.dev>
      Signed-off-by: default avatarAlexander Merritt <alexander@edera.dev>
      Signed-off-by: default avatarAriadne Conill <ariadne@ariadne.space>
      Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
      Message-ID: <20241121225100.5736-1-alexander@edera.dev>
      [Dominique: remove confusing variable reset to 0]
      Signed-off-by: default avatarDominique Martinet <asmadeus@codewreck.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7f5a2ed5
    • Alex Zenla's avatar
      9p/xen: fix init sequence · fa365f68
      Alex Zenla authored
      
      [ Upstream commit 7ef3ae82 ]
      
      Large amount of mount hangs observed during hotplugging of 9pfs devices. The
      9pfs Xen driver attempts to initialize itself more than once, causing the
      frontend and backend to disagree: the backend listens on a channel that the
      frontend does not send on, resulting in stalled processing.
      
      Only allow initialization of 9p frontend once.
      
      Fixes: c15fe55d ("9p/xen: fix connection sequence")
      Signed-off-by: default avatarAlex Zenla <alex@edera.dev>
      Signed-off-by: default avatarAlexander Merritt <alexander@edera.dev>
      Signed-off-by: default avatarAriadne Conill <ariadne@ariadne.space>
      Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
      Message-ID: <20241119211633.38321-1-alexander@edera.dev>
      Signed-off-by: default avatarDominique Martinet <asmadeus@codewreck.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fa365f68
    • Christoph Hellwig's avatar
      block: return unsigned int from bdev_io_min · 57ee79e9
      Christoph Hellwig authored
      
      [ Upstream commit 46fd48ab ]
      
      The underlying limit is defined as an unsigned int, so return that from
      bdev_io_min as well.
      
      Fixes: ac481c20 ("block: Topology ioctls")
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Reviewed-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Link: https://lore.kernel.org/r/20241119072602.1059488-1-hch@lst.de
      
      
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      57ee79e9
    • Qingfang Deng's avatar
      jffs2: fix use of uninitialized variable · 25ec6cd7
      Qingfang Deng authored
      
      [ Upstream commit 3ba44ee9 ]
      
      When building the kernel with -Wmaybe-uninitialized, the compiler
      reports this warning:
      
      In function 'jffs2_mark_erased_block',
          inlined from 'jffs2_erase_pending_blocks' at fs/jffs2/erase.c:116:4:
      fs/jffs2/erase.c:474:9: warning: 'bad_offset' may be used uninitialized [-Wmaybe-uninitialized]
        474 |         jffs2_erase_failed(c, jeb, bad_offset);
            |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      fs/jffs2/erase.c: In function 'jffs2_erase_pending_blocks':
      fs/jffs2/erase.c:402:18: note: 'bad_offset' was declared here
        402 |         uint32_t bad_offset;
            |                  ^~~~~~~~~~
      
      When mtd->point() is used, jffs2_erase_pending_blocks can return -EIO
      without initializing bad_offset, which is later used at the filebad
      label in jffs2_mark_erased_block.
      Fix it by initializing this variable.
      
      Fixes: 8a0f5723 ("[JFFS2] Return values of jffs2_block_check_erase error paths")
      Signed-off-by: default avatarQingfang Deng <qingfang.deng@siflower.com.cn>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      25ec6cd7
    • Waqar Hameed's avatar
      ubifs: authentication: Fix use-after-free in ubifs_tnc_end_commit · 8d8b3f5f
      Waqar Hameed authored
      
      [ Upstream commit 4617fb8f ]
      
      After an insertion in TNC, the tree might split and cause a node to
      change its `znode->parent`. A further deletion of other nodes in the
      tree (which also could free the nodes), the aforementioned node's
      `znode->cparent` could still point to a freed node. This
      `znode->cparent` may not be updated when getting nodes to commit in
      `ubifs_tnc_start_commit()`. This could then trigger a use-after-free
      when accessing the `znode->cparent` in `write_index()` in
      `ubifs_tnc_end_commit()`.
      
      This can be triggered by running
      
        rm -f /etc/test-file.bin
        dd if=/dev/urandom of=/etc/test-file.bin bs=1M count=60 conv=fsync
      
      in a loop, and with `CONFIG_UBIFS_FS_AUTHENTICATION`. KASAN then
      reports:
      
        BUG: KASAN: use-after-free in ubifs_tnc_end_commit+0xa5c/0x1950
        Write of size 32 at addr ffffff800a3af86c by task ubifs_bgt0_20/153
      
        Call trace:
         dump_backtrace+0x0/0x340
         show_stack+0x18/0x24
         dump_stack_lvl+0x9c/0xbc
         print_address_description.constprop.0+0x74/0x2b0
         kasan_report+0x1d8/0x1f0
         kasan_check_range+0xf8/0x1a0
         memcpy+0x84/0xf4
         ubifs_tnc_end_commit+0xa5c/0x1950
         do_commit+0x4e0/0x1340
         ubifs_bg_thread+0x234/0x2e0
         kthread+0x36c/0x410
         ret_from_fork+0x10/0x20
      
        Allocated by task 401:
         kasan_save_stack+0x38/0x70
         __kasan_kmalloc+0x8c/0xd0
         __kmalloc+0x34c/0x5bc
         tnc_insert+0x140/0x16a4
         ubifs_tnc_add+0x370/0x52c
         ubifs_jnl_write_data+0x5d8/0x870
         do_writepage+0x36c/0x510
         ubifs_writepage+0x190/0x4dc
         __writepage+0x58/0x154
         write_cache_pages+0x394/0x830
         do_writepages+0x1f0/0x5b0
         filemap_fdatawrite_wbc+0x170/0x25c
         file_write_and_wait_range+0x140/0x190
         ubifs_fsync+0xe8/0x290
         vfs_fsync_range+0xc0/0x1e4
         do_fsync+0x40/0x90
         __arm64_sys_fsync+0x34/0x50
         invoke_syscall.constprop.0+0xa8/0x260
         do_el0_svc+0xc8/0x1f0
         el0_svc+0x34/0x70
         el0t_64_sync_handler+0x108/0x114
         el0t_64_sync+0x1a4/0x1a8
      
        Freed by task 403:
         kasan_save_stack+0x38/0x70
         kasan_set_track+0x28/0x40
         kasan_set_free_info+0x28/0x4c
         __kasan_slab_free+0xd4/0x13c
         kfree+0xc4/0x3a0
         tnc_delete+0x3f4/0xe40
         ubifs_tnc_remove_range+0x368/0x73c
         ubifs_tnc_remove_ino+0x29c/0x2e0
         ubifs_jnl_delete_inode+0x150/0x260
         ubifs_evict_inode+0x1d4/0x2e4
         evict+0x1c8/0x450
         iput+0x2a0/0x3c4
         do_unlinkat+0x2cc/0x490
         __arm64_sys_unlinkat+0x90/0x100
         invoke_syscall.constprop.0+0xa8/0x260
         do_el0_svc+0xc8/0x1f0
         el0_svc+0x34/0x70
         el0t_64_sync_handler+0x108/0x114
         el0t_64_sync+0x1a4/0x1a8
      
      The offending `memcpy()` in `ubifs_copy_hash()` has a use-after-free
      when a node becomes root in TNC but still has a `cparent` to an already
      freed node. More specifically, consider the following TNC:
      
               zroot
               /
              /
            zp1
            /
           /
          zn
      
      Inserting a new node `zn_new` with a key smaller then `zn` will trigger
      a split in `tnc_insert()` if `zp1` is full:
      
               zroot
               /   \
              /     \
            zp1     zp2
            /         \
           /           \
        zn_new          zn
      
      `zn->parent` has now been moved to `zp2`, *but* `zn->cparent` still
      points to `zp1`.
      
      Now, consider a removal of all the nodes _except_ `zn`. Just when
      `tnc_delete()` is about to delete `zroot` and `zp2`:
      
               zroot
                   \
                    \
                    zp2
                      \
                       \
                       zn
      
      `zroot` and `zp2` get freed and the tree collapses:
      
                 zn
      
      `zn` now becomes the new `zroot`.
      
      `get_znodes_to_commit()` will now only find `zn`, the new `zroot`, and
      `write_index()` will check its `znode->cparent` that wrongly points to
      the already freed `zp1`. `ubifs_copy_hash()` thus gets wrongly called
      with `znode->cparent->zbranch[znode->iip].hash` that triggers the
      use-after-free!
      
      Fix this by explicitly setting `znode->cparent` to `NULL` in
      `get_znodes_to_commit()` for the root node. The search for the dirty
      nodes is bottom-up in the tree. Thus, when `find_next_dirty(znode)`
      returns NULL, the current `znode` _is_ the root node. Add an assert for
      this.
      
      Fixes: 16a26b20 ("ubifs: authentication: Add hashes to index nodes")
      Tested-by: default avatarWaqar Hameed <waqar.hameed@axis.com>
      Co-developed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarWaqar Hameed <waqar.hameed@axis.com>
      Reviewed-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8d8b3f5f
    • Zhihao Cheng's avatar
      ubi: fastmap: Fix duplicate slab cache names while attaching · 04c0b0f3
      Zhihao Cheng authored
      
      [ Upstream commit bcddf52b ]
      
      Since commit 4c395296 ("slab: Warn on duplicate cache names when
      DEBUG_VM=y"), the duplicate slab cache names can be detected and a
      kernel WARNING is thrown out.
      In UBI fast attaching process, alloc_ai() could be invoked twice
      with the same slab cache name 'ubi_aeb_slab_cache', which will trigger
      following warning messages:
       kmem_cache of name 'ubi_aeb_slab_cache' already exists
       WARNING: CPU: 0 PID: 7519 at mm/slab_common.c:107
                __kmem_cache_create_args+0x100/0x5f0
       Modules linked in: ubi(+) nandsim [last unloaded: nandsim]
       CPU: 0 UID: 0 PID: 7519 Comm: modprobe Tainted: G 6.12.0-rc2
       RIP: 0010:__kmem_cache_create_args+0x100/0x5f0
       Call Trace:
         __kmem_cache_create_args+0x100/0x5f0
         alloc_ai+0x295/0x3f0 [ubi]
         ubi_attach+0x3c3/0xcc0 [ubi]
         ubi_attach_mtd_dev+0x17cf/0x3fa0 [ubi]
         ubi_init+0x3fb/0x800 [ubi]
         do_init_module+0x265/0x7d0
         __x64_sys_finit_module+0x7a/0xc0
      
      The problem could be easily reproduced by loading UBI device by fastmap
      with CONFIG_DEBUG_VM=y.
      Fix it by using different slab names for alloc_ai() callers.
      
      Fixes: d2158f69 ("UBI: Remove alloc_ai() slab name from parameter list")
      Fixes: fdf10ed7 ("ubi: Rework Fastmap attach base code")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      04c0b0f3
    • Zhihao Cheng's avatar
      ubifs: Correct the total block count by deducting journal reservation · 36b25baf
      Zhihao Cheng authored
      
      [ Upstream commit 84a2bee9 ]
      
      Since commit e874dcde ("ubifs: Reserve one leb for each journal
      head while doing budget"), available space is calulated by deducting
      reservation for all journal heads. However, the total block count (
      which is only used by statfs) is not updated yet, which will cause
      the wrong displaying for used space(total - available).
      Fix it by deducting reservation for all journal heads from total
      block count.
      
      Fixes: e874dcde ("ubifs: Reserve one leb for each journal head while doing budget")
      Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      36b25baf
    • Yongliang Gao's avatar
      rtc: check if __rtc_read_time was successful in rtc_timer_do_work() · 0d68e851
      Yongliang Gao authored
      
      [ Upstream commit e8ba8a2b ]
      
      If the __rtc_read_time call fails,, the struct rtc_time tm; may contain
      uninitialized data, or an illegal date/time read from the RTC hardware.
      
      When calling rtc_tm_to_ktime later, the result may be a very large value
      (possibly KTIME_MAX). If there are periodic timers in rtc->timerqueue,
      they will continually expire, may causing kernel softlockup.
      
      Fixes: 6610e089 ("RTC: Rework RTC code to use timerqueue for events")
      Signed-off-by: default avatarYongliang Gao <leonylgao@tencent.com>
      Acked-by: default avatarJingqun Li <jingqunli@tencent.com>
      Link: https://lore.kernel.org/r/20241011043153.3788112-1-leonylgao@gmail.com
      
      
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0d68e851
    • Nobuhiro Iwamatsu's avatar
      rtc: abx80x: Fix WDT bit position of the status register · cd154812
      Nobuhiro Iwamatsu authored
      [ Upstream commit 10e078b2 ]
      
      The WDT bit in the status register is 5, not 6. This fixes from 6 to 5.
      
      Link: https://abracon.com/Support/AppsManuals/Precisiontiming/AB08XX-Application-Manual.pdf
      Link: https://www.microcrystal.com/fileadmin/Media/Products/RTC/App.Manual/RV-1805-C3_App-Manual.pdf
      
      
      Fixes: 749e36d0 ("rtc: abx80x: add basic watchdog support")
      Cc: Jeremy Gebben <jgebben@sweptlaser.com>
      Signed-off-by: default avatarNobuhiro Iwamatsu <iwamatsu@nigauri.org>
      Link: https://lore.kernel.org/r/20241008041737.1640633-1-iwamatsu@nigauri.org
      
      
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      cd154812
    • Jinjie Ruan's avatar
      rtc: st-lpc: Use IRQF_NO_AUTOEN flag in request_irq() · c48db314
      Jinjie Ruan authored
      
      [ Upstream commit b6cd7ade ]
      
      If request_irq() fails in st_rtc_probe(), there is no need to enable
      the irq, and if it succeeds, disable_irq() after request_irq() still has
      a time gap in which interrupts can come.
      
      request_irq() with IRQF_NO_AUTOEN flag will disable IRQ auto-enable when
      request IRQ.
      
      Fixes: b5b2bdfc ("rtc: st: Add new driver for ST's LPC RTC")
      Signed-off-by: default avatarJinjie Ruan <ruanjinjie@huawei.com>
      Link: https://lore.kernel.org/r/20240912033727.3013951-1-ruanjinjie@huawei.com
      
      
      Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c48db314
    • Trond Myklebust's avatar
      NFSv4.0: Fix a use-after-free problem in the asynchronous open() · 5237a297
      Trond Myklebust authored
      
      [ Upstream commit 2fdb05dc ]
      
      Yang Erkun reports that when two threads are opening files at the same
      time, and are forced to abort before a reply is seen, then the call to
      nfs_release_seqid() in nfs4_opendata_free() can result in a
      use-after-free of the pointer to the defunct rpc task of the other
      thread.
      The fix is to ensure that if the RPC call is aborted before the call to
      nfs_wait_on_sequence() is complete, then we must call nfs_release_seqid()
      in nfs4_open_release() before the rpc_task is freed.
      
      Reported-by: default avatarYang Erkun <yangerkun@huawei.com>
      Fixes: 24ac23ab ("NFSv4: Convert open() into an asynchronous RPC call")
      Reviewed-by: default avatarYang Erkun <yangerkun@huawei.com>
      Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5237a297
    • Tiwei Bie's avatar
      um: Always dump trace for specified task in show_stack · 2365f578
      Tiwei Bie authored
      
      [ Upstream commit 0f659ff3 ]
      
      Currently, show_stack() always dumps the trace of the current task.
      However, it should dump the trace of the specified task if one is
      provided. Otherwise, things like running "echo t > sysrq-trigger"
      won't work as expected.
      
      Fixes: 970e51fe ("um: Add support for CONFIG_STACKTRACE")
      Signed-off-by: default avatarTiwei Bie <tiwei.btw@antgroup.com>
      Link: https://patch.msgid.link/20241106103933.1132365-1-tiwei.btw@antgroup.com
      
      
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2365f578
    • Tiwei Bie's avatar
      um: Fix the return value of elf_core_copy_task_fpregs · 634b3c3d
      Tiwei Bie authored
      
      [ Upstream commit 865e3845 ]
      
      This function is expected to return a boolean value, which should be
      true on success and false on failure.
      
      Fixes: d1254b12 ("uml: fix x86_64 core dump crash")
      Signed-off-by: default avatarTiwei Bie <tiwei.btw@antgroup.com>
      Link: https://patch.msgid.link/20240913023302.130300-1-tiwei.btw@antgroup.com
      
      
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      634b3c3d
    • Tiwei Bie's avatar
      um: Fix potential integer overflow during physmem setup · e6102b72
      Tiwei Bie authored
      
      [ Upstream commit a98b7761 ]
      
      This issue happens when the real map size is greater than LONG_MAX,
      which can be easily triggered on UML/i386.
      
      Fixes: fe205bdd ("um: Print minimum physical memory requirement")
      Signed-off-by: default avatarTiwei Bie <tiwei.btw@antgroup.com>
      Link: https://patch.msgid.link/20240916045950.508910-3-tiwei.btw@antgroup.com
      
      
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e6102b72
    • Bjorn Andersson's avatar
      rpmsg: glink: Propagate TX failures in intentless mode as well · 52ee4145
      Bjorn Andersson authored
      
      commit 7a68f9fa upstream.
      
      As support for splitting transmission over several messages using
      TX_DATA_CONT was introduced it does not immediately return the return
      value of qcom_glink_tx().
      
      The result is that in the intentless case (i.e. intent == NULL), the
      code will continue to send all additional chunks. This is wasteful, and
      it's possible that the send operation could incorrectly indicate
      success, if the last chunk fits in the TX fifo.
      
      Fix the condition.
      
      Fixes: 8956927f ("rpmsg: glink: Add TX_DATA_CONT command while sending")
      Reviewed-by: default avatarChris Lew <quic_clew@quicinc.com>
      Signed-off-by: default avatarBjorn Andersson <quic_bjorande@quicinc.com>
      Signed-off-by: default avatarBjorn Andersson <andersson@kernel.org>
      Link: https://lore.kernel.org/r/20230418163018.785524-2-quic_bjorande@quicinc.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      52ee4145
    • Yang Erkun's avatar
      SUNRPC: make sure cache entry active before cache_show · 02999e13
      Yang Erkun authored
      
      commit 2862eee0 upstream.
      
      The function `c_show` was called with protection from RCU. This only
      ensures that `cp` will not be freed. Therefore, the reference count for
      `cp` can drop to zero, which will trigger a refcount use-after-free
      warning when `cache_get` is called. To resolve this issue, use
      `cache_get_rcu` to ensure that `cp` remains active.
      
      ------------[ cut here ]------------
      refcount_t: addition on 0; use-after-free.
      WARNING: CPU: 7 PID: 822 at lib/refcount.c:25
      refcount_warn_saturate+0xb1/0x120
      CPU: 7 UID: 0 PID: 822 Comm: cat Not tainted 6.12.0-rc3+ #1
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
      1.16.1-2.fc37 04/01/2014
      RIP: 0010:refcount_warn_saturate+0xb1/0x120
      
      Call Trace:
       <TASK>
       c_show+0x2fc/0x380 [sunrpc]
       seq_read_iter+0x589/0x770
       seq_read+0x1e5/0x270
       proc_reg_read+0xe1/0x140
       vfs_read+0x125/0x530
       ksys_read+0xc1/0x160
       do_syscall_64+0x5f/0x170
       entry_SYSCALL_64_after_hwframe+0x76/0x7e
      
      Cc: stable@vger.kernel.org # v4.20+
      Signed-off-by: default avatarYang Erkun <yangerkun@huawei.com>
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      02999e13
    • Chuck Lever's avatar
      NFSD: Prevent a potential integer overflow · 3c5f545c
      Chuck Lever authored
      
      commit 7f33b92e upstream.
      
      If the tag length is >= U32_MAX - 3 then the "length + 4" addition
      can result in an integer overflow. Address this by splitting the
      decoding into several steps so that decode_cb_compound4res() does
      not have to perform arithmetic on the unsafe length value.
      
      Reported-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3c5f545c
    • Bartosz Golaszewski's avatar
      lib: string_helpers: silence snprintf() output truncation warning · a44a4260
      Bartosz Golaszewski authored
      
      commit a508ef4b upstream.
      
      The output of ".%03u" with the unsigned int in range [0, 4294966295] may
      get truncated if the target buffer is not 12 bytes. This can't really
      happen here as the 'remainder' variable cannot exceed 999 but the
      compiler doesn't know it. To make it happy just increase the buffer to
      where the warning goes away.
      
      Fixes: 3c9f3681 ("[SCSI] lib: add generic helper to print sizes rounded to the correct SI range")
      Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
      Reviewed-by: default avatarAndy Shevchenko <andy@kernel.org>
      Cc: James E.J. Bottomley <James.Bottomley@HansenPartnership.com>
      Cc: Kees Cook <kees@kernel.org>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Link: https://lore.kernel.org/r/20241101205453.9353-1-brgl@bgdev.pl
      
      
      Signed-off-by: default avatarKees Cook <kees@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a44a4260
    • Thinh Nguyen's avatar
      usb: dwc3: gadget: Fix looping of queued SG entries · 8ceb21d7
      Thinh Nguyen authored
      
      commit b7fc65f5 upstream.
      
      The dwc3_request->num_queued_sgs is decremented on completion. If a
      partially completed request is handled, then the
      dwc3_request->num_queued_sgs no longer reflects the total number of
      num_queued_sgs (it would be cleared).
      
      Correctly check the number of request SG entries remained to be prepare
      and queued. Failure to do this may cause null pointer dereference when
      accessing non-existent SG entry.
      
      Cc: stable@vger.kernel.org
      Fixes: c96e6725 ("usb: dwc3: gadget: Correct the logic for queuing sgs")
      Signed-off-by: default avatarThinh Nguyen <Thinh.Nguyen@synopsys.com>
      Link: https://lore.kernel.org/r/d07a7c4aa0fcf746cdca0515150dbe5c52000af7.1731545781.git.Thinh.Nguyen@synopsys.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8ceb21d7
Loading