Skip to content
  1. Nov 26, 2022
    • Cong Wang's avatar
      kcm: close race conditions on sk_receive_queue · 22f6b5d4
      Cong Wang authored
      commit 5121197e upstream.
      
      sk->sk_receive_queue is protected by skb queue lock, but for KCM
      sockets its RX path takes mux->rx_lock to protect more than just
      skb queue. However, kcm_recvmsg() still only grabs the skb queue
      lock, so race conditions still exist.
      
      We can teach kcm_recvmsg() to grab mux->rx_lock too but this would
      introduce a potential performance regression as struct kcm_mux can
      be shared by multiple KCM sockets.
      
      So we have to enforce skb queue lock in requeue_rx_msgs() and handle
      skb peek case carefully in kcm_wait_data(). Fortunately,
      skb_recv_datagram() already handles it nicely and is widely used by
      other sockets, we can just switch to skb_recv_datagram() after
      getting rid of the unnecessary sock lock in kcm_recvmsg() and
      kcm_splice_read(). Side note: SOCK_DONE is not used by KCM sockets,
      so it is safe to get rid of this check too.
      
      I ran the original syzbot reproducer for 30 min without seeing any
      issue.
      
      Fixes: ab7ac4eb
      
       ("kcm: Kernel Connection Multiplexor module")
      Reported-by: default avatar <syzbot+278279efdd2730dd14bf@syzkaller.appspotmail.com>
      Reported-by: default avatarshaozhengchao <shaozhengchao@huawei.com>
      Cc: Paolo Abeni <pabeni@redhat.com>
      Cc: Tom Herbert <tom@herbertland.com>
      Signed-off-by: default avatarCong Wang <cong.wang@bytedance.com>
      Link: https://lore.kernel.org/r/20221114005119.597905-1-xiyou.wangcong@gmail.com
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      22f6b5d4
    • Baisong Zhong's avatar
      bpf, test_run: Fix alignment problem in bpf_prog_test_run_skb() · 047824a7
      Baisong Zhong authored
      commit d3fd203f upstream.
      
      We got a syzkaller problem because of aarch64 alignment fault
      if KFENCE enabled. When the size from user bpf program is an odd
      number, like 399, 407, etc, it will cause the struct skb_shared_info's
      unaligned access. As seen below:
      
        BUG: KFENCE: use-after-free read in __skb_clone+0x23c/0x2a0 net/core/skbuff.c:1032
      
        Use-after-free read at 0xffff6254fffac077 (in kfence-#213):
         __lse_atomic_add arch/arm64/include/asm/atomic_lse.h:26 [inline]
         arch_atomic_add arch/arm64/include/asm/atomic.h:28 [inline]
         arch_atomic_inc include/linux/atomic-arch-fallback.h:270 [inline]
         atomic_inc include/asm-generic/atomic-instrumented.h:241 [inline]
         __skb_clone+0x23c/0x2a0 net/core/skbuff.c:1032
         skb_clone+0xf4/0x214 net/core/skbuff.c:1481
         ____bpf_clone_redirect net/core/filter.c:2433 [inline]
         bpf_clone_redirect+0x78/0x1c0 net/core/filter.c:2420
         bpf_prog_d3839dd9068ceb51+0x80/0x330
         bpf_dispatcher_nop_func include/linux/bpf.h:728 [inline]
         bpf_test_run+0x3c0/0x6c0 net/bpf/test_run.c:53
         bpf_prog_test_run_skb+0x638/0xa7c net/bpf/test_run.c:594
         bpf_prog_test_run kernel/bpf/syscall.c:3148 [inline]
         __do_sys_bpf kernel/bpf/syscall.c:4441 [inline]
         __se_sys_bpf+0xad0/0x1634 kernel/bpf/syscall.c:4381
      
        kfence-#213: 0xffff6254fffac000-0xffff6254fffac196, size=407, cache=kmalloc-512
      
        allocated by task 15074 on cpu 0 at 1342.585390s:
         kmalloc include/linux/slab.h:568 [inline]
         kzalloc include/linux/slab.h:675 [inline]
         bpf_test_init.isra.0+0xac/0x290 net/bpf/test_run.c:191
         bpf_prog_test_run_skb+0x11c/0xa7c net/bpf/test_run.c:512
         bpf_prog_test_run kernel/bpf/syscall.c:3148 [inline]
         __do_sys_bpf kernel/bpf/syscall.c:4441 [inline]
         __se_sys_bpf+0xad0/0x1634 kernel/bpf/syscall.c:4381
         __arm64_sys_bpf+0x50/0x60 kernel/bpf/syscall.c:4381
      
      To fix the problem, we adjust @size so that (@size + @hearoom) is a
      multiple of SMP_CACHE_BYTES. So we make sure the struct skb_shared_info
      is aligned to a cache line.
      
      Fixes: 1cf1cae9
      
       ("bpf: introduce BPF_PROG_TEST_RUN command")
      Signed-off-by: default avatarBaisong Zhong <zhongbaisong@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Cc: Eric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/bpf/20221102081620.1465154-1-zhongbaisong@huawei.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      047824a7
    • Eric Dumazet's avatar
      kcm: avoid potential race in kcm_tx_work · 381b6cb3
      Eric Dumazet authored
      commit ec7eede3 upstream.
      
      syzbot found that kcm_tx_work() could crash [1] in:
      
      	/* Primarily for SOCK_SEQPACKET sockets */
      	if (likely(sk->sk_socket) &&
      	    test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) {
      <<*>>	clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
      		sk->sk_write_space(sk);
      	}
      
      I think the reason is that another thread might concurrently
      run in kcm_release() and call sock_orphan(sk) while sk is not
      locked. kcm_tx_work() find sk->sk_socket being NULL.
      
      [1]
      BUG: KASAN: null-ptr-deref in instrument_atomic_write include/linux/instrumented.h:86 [inline]
      BUG: KASAN: null-ptr-deref in clear_bit include/asm-generic/bitops/instrumented-atomic.h:41 [inline]
      BUG: KASAN: null-ptr-deref in kcm_tx_work+0xff/0x160 net/kcm/kcmsock.c:742
      Write of size 8 at addr 0000000000000008 by task kworker/u4:3/53
      
      CPU: 0 PID: 53 Comm: kworker/u4:3 Not tainted 5.19.0-rc3-next-20220621-syzkaller #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      Workqueue: kkcmd kcm_tx_work
      Call Trace:
      <TASK>
      __dump_stack lib/dump_stack.c:88 [inline]
      dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
      kasan_report+0xbe/0x1f0 mm/kasan/report.c:495
      check_region_inline mm/kasan/generic.c:183 [inline]
      kasan_check_range+0x13d/0x180 mm/kasan/generic.c:189
      instrument_atomic_write include/linux/instrumented.h:86 [inline]
      clear_bit include/asm-generic/bitops/instrumented-atomic.h:41 [inline]
      kcm_tx_work+0xff/0x160 net/kcm/kcmsock.c:742
      process_one_work+0x996/0x1610 kernel/workqueue.c:2289
      worker_thread+0x665/0x1080 kernel/workqueue.c:2436
      kthread+0x2e9/0x3a0 kernel/kthread.c:376
      ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:302
      </TASK>
      
      Fixes: ab7ac4eb
      
       ("kcm: Kernel Connection Multiplexor module")
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Cc: Tom Herbert <tom@herbertland.com>
      Link: https://lore.kernel.org/r/20221012133412.519394-1-edumazet@google.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      381b6cb3
    • Eric Dumazet's avatar
      tcp: cdg: allow tcp_cdg_release() to be called multiple times · 40260339
      Eric Dumazet authored
      commit 72e560cb upstream.
      
      Apparently, mptcp is able to call tcp_disconnect() on an already
      disconnected flow. This is generally fine, unless current congestion
      control is CDG, because it might trigger a double-free [1]
      
      Instead of fixing MPTCP, and future bugs, we can make tcp_disconnect()
      more resilient.
      
      [1]
      BUG: KASAN: double-free in slab_free mm/slub.c:3539 [inline]
      BUG: KASAN: double-free in kfree+0xe2/0x580 mm/slub.c:4567
      
      CPU: 0 PID: 3645 Comm: kworker/0:7 Not tainted 6.0.0-syzkaller-02734-g0326074ff465 #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/22/2022
      Workqueue: events mptcp_worker
      Call Trace:
      <TASK>
      __dump_stack lib/dump_stack.c:88 [inline]
      dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
      print_address_description mm/kasan/report.c:317 [inline]
      print_report.cold+0x2ba/0x719 mm/kasan/report.c:433
      kasan_report_invalid_free+0x81/0x190 mm/kasan/report.c:462
      ____kasan_slab_free+0x18b/0x1c0 mm/kasan/common.c:356
      kasan_slab_free include/linux/kasan.h:200 [inline]
      slab_free_hook mm/slub.c:1759 [inline]
      slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1785
      slab_free mm/slub.c:3539 [inline]
      kfree+0xe2/0x580 mm/slub.c:4567
      tcp_disconnect+0x980/0x1e20 net/ipv4/tcp.c:3145
      __mptcp_close_ssk+0x5ca/0x7e0 net/mptcp/protocol.c:2327
      mptcp_do_fastclose net/mptcp/protocol.c:2592 [inline]
      mptcp_worker+0x78c/0xff0 net/mptcp/protocol.c:2627
      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
      </TASK>
      
      Allocated by task 3671:
      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_kmalloc mm/kasan/common.c:516 [inline]
      ____kasan_kmalloc mm/kasan/common.c:475 [inline]
      __kasan_kmalloc+0xa9/0xd0 mm/kasan/common.c:525
      kmalloc_array include/linux/slab.h:640 [inline]
      kcalloc include/linux/slab.h:671 [inline]
      tcp_cdg_init+0x10d/0x170 net/ipv4/tcp_cdg.c:380
      tcp_init_congestion_control+0xab/0x550 net/ipv4/tcp_cong.c:193
      tcp_reinit_congestion_control net/ipv4/tcp_cong.c:217 [inline]
      tcp_set_congestion_control+0x96c/0xaa0 net/ipv4/tcp_cong.c:391
      do_tcp_setsockopt+0x505/0x2320 net/ipv4/tcp.c:3513
      tcp_setsockopt+0xd4/0x100 net/ipv4/tcp.c:3801
      mptcp_setsockopt+0x35f/0x2570 net/mptcp/sockopt.c:844
      __sys_setsockopt+0x2d6/0x690 net/socket.c:2252
      __do_sys_setsockopt net/socket.c:2263 [inline]
      __se_sys_setsockopt net/socket.c:2260 [inline]
      __x64_sys_setsockopt+0xba/0x150 net/socket.c:2260
      do_syscall_x64 arch/x86/entry/common.c:50 [inline]
      do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
      entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      Freed by task 16:
      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/0x30 mm/kasan/generic.c:370
      ____kasan_slab_free mm/kasan/common.c:367 [inline]
      ____kasan_slab_free+0x166/0x1c0 mm/kasan/common.c:329
      kasan_slab_free include/linux/kasan.h:200 [inline]
      slab_free_hook mm/slub.c:1759 [inline]
      slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1785
      slab_free mm/slub.c:3539 [inline]
      kfree+0xe2/0x580 mm/slub.c:4567
      tcp_cleanup_congestion_control+0x70/0x120 net/ipv4/tcp_cong.c:226
      tcp_v4_destroy_sock+0xdd/0x750 net/ipv4/tcp_ipv4.c:2254
      tcp_v6_destroy_sock+0x11/0x20 net/ipv6/tcp_ipv6.c:1969
      inet_csk_destroy_sock+0x196/0x440 net/ipv4/inet_connection_sock.c:1157
      tcp_done+0x23b/0x340 net/ipv4/tcp.c:4649
      tcp_rcv_state_process+0x40e7/0x4990 net/ipv4/tcp_input.c:6624
      tcp_v6_do_rcv+0x3fc/0x13c0 net/ipv6/tcp_ipv6.c:1525
      tcp_v6_rcv+0x2e8e/0x3830 net/ipv6/tcp_ipv6.c:1759
      ip6_protocol_deliver_rcu+0x2db/0x1950 net/ipv6/ip6_input.c:439
      ip6_input_finish+0x14c/0x2c0 net/ipv6/ip6_input.c:484
      NF_HOOK include/linux/netfilter.h:302 [inline]
      NF_HOOK include/linux/netfilter.h:296 [inline]
      ip6_input+0x9c/0xd0 net/ipv6/ip6_input.c:493
      dst_input include/net/dst.h:455 [inline]
      ip6_rcv_finish+0x193/0x2c0 net/ipv6/ip6_input.c:79
      ip_sabotage_in net/bridge/br_netfilter_hooks.c:874 [inline]
      ip_sabotage_in+0x1fa/0x260 net/bridge/br_netfilter_hooks.c:865
      nf_hook_entry_hookfn include/linux/netfilter.h:142 [inline]
      nf_hook_slow+0xc5/0x1f0 net/netfilter/core.c:614
      nf_hook.constprop.0+0x3ac/0x650 include/linux/netfilter.h:257
      NF_HOOK include/linux/netfilter.h:300 [inline]
      ipv6_rcv+0x9e/0x380 net/ipv6/ip6_input.c:309
      __netif_receive_skb_one_core+0x114/0x180 net/core/dev.c:5485
      __netif_receive_skb+0x1f/0x1c0 net/core/dev.c:5599
      netif_receive_skb_internal net/core/dev.c:5685 [inline]
      netif_receive_skb+0x12f/0x8d0 net/core/dev.c:5744
      NF_HOOK include/linux/netfilter.h:302 [inline]
      NF_HOOK include/linux/netfilter.h:296 [inline]
      br_pass_frame_up+0x303/0x410 net/bridge/br_input.c:68
      br_handle_frame_finish+0x909/0x1aa0 net/bridge/br_input.c:199
      br_nf_hook_thresh+0x2f8/0x3d0 net/bridge/br_netfilter_hooks.c:1041
      br_nf_pre_routing_finish_ipv6+0x695/0xef0 net/bridge/br_netfilter_ipv6.c:207
      NF_HOOK include/linux/netfilter.h:302 [inline]
      br_nf_pre_routing_ipv6+0x417/0x7c0 net/bridge/br_netfilter_ipv6.c:237
      br_nf_pre_routing+0x1496/0x1fe0 net/bridge/br_netfilter_hooks.c:507
      nf_hook_entry_hookfn include/linux/netfilter.h:142 [inline]
      nf_hook_bridge_pre net/bridge/br_input.c:255 [inline]
      br_handle_frame+0x9c9/0x12d0 net/bridge/br_input.c:399
      __netif_receive_skb_core+0x9fe/0x38f0 net/core/dev.c:5379
      __netif_receive_skb_one_core+0xae/0x180 net/core/dev.c:5483
      __netif_receive_skb+0x1f/0x1c0 net/core/dev.c:5599
      process_backlog+0x3a0/0x7c0 net/core/dev.c:5927
      __napi_poll+0xb3/0x6d0 net/core/dev.c:6494
      napi_poll net/core/dev.c:6561 [inline]
      net_rx_action+0x9c1/0xd90 net/core/dev.c:6672
      __do_softirq+0x1d0/0x9c8 kernel/softirq.c:571
      
      Fixes: 2b0a8c9e
      
       ("tcp: add CDG congestion control")
      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 avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      40260339
    • Eric Dumazet's avatar
      macvlan: enforce a consistent minimal mtu · d2fee7d1
      Eric Dumazet authored
      commit b64085b0 upstream.
      
      macvlan should enforce a minimal mtu of 68, even at link creation.
      
      This patch avoids the current behavior (which could lead to crashes
      in ipv6 stack if the link is brought up)
      
      $ ip link add macvlan1 link eno1 mtu 8 type macvlan  # This should fail !
      $ ip link sh dev macvlan1
      5: macvlan1@eno1: <BROADCAST,MULTICAST> mtu 8 qdisc noop
          state DOWN mode DEFAULT group default qlen 1000
          link/ether 02:47:6c:24:74:82 brd ff:ff:ff:ff:ff:ff
      $ ip link set macvlan1 mtu 67
      Error: mtu less than device minimum.
      $ ip link set macvlan1 mtu 68
      $ ip link set macvlan1 mtu 8
      Error: mtu less than device minimum.
      
      Fixes: 91572088
      
       ("net: use core MTU range checking in core net infra")
      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 avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d2fee7d1
    • Ilpo Järvinen's avatar
      serial: 8250: Flush DMA Rx on RLSI · fe517db0
      Ilpo Järvinen authored
      commit 1980860e upstream.
      
      Returning true from handle_rx_dma() without flushing DMA first creates
      a data ordering hazard. If DMA Rx has handled any character at the
      point when RLSI occurs, the non-DMA path handles any pending characters
      jumping them ahead of those characters that are pending under DMA.
      
      Fixes: 75df022b
      
       ("serial: 8250_dma: Fix RX handling")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
      Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Link: https://lore.kernel.org/r/20221108121952.5497-5-ilpo.jarvinen@linux.intel.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fe517db0
    • Ryusuke Konishi's avatar
      nilfs2: fix use-after-free bug of ns_writer on remount · 39a3ed68
      Ryusuke Konishi authored
      commit 8cccf05f
      
       upstream.
      
      If a nilfs2 filesystem is downgraded to read-only due to metadata
      corruption on disk and is remounted read/write, or if emergency read-only
      remount is performed, detaching a log writer and synchronizing the
      filesystem can be done at the same time.
      
      In these cases, use-after-free of the log writer (hereinafter
      nilfs->ns_writer) can happen as shown in the scenario below:
      
       Task1                               Task2
       --------------------------------    ------------------------------
       nilfs_construct_segment
         nilfs_segctor_sync
           init_wait
           init_waitqueue_entry
           add_wait_queue
           schedule
                                           nilfs_remount (R/W remount case)
      				       nilfs_attach_log_writer
                                               nilfs_detach_log_writer
                                                 nilfs_segctor_destroy
                                                   kfree
           finish_wait
             _raw_spin_lock_irqsave
               __raw_spin_lock_irqsave
                 do_raw_spin_lock
                   debug_spin_lock_before  <-- use-after-free
      
      While Task1 is sleeping, nilfs->ns_writer is freed by Task2.  After Task1
      waked up, Task1 accesses nilfs->ns_writer which is already freed.  This
      scenario diagram is based on the Shigeru Yoshida's post [1].
      
      This patch fixes the issue by not detaching nilfs->ns_writer on remount so
      that this UAF race doesn't happen.  Along with this change, this patch
      also inserts a few necessary read-only checks with superblock instance
      where only the ns_writer pointer was used to check if the filesystem is
      read-only.
      
      Link: https://syzkaller.appspot.com/bug?id=79a4c002e960419ca173d55e863bd09e8112df8b
      Link: https://lkml.kernel.org/r/20221103141759.1836312-1-syoshida@redhat.com [1]
      Link: https://lkml.kernel.org/r/20221104142959.28296-1-konishi.ryusuke@gmail.com
      Signed-off-by: default avatarRyusuke Konishi <konishi.ryusuke@gmail.com>
      Reported-by: default avatar <syzbot+f816fa82f8783f7a02bb@syzkaller.appspotmail.com>
      Reported-by: default avatarShigeru Yoshida <syoshida@redhat.com>
      Tested-by: default avatarRyusuke Konishi <konishi.ryusuke@gmail.com>
      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>
      39a3ed68
    • Alexander Potapenko's avatar
      misc/vmw_vmci: fix an infoleak in vmci_host_do_receive_datagram() · f04586c2
      Alexander Potapenko authored
      commit e5b0d06d
      
       upstream.
      
      `struct vmci_event_qp` allocated by qp_notify_peer() contains padding,
      which may carry uninitialized data to the userspace, as observed by
      KMSAN:
      
        BUG: KMSAN: kernel-infoleak in instrument_copy_to_user ./include/linux/instrumented.h:121
         instrument_copy_to_user ./include/linux/instrumented.h:121
         _copy_to_user+0x5f/0xb0 lib/usercopy.c:33
         copy_to_user ./include/linux/uaccess.h:169
         vmci_host_do_receive_datagram drivers/misc/vmw_vmci/vmci_host.c:431
         vmci_host_unlocked_ioctl+0x33d/0x43d0 drivers/misc/vmw_vmci/vmci_host.c:925
         vfs_ioctl fs/ioctl.c:51
        ...
      
        Uninit was stored to memory at:
         kmemdup+0x74/0xb0 mm/util.c:131
         dg_dispatch_as_host drivers/misc/vmw_vmci/vmci_datagram.c:271
         vmci_datagram_dispatch+0x4f8/0xfc0 drivers/misc/vmw_vmci/vmci_datagram.c:339
         qp_notify_peer+0x19a/0x290 drivers/misc/vmw_vmci/vmci_queue_pair.c:1479
         qp_broker_attach drivers/misc/vmw_vmci/vmci_queue_pair.c:1662
         qp_broker_alloc+0x2977/0x2f30 drivers/misc/vmw_vmci/vmci_queue_pair.c:1750
         vmci_qp_broker_alloc+0x96/0xd0 drivers/misc/vmw_vmci/vmci_queue_pair.c:1940
         vmci_host_do_alloc_queuepair drivers/misc/vmw_vmci/vmci_host.c:488
         vmci_host_unlocked_ioctl+0x24fd/0x43d0 drivers/misc/vmw_vmci/vmci_host.c:927
        ...
      
        Local variable ev created at:
         qp_notify_peer+0x54/0x290 drivers/misc/vmw_vmci/vmci_queue_pair.c:1456
         qp_broker_attach drivers/misc/vmw_vmci/vmci_queue_pair.c:1662
         qp_broker_alloc+0x2977/0x2f30 drivers/misc/vmw_vmci/vmci_queue_pair.c:1750
      
        Bytes 28-31 of 48 are uninitialized
        Memory access of size 48 starts at ffff888035155e00
        Data copied to user address 0000000020000100
      
      Use memset() to prevent the infoleaks.
      
      Also speculatively fix qp_notify_peer_local(), which may suffer from the
      same problem.
      
      Reported-by: default avatar <syzbot+39be4da489ed2493ba25@syzkaller.appspotmail.com>
      Cc: stable <stable@kernel.org>
      Fixes: 06164d2b
      
       ("VMCI: queue pairs implementation.")
      Signed-off-by: default avatarAlexander Potapenko <glider@google.com>
      Reviewed-by: default avatarVishnu Dasa <vdasa@vmware.com>
      Link: https://lore.kernel.org/r/20221104175849.2782567-1-glider@google.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f04586c2
    • Xiongfeng Wang's avatar
      mmc: sdhci-pci: Fix possible memory leak caused by missing pci_dev_put() · 7570e5b5
      Xiongfeng Wang authored
      commit 222cfa01 upstream.
      
      pci_get_device() will increase the reference count for the returned
      pci_dev. We need to use pci_dev_put() to decrease the reference count
      before amd_probe() returns. There is no problem for the 'smbus_dev ==
      NULL' branch because pci_dev_put() can also handle the NULL input
      parameter case.
      
      Fixes: 659c9bc1
      
       ("mmc: sdhci-pci: Build o2micro support in the same module")
      Signed-off-by: default avatarXiongfeng Wang <wangxiongfeng2@huawei.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20221114083100.149200-1-wangxiongfeng2@huawei.com
      Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7570e5b5
    • Yann Gautier's avatar
      mmc: core: properly select voltage range without power cycle · d8610203
      Yann Gautier authored
      commit 39a72dbf upstream.
      
      In mmc_select_voltage(), if there is no full power cycle, the voltage
      range selected at the end of the function will be on a single range
      (e.g. 3.3V/3.4V). To keep a range around the selected voltage (3.2V/3.4V),
      the mask shift should be reduced by 1.
      
      This issue was triggered by using a specific SD-card (Verbatim Premium
      16GB UHS-1) on an STM32MP157C-DK2 board. This board cannot do UHS modes
      and there is no power cycle. And the card was failing to switch to
      high-speed mode. When adding the range 3.2V/3.3V for this card with the
      proposed shift change, the card can switch to high-speed mode.
      
      Fixes: ce69d37b
      
       ("mmc: core: Prevent violation of specs while initializing cards")
      Signed-off-by: default avatarYann Gautier <yann.gautier@foss.st.com>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20221028073740.7259-1-yann.gautier@foss.st.com
      Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d8610203
    • Ilpo Järvinen's avatar
      serial: 8250_lpss: Configure DMA also w/o DMA filter · b0d01775
      Ilpo Järvinen authored
      commit 1bfcbe58
      
       upstream.
      
      If the platform doesn't use DMA device filter (as is the case with
      Elkhart Lake), whole lpss8250_dma_setup() setup is skipped. This
      results in skipping also *_maxburst setup which is undesirable.
      Refactor lpss8250_dma_setup() to configure DMA even if filter is not
      setup.
      
      Cc: stable <stable@kernel.org>
      Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
      Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Link: https://lore.kernel.org/r/20221108121952.5497-3-ilpo.jarvinen@linux.intel.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b0d01775
    • Ilpo Järvinen's avatar
      serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs · cc19663d
      Ilpo Järvinen authored
      commit a931237c upstream.
      
      DW UART sometimes triggers IIR_RDI during DMA Rx when IIR_RX_TIMEOUT
      should have been triggered instead. Since IIR_RDI has higher priority
      than IIR_RX_TIMEOUT, this causes the Rx to hang into interrupt loop.
      The problem seems to occur at least with some combinations of
      small-sized transfers (I've reproduced the problem on Elkhart Lake PSE
      UARTs).
      
      If there's already an on-going Rx DMA and IIR_RDI triggers, fall
      graciously back to non-DMA Rx. That is, behave as if IIR_RX_TIMEOUT had
      occurred.
      
      8250_omap already considers IIR_RDI similar to this change so its
      nothing unheard of.
      
      Fixes: 75df022b
      
       ("serial: 8250_dma: Fix RX handling")
      Cc: <stable@vger.kernel.org>
      Co-developed-by: default avatarSrikanth Thokala <srikanth.thokala@intel.com>
      Signed-off-by: default avatarSrikanth Thokala <srikanth.thokala@intel.com>
      Co-developed-by: default avatarAman Kumar <aman.kumar@intel.com>
      Signed-off-by: default avatarAman Kumar <aman.kumar@intel.com>
      Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
      Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Link: https://lore.kernel.org/r/20221108121952.5497-2-ilpo.jarvinen@linux.intel.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cc19663d
    • Mikulas Patocka's avatar
      dm ioctl: fix misbehavior if list_versions races with module loading · 6a818db0
      Mikulas Patocka authored
      commit 4fe1ec99
      
       upstream.
      
      __list_versions will first estimate the required space using the
      "dm_target_iterate(list_version_get_needed, &needed)" call and then will
      fill the space using the "dm_target_iterate(list_version_get_info,
      &iter_info)" call. Each of these calls locks the targets using the
      "down_read(&_lock)" and "up_read(&_lock)" calls, however between the first
      and second "dm_target_iterate" there is no lock held and the target
      modules can be loaded at this point, so the second "dm_target_iterate"
      call may need more space than what was the first "dm_target_iterate"
      returned.
      
      The code tries to handle this overflow (see the beginning of
      list_version_get_info), however this handling is incorrect.
      
      The code sets "param->data_size = param->data_start + needed" and
      "iter_info.end = (char *)vers+len" - "needed" is the size returned by the
      first dm_target_iterate call; "len" is the size of the buffer allocated by
      userspace.
      
      "len" may be greater than "needed"; in this case, the code will write up
      to "len" bytes into the buffer, however param->data_size is set to
      "needed", so it may write data past the param->data_size value. The ioctl
      interface copies only up to param->data_size into userspace, thus part of
      the result will be truncated.
      
      Fix this bug by setting "iter_info.end = (char *)vers + needed;" - this
      guarantees that the second "dm_target_iterate" call will write only up to
      the "needed" buffer and it will exit with "DM_BUFFER_FULL_FLAG" if it
      overflows the "needed" space - in this case, userspace will allocate a
      larger buffer and retry.
      
      Note that there is also a bug in list_version_get_needed - we need to add
      "strlen(tt->name) + 1" to the needed size, not "strlen(tt->name)".
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6a818db0
    • Mitja Spes's avatar
      iio: pressure: ms5611: changed hardcoded SPI speed to value limited · e59a9491
      Mitja Spes authored
      commit 741cec30
      
       upstream.
      
      Don't hardcode the ms5611 SPI speed, limit it instead.
      
      Signed-off-by: default avatarMitja Spes <mitja@lxnav.com>
      Fixes: c0644160
      
       ("iio: pressure: add support for MS5611 pressure and temperature sensor")
      Link: https://lore.kernel.org/r/20221021135827.1444793-3-mitja@lxnav.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>
      e59a9491
    • Yang Yingliang's avatar
      iio: trigger: sysfs: fix possible memory leak in iio_sysfs_trig_init() · 5a39382a
      Yang Yingliang authored
      commit efa17e90 upstream.
      
      dev_set_name() allocates memory for name, it need be freed
      when device_add() fails, call put_device() to give up the
      reference that hold in device_initialize(), so that it can
      be freed in kobject_cleanup() when the refcount hit to 0.
      
      Fault injection test can trigger this:
      
      unreferenced object 0xffff8e8340a7b4c0 (size 32):
        comm "modprobe", pid 243, jiffies 4294678145 (age 48.845s)
        hex dump (first 32 bytes):
          69 69 6f 5f 73 79 73 66 73 5f 74 72 69 67 67 65  iio_sysfs_trigge
          72 00 a7 40 83 8e ff ff 00 86 13 c4 f6 ee ff ff  r..@............
        backtrace:
          [<0000000074999de8>] __kmem_cache_alloc_node+0x1e9/0x360
          [<00000000497fd30b>] __kmalloc_node_track_caller+0x44/0x1a0
          [<000000003636c520>] kstrdup+0x2d/0x60
          [<0000000032f84da2>] kobject_set_name_vargs+0x1e/0x90
          [<0000000092efe493>] dev_set_name+0x4e/0x70
      
      Fixes: 1f785681
      
       ("staging:iio:trigger sysfs userspace trigger rework.")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Cc: <Stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20221022074212.1386424-1-yangyingliang@huawei.com
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5a39382a
    • Yang Yingliang's avatar
      iio: adc: at91_adc: fix possible memory leak in at91_adc_allocate_trigger() · a0d98ae5
      Yang Yingliang authored
      commit 65f20301 upstream.
      
      If iio_trigger_register() returns error, it should call iio_trigger_free()
      to give up the reference that hold in iio_trigger_alloc(), so that it can
      call iio_trig_release() to free memory when the refcount hit to 0.
      
      Fixes: 0e589d5f
      
       ("ARM: AT91: IIO: Add AT91 ADC driver.")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Link: https://lore.kernel.org/r/20221024084511.815096-1-yangyingliang@huawei.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>
      a0d98ae5
    • Duoming Zhou's avatar
      usb: chipidea: fix deadlock in ci_otg_del_timer · 88f4f15b
      Duoming Zhou authored
      commit 7a58b8d6 upstream.
      
      There is a deadlock in ci_otg_del_timer(), the process is
      shown below:
      
          (thread 1)                  |        (thread 2)
      ci_otg_del_timer()              | ci_otg_hrtimer_func()
        ...                           |
        spin_lock_irqsave() //(1)     |  ...
        ...                           |
        hrtimer_cancel()              |  spin_lock_irqsave() //(2)
        (block forever)
      
      We hold ci->lock in position (1) and use hrtimer_cancel() to
      wait ci_otg_hrtimer_func() to stop, but ci_otg_hrtimer_func()
      also need ci->lock in position (2). As a result, the
      hrtimer_cancel() in ci_otg_del_timer() will be blocked forever.
      
      This patch extracts hrtimer_cancel() from the protection of
      spin_lock_irqsave() in order that the ci_otg_hrtimer_func()
      could obtain the ci->lock.
      
      What`s more, there will be no race happen. Because the
      "next_timer" is always under the protection of
      spin_lock_irqsave() and we only check whether "next_timer"
      equals to NUM_OTG_FSM_TIMERS in the following code.
      
      Fixes: 3a316ec4
      
       ("usb: chipidea: use hrtimer for otg fsm timers")
      Cc: stable <stable@kernel.org>
      Signed-off-by: default avatarDuoming Zhou <duoming@zju.edu.cn>
      Link: https://lore.kernel.org/r/20220918033312.94348-1-duoming@zju.edu.cn
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      88f4f15b
    • Nicolas Dumazet's avatar
      usb: add NO_LPM quirk for Realforce 87U Keyboard · a85bffde
      Nicolas Dumazet authored
      commit 181135bb
      
       upstream.
      
      Before adding this quirk, this (mechanical keyboard) device would not be
      recognized, logging:
      
        new full-speed USB device number 56 using xhci_hcd
        unable to read config index 0 descriptor/start: -32
        chopping to 0 config(s)
      
      It would take dozens of plugging/unpuggling cycles for the keyboard to
      be recognized. Keyboard seems to simply work after applying this quirk.
      
      This issue had been reported by users in two places already ([1], [2])
      but nobody tried upstreaming a patch yet. After testing I believe their
      suggested fix (DELAY_INIT + NO_LPM + DEVICE_QUALIFIER) was probably a
      little overkill. I assume this particular combination was tested because
      it had been previously suggested in [3], but only NO_LPM seems
      sufficient for this device.
      
      [1]: https://qiita.com/float168/items/fed43d540c8e2201b543
      [2]: https://blog.kostic.dev/posts/making-the-realforce-87ub-work-with-usb30-on-Ubuntu/
      [3]: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1678477
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarNicolas Dumazet <ndumazet@google.com>
      Link: https://lore.kernel.org/r/20221109122946.706036-1-ndumazet@google.com
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a85bffde
    • Reinhard Speyerer's avatar
      USB: serial: option: add Fibocom FM160 0x0111 composition · 1cb10f5f
      Reinhard Speyerer authored
      commit 148f4b32
      
       upstream.
      
      Add support for the following Fibocom FM160 composition:
      
      0x0111: MBIM + MODEM + DIAG + AT
      
      T:  Bus=01 Lev=02 Prnt=125 Port=01 Cnt=02 Dev#= 93 Spd=480  MxCh= 0
      D:  Ver= 2.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
      P:  Vendor=2cb7 ProdID=0111 Rev= 5.04
      S:  Manufacturer=Fibocom
      S:  Product=Fibocom FM160 Modem_SN:12345678
      S:  SerialNumber=12345678
      C:* #Ifs= 5 Cfg#= 1 Atr=a0 MxPwr=500mA
      A:  FirstIf#= 0 IfCount= 2 Cls=02(comm.) Sub=0e Prot=00
      I:* If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=0e Prot=00 Driver=cdc_mbim
      E:  Ad=81(I) Atr=03(Int.) MxPS=  64 Ivl=32ms
      I:  If#= 1 Alt= 0 #EPs= 0 Cls=0a(data ) Sub=00 Prot=02 Driver=cdc_mbim
      I:* If#= 1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=02 Driver=cdc_mbim
      E:  Ad=8e(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
      E:  Ad=0f(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
      I:* If#= 2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option
      E:  Ad=83(I) Atr=03(Int.) MxPS=  10 Ivl=32ms
      E:  Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
      E:  Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
      I:* If#= 3 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=30 Driver=option
      E:  Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
      E:  Ad=84(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
      I:* If#= 4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=40 Driver=option
      E:  Ad=86(I) Atr=03(Int.) MxPS=  10 Ivl=32ms
      E:  Ad=85(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
      E:  Ad=03(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
      
      Signed-off-by: default avatarReinhard Speyerer <rspmn@arcor.de>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1cb10f5f
    • Davide Tronchin's avatar
      USB: serial: option: add u-blox LARA-L6 modem · e6c2705b
      Davide Tronchin authored
      commit c1547f12
      
       upstream.
      
      Add LARA-L6 PIDs for three different USB compositions.
      
      LARA-L6 module can be configured (by AT interface) in three different
      USB modes:
      * Default mode (Vendor ID: 0x1546 Product ID: 0x1341) with 4 serial
      interfaces
      * RmNet mode (Vendor ID: 0x1546 Product ID: 0x1342) with 4 serial
      interfaces and 1 RmNet virtual network interface
      * CDC-ECM mode (Vendor ID: 0x1546 Product ID: 0x1343) with 4 serial
      interface and 1 CDC-ECM virtual network interface
      
      In default mode LARA-L6 exposes the following interfaces:
      If 0: Diagnostic
      If 1: AT parser
      If 2: AT parser
      If 3: AT parser/alternative functions
      
      In RmNet mode LARA-L6 exposes the following interfaces:
      If 0: Diagnostic
      If 1: AT parser
      If 2: AT parser
      If 3: AT parset/alternative functions
      If 4: RMNET interface
      
      In CDC-ECM mode LARA-L6 exposes the following interfaces:
      If 0: Diagnostic
      If 1: AT parser
      If 2: AT parser
      If 3: AT parset/alternative functions
      If 4: CDC-ECM interface
      
      Signed-off-by: default avatarDavide Tronchin <davide.tronchin.94@gmail.com>
      [ johan: drop PID defines in favour of comments ]
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e6c2705b
    • Davide Tronchin's avatar
      USB: serial: option: add u-blox LARA-R6 00B modem · 42a9dec9
      Davide Tronchin authored
      commit d9e37a5c
      
       upstream.
      
      The official LARA-R6 (00B) modem uses 0x908b PID. LARA-R6 00B does not
      implement a QMI interface on port 4, the reservation (RSVD(4)) has been
      added to meet other companies that implement QMI on that interface.
      
      LARA-R6 00B USB composition exposes the following interfaces:
      If 0: Diagnostic
      If 1: AT parser
      If 2: AT parser
      If 3: AT parser/alternative functions
      
      Signed-off-by: default avatarDavide Tronchin <davide.tronchin.94@gmail.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      42a9dec9
    • Davide Tronchin's avatar
      USB: serial: option: remove old LARA-R6 PID · 84ff5052
      Davide Tronchin authored
      commit 2ec106b9
      
       upstream.
      
      Remove the UBLOX_PRODUCT_R6XX 0x90fa association since LARA-R6 00B final
      product uses a new USB composition with different PID. 0x90fa PID used
      only by LARA-R6 internal prototypes.
      
      Move 0x90fa PID directly in the option_ids array since used by other
      Qualcomm based modem vendors as pointed out in:
      
        https://lore.kernel.org/all/6572c4e6-d8bc-b8d3-4396-d879e4e76338@gmail.com
      
      Signed-off-by: default avatarDavide Tronchin <davide.tronchin.94@gmail.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      84ff5052
    • Benoît Monin's avatar
      USB: serial: option: add Sierra Wireless EM9191 · d9012497
      Benoît Monin authored
      commit df3414b0 upstream.
      
      Add support for the AT and diag ports, similar to other qualcomm SDX55
      modems. In QDL mode, the modem uses a different device ID and support
      is provided by qcserial in commit 11c52d25
      
       ("USB: serial: qcserial:
      add EM9191 QDL support").
      
      T:  Bus=08 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#=  3 Spd=5000 MxCh= 0
      D:  Ver= 3.20 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 9 #Cfgs=  1
      P:  Vendor=1199 ProdID=90d3 Rev=00.06
      S:  Manufacturer=Sierra Wireless, Incorporated
      S:  Product=Sierra Wireless EM9191
      S:  SerialNumber=xxxxxxxxxxxxxxxx
      C:  #Ifs= 4 Cfg#= 1 Atr=a0 MxPwr=896mA
      I:  If#=0x0 Alt= 0 #EPs= 1 Cls=02(commc) Sub=0e Prot=00 Driver=cdc_mbim
      I:  If#=0x1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=02 Driver=cdc_mbim
      I:  If#=0x3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=(none)
      I:  If#=0x4 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=30 Driver=(none)
      
      Signed-off-by: default avatarBenoît Monin <benoit.monin@gmx.fr>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d9012497
    • Takashi Iwai's avatar
      ALSA: usb-audio: Drop snd_BUG_ON() from snd_usbmidi_output_open() · 368a01e5
      Takashi Iwai authored
      commit ad72c3c3
      
       upstream.
      
      snd_usbmidi_output_open() has a check of the NULL port with
      snd_BUG_ON().  snd_BUG_ON() was used as this shouldn't have happened,
      but in reality, the NULL port may be seen when the device gives an
      invalid endpoint setup at the descriptor, hence the driver skips the
      allocation.  That is, the check itself is valid and snd_BUG_ON()
      should be dropped from there.  Otherwise it's confusing as if it were
      a real bug, as recently syzbot stumbled on it.
      
      Reported-by: default avatar <syzbot+9abda841d636d86c41da@syzkaller.appspotmail.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/syzbot+9abda841d636d86c41da@syzkaller.appspotmail.com
      Link: https://lore.kernel.org/r/20221112141223.6144-1-tiwai@suse.de
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      368a01e5
    • Daniil Tatianin's avatar
      ring_buffer: Do not deactivate non-existant pages · 4c9338db
      Daniil Tatianin authored
      commit 56f4ca0a upstream.
      
      rb_head_page_deactivate() expects cpu_buffer to contain a valid list of
      ->pages, so verify that the list is actually present before calling it.
      
      Found by Linux Verification Center (linuxtesting.org) with the SVACE
      static analysis tool.
      
      Link: https://lkml.kernel.org/r/20221114143129.3534443-1-d-tatianin@yandex-team.ru
      
      Cc: stable@vger.kernel.org
      Fixes: 77ae365e
      
       ("ring-buffer: make lockless")
      Signed-off-by: default avatarDaniil Tatianin <d-tatianin@yandex-team.ru>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4c9338db
    • Xiu Jianfeng's avatar
      ftrace: Fix null pointer dereference in ftrace_add_mod() · 665b4c66
      Xiu Jianfeng authored
      commit 19ba6c8a upstream.
      
      The @ftrace_mod is allocated by kzalloc(), so both the members {prev,next}
      of @ftrace_mode->list are NULL, it's not a valid state to call list_del().
      If kstrdup() for @ftrace_mod->{func|module} fails, it goes to @out_free
      tag and calls free_ftrace_mod() to destroy @ftrace_mod, then list_del()
      will write prev->next and next->prev, where null pointer dereference
      happens.
      
      BUG: kernel NULL pointer dereference, address: 0000000000000008
      Oops: 0002 [#1] PREEMPT SMP NOPTI
      Call Trace:
       <TASK>
       ftrace_mod_callback+0x20d/0x220
       ? do_filp_open+0xd9/0x140
       ftrace_process_regex.isra.51+0xbf/0x130
       ftrace_regex_write.isra.52.part.53+0x6e/0x90
       vfs_write+0xee/0x3a0
       ? __audit_filter_op+0xb1/0x100
       ? auditd_test_task+0x38/0x50
       ksys_write+0xa5/0xe0
       do_syscall_64+0x3a/0x90
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      Kernel panic - not syncing: Fatal exception
      
      So call INIT_LIST_HEAD() to initialize the list member to fix this issue.
      
      Link: https://lkml.kernel.org/r/20221116015207.30858-1-xiujianfeng@huawei.com
      
      Cc: stable@vger.kernel.org
      Fixes: 673feb9d
      
       ("ftrace: Add :mod: caching infrastructure to trace_array")
      Signed-off-by: default avatarXiu Jianfeng <xiujianfeng@huawei.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      665b4c66
    • Wang Wensheng's avatar
      ftrace: Optimize the allocation for mcount entries · 7eb7b342
      Wang Wensheng authored
      commit bcea02b0 upstream.
      
      If we can't allocate this size, try something smaller with half of the
      size. Its order should be decreased by one instead of divided by two.
      
      Link: https://lkml.kernel.org/r/20221109094434.84046-3-wangwensheng4@huawei.com
      
      Cc: <mhiramat@kernel.org>
      Cc: <mark.rutland@arm.com>
      Cc: stable@vger.kernel.org
      Fixes: a7900875
      
       ("ftrace: Allocate the mcount record pages as groups")
      Signed-off-by: default avatarWang Wensheng <wangwensheng4@huawei.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7eb7b342
    • Wang Wensheng's avatar
      ftrace: Fix the possible incorrect kernel message · c07fd111
      Wang Wensheng authored
      commit 08948cae upstream.
      
      If the number of mcount entries is an integer multiple of
      ENTRIES_PER_PAGE, the page count showing on the console would be wrong.
      
      Link: https://lkml.kernel.org/r/20221109094434.84046-2-wangwensheng4@huawei.com
      
      Cc: <mhiramat@kernel.org>
      Cc: <mark.rutland@arm.com>
      Cc: stable@vger.kernel.org
      Fixes: 5821e1b7
      
       ("function tracing: fix wrong pos computing when read buffer has been fulfilled")
      Signed-off-by: default avatarWang Wensheng <wangwensheng4@huawei.com>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c07fd111
    • Zhang Xiaoxu's avatar
      cifs: Fix wrong return value checking when GETFLAGS · fd13959a
      Zhang Xiaoxu authored
      [ Upstream commit 92bbd67a ]
      
      The return value of CIFSGetExtAttr is negative, should be checked
      with -EOPNOTSUPP rather than EOPNOTSUPP.
      
      Fixes: 64a5cfa6
      
       ("Allow setting per-file compression via SMB2/3")
      Signed-off-by: default avatarZhang Xiaoxu <zhangxiaoxu5@huawei.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fd13959a
    • Wei Yongjun's avatar
      net/x25: Fix skb leak in x25_lapb_receive_frame() · dfcfbe4f
      Wei Yongjun authored
      [ Upstream commit 2929cceb ]
      
      x25_lapb_receive_frame() using skb_copy() to get a private copy of
      skb, the new skb should be freed in the undersized/fragmented skb
      error handling path. Otherwise there is a memory leak.
      
      Fixes: cb101ed2
      
       ("x25: Handle undersized/fragmented skbs")
      Signed-off-by: default avatarWei Yongjun <weiyongjun1@huawei.com>
      Acked-by: default avatarMartin Schiller <ms@dev.tdt.de>
      Link: https://lore.kernel.org/r/20221114110519.514538-1-weiyongjun@huaweicloud.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      dfcfbe4f
    • Dan Carpenter's avatar
      drbd: use after free in drbd_create_device() · fc1897f1
      Dan Carpenter authored
      [ Upstream commit a7a15981 ]
      
      The drbd_destroy_connection() frees the "connection" so use the _safe()
      iterator to prevent a use after free.
      
      Fixes: b6f85ef9
      
       ("drbd: Iterate over all connections")
      Signed-off-by: default avatarDan Carpenter <error27@gmail.com>
      Reviewed-by: default avatarChristoph Böhmwalder <christoph.boehmwalder@linbit.com>
      Link: https://lore.kernel.org/r/Y3Jd5iZRbNQ9w6gm@kili
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fc1897f1
    • Yang Yingliang's avatar
      xen/pcpu: fix possible memory leak in register_pcpu() · 7ed540bc
      Yang Yingliang authored
      [ Upstream commit da36a2a7 ]
      
      In device_add(), dev_set_name() is called to allocate name, if it returns
      error, the name need be freed. As comment of device_register() says, it
      should use put_device() to give up the reference in the error path. So fix
      this by calling put_device(), then the name can be freed in kobject_cleanup().
      
      Fixes: f65c9bb3
      
       ("xen/pcpu: Xen physical cpus online/offline sys interface")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
      Link: https://lore.kernel.org/r/20221110152441.401630-1-yangyingliang@huawei.com
      Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7ed540bc
    • Zhengchao Shao's avatar
      net: caif: fix double disconnect client in chnl_net_open() · 93d0af10
      Zhengchao Shao authored
      [ Upstream commit 8fbb53c8 ]
      
      When connecting to client timeout, disconnect client for twice in
      chnl_net_open(). Remove one. Compile tested only.
      
      Fixes: 2aa40aef
      
       ("caif: Use link layer MTU instead of fixed MTU")
      Signed-off-by: default avatarZhengchao Shao <shaozhengchao@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      93d0af10
    • Wang ShaoBo's avatar
      mISDN: fix misuse of put_device() in mISDN_register_device() · 81db4f18
      Wang ShaoBo authored
      [ Upstream commit 2d25107e ]
      
      We should not release reference by put_device() before calling device_initialize().
      
      Fixes: e7d1d4d9
      
       ("mISDN: fix possible memory leak in mISDN_register_device()")
      Signed-off-by: default avatarWang ShaoBo <bobo.shaobowang@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      81db4f18
    • Yang Yingliang's avatar
      mISDN: fix possible memory leak in mISDN_dsp_element_register() · b119bedb
      Yang Yingliang authored
      [ Upstream commit 98a2ac1c ]
      
      Afer commit 1fa5ae85 ("driver core: get rid of struct device's
      bus_id string array"), the name of device is allocated dynamically,
      use put_device() to give up the reference, so that the name can be
      freed in kobject_cleanup() when the refcount is 0.
      
      The 'entry' is going to be freed in mISDN_dsp_dev_release(), so the
      kfree() is removed. list_del() is called in mISDN_dsp_dev_release(),
      so it need be initialized.
      
      Fixes: 1fa5ae85
      
       ("driver core: get rid of struct device's bus_id string array")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Link: https://lore.kernel.org/r/20221109132832.3270119-1-yangyingliang@huawei.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b119bedb
    • Wei Yongjun's avatar
      net: bgmac: Drop free_netdev() from bgmac_enet_remove() · 4dfb4d30
      Wei Yongjun authored
      [ Upstream commit 6f928ab8 ]
      
      netdev is allocated in bgmac_alloc() with devm_alloc_etherdev() and will
      be auto released in ->remove and ->probe failure path. Using free_netdev()
      in bgmac_enet_remove() leads to double free.
      
      Fixes: 34a5102c
      
       ("net: bgmac: allocate struct bgmac just once & don't copy it")
      Signed-off-by: default avatarWei Yongjun <weiyongjun1@huawei.com>
      
      Link: https://lore.kernel.org/r/20221109150136.2991171-1-weiyongjun@huaweicloud.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4dfb4d30
    • Zeng Heng's avatar
      pinctrl: devicetree: fix null pointer dereferencing in pinctrl_dt_to_map · b4d9f55c
      Zeng Heng authored
      [ Upstream commit 91d5c506 ]
      
      Here is the BUG report by KASAN about null pointer dereference:
      
      BUG: KASAN: null-ptr-deref in strcmp+0x2e/0x50
      Read of size 1 at addr 0000000000000000 by task python3/2640
      Call Trace:
       strcmp
       __of_find_property
       of_find_property
       pinctrl_dt_to_map
      
      kasprintf() would return NULL pointer when kmalloc() fail to allocate.
      So directly return ENOMEM, if kasprintf() return NULL pointer.
      
      Fixes: 57291ce2
      
       ("pinctrl: core device tree mapping table parsing support")
      Signed-off-by: default avatarZeng Heng <zengheng4@huawei.com>
      Link: https://lore.kernel.org/r/20221110082056.2014898-1-zengheng4@huawei.com
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b4d9f55c
    • Maciej W. Rozycki's avatar
      parport_pc: Avoid FIFO port location truncation · 326629b4
      Maciej W. Rozycki authored
      [ Upstream commit ab126f51
      
       ]
      
      Match the data type of a temporary holding a reference to the FIFO port
      with the type of the original reference coming from `struct parport',
      avoiding data truncation with LP64 ports such as SPARC64 that refer to
      PCI port I/O locations via their corresponding MMIO addresses and will
      therefore have non-zero bits in the high 32-bit part of the reference.
      And in any case it is cleaner to have the data types matching here.
      
      Signed-off-by: default avatarMaciej W. Rozycki <macro@orcam.me.uk>
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Link: https://lore.kernel.org/linux-pci/20220419033752.GA1101844@bhelgaas/
      Acked-by: default avatarSudip Mukherjee <sudipm.mukherjee@gmail.com>
      Link: https://lore.kernel.org/r/alpine.DEB.2.21.2209231912550.29493@angie.orcam.me.uk
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      326629b4
    • Serge Semin's avatar
      block: sed-opal: kmalloc the cmd/resp buffers · 53699e24
      Serge Semin authored
      [ Upstream commit f829230d ]
      
      In accordance with [1] the DMA-able memory buffers must be
      cacheline-aligned otherwise the cache writing-back and invalidation
      performed during the mapping may cause the adjacent data being lost. It's
      specifically required for the DMA-noncoherent platforms [2]. Seeing the
      opal_dev.{cmd,resp} buffers are implicitly used for DMAs in the NVME and
      SCSI/SD drivers in framework of the nvme_sec_submit() and sd_sec_submit()
      methods respectively they must be cacheline-aligned to prevent the denoted
      problem. One of the option to guarantee that is to kmalloc the buffers
      [2]. Let's explicitly allocate them then instead of embedding into the
      opal_dev structure instance.
      
      Note this fix was inspired by the commit c94b7f9b ("nvme-hwmon:
      kmalloc the NVME SMART log buffer").
      
      [1] Documentation/core-api/dma-api.rst
      [2] Documentation/core-api/dma-api-howto.rst
      
      Fixes: 455a7b23
      
       ("block: Add Sed-opal library")
      Signed-off-by: default avatarSerge Semin <Sergey.Semin@baikalelectronics.ru>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Link: https://lore.kernel.org/r/20221107203944.31686-1-Sergey.Semin@baikalelectronics.ru
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      53699e24
    • Chen Zhongjin's avatar
      ASoC: soc-utils: Remove __exit for snd_soc_util_exit() · c1dfa6b6
      Chen Zhongjin authored
      [ Upstream commit 314d34fe ]
      
      snd_soc_util_exit() is called in __init snd_soc_init() for cleanup.
      Remove the __exit annotation for it to fix the build warning:
      
      WARNING: modpost: sound/soc/snd-soc-core.o: section mismatch in reference: init_module (section: .init.text) -> snd_soc_util_exit (section: .exit.text)
      
      Fixes: 6ec27c53
      
       ("ASoC: core: Fix use-after-free in snd_soc_exit()")
      Signed-off-by: default avatarChen Zhongjin <chenzhongjin@huawei.com>
      Link: https://lore.kernel.org/r/20221031134031.256511-1-chenzhongjin@huawei.com
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      c1dfa6b6