Skip to content
  1. Nov 03, 2022
    • Eric Dumazet's avatar
      kcm: annotate data-races around kcm->rx_wait · f1f7122b
      Eric Dumazet authored
      [ Upstream commit 0c745b51 ]
      
      kcm->rx_psock can be read locklessly in kcm_rfree().
      Annotate the read and writes accordingly.
      
      syzbot reported:
      
      BUG: KCSAN: data-race in kcm_rcv_strparser / kcm_rfree
      
      write to 0xffff88810784e3d0 of 1 bytes by task 1823 on cpu 1:
      reserve_rx_kcm net/kcm/kcmsock.c:283 [inline]
      kcm_rcv_strparser+0x250/0x3a0 net/kcm/kcmsock.c:363
      __strp_recv+0x64c/0xd20 net/strparser/strparser.c:301
      strp_recv+0x6d/0x80 net/strparser/strparser.c:335
      tcp_read_sock+0x13e/0x5a0 net/ipv4/tcp.c:1703
      strp_read_sock net/strparser/strparser.c:358 [inline]
      do_strp_work net/strparser/strparser.c:406 [inline]
      strp_work+0xe8/0x180 net/strparser/strparser.c:415
      process_one_work+0x3d3/0x720 kernel/workqueue.c:2289
      worker_thread+0x618/0xa70 kernel/workqueue.c:2436
      kthread+0x1a9/0x1e0 kernel/kthread.c:376
      ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306
      
      read to 0xffff88810784e3d0 of 1 bytes by task 17869 on cpu 0:
      kcm_rfree+0x121/0x220 net/kcm/kcmsock.c:181
      skb_release_head_state+0x8e/0x160 net/core/skbuff.c:841
      skb_release_all net/core/skbuff.c:852 [inline]
      __kfree_skb net/core/skbuff.c:868 [inline]
      kfree_skb_reason+0x5c/0x260 net/core/skbuff.c:891
      kfree_skb include/linux/skbuff.h:1216 [inline]
      kcm_recvmsg+0x226/0x2b0 net/kcm/kcmsock.c:1161
      ____sys_recvmsg+0x16c/0x2e0
      ___sys_recvmsg net/socket.c:2743 [inline]
      do_recvmmsg+0x2f1/0x710 net/socket.c:2837
      __sys_recvmmsg net/socket.c:2916 [inline]
      __do_sys_recvmmsg net/socket.c:2939 [inline]
      __se_sys_recvmmsg net/socket.c:2932 [inline]
      __x64_sys_recvmmsg+0xde/0x160 net/socket.c:2932
      do_syscall_x64 arch/x86/entry/common.c:50 [inline]
      do_syscall_64+0x2b/0x70 arch/x86/entry/common.c:80
      entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      value changed: 0x01 -> 0x00
      
      Reported by Kernel Concurrency Sanitizer on:
      CPU: 0 PID: 17869 Comm: syz-executor.2 Not tainted 6.1.0-rc1-syzkaller-00010-gbb1a1146467a-dirty #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/22/2022
      
      Fixes: ab7ac4eb
      
       ("kcm: Kernel Connection Multiplexor module")
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f1f7122b
    • Eric Dumazet's avatar
      kcm: annotate data-races around kcm->rx_psock · 1b8a5692
      Eric Dumazet authored
      [ Upstream commit 15e4dabd ]
      
      kcm->rx_psock can be read locklessly in kcm_rfree().
      Annotate the read and writes accordingly.
      
      We do the same for kcm->rx_wait in the following patch.
      
      syzbot reported:
      BUG: KCSAN: data-race in kcm_rfree / unreserve_rx_kcm
      
      write to 0xffff888123d827b8 of 8 bytes by task 2758 on cpu 1:
      unreserve_rx_kcm+0x72/0x1f0 net/kcm/kcmsock.c:313
      kcm_rcv_strparser+0x2b5/0x3a0 net/kcm/kcmsock.c:373
      __strp_recv+0x64c/0xd20 net/strparser/strparser.c:301
      strp_recv+0x6d/0x80 net/strparser/strparser.c:335
      tcp_read_sock+0x13e/0x5a0 net/ipv4/tcp.c:1703
      strp_read_sock net/strparser/strparser.c:358 [inline]
      do_strp_work net/strparser/strparser.c:406 [inline]
      strp_work+0xe8/0x180 net/strparser/strparser.c:415
      process_one_work+0x3d3/0x720 kernel/workqueue.c:2289
      worker_thread+0x618/0xa70 kernel/workqueue.c:2436
      kthread+0x1a9/0x1e0 kernel/kthread.c:376
      ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306
      
      read to 0xffff888123d827b8 of 8 bytes by task 5859 on cpu 0:
      kcm_rfree+0x14c/0x220 net/kcm/kcmsock.c:181
      skb_release_head_state+0x8e/0x160 net/core/skbuff.c:841
      skb_release_all net/core/skbuff.c:852 [inline]
      __kfree_skb net/core/skbuff.c:868 [inline]
      kfree_skb_reason+0x5c/0x260 net/core/skbuff.c:891
      kfree_skb include/linux/skbuff.h:1216 [inline]
      kcm_recvmsg+0x226/0x2b0 net/kcm/kcmsock.c:1161
      ____sys_recvmsg+0x16c/0x2e0
      ___sys_recvmsg net/socket.c:2743 [inline]
      do_recvmmsg+0x2f1/0x710 net/socket.c:2837
      __sys_recvmmsg net/socket.c:2916 [inline]
      __do_sys_recvmmsg net/socket.c:2939 [inline]
      __se_sys_recvmmsg net/socket.c:2932 [inline]
      __x64_sys_recvmmsg+0xde/0x160 net/socket.c:2932
      do_syscall_x64 arch/x86/entry/common.c:50 [inline]
      do_syscall_64+0x2b/0x70 arch/x86/entry/common.c:80
      entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      value changed: 0xffff88812971ce00 -> 0x0000000000000000
      
      Reported by Kernel Concurrency Sanitizer on:
      CPU: 0 PID: 5859 Comm: syz-executor.3 Not tainted 6.0.0-syzkaller-12189-g19d17ab7c68b-dirty #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/22/2022
      
      Fixes: ab7ac4eb
      
       ("kcm: Kernel Connection Multiplexor module")
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1b8a5692
    • Raju Rangoju's avatar
      amd-xgbe: add the bit rate quirk for Molex cables · 4c03f159
      Raju Rangoju authored
      [ Upstream commit 170a9e34 ]
      
      The offset 12 (bit-rate) of EEPROM SFP DAC (passive) cables is expected
      to be in the range 0x64 to 0x68. However, the 5 meter and 7 meter Molex
      passive cables have the rate ceiling 0x78 at offset 12.
      
      Add a quirk for Molex passive cables to extend the rate ceiling to 0x78.
      
      Fixes: abf0a1c2
      
       ("amd-xgbe: Add support for SFP+ modules")
      Signed-off-by: default avatarRaju Rangoju <Raju.Rangoju@amd.com>
      Acked-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4c03f159
    • Raju Rangoju's avatar
      amd-xgbe: fix the SFP compliance codes check for DAC cables · ff79bd38
      Raju Rangoju authored
      [ Upstream commit 09c5f6bf ]
      
      The current XGBE code assumes that offset 6 of EEPROM SFP DAC (passive)
      cables is NULL. However, some cables (the 5 meter and 7 meter Molex
      passive cables) have non-zero data at offset 6. Fix the logic by moving
      the passive cable check above the active checks, so as not to be
      improperly identified as an active cable. This will fix the issue for
      any passive cable that advertises 1000Base-CX in offset 6.
      
      Fixes: abf0a1c2
      
       ("amd-xgbe: Add support for SFP+ modules")
      Signed-off-by: default avatarRaju Rangoju <Raju.Rangoju@amd.com>
      Acked-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ff79bd38
    • Chen Zhongjin's avatar
      x86/unwind/orc: Fix unreliable stack dump with gcov · 47be0127
      Chen Zhongjin authored
      [ Upstream commit 230db824 ]
      
      When a console stack dump is initiated with CONFIG_GCOV_PROFILE_ALL
      enabled, show_trace_log_lvl() gets out of sync with the ORC unwinder,
      causing the stack trace to show all text addresses as unreliable:
      
        # echo l > /proc/sysrq-trigger
        [  477.521031] sysrq: Show backtrace of all active CPUs
        [  477.523813] NMI backtrace for cpu 0
        [  477.524492] CPU: 0 PID: 1021 Comm: bash Not tainted 6.0.0 #65
        [  477.525295] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.0-1.fc36 04/01/2014
        [  477.526439] Call Trace:
        [  477.526854]  <TASK>
        [  477.527216]  ? dump_stack_lvl+0xc7/0x114
        [  477.527801]  ? dump_stack+0x13/0x1f
        [  477.528331]  ? nmi_cpu_backtrace.cold+0xb5/0x10d
        [  477.528998]  ? lapic_can_unplug_cpu+0xa0/0xa0
        [  477.529641]  ? nmi_trigger_cpumask_backtrace+0x16a/0x1f0
        [  477.530393]  ? arch_trigger_cpumask_backtrace+0x1d/0x30
        [  477.531136]  ? sysrq_handle_showallcpus+0x1b/0x30
        [  477.531818]  ? __handle_sysrq.cold+0x4e/0x1ae
        [  477.532451]  ? write_sysrq_trigger+0x63/0x80
        [  477.533080]  ? proc_reg_write+0x92/0x110
        [  477.533663]  ? vfs_write+0x174/0x530
        [  477.534265]  ? handle_mm_fault+0x16f/0x500
        [  477.534940]  ? ksys_write+0x7b/0x170
        [  477.535543]  ? __x64_sys_write+0x1d/0x30
        [  477.536191]  ? do_syscall_64+0x6b/0x100
        [  477.536809]  ? entry_SYSCALL_64_after_hwframe+0x63/0xcd
        [  477.537609]  </TASK>
      
      This happens when the compiled code for show_stack() has a single word
      on the stack, and doesn't use a tail call to show_stack_log_lvl().
      (CONFIG_GCOV_PROFILE_ALL=y is the only known case of this.)  Then the
      __unwind_start() skip logic hits an off-by-one bug and fails to unwind
      all the way to the intended starting frame.
      
      Fix it by reverting the following commit:
      
        f1d9a2ab ("x86/unwind/orc: Don't skip the first frame for inactive tasks")
      
      The original justification for that commit no longer exists.  That
      original issue was later fixed in a different way, with the following
      commit:
      
        f2ac57a4 ("x86/unwind/orc: Fix inactive tasks with stack pointer in %sp on GCC 10 compiled kernels")
      
      Fixes: f1d9a2ab
      
       ("x86/unwind/orc: Don't skip the first frame for inactive tasks")
      Signed-off-by: default avatarChen Zhongjin <chenzhongjin@huawei.com>
      [jpoimboe: rewrite commit log]
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@kernel.org>
      Signed-off-by: default avatarPeter Zijlstra <peterz@infradead.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      47be0127
    • Yang Yingliang's avatar
      net: netsec: fix error handling in netsec_register_mdio() · 728884b2
      Yang Yingliang authored
      [ Upstream commit 94423589 ]
      
      If phy_device_register() fails, phy_device_free() need be called to
      put refcount, so memory of phy device and device name can be freed
      in callback function.
      
      If get_phy_device() fails, mdiobus_unregister() need be called,
      or it will cause warning in mdiobus_free() and kobject is leaked.
      
      Fixes: 533dd11a
      
       ("net: socionext: Add Synquacer NetSec driver")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Link: https://lore.kernel.org/r/20221019064104.3228892-1-yangyingliang@huawei.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      728884b2
    • Xin Long's avatar
      tipc: fix a null-ptr-deref in tipc_topsrv_accept · ce69bdac
      Xin Long authored
      [ Upstream commit 82cb4e46 ]
      
      syzbot found a crash in tipc_topsrv_accept:
      
        KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
        Workqueue: tipc_rcv tipc_topsrv_accept
        RIP: 0010:kernel_accept+0x22d/0x350 net/socket.c:3487
        Call Trace:
         <TASK>
         tipc_topsrv_accept+0x197/0x280 net/tipc/topsrv.c:460
         process_one_work+0x991/0x1610 kernel/workqueue.c:2289
         worker_thread+0x665/0x1080 kernel/workqueue.c:2436
         kthread+0x2e4/0x3a0 kernel/kthread.c:376
         ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306
      
      It was caused by srv->listener that might be set to null by
      tipc_topsrv_stop() in net .exit whereas it's still used in
      tipc_topsrv_accept() worker.
      
      srv->listener is protected by srv->idr_lock in tipc_topsrv_stop(), so add
      a check for srv->listener under srv->idr_lock in tipc_topsrv_accept() to
      avoid the null-ptr-deref. To ensure the lsock is not released during the
      tipc_topsrv_accept(), move sock_release() after tipc_topsrv_work_stop()
      where it's waiting until the tipc_topsrv_accept worker to be done.
      
      Note that sk_callback_lock is used to protect sk->sk_user_data instead of
      srv->listener, and it should check srv in tipc_topsrv_listener_data_ready()
      instead. This also ensures that no more tipc_topsrv_accept worker will be
      started after tipc_conn_close() is called in tipc_topsrv_stop() where it
      sets sk->sk_user_data to null.
      
      Fixes: 0ef897be
      
       ("tipc: separate topology server listener socket from subcsriber sockets")
      Reported-by: default avatar <syzbot+c5ce866a8d30f4be0651@syzkaller.appspotmail.com>
      Signed-off-by: default avatarXin Long <lucien.xin@gmail.com>
      Acked-by: default avatarJon Maloy <jmaloy@redhat.com>
      Link: https://lore.kernel.org/r/4eee264380c409c61c6451af1059b7fb271a7e7b.1666120790.git.lucien.xin@gmail.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ce69bdac
    • Yang Yingliang's avatar
      ALSA: ac97: fix possible memory leak in snd_ac97_dev_register() · ee8bf094
      Yang Yingliang authored
      [ Upstream commit 4881bda5 ]
      
      If device_register() fails in snd_ac97_dev_register(), it should
      call put_device() to give up reference, or the name allocated in
      dev_set_name() is leaked.
      
      Fixes: 0ca06a00
      
       ("[ALSA] AC97 bus interface for ad-hoc drivers")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Link: https://lore.kernel.org/r/20221019093025.1179475-1-yangyingliang@huawei.com
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ee8bf094
    • Randy Dunlap's avatar
      arc: iounmap() arg is volatile · 13626e56
      Randy Dunlap authored
      [ Upstream commit c44f15c1 ]
      
      Add 'volatile' to iounmap()'s argument to prevent build warnings.
      This make it the same as other major architectures.
      
      Placates these warnings: (12 such warnings)
      
      ../drivers/video/fbdev/riva/fbdev.c: In function 'rivafb_probe':
      ../drivers/video/fbdev/riva/fbdev.c:2067:42: error: passing argument 1 of 'iounmap' discards 'volatile' qualifier from pointer target type [-Werror=discarded-qualifiers]
       2067 |                 iounmap(default_par->riva.PRAMIN);
      
      Fixes: 1162b070
      
       ("ARC: I/O and DMA Mappings")
      Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Cc: Vineet Gupta <vgupta@kernel.org>
      Cc: linux-snps-arc@lists.infradead.org
      Cc: Arnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarVineet Gupta <vgupta@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      13626e56
    • Nathan Huckleberry's avatar
      drm/msm: Fix return type of mdp4_lvds_connector_mode_valid · 5642da89
      Nathan Huckleberry authored
      [ Upstream commit 0b33a33b
      
       ]
      
      The mode_valid field in drm_connector_helper_funcs is expected to be of
      type:
      enum drm_mode_status (* mode_valid) (struct drm_connector *connector,
                                           struct drm_display_mode *mode);
      
      The mismatched return type breaks forward edge kCFI since the underlying
      function definition does not match the function hook definition.
      
      The return type of mdp4_lvds_connector_mode_valid should be changed from
      int to enum drm_mode_status.
      
      Reported-by: default avatarDan Carpenter <error27@gmail.com>
      Link: https://github.com/ClangBuiltLinux/linux/issues/1703
      Cc: llvm@lists.linux.dev
      Signed-off-by: default avatarNathan Huckleberry <nhuck@google.com>
      Fixes: 3e87599b
      
       ("drm/msm/mdp4: add LVDS panel support")
      Reviewed-by: default avatarAbhinav Kumar <quic_abhinavk@quicinc.com>
      Reviewed-by: default avatarNathan Chancellor <nathan@kernel.org>
      Patchwork: https://patchwork.freedesktop.org/patch/502878/
      Link: https://lore.kernel.org/r/20220913205551.155128-1-nhuck@google.com
      Signed-off-by: default avatarAbhinav Kumar <quic_abhinavk@quicinc.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5642da89
    • Wei Yongjun's avatar
      net: ieee802154: fix error return code in dgram_bind() · 7bce13b4
      Wei Yongjun authored
      commit 444d8ad4 upstream.
      
      Fix to return error code -EINVAL from the error handling
      case instead of 0, as done elsewhere in this function.
      
      Fixes: 94160108
      
       ("net/ieee802154: fix uninit value bug in dgram_sendmsg")
      Signed-off-by: default avatarWei Yongjun <weiyongjun1@huawei.com>
      Link: https://lore.kernel.org/r/20220919160830.1436109-1-weiyongjun@huaweicloud.com
      Signed-off-by: default avatarStefan Schmidt <stefan@datenfreihafen.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7bce13b4
    • Rik van Riel's avatar
      mm,hugetlb: take hugetlb_lock before decrementing h->resv_huge_pages · 2b35432d
      Rik van Riel authored
      commit 12df140f upstream.
      
      The h->*_huge_pages counters are protected by the hugetlb_lock, but
      alloc_huge_page has a corner case where it can decrement the counter
      outside of the lock.
      
      This could lead to a corrupted value of h->resv_huge_pages, which we have
      observed on our systems.
      
      Take the hugetlb_lock before decrementing h->resv_huge_pages to avoid a
      potential race.
      
      Link: https://lkml.kernel.org/r/20221017202505.0e6a4fcd@imladris.surriel.com
      Fixes: a88c7695
      
       ("mm: hugetlb: fix hugepage memory leak caused by wrong reserve count")
      Signed-off-by: default avatarRik van Riel <riel@surriel.com>
      Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
      Cc: Glen McCready <gkmccready@meta.com>
      Cc: Mike Kravetz <mike.kravetz@oracle.com>
      Cc: Muchun Song <songmuchun@bytedance.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2b35432d
    • M. Vefa Bicakci's avatar
      xen/gntdev: Prevent leaking grants · cb1ccfe7
      M. Vefa Bicakci authored
      commit 0991028c upstream.
      
      Prior to this commit, if a grant mapping operation failed partially,
      some of the entries in the map_ops array would be invalid, whereas all
      of the entries in the kmap_ops array would be valid. This in turn would
      cause the following logic in gntdev_map_grant_pages to become invalid:
      
        for (i = 0; i < map->count; i++) {
          if (map->map_ops[i].status == GNTST_okay) {
            map->unmap_ops[i].handle = map->map_ops[i].handle;
            if (!use_ptemod)
              alloced++;
          }
          if (use_ptemod) {
            if (map->kmap_ops[i].status == GNTST_okay) {
              if (map->map_ops[i].status == GNTST_okay)
                alloced++;
              map->kunmap_ops[i].handle = map->kmap_ops[i].handle;
            }
          }
        }
        ...
        atomic_add(alloced, &map->live_grants);
      
      Assume that use_ptemod is true (i.e., the domain mapping the granted
      pages is a paravirtualized domain). In the code excerpt above, note that
      the "alloced" variable is only incremented when both kmap_ops[i].status
      and map_ops[i].status are set to GNTST_okay (i.e., both mapping
      operations are successful).  However, as also noted above, there are
      cases where a grant mapping operation fails partially, breaking the
      assumption of the code excerpt above.
      
      The aforementioned causes map->live_grants to be incorrectly set. In
      some cases, all of the map_ops mappings fail, but all of the kmap_ops
      mappings succeed, meaning that live_grants may remain zero. This in turn
      makes it impossible to unmap the successfully grant-mapped pages pointed
      to by kmap_ops, because unmap_grant_pages has the following snippet of
      code at its beginning:
      
        if (atomic_read(&map->live_grants) == 0)
          return; /* Nothing to do */
      
      In other cases where only some of the map_ops mappings fail but all
      kmap_ops mappings succeed, live_grants is made positive, but when the
      user requests unmapping the grant-mapped pages, __unmap_grant_pages_done
      will then make map->live_grants negative, because the latter function
      does not check if all of the pages that were requested to be unmapped
      were actually unmapped, and the same function unconditionally subtracts
      "data->count" (i.e., a value that can be greater than map->live_grants)
      from map->live_grants. The side effects of a negative live_grants value
      have not been studied.
      
      The net effect of all of this is that grant references are leaked in one
      of the above conditions. In Qubes OS v4.1 (which uses Xen's grant
      mechanism extensively for X11 GUI isolation), this issue manifests
      itself with warning messages like the following to be printed out by the
      Linux kernel in the VM that had granted pages (that contain X11 GUI
      window data) to dom0: "g.e. 0x1234 still pending", especially after the
      user rapidly resizes GUI VM windows (causing some grant-mapping
      operations to partially or completely fail, due to the fact that the VM
      unshares some of the pages as part of the window resizing, making the
      pages impossible to grant-map from dom0).
      
      The fix for this issue involves counting all successful map_ops and
      kmap_ops mappings separately, and then adding the sum to live_grants.
      During unmapping, only the number of successfully unmapped grants is
      subtracted from live_grants. The code is also modified to check for
      negative live_grants values after the subtraction and warn the user.
      
      Link: https://github.com/QubesOS/qubes-issues/issues/7631
      Fixes: dbe97cff
      
       ("xen/gntdev: Avoid blocking in unmap_grant_pages()")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarM. Vefa Bicakci <m.v.b@runbox.com>
      Acked-by: default avatarDemi Marie Obenour <demi@invisiblethingslab.com>
      Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
      Link: https://lore.kernel.org/r/20221002222006.2077-2-m.v.b@runbox.com
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      Signed-off-by: default avatarDemi Marie Obenour <demi@invisiblethingslab.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cb1ccfe7
    • Jan Beulich's avatar
      Xen/gntdev: don't ignore kernel unmapping error · fce19bd9
      Jan Beulich authored
      commit f28347cc
      
       upstream.
      
      While working on XSA-361 and its follow-ups, I failed to spot another
      place where the kernel mapping part of an operation was not treated the
      same as the user space part. Detect and propagate errors and add a 2nd
      pr_debug().
      
      Signed-off-by: default avatarJan Beulich <jbeulich@suse.com>
      Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
      Link: https://lore.kernel.org/r/c2513395-74dc-aea3-9192-fd265aa44e35@suse.com
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      Signed-off-by: default avatarDemi Marie Obenour <demi@invisiblethingslab.com>
      Co-authored-by: default avatarDemi Marie Obenour <demi@invisiblethingslab.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fce19bd9
    • Heiko Carstens's avatar
      s390/futex: add missing EX_TABLE entry to __futex_atomic_op() · e2efdae0
      Heiko Carstens authored
      commit a262d3ad
      
       upstream.
      
      For some exception types the instruction address points behind the
      instruction that caused the exception. Take that into account and add
      the missing exception table entry.
      
      Cc: <stable@vger.kernel.org>
      Reviewed-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Signed-off-by: default avatarHeiko Carstens <hca@linux.ibm.com>
      Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e2efdae0
    • Adrian Hunter's avatar
      perf auxtrace: Fix address filter symbol name match for modules · 24051c7b
      Adrian Hunter authored
      commit cba04f31 upstream.
      
      For modules, names from kallsyms__parse() contain the module name which
      meant that module symbols did not match exactly by name.
      
      Fix by matching the name string up to the separating tab character.
      
      Fixes: 1b36c03e
      
       ("perf record: Add support for using symbols in address filters")
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20221026072736.2982-1-adrian.hunter@intel.com
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      24051c7b
    • Christian A. Ehrhardt's avatar
      kernfs: fix use-after-free in __kernfs_remove · 028cf780
      Christian A. Ehrhardt authored
      commit 4abc9965
      
       upstream.
      
      Syzkaller managed to trigger concurrent calls to
      kernfs_remove_by_name_ns() for the same file resulting in
      a KASAN detected use-after-free. The race occurs when the root
      node is freed during kernfs_drain().
      
      To prevent this acquire an additional reference for the root
      of the tree that is removed before calling __kernfs_remove().
      
      Found by syzkaller with the following reproducer (slab_nomerge is
      required):
      
      syz_mount_image$ext4(0x0, &(0x7f0000000100)='./file0\x00', 0x100000, 0x0, 0x0, 0x0, 0x0)
      r0 = openat(0xffffffffffffff9c, &(0x7f0000000080)='/proc/self/exe\x00', 0x0, 0x0)
      close(r0)
      pipe2(&(0x7f0000000140)={0xffffffffffffffff, <r1=>0xffffffffffffffff}, 0x800)
      mount$9p_fd(0x0, &(0x7f0000000040)='./file0\x00', &(0x7f00000000c0), 0x408, &(0x7f0000000280)={'trans=fd,', {'rfdno', 0x3d, r0}, 0x2c, {'wfdno', 0x3d, r1}, 0x2c, {[{@cache_loose}, {@mmap}, {@loose}, {@loose}, {@mmap}], [{@mask={'mask', 0x3d, '^MAY_EXEC'}}, {@fsmagic={'fsmagic', 0x3d, 0x10001}}, {@dont_hash}]}})
      
      Sample report:
      
      ==================================================================
      BUG: KASAN: use-after-free in kernfs_type include/linux/kernfs.h:335 [inline]
      BUG: KASAN: use-after-free in kernfs_leftmost_descendant fs/kernfs/dir.c:1261 [inline]
      BUG: KASAN: use-after-free in __kernfs_remove.part.0+0x843/0x960 fs/kernfs/dir.c:1369
      Read of size 2 at addr ffff8880088807f0 by task syz-executor.2/857
      
      CPU: 0 PID: 857 Comm: syz-executor.2 Not tainted 6.0.0-rc3-00363-g7726d4c3e60b #5
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
      Call Trace:
       <TASK>
       __dump_stack lib/dump_stack.c:88 [inline]
       dump_stack_lvl+0x6e/0x91 lib/dump_stack.c:106
       print_address_description mm/kasan/report.c:317 [inline]
       print_report.cold+0x5e/0x5e5 mm/kasan/report.c:433
       kasan_report+0xa3/0x130 mm/kasan/report.c:495
       kernfs_type include/linux/kernfs.h:335 [inline]
       kernfs_leftmost_descendant fs/kernfs/dir.c:1261 [inline]
       __kernfs_remove.part.0+0x843/0x960 fs/kernfs/dir.c:1369
       __kernfs_remove fs/kernfs/dir.c:1356 [inline]
       kernfs_remove_by_name_ns+0x108/0x190 fs/kernfs/dir.c:1589
       sysfs_slab_add+0x133/0x1e0 mm/slub.c:5943
       __kmem_cache_create+0x3e0/0x550 mm/slub.c:4899
       create_cache mm/slab_common.c:229 [inline]
       kmem_cache_create_usercopy+0x167/0x2a0 mm/slab_common.c:335
       p9_client_create+0xd4d/0x1190 net/9p/client.c:993
       v9fs_session_init+0x1e6/0x13c0 fs/9p/v9fs.c:408
       v9fs_mount+0xb9/0xbd0 fs/9p/vfs_super.c:126
       legacy_get_tree+0xf1/0x200 fs/fs_context.c:610
       vfs_get_tree+0x85/0x2e0 fs/super.c:1530
       do_new_mount fs/namespace.c:3040 [inline]
       path_mount+0x675/0x1d00 fs/namespace.c:3370
       do_mount fs/namespace.c:3383 [inline]
       __do_sys_mount fs/namespace.c:3591 [inline]
       __se_sys_mount fs/namespace.c:3568 [inline]
       __x64_sys_mount+0x282/0x300 fs/namespace.c:3568
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x38/0x90 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      RIP: 0033:0x7f725f983aed
      Code: 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b0 ff ff ff f7 d8 64 89 01 48
      RSP: 002b:00007f725f0f7028 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
      RAX: ffffffffffffffda RBX: 00007f725faa3f80 RCX: 00007f725f983aed
      RDX: 00000000200000c0 RSI: 0000000020000040 RDI: 0000000000000000
      RBP: 00007f725f9f419c R08: 0000000020000280 R09: 0000000000000000
      R10: 0000000000000408 R11: 0000000000000246 R12: 0000000000000000
      R13: 0000000000000006 R14: 00007f725faa3f80 R15: 00007f725f0d7000
       </TASK>
      
      Allocated by task 855:
       kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
       kasan_set_track mm/kasan/common.c:45 [inline]
       set_alloc_info mm/kasan/common.c:437 [inline]
       __kasan_slab_alloc+0x66/0x80 mm/kasan/common.c:470
       kasan_slab_alloc include/linux/kasan.h:224 [inline]
       slab_post_alloc_hook mm/slab.h:727 [inline]
       slab_alloc_node mm/slub.c:3243 [inline]
       slab_alloc mm/slub.c:3251 [inline]
       __kmem_cache_alloc_lru mm/slub.c:3258 [inline]
       kmem_cache_alloc+0xbf/0x200 mm/slub.c:3268
       kmem_cache_zalloc include/linux/slab.h:723 [inline]
       __kernfs_new_node+0xd4/0x680 fs/kernfs/dir.c:593
       kernfs_new_node fs/kernfs/dir.c:655 [inline]
       kernfs_create_dir_ns+0x9c/0x220 fs/kernfs/dir.c:1010
       sysfs_create_dir_ns+0x127/0x290 fs/sysfs/dir.c:59
       create_dir lib/kobject.c:63 [inline]
       kobject_add_internal+0x24a/0x8d0 lib/kobject.c:223
       kobject_add_varg lib/kobject.c:358 [inline]
       kobject_init_and_add+0x101/0x160 lib/kobject.c:441
       sysfs_slab_add+0x156/0x1e0 mm/slub.c:5954
       __kmem_cache_create+0x3e0/0x550 mm/slub.c:4899
       create_cache mm/slab_common.c:229 [inline]
       kmem_cache_create_usercopy+0x167/0x2a0 mm/slab_common.c:335
       p9_client_create+0xd4d/0x1190 net/9p/client.c:993
       v9fs_session_init+0x1e6/0x13c0 fs/9p/v9fs.c:408
       v9fs_mount+0xb9/0xbd0 fs/9p/vfs_super.c:126
       legacy_get_tree+0xf1/0x200 fs/fs_context.c:610
       vfs_get_tree+0x85/0x2e0 fs/super.c:1530
       do_new_mount fs/namespace.c:3040 [inline]
       path_mount+0x675/0x1d00 fs/namespace.c:3370
       do_mount fs/namespace.c:3383 [inline]
       __do_sys_mount fs/namespace.c:3591 [inline]
       __se_sys_mount fs/namespace.c:3568 [inline]
       __x64_sys_mount+0x282/0x300 fs/namespace.c:3568
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x38/0x90 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      Freed by task 857:
       kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
       kasan_set_track+0x21/0x30 mm/kasan/common.c:45
       kasan_set_free_info+0x20/0x40 mm/kasan/generic.c:370
       ____kasan_slab_free mm/kasan/common.c:367 [inline]
       ____kasan_slab_free mm/kasan/common.c:329 [inline]
       __kasan_slab_free+0x108/0x190 mm/kasan/common.c:375
       kasan_slab_free include/linux/kasan.h:200 [inline]
       slab_free_hook mm/slub.c:1754 [inline]
       slab_free_freelist_hook mm/slub.c:1780 [inline]
       slab_free mm/slub.c:3534 [inline]
       kmem_cache_free+0x9c/0x340 mm/slub.c:3551
       kernfs_put.part.0+0x2b2/0x520 fs/kernfs/dir.c:547
       kernfs_put+0x42/0x50 fs/kernfs/dir.c:521
       __kernfs_remove.part.0+0x72d/0x960 fs/kernfs/dir.c:1407
       __kernfs_remove fs/kernfs/dir.c:1356 [inline]
       kernfs_remove_by_name_ns+0x108/0x190 fs/kernfs/dir.c:1589
       sysfs_slab_add+0x133/0x1e0 mm/slub.c:5943
       __kmem_cache_create+0x3e0/0x550 mm/slub.c:4899
       create_cache mm/slab_common.c:229 [inline]
       kmem_cache_create_usercopy+0x167/0x2a0 mm/slab_common.c:335
       p9_client_create+0xd4d/0x1190 net/9p/client.c:993
       v9fs_session_init+0x1e6/0x13c0 fs/9p/v9fs.c:408
       v9fs_mount+0xb9/0xbd0 fs/9p/vfs_super.c:126
       legacy_get_tree+0xf1/0x200 fs/fs_context.c:610
       vfs_get_tree+0x85/0x2e0 fs/super.c:1530
       do_new_mount fs/namespace.c:3040 [inline]
       path_mount+0x675/0x1d00 fs/namespace.c:3370
       do_mount fs/namespace.c:3383 [inline]
       __do_sys_mount fs/namespace.c:3591 [inline]
       __se_sys_mount fs/namespace.c:3568 [inline]
       __x64_sys_mount+0x282/0x300 fs/namespace.c:3568
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x38/0x90 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      The buggy address belongs to the object at ffff888008880780
       which belongs to the cache kernfs_node_cache of size 128
      The buggy address is located 112 bytes inside of
       128-byte region [ffff888008880780, ffff888008880800)
      
      The buggy address belongs to the physical page:
      page:00000000732833f8 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x8880
      flags: 0x100000000000200(slab|node=0|zone=1)
      raw: 0100000000000200 0000000000000000 dead000000000122 ffff888001147280
      raw: 0000000000000000 0000000000150015 00000001ffffffff 0000000000000000
      page dumped because: kasan: bad access detected
      
      Memory state around the buggy address:
       ffff888008880680: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb
       ffff888008880700: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
      >ffff888008880780: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                                   ^
       ffff888008880800: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb
       ffff888008880880: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
      ==================================================================
      
      Acked-by: default avatarTejun Heo <tj@kernel.org>
      Cc: stable <stable@kernel.org> # -rc3
      Signed-off-by: default avatarChristian A. Ehrhardt <lk@c--e.de>
      Link: https://lore.kernel.org/r/20220913121723.691454-1-lk@c--e.de
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      028cf780
    • Matthew Ma's avatar
      mmc: core: Fix kernel panic when remove non-standard SDIO card · 1fb79478
      Matthew Ma authored
      commit 9972e6b4 upstream.
      
      SDIO tuple is only allocated for standard SDIO card, especially it causes
      memory corruption issues when the non-standard SDIO card has removed, which
      is because the card device's reference counter does not increase for it at
      sdio_init_func(), but all SDIO card device reference counter gets decreased
      at sdio_release_func().
      
      Fixes: 6f51be3d
      
       ("sdio: allow non-standard SDIO cards")
      Signed-off-by: default avatarMatthew Ma <mahongwei@zeku.com>
      Reviewed-by: default avatarWeizhao Ouyang <ouyangweizhao@zeku.com>
      Reviewed-by: default avatarJohn Wang <wangdayu@zeku.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20221014034951.2300386-1-ouyangweizhao@zeku.com
      Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1fb79478
    • Johan Hovold's avatar
      drm/msm/hdmi: fix memory corruption with too many bridges · 3c43f3ec
      Johan Hovold authored
      commit 4c1294da upstream.
      
      Add the missing sanity check on the bridge counter to avoid corrupting
      data beyond the fixed-sized bridge array in case there are ever more
      than eight bridges.
      
      Fixes: a3376e3e
      
       ("drm/msm: convert to drm_bridge")
      Cc: stable@vger.kernel.org	# 3.12
      Signed-off-by: default avatarJohan Hovold <johan+linaro@kernel.org>
      Tested-by: default avatarKuogee Hsieh <quic_khsieh@quicinc.com>
      Reviewed-by: default avatarKuogee Hsieh <quic_khsieh@quicinc.com>
      Reviewed-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
      Patchwork: https://patchwork.freedesktop.org/patch/502670/
      Link: https://lore.kernel.org/r/20220913085320.8577-5-johan+linaro@kernel.org
      Signed-off-by: default avatarAbhinav Kumar <quic_abhinavk@quicinc.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3c43f3ec
    • Johan Hovold's avatar
      drm/msm/dsi: fix memory corruption with too many bridges · 4e5587cd
      Johan Hovold authored
      commit 2e786eb2 upstream.
      
      Add the missing sanity check on the bridge counter to avoid corrupting
      data beyond the fixed-sized bridge array in case there are ever more
      than eight bridges.
      
      Fixes: a689554b
      
       ("drm/msm: Initial add DSI connector support")
      Cc: stable@vger.kernel.org	# 4.1
      Signed-off-by: default avatarJohan Hovold <johan+linaro@kernel.org>
      Tested-by: default avatarKuogee Hsieh <quic_khsieh@quicinc.com>
      Reviewed-by: default avatarKuogee Hsieh <quic_khsieh@quicinc.com>
      Reviewed-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
      Patchwork: https://patchwork.freedesktop.org/patch/502668/
      Link: https://lore.kernel.org/r/20220913085320.8577-4-johan+linaro@kernel.org
      Signed-off-by: default avatarAbhinav Kumar <quic_abhinavk@quicinc.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4e5587cd
    • Miquel Raynal's avatar
      mac802154: Fix LQI recording · 4f1a7bd9
      Miquel Raynal authored
      commit 5a5c4e06 upstream.
      
      Back in 2014, the LQI was saved in the skb control buffer (skb->cb, or
      mac_cb(skb)) without any actual reset of this area prior to its use.
      
      As part of a useful rework of the use of this region, 32edc40a
      ("ieee802154: change _cb handling slightly") introduced mac_cb_init() to
      basically memset the cb field to 0. In particular, this new function got
      called at the beginning of mac802154_parse_frame_start(), right before
      the location where the buffer got actually filled.
      
      What went through unnoticed however, is the fact that the very first
      helper called by device drivers in the receive path already used this
      area to save the LQI value for later extraction. Resetting the cb field
      "so late" led to systematically zeroing the LQI.
      
      If we consider the reset of the cb field needed, we can make it as soon
      as we get an skb from a device driver, right before storing the LQI,
      as is the very first time we need to write something there.
      
      Cc: stable@vger.kernel.org
      Fixes: 32edc40a
      
       ("ieee802154: change _cb handling slightly")
      Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
      Acked-by: default avatarAlexander Aring <aahringo@redhat.com>
      Link: https://lore.kernel.org/r/20221020142535.1038885-1-miquel.raynal@bootlin.com
      Signed-off-by: default avatarStefan Schmidt <stefan@datenfreihafen.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4f1a7bd9
    • Hyunwoo Kim's avatar
      fbdev: smscufx: Fix several use-after-free bugs · 70faf9d9
      Hyunwoo Kim authored
      commit cc67482c
      
       upstream.
      
      Several types of UAFs can occur when physically removing a USB device.
      
      Adds ufx_ops_destroy() function to .fb_destroy of fb_ops, and
      in this function, there is kref_put() that finally calls ufx_free().
      
      This fix prevents multiple UAFs.
      
      Signed-off-by: default avatarHyunwoo Kim <imv4bel@gmail.com>
      Link: https://lore.kernel.org/linux-fbdev/20221011153436.GA4446@ubuntu/
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarHelge Deller <deller@gmx.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      70faf9d9
    • Shreeya Patel's avatar
      iio: light: tsl2583: Fix module unloading · 971a76b9
      Shreeya Patel authored
      commit 0dec4d2f upstream.
      
      tsl2583 probe() uses devm_iio_device_register() and calling
      iio_device_unregister() causes the unregister to occur twice. s
      Switch to iio_device_register() instead of devm_iio_device_register()
      in probe to avoid the device managed cleanup.
      
      Fixes: 371894f5
      
       ("iio: tsl2583: add runtime power management support")
      Signed-off-by: default avatarShreeya Patel <shreeya.patel@collabora.com>
      Link: https://lore.kernel.org/r/20220826122352.288438-1-shreeya.patel@collabora.com
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      971a76b9
    • Matti Vaittinen's avatar
      tools: iio: iio_utils: fix digit calculation · 37ecf8cb
      Matti Vaittinen authored
      commit 72b2aa38 upstream.
      
      The iio_utils uses a digit calculation in order to know length of the
      file name containing a buffer number. The digit calculation does not
      work for number 0.
      
      This leads to allocation of one character too small buffer for the
      file-name when file name contains value '0'. (Eg. buffer0).
      
      Fix digit calculation by returning one digit to be present for number
      '0'.
      
      Fixes: 096f9b86
      
       ("tools:iio:iio_utils: implement digit calculation")
      Signed-off-by: default avatarMatti Vaittinen <mazziesaccount@gmail.com>
      Link: https://lore.kernel.org/r/Y0f+tKCz+ZAIoroQ@dc75zzyyyyyyyyyyyyycy-3.rev.dnainternet.fi
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      37ecf8cb
    • Mathias Nyman's avatar
      xhci: Remove device endpoints from bandwidth list when freeing the device · cebbc8d3
      Mathias Nyman authored
      commit 5aed5b7c
      
       upstream.
      
      Endpoints are normally deleted from the bandwidth list when they are
      dropped, before the virt device is freed.
      
      If xHC host is dying or being removed then the endpoints aren't dropped
      cleanly due to functions returning early to avoid interacting with a
      non-accessible host controller.
      
      So check and delete endpoints that are still on the bandwidth list when
      freeing the virt device.
      
      Solves a list_del corruption kernel crash when unbinding xhci-pci,
      caused by xhci_mem_cleanup() when it later tried to delete already freed
      endpoints from the bandwidth list.
      
      This only affects hosts that use software bandwidth checking, which
      currenty is only the xHC in intel Panther Point PCH (Ivy Bridge)
      
      Cc: stable@vger.kernel.org
      Reported-by: default avatarMarek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
      Tested-by: default avatarMarek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/20221024142720.4122053-5-mathias.nyman@intel.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cebbc8d3
    • Jens Glathe's avatar
      usb: xhci: add XHCI_SPURIOUS_SUCCESS to ASM1042 despite being a V0.96 controller · e72168e0
      Jens Glathe authored
      commit 4f547472
      
       upstream.
      
      This appears to fix the error:
      "xhci_hcd <address>; ERROR Transfer event TRB DMA ptr not part of
      current TD ep_index 2 comp_code 13" that appear spuriously (or pretty
      often) when using a r8152 USB3 ethernet adapter with integrated hub.
      
      ASM1042 reports as a 0.96 controller, but appears to behave more like 1.0
      
      Inspired by this email thread: https://markmail.org/thread/7vzqbe7t6du6qsw3
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJens Glathe <jens.glathe@oldschoolsolutions.biz>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/20221024142720.4122053-2-mathias.nyman@intel.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e72168e0
    • Justin Chen's avatar
      usb: bdc: change state when port disconnected · 71316fe2
      Justin Chen authored
      commit fb8f60dd
      
       upstream.
      
      When port is connected and then disconnected, the state stays as
      configured. Which is incorrect as the port is no longer configured,
      but in a not attached state.
      
      Signed-off-by: default avatarJustin Chen <justinpopo6@gmail.com>
      Acked-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Fixes: efed421a
      
       ("usb: gadget: Add UDC driver for Broadcom USB3.0 device controller IP BDC")
      Cc: stable <stable@kernel.org>
      Link: https://lore.kernel.org/r/1664997235-18198-1-git-send-email-justinpopo6@gmail.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      71316fe2
    • Thinh Nguyen's avatar
      usb: dwc3: gadget: Don't set IMI for no_interrupt · 37082710
      Thinh Nguyen authored
      commit 308c316d upstream.
      
      The gadget driver may have a certain expectation of how the request
      completion flow should be from to its configuration. Make sure the
      controller driver respect that. That is, don't set IMI (Interrupt on
      Missed Isoc) when usb_request->no_interrupt is set. Also, the driver
      should only set IMI to the last TRB of a chain.
      
      Fixes: 72246da4
      
       ("usb: Introduce DesignWare USB3 DRD Driver")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarThinh Nguyen <Thinh.Nguyen@synopsys.com>
      Reviewed-by: default avatarJeff Vanhoof <jdv1029@gmail.com>
      Tested-by: default avatarJeff Vanhoof <jdv1029@gmail.com>
      Link: https://lore.kernel.org/r/ced336c84434571340c07994e3667a0ee284fefe.1666735451.git.Thinh.Nguyen@synopsys.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      37082710
    • Thinh Nguyen's avatar
      usb: dwc3: gadget: Stop processing more requests on IMI · 5a8fe9a5
      Thinh Nguyen authored
      commit f78961f8 upstream.
      
      When servicing a transfer completion event, the dwc3 driver will reclaim
      TRBs of started requests up to the request associated with the interrupt
      event. Currently we don't check for interrupt due to missed isoc, and
      the driver may attempt to reclaim TRBs beyond the associated event. This
      causes invalid memory access when the hardware still owns the TRB. If
      there's a missed isoc TRB with IMI (interrupt on missed isoc), make sure
      to stop servicing further.
      
      Note that only the last TRB of chained TRBs has its status updated with
      missed isoc.
      
      Fixes: 72246da4
      
       ("usb: Introduce DesignWare USB3 DRD Driver")
      Cc: stable@vger.kernel.org
      Reported-by: default avatarJeff Vanhoof <jdv1029@gmail.com>
      Reported-by: default avatarDan Vacura <w36195@motorola.com>
      Signed-off-by: default avatarThinh Nguyen <Thinh.Nguyen@synopsys.com>
      Reviewed-by: default avatarJeff Vanhoof <jdv1029@gmail.com>
      Tested-by: default avatarJeff Vanhoof <jdv1029@gmail.com>
      Link: https://lore.kernel.org/r/b29acbeab531b666095dfdafd8cb5c7654fbb3e1.1666735451.git.Thinh.Nguyen@synopsys.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5a8fe9a5
    • Hannu Hartikainen's avatar
      USB: add RESET_RESUME quirk for NVIDIA Jetson devices in RCM · 126b0a2d
      Hannu Hartikainen authored
      commit fc4ade55
      
       upstream.
      
      NVIDIA Jetson devices in Force Recovery mode (RCM) do not support
      suspending, ie. flashing fails if the device has been suspended. The
      devices are still visible in lsusb and seem to work otherwise, making
      the issue hard to debug. This has been discovered in various forum
      posts, eg. [1].
      
      The patch has been tested on NVIDIA Jetson AGX Xavier, but I'm adding
      all the Jetson models listed in [2] on the assumption that they all
      behave similarly.
      
      [1]: https://forums.developer.nvidia.com/t/flashing-not-working/72365
      [2]: https://docs.nvidia.com/jetson/archives/l4t-archived/l4t-3271/index.html#page/Tegra%20Linux%20Driver%20Package%20Development%20Guide/quick_start.html
      
      Signed-off-by: default avatarHannu Hartikainen <hannu@hrtk.in>
      Cc: stable <stable@kernel.org>  # after 6.1-rc3
      Link: https://lore.kernel.org/r/20220919171610.30484-1-hannu@hrtk.in
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      126b0a2d
    • Jason A. Donenfeld's avatar
      ALSA: au88x0: use explicitly signed char · bcecbec2
      Jason A. Donenfeld authored
      commit ee03c0f2
      
       upstream.
      
      With char becoming unsigned by default, and with `char` alone being
      ambiguous and based on architecture, signed chars need to be marked
      explicitly as such. This fixes warnings like:
      
      sound/pci/au88x0/au88x0_core.c:2029 vortex_adb_checkinout() warn: signedness bug returning '(-22)'
      sound/pci/au88x0/au88x0_core.c:2046 vortex_adb_checkinout() warn: signedness bug returning '(-12)'
      sound/pci/au88x0/au88x0_core.c:2125 vortex_adb_allocroute() warn: 'vortex_adb_checkinout(vortex, (0), en, 0)' is unsigned
      sound/pci/au88x0/au88x0_core.c:2170 vortex_adb_allocroute() warn: 'vortex_adb_checkinout(vortex, stream->resources, en, 4)' is unsigned
      
      As well, since one function returns errnos, return an `int` rather than
      a `signed char`.
      
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20221024162929.536004-1-Jason@zx2c4.com
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bcecbec2
    • Steven Rostedt (Google)'s avatar
      ALSA: Use del_timer_sync() before freeing timer · 904209ea
      Steven Rostedt (Google) authored
      commit f0a86878 upstream.
      
      The current code for freeing the emux timer is extremely dangerous:
      
        CPU0				CPU1
        ----				----
      snd_emux_timer_callback()
      			    snd_emux_free()
      			      spin_lock(&emu->voice_lock)
      			      del_timer(&emu->tlist); <-- returns immediately
      			      spin_unlock(&emu->voice_lock);
      			      [..]
      			      kfree(emu);
      
        spin_lock(&emu->voice_lock);
      
       [BOOM!]
      
      Instead just use del_timer_sync() which will wait for the timer to finish
      before continuing. No need to check if the timer is active or not when
      doing so.
      
      This doesn't fix the race of a possible re-arming of the timer, but at
      least it won't use the data that has just been freed.
      
      [ Fixed unused variable warning by tiwai ]
      
      Cc: stable@vger.kernel.org
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Link: https://lore.kernel.org/r/20221026231236.6834b551@gandalf.local.home
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      904209ea
    • Anssi Hannula's avatar
      can: kvaser_usb: Fix possible completions during init_completion · db226f39
      Anssi Hannula authored
      commit 2871edb3 upstream.
      
      kvaser_usb uses completions to signal when a response event is received
      for outgoing commands.
      
      However, it uses init_completion() to reinitialize the start_comp and
      stop_comp completions before sending the start/stop commands.
      
      In case the device sends the corresponding response just before the
      actual command is sent, complete() may be called concurrently with
      init_completion() which is not safe.
      
      This might be triggerable even with a properly functioning device by
      stopping the interface (CMD_STOP_CHIP) just after it goes bus-off (which
      also causes the driver to send CMD_STOP_CHIP when restart-ms is off),
      but that was not tested.
      
      Fix the issue by using reinit_completion() instead.
      
      Fixes: 080f40a6
      
       ("can: kvaser_usb: Add support for Kvaser CAN/USB devices")
      Tested-by: default avatarJimmy Assarsson <extja@kvaser.com>
      Signed-off-by: default avatarAnssi Hannula <anssi.hannula@bitwise.fi>
      Signed-off-by: default avatarJimmy Assarsson <extja@kvaser.com>
      Link: https://lore.kernel.org/all/20221010185237.319219-2-extja@kvaser.com
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      db226f39
    • Seth Jenkins's avatar
      mm: /proc/pid/smaps_rollup: fix no vma's null-deref · dbe863bc
      Seth Jenkins authored
      Commit 258f669e ("mm: /proc/pid/smaps_rollup: convert to single value
      seq_file") introduced a null-deref if there are no vma's in the task in
      show_smaps_rollup.
      
      Fixes: 258f669e
      
       ("mm: /proc/pid/smaps_rollup: convert to single value seq_file")
      Signed-off-by: default avatarSeth Jenkins <sethjenkins@google.com>
      Reviewed-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
      Tested-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      dbe863bc
    • Gaurav Kohli's avatar
      hv_netvsc: Fix race between VF offering and VF association message from host · 0f10976b
      Gaurav Kohli authored
      commit 365e1ece upstream.
      
      During vm boot, there might be possibility that vf registration
      call comes before the vf association from host to vm.
      
      And this might break netvsc vf path, To prevent the same block
      vf registration until vf bind message comes from host.
      
      Cc: stable@vger.kernel.org
      Fixes: 00d7ddba
      
       ("hv_netvsc: pair VF based on serial number")
      Reviewed-by: default avatarHaiyang Zhang <haiyangz@microsoft.com>
      Signed-off-by: default avatarGaurav Kohli <gauravkohli@linux.microsoft.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0f10976b
    • Nick Desaulniers's avatar
      Makefile.debug: re-enable debug info for .S files · b442ad83
      Nick Desaulniers authored
      This is _not_ an upstream commit and just for 4.19.y only. It is based
      on commit 32ef9e50 upstream.
      
      Alexey reported that the fraction of unknown filename instances in
      kallsyms grew from ~0.3% to ~10% recently; Bill and Greg tracked it down
      to assembler defined symbols, which regressed as a result of:
      
      commit b8a90923 ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")
      
      In that commit, I allude to restoring debug info for assembler defined
      symbols in a follow up patch, but it seems I forgot to do so in
      
      commit a66049e2 ("Kbuild: make DWARF version a choice")
      
      Fixes: b8a90923
      
       ("Kbuild: do not emit debug info for assembly with LLVM_IAS=1")
      Signed-off-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b442ad83
    • Werner Sembach's avatar
      ACPI: video: Force backlight native for more TongFang devices · e0eaf41b
      Werner Sembach authored
      commit 3dbc80a3 upstream.
      
      This commit is very different from the upstream commit! It fixes the same
      issue by adding more quirks, rather then the general fix from the 6.1
      kernel, because the general fix from the 6.1 kernel is part of a larger
      refactoring of the backlight code which is not suitable for the stable
      series.
      
      As described in "ACPI: video: Drop NL5x?U, PF4NU1F and PF5?U??
      acpi_backlight=native quirks" (10212754) the upstream commit "ACPI:
      video: Make backlight class device registration a separate step (v2)"
      (3dbc80a3
      
      ) makes these quirks unnecessary. However as mentioned in this
      bugtracker ticket https://bugzilla.kernel.org/show_bug.cgi?id=215683#c17
      the upstream fix is part of a larger patchset that is overall too complex
      for stable.
      
      The TongFang GKxNRxx, GMxNGxx, GMxZGxx, and GMxRGxx / TUXEDO
      Stellaris/Polaris Gen 1-4, have the same problem as the Clevo NL5xRU and
      NL5xNU / TUXEDO Aura 15 Gen1 and Gen2:
      They have a working native and video interface for screen backlight.
      However the default detection mechanism first registers the video interface
      before unregistering it again and switching to the native interface during
      boot. This results in a dangling SBIOS request for backlight change for
      some reason, causing the backlight to switch to ~2% once per boot on the
      first power cord connect or disconnect event. Setting the native interface
      explicitly circumvents this buggy behaviour by avoiding the unregistering
      process.
      
      Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
      Signed-off-by: default avatarWerner Sembach <wse@tuxedocomputers.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e0eaf41b
    • Chen-Yu Tsai's avatar
      media: v4l2-mem2mem: Apply DST_QUEUE_OFF_BASE on MMAP buffers across ioctls · 95c47517
      Chen-Yu Tsai authored
      commit 8310ca94 upstream.
      
      DST_QUEUE_OFF_BASE is applied to offset/mem_offset on MMAP capture buffers
      only for the VIDIOC_QUERYBUF ioctl, while the userspace fields (including
      offset/mem_offset) are filled in for VIDIOC_{QUERY,PREPARE,Q,DQ}BUF
      ioctls. This leads to differences in the values presented to userspace.
      If userspace attempts to mmap the capture buffer directly using values
      from DQBUF, it will fail.
      
      Move the code that applies the magic offset into a helper, and call
      that helper from all four ioctl entry points.
      
      [hverkuil: drop unnecessary '= 0' in v4l2_m2m_querybuf() for ret]
      
      Fixes: 7f98639d ("V4L/DVB: add memory-to-memory device helper framework for videobuf")
      Fixes: 908a0d7c
      
       ("[media] v4l: mem2mem: port to videobuf2")
      Signed-off-by: default avatarChen-Yu Tsai <wenst@chromium.org>
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
      [OP: adjusted return logic for 4.19]
      Signed-off-by: default avatarOvidiu Panait <ovidiu.panait@windriver.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      95c47517
    • Jerry Snitselaar's avatar
      iommu/vt-d: Clean up si_domain in the init_dmars() error path · 5cecfe15
      Jerry Snitselaar authored
      [ Upstream commit 620bf9f9 ]
      
      A splat from kmem_cache_destroy() was seen with a kernel prior to
      commit ee2653bb ("iommu/vt-d: Remove domain and devinfo mempool")
      when there was a failure in init_dmars(), because the iommu_domain
      cache still had objects. While the mempool code is now gone, there
      still is a leak of the si_domain memory if init_dmars() fails. So
      clean up si_domain in the init_dmars() error path.
      
      Cc: Lu Baolu <baolu.lu@linux.intel.com>
      Cc: Joerg Roedel <joro@8bytes.org>
      Cc: Will Deacon <will@kernel.org>
      Cc: Robin Murphy <robin.murphy@arm.com>
      Fixes: 86080ccc
      
       ("iommu/vt-d: Allocate si_domain in init_dmars()")
      Signed-off-by: default avatarJerry Snitselaar <jsnitsel@redhat.com>
      Link: https://lore.kernel.org/r/20221010144842.308890-1-jsnitsel@redhat.com
      Signed-off-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
      Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5cecfe15
    • Yang Yingliang's avatar
      net: hns: fix possible memory leak in hnae_ae_register() · 7ae1345f
      Yang Yingliang authored
      [ Upstream commit ff2f5ec5 ]
      
      Inject fault while probing module, if device_register() fails,
      but the refcount of kobject is not decreased to 0, the name
      allocated in dev_set_name() is leaked. Fix this by calling
      put_device(), so that name can be freed in callback function
      kobject_cleanup().
      
      unreferenced object 0xffff00c01aba2100 (size 128):
        comm "systemd-udevd", pid 1259, jiffies 4294903284 (age 294.152s)
        hex dump (first 32 bytes):
          68 6e 61 65 30 00 00 00 18 21 ba 1a c0 00 ff ff  hnae0....!......
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<0000000034783f26>] slab_post_alloc_hook+0xa0/0x3e0
          [<00000000748188f2>] __kmem_cache_alloc_node+0x164/0x2b0
          [<00000000ab0743e8>] __kmalloc_node_track_caller+0x6c/0x390
          [<000000006c0ffb13>] kvasprintf+0x8c/0x118
          [<00000000fa27bfe1>] kvasprintf_const+0x60/0xc8
          [<0000000083e10ed7>] kobject_set_name_vargs+0x3c/0xc0
          [<000000000b87affc>] dev_set_name+0x7c/0xa0
          [<000000003fd8fe26>] hnae_ae_register+0xcc/0x190 [hnae]
          [<00000000fe97edc9>] hns_dsaf_ae_init+0x9c/0x108 [hns_dsaf]
          [<00000000c36ff1eb>] hns_dsaf_probe+0x548/0x748 [hns_dsaf]
      
      Fixes: 6fe6611f
      
       ("net: add Hisilicon Network Subsystem hnae framework support")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Reviewed-by: default avatarLeon Romanovsky <leonro@nvidia.com>
      Link: https://lore.kernel.org/r/20221018122451.1749171-1-yangyingliang@huawei.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7ae1345f