1. 26 Oct, 2022 40 commits
    • Greg Kroah-Hartman's avatar
    • Rafael J. Wysocki's avatar
      thermal: intel_powerclamp: Use first online CPU as control_cpu · d9fdda5e
      Rafael J. Wysocki authored
      commit 4bb7f6c2 upstream.
      
      Commit 68b99e94 ("thermal: intel_powerclamp: Use get_cpu() instead
      of smp_processor_id() to avoid crash") fixed an issue related to using
      smp_processor_id() in preemptible context by replacing it with a pair
      of get_cpu()/put_cpu(), but what is needed there really is any online
      CPU and not necessarily the one currently running the code.  Arguably,
      getting the one that's running the code in there is confusing.
      
      For this reason, simply give the control CPU role to the first online
      one which automatically will be CPU0 if it is online, so one check
      can be dropped from the code for an added benefit.
      
      Link: https://lore.kernel.org/linux-pm/20221011113646.GA12080@duo.ucw.cz/
      Fixes: 68b99e94
      
       ("thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash")
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: default avatarChen Yu <yu.c.chen@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d9fdda5e
    • Eric Dumazet's avatar
      inet: fully convert sk->sk_rx_dst to RCU rules · c3bb4a7e
      Eric Dumazet authored
      commit 8f905c0e upstream.
      
      syzbot reported various issues around early demux,
      one being included in this changelog [1]
      
      sk->sk_rx_dst is using RCU protection without clearly
      documenting it.
      
      And following sequences in tcp_v4_do_rcv()/tcp_v6_do_rcv()
      are not following standard RCU rules.
      
      [a]    dst_release(dst);
      [b]    sk->sk_rx_dst = NULL;
      
      They look wrong because a delete operation of RCU protected
      pointer is supposed to clear the pointer before
      the call_rcu()/synchronize_rcu() guarding actual memory freeing.
      
      In some cases indeed, dst could be freed before [b] is done.
      
      We could cheat by clearing sk_rx_dst before calling
      dst_release(), but this seems the right time to stick
      to standard RCU annotations and debugging facilities.
      
      [1]
      BUG: KASAN: use-after-free in dst_check include/net/dst.h:470 [inline]
      BUG: KASAN: use-after-free in tcp_v4_early_demux+0x95b/0x960 net/ipv4/tcp_ipv4.c:1792
      Read of size 2 at addr ffff88807f1cb73a by task syz-executor.5/9204
      
      CPU: 0 PID: 9204 Comm: syz-executor.5 Not tainted 5.16.0-rc5-syzkaller #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      Call Trace:
       <TASK>
       __dump_stack lib/dump_stack.c:88 [inline]
       dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
       print_address_description.constprop.0.cold+0x8d/0x320 mm/kasan/report.c:247
       __kasan_report mm/kasan/report.c:433 [inline]
       kasan_report.cold+0x83/0xdf mm/kasan/report.c:450
       dst_check include/net/dst.h:470 [inline]
       tcp_v4_early_demux+0x95b/0x960 net/ipv4/tcp_ipv4.c:1792
       ip_rcv_finish_core.constprop.0+0x15de/0x1e80 net/ipv4/ip_input.c:340
       ip_list_rcv_finish.constprop.0+0x1b2/0x6e0 net/ipv4/ip_input.c:583
       ip_sublist_rcv net/ipv4/ip_input.c:609 [inline]
       ip_list_rcv+0x34e/0x490 net/ipv4/ip_input.c:644
       __netif_receive_skb_list_ptype net/core/dev.c:5508 [inline]
       __netif_receive_skb_list_core+0x549/0x8e0 net/core/dev.c:5556
       __netif_receive_skb_list net/core/dev.c:5608 [inline]
       netif_receive_skb_list_internal+0x75e/0xd80 net/core/dev.c:5699
       gro_normal_list net/core/dev.c:5853 [inline]
       gro_normal_list net/core/dev.c:5849 [inline]
       napi_complete_done+0x1f1/0x880 net/core/dev.c:6590
       virtqueue_napi_complete drivers/net/virtio_net.c:339 [inline]
       virtnet_poll+0xca2/0x11b0 drivers/net/virtio_net.c:1557
       __napi_poll+0xaf/0x440 net/core/dev.c:7023
       napi_poll net/core/dev.c:7090 [inline]
       net_rx_action+0x801/0xb40 net/core/dev.c:7177
       __do_softirq+0x29b/0x9c2 kernel/softirq.c:558
       invoke_softirq kernel/softirq.c:432 [inline]
       __irq_exit_rcu+0x123/0x180 kernel/softirq.c:637
       irq_exit_rcu+0x5/0x20 kernel/softirq.c:649
       common_interrupt+0x52/0xc0 arch/x86/kernel/irq.c:240
       asm_common_interrupt+0x1e/0x40 arch/x86/include/asm/idtentry.h:629
      RIP: 0033:0x7f5e972bfd57
      Code: 39 d1 73 14 0f 1f 80 00 00 00 00 48 8b 50 f8 48 83 e8 08 48 39 ca 77 f3 48 39 c3 73 3e 48 89 13 48 8b 50 f8 48 89 38 49 8b 0e <48> 8b 3e 48 83 c3 08 48 83 c6 08 eb bc 48 39 d1 72 9e 48 39 d0 73
      RSP: 002b:00007fff8a413210 EFLAGS: 00000283
      RAX: 00007f5e97108990 RBX: 00007f5e97108338 RCX: ffffffff81d3aa45
      RDX: ffffffff81d3aa45 RSI: 00007f5e97108340 RDI: ffffffff81d3aa45
      RBP: 00007f5e97107eb8 R08: 00007f5e97108d88 R09: 0000000093c2e8d9
      R10: 0000000000000000 R11: 0000000000000000 R12: 00007f5e97107eb0
      R13: 00007f5e97108338 R14: 00007f5e97107ea8 R15: 0000000000000019
       </TASK>
      
      Allocated by task 13:
       kasan_save_stack+0x1e/0x50 mm/kasan/common.c:38
       kasan_set_track mm/kasan/common.c:46 [inline]
       set_alloc_info mm/kasan/common.c:434 [inline]
       __kasan_slab_alloc+0x90/0xc0 mm/kasan/common.c:467
       kasan_slab_alloc include/linux/kasan.h:259 [inline]
       slab_post_alloc_hook mm/slab.h:519 [inline]
       slab_alloc_node mm/slub.c:3234 [inline]
       slab_alloc mm/slub.c:3242 [inline]
       kmem_cache_alloc+0x202/0x3a0 mm/slub.c:3247
       dst_alloc+0x146/0x1f0 net/core/dst.c:92
       rt_dst_alloc+0x73/0x430 net/ipv4/route.c:1613
       ip_route_input_slow+0x1817/0x3a20 net/ipv4/route.c:2340
       ip_route_input_rcu net/ipv4/route.c:2470 [inline]
       ip_route_input_noref+0x116/0x2a0 net/ipv4/route.c:2415
       ip_rcv_finish_core.constprop.0+0x288/0x1e80 net/ipv4/ip_input.c:354
       ip_list_rcv_finish.constprop.0+0x1b2/0x6e0 net/ipv4/ip_input.c:583
       ip_sublist_rcv net/ipv4/ip_input.c:609 [inline]
       ip_list_rcv+0x34e/0x490 net/ipv4/ip_input.c:644
       __netif_receive_skb_list_ptype net/core/dev.c:5508 [inline]
       __netif_receive_skb_list_core+0x549/0x8e0 net/core/dev.c:5556
       __netif_receive_skb_list net/core/dev.c:5608 [inline]
       netif_receive_skb_list_internal+0x75e/0xd80 net/core/dev.c:5699
       gro_normal_list net/core/dev.c:5853 [inline]
       gro_normal_list net/core/dev.c:5849 [inline]
       napi_complete_done+0x1f1/0x880 net/core/dev.c:6590
       virtqueue_napi_complete drivers/net/virtio_net.c:339 [inline]
       virtnet_poll+0xca2/0x11b0 drivers/net/virtio_net.c:1557
       __napi_poll+0xaf/0x440 net/core/dev.c:7023
       napi_poll net/core/dev.c:7090 [inline]
       net_rx_action+0x801/0xb40 net/core/dev.c:7177
       __do_softirq+0x29b/0x9c2 kernel/softirq.c:558
      
      Freed by task 13:
       kasan_save_stack+0x1e/0x50 mm/kasan/common.c:38
       kasan_set_track+0x21/0x30 mm/kasan/common.c:46
       kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370
       ____kasan_slab_free mm/kasan/common.c:366 [inline]
       ____kasan_slab_free mm/kasan/common.c:328 [inline]
       __kasan_slab_free+0xff/0x130 mm/kasan/common.c:374
       kasan_slab_free include/linux/kasan.h:235 [inline]
       slab_free_hook mm/slub.c:1723 [inline]
       slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1749
       slab_free mm/slub.c:3513 [inline]
       kmem_cache_free+0xbd/0x5d0 mm/slub.c:3530
       dst_destroy+0x2d6/0x3f0 net/core/dst.c:127
       rcu_do_batch kernel/rcu/tree.c:2506 [inline]
       rcu_core+0x7ab/0x1470 kernel/rcu/tree.c:2741
       __do_softirq+0x29b/0x9c2 kernel/softirq.c:558
      
      Last potentially related work creation:
       kasan_save_stack+0x1e/0x50 mm/kasan/common.c:38
       __kasan_record_aux_stack+0xf5/0x120 mm/kasan/generic.c:348
       __call_rcu kernel/rcu/tree.c:2985 [inline]
       call_rcu+0xb1/0x740 kernel/rcu/tree.c:3065
       dst_release net/core/dst.c:177 [inline]
       dst_release+0x79/0xe0 net/core/dst.c:167
       tcp_v4_do_rcv+0x612/0x8d0 net/ipv4/tcp_ipv4.c:1712
       sk_backlog_rcv include/net/sock.h:1030 [inline]
       __release_sock+0x134/0x3b0 net/core/sock.c:2768
       release_sock+0x54/0x1b0 net/core/sock.c:3300
       tcp_sendmsg+0x36/0x40 net/ipv4/tcp.c:1441
       inet_sendmsg+0x99/0xe0 net/ipv4/af_inet.c:819
       sock_sendmsg_nosec net/socket.c:704 [inline]
       sock_sendmsg+0xcf/0x120 net/socket.c:724
       sock_write_iter+0x289/0x3c0 net/socket.c:1057
       call_write_iter include/linux/fs.h:2162 [inline]
       new_sync_write+0x429/0x660 fs/read_write.c:503
       vfs_write+0x7cd/0xae0 fs/read_write.c:590
       ksys_write+0x1ee/0x250 fs/read_write.c:643
       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+0x44/0xae
      
      The buggy address belongs to the object at ffff88807f1cb700
       which belongs to the cache ip_dst_cache of size 176
      The buggy address is located 58 bytes inside of
       176-byte region [ffff88807f1cb700, ffff88807f1cb7b0)
      The buggy address belongs to the page:
      page:ffffea0001fc72c0 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7f1cb
      flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
      raw: 00fff00000000200 dead000000000100 dead000000000122 ffff8881413bb780
      raw: 0000000000000000 0000000000100010 00000001ffffffff 0000000000000000
      page dumped because: kasan: bad access detected
      page_owner tracks the page as allocated
      page last allocated via order 0, migratetype Unmovable, gfp_mask 0x112a20(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_HARDWALL), pid 5, ts 108466983062, free_ts 108048976062
       prep_new_page mm/page_alloc.c:2418 [inline]
       get_page_from_freelist+0xa72/0x2f50 mm/page_alloc.c:4149
       __alloc_pages+0x1b2/0x500 mm/page_alloc.c:5369
       alloc_pages+0x1a7/0x300 mm/mempolicy.c:2191
       alloc_slab_page mm/slub.c:1793 [inline]
       allocate_slab mm/slub.c:1930 [inline]
       new_slab+0x32d/0x4a0 mm/slub.c:1993
       ___slab_alloc+0x918/0xfe0 mm/slub.c:3022
       __slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3109
       slab_alloc_node mm/slub.c:3200 [inline]
       slab_alloc mm/slub.c:3242 [inline]
       kmem_cache_alloc+0x35c/0x3a0 mm/slub.c:3247
       dst_alloc+0x146/0x1f0 net/core/dst.c:92
       rt_dst_alloc+0x73/0x430 net/ipv4/route.c:1613
       __mkroute_output net/ipv4/route.c:2564 [inline]
       ip_route_output_key_hash_rcu+0x921/0x2d00 net/ipv4/route.c:2791
       ip_route_output_key_hash+0x18b/0x300 net/ipv4/route.c:2619
       __ip_route_output_key include/net/route.h:126 [inline]
       ip_route_output_flow+0x23/0x150 net/ipv4/route.c:2850
       ip_route_output_key include/net/route.h:142 [inline]
       geneve_get_v4_rt+0x3a6/0x830 drivers/net/geneve.c:809
       geneve_xmit_skb drivers/net/geneve.c:899 [inline]
       geneve_xmit+0xc4a/0x3540 drivers/net/geneve.c:1082
       __netdev_start_xmit include/linux/netdevice.h:4994 [inline]
       netdev_start_xmit include/linux/netdevice.h:5008 [inline]
       xmit_one net/core/dev.c:3590 [inline]
       dev_hard_start_xmit+0x1eb/0x920 net/core/dev.c:3606
       __dev_queue_xmit+0x299a/0x3650 net/core/dev.c:4229
      page last free stack trace:
       reset_page_owner include/linux/page_owner.h:24 [inline]
       free_pages_prepare mm/page_alloc.c:1338 [inline]
       free_pcp_prepare+0x374/0x870 mm/page_alloc.c:1389
       free_unref_page_prepare mm/page_alloc.c:3309 [inline]
       free_unref_page+0x19/0x690 mm/page_alloc.c:3388
       qlink_free mm/kasan/quarantine.c:146 [inline]
       qlist_free_all+0x5a/0xc0 mm/kasan/quarantine.c:165
       kasan_quarantine_reduce+0x180/0x200 mm/kasan/quarantine.c:272
       __kasan_slab_alloc+0xa2/0xc0 mm/kasan/common.c:444
       kasan_slab_alloc include/linux/kasan.h:259 [inline]
       slab_post_alloc_hook mm/slab.h:519 [inline]
       slab_alloc_node mm/slub.c:3234 [inline]
       kmem_cache_alloc_node+0x255/0x3f0 mm/slub.c:3270
       __alloc_skb+0x215/0x340 net/core/skbuff.c:414
       alloc_skb include/linux/skbuff.h:1126 [inline]
       alloc_skb_with_frags+0x93/0x620 net/core/skbuff.c:6078
       sock_alloc_send_pskb+0x783/0x910 net/core/sock.c:2575
       mld_newpack+0x1df/0x770 net/ipv6/mcast.c:1754
       add_grhead+0x265/0x330 net/ipv6/mcast.c:1857
       add_grec+0x1053/0x14e0 net/ipv6/mcast.c:1995
       mld_send_initial_cr.part.0+0xf6/0x230 net/ipv6/mcast.c:2242
       mld_send_initial_cr net/ipv6/mcast.c:1232 [inline]
       mld_dad_work+0x1d3/0x690 net/ipv6/mcast.c:2268
       process_one_work+0x9b2/0x1690 kernel/workqueue.c:2298
       worker_thread+0x658/0x11f0 kernel/workqueue.c:2445
      
      Memory state around the buggy address:
       ffff88807f1cb600: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
       ffff88807f1cb680: fb fb fb fb fb fb fc fc fc fc fc fc fc fc fc fc
      >ffff88807f1cb700: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                              ^
       ffff88807f1cb780: fb fb fb fb fb fb fc fc fc fc fc fc fc fc fc fc
       ffff88807f1cb800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      
      Fixes: 41063e9d
      
       ("ipv4: Early TCP socket demux.")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20211220143330.680945-1-eric.dumazet@gmail.com
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      [cmllamas: fixed trivial merge conflict]
      Signed-off-by: default avatarCarlos Llamas <cmllamas@google.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c3bb4a7e
    • Ard Biesheuvel's avatar
      efi: libstub: drop pointless get_memory_map() call · 96e2e212
      Ard Biesheuvel authored
      commit d80ca810 upstream.
      
      Currently, the non-x86 stub code calls get_memory_map() redundantly,
      given that the data it returns is never used anywhere. So drop the call.
      
      Cc: <stable@vger.kernel.org> # v4.14+
      Fixes: 24d7c494
      
       ("efi/arm-stub: Round up FDT allocation to mapping size")
      Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      96e2e212
    • Saurabh Sengar's avatar
      md: Replace snprintf with scnprintf · 97238b88
      Saurabh Sengar authored
      commit 1727fd50 upstream.
      
      Current code produces a warning as shown below when total characters
      in the constituent block device names plus the slashes exceeds 200.
      snprintf() returns the number of characters generated from the given
      input, which could cause the expression “200 – len” to wrap around
      to a large positive number. Fix this by using scnprintf() instead,
      which returns the actual number of characters written into the buffer.
      
      [ 1513.267938] ------------[ cut here ]------------
      [ 1513.267943] WARNING: CPU: 15 PID: 37247 at <snip>/lib/vsprintf.c:2509 vsnprintf+0x2c8/0x510
      [ 1513.267944] Modules linked in:  <snip>
      [ 1513.267969] CPU: 15 PID: 37247 Comm: mdadm Not tainted 5.4.0-1085-azure #90~18.04.1-Ubuntu
      [ 1513.267969] Hardware name: Microsoft Corporation Virtual Machine/Virtual Machine, BIOS Hyper-V UEFI Release v4.1 05/09/2022
      [ 1513.267971] RIP: 0010:vsnprintf+0x2c8/0x510
      <-snip->
      [ 1513.267982] Call Trace:
      [ 1513.267986]  snprintf+0x45/0x70
      [ 1513.267990]  ? disk_name+0x71/0xa0
      [ 1513.267993]  dump_zones+0x114/0x240 [raid0]
      [ 1513.267996]  ? _cond_resched+0x19/0x40
      [ 1513.267998]  raid0_run+0x19e/0x270 [raid0]
      [ 1513.268000]  md_run+0x5e0/0xc50
      [ 1513.268003]  ? security_capable+0x3f/0x60
      [ 1513.268005]  do_md_run+0x19/0x110
      [ 1513.268006]  md_ioctl+0x195e/0x1f90
      [ 1513.268007]  blkdev_ioctl+0x91f/0x9f0
      [ 1513.268010]  block_ioctl+0x3d/0x50
      [ 1513.268012]  do_vfs_ioctl+0xa9/0x640
      [ 1513.268014]  ? __fput+0x162/0x260
      [ 1513.268016]  ksys_ioctl+0x75/0x80
      [ 1513.268017]  __x64_sys_ioctl+0x1a/0x20
      [ 1513.268019]  do_syscall_64+0x5e/0x200
      [ 1513.268021]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      Fixes: 76603884
      
       ("md/raid0: replace printk() with pr_*()")
      Reviewed-by: default avatarMichael Kelley <mikelley@microsoft.com>
      Acked-by: default avatarGuoqing Jiang <guoqing.jiang@linux.dev>
      Signed-off-by: default avatarSaurabh Sengar <ssengar@linux.microsoft.com>
      Signed-off-by: default avatarSong Liu <song@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      97238b88
    • Jerry Lee 李修賢's avatar
      ext4: continue to expand file system when the target size doesn't reach · 8b766dd7
      Jerry Lee 李修賢 authored
      commit df3cb754
      
       upstream.
      
      When expanding a file system from (16TiB-2MiB) to 18TiB, the operation
      exits early which leads to result inconsistency between resize2fs and
      Ext4 kernel driver.
      
      === before ===
      ○ → resize2fs /dev/mapper/thin
      resize2fs 1.45.5 (07-Jan-2020)
      Filesystem at /dev/mapper/thin is mounted on /mnt/test; on-line resizing required
      old_desc_blocks = 2048, new_desc_blocks = 2304
      The filesystem on /dev/mapper/thin is now 4831837696 (4k) blocks long.
      
      [  865.186308] EXT4-fs (dm-5): mounted filesystem with ordered data mode. Opts: (null). Quota mode: none.
      [  912.091502] dm-4: detected capacity change from 34359738368 to 38654705664
      [  970.030550] dm-5: detected capacity change from 34359734272 to 38654701568
      [ 1000.012751] EXT4-fs (dm-5): resizing filesystem from 4294966784 to 4831837696 blocks
      [ 1000.012878] EXT4-fs (dm-5): resized filesystem to 4294967296
      
      === after ===
      [  129.104898] EXT4-fs (dm-5): mounted filesystem with ordered data mode. Opts: (null). Quota mode: none.
      [  143.773630] dm-4: detected capacity change from 34359738368 to 38654705664
      [  198.203246] dm-5: detected capacity change from 34359734272 to 38654701568
      [  207.918603] EXT4-fs (dm-5): resizing filesystem from 4294966784 to 4831837696 blocks
      [  207.918754] EXT4-fs (dm-5): resizing filesystem from 4294967296 to 4831837696 blocks
      [  207.918758] EXT4-fs (dm-5): Converting file system to meta_bg
      [  207.918790] EXT4-fs (dm-5): resizing filesystem from 4294967296 to 4831837696 blocks
      [  221.454050] EXT4-fs (dm-5): resized to 4658298880 blocks
      [  227.634613] EXT4-fs (dm-5): resized filesystem to 4831837696
      Signed-off-by: default avatarJerry Lee <jerrylee@qnap.com>
      Link: https://lore.kernel.org/r/PU1PR04MB22635E739BD21150DC182AC6A18C9@PU1PR04MB2263.apcprd04.prod.outlook.com
      
      Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8b766dd7
    • Tetsuo Handa's avatar
      net/ieee802154: don't warn zero-sized raw_sendmsg() · 4a36de89
      Tetsuo Handa authored
      [ Upstream commit b12e924a ]
      
      syzbot is hitting skb_assert_len() warning at __dev_queue_xmit() [1],
      for PF_IEEE802154 socket's zero-sized raw_sendmsg() request is hitting
      __dev_queue_xmit() with skb->len == 0.
      
      Since PF_IEEE802154 socket's zero-sized raw_sendmsg() request was
      able to return 0, don't call __dev_queue_xmit() if packet length is 0.
      
        ----------
        #include <sys/socket.h>
        #include <netinet/in.h>
      
        int main(int argc, char *argv[])
        {
          struct sockaddr_in addr = { .sin_family = AF_INET, .sin_addr.s_addr = htonl(INADDR_LOOPBACK) };
          struct iovec iov = { };
          struct msghdr hdr = { .msg_name = &addr, .msg_namelen = sizeof(addr), .msg_iov = &iov, .msg_iovlen = 1 };
          sendmsg(socket(PF_IEEE802154, SOCK_RAW, 0), &hdr, 0);
          return 0;
        }
        ----------
      
      Note that this might be a sign that commit fd189422 ("bpf: Don't
      redirect packets with invalid pkt_len") should be reverted, for
      skb->len == 0 was acceptable for at least PF_IEEE802154 socket.
      
      Link: https://syzkaller.appspot.com/bug?extid=5ea725c25d06fb9114c4
      
       [1]
      Reported-by: default avatarsyzbot <syzbot+5ea725c25d06fb9114c4@syzkaller.appspotmail.com>
      Fixes: fd189422
      
       ("bpf: Don't redirect packets with invalid pkt_len")
      Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Signed-off-by: default avatarAlexander Aring <aahringo@redhat.com>
      Link: https://lore.kernel.org/r/20221005014750.3685555-2-aahringo@redhat.com
      
      Signed-off-by: default avatarStefan Schmidt <stefan@datenfreihafen.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4a36de89
    • Alexander Aring's avatar
      Revert "net/ieee802154: reject zero-sized raw_sendmsg()" · cff61312
      Alexander Aring authored
      [ Upstream commit 2eb2756f ]
      
      This reverts commit 3a4d061c
      
      .
      
      There is a v2 which does return zero if zero length is given.
      Signed-off-by: default avatarAlexander Aring <aahringo@redhat.com>
      Link: https://lore.kernel.org/r/20221005014750.3685555-1-aahringo@redhat.com
      
      Signed-off-by: default avatarStefan Schmidt <stefan@datenfreihafen.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      cff61312
    • Alexander Aring's avatar
      net: ieee802154: return -EINVAL for unknown addr type · 1210359a
      Alexander Aring authored
      commit 30393181 upstream.
      
      This patch adds handling to return -EINVAL for an unknown addr type. The
      current behaviour is to return 0 as successful but the size of an
      unknown addr type is not defined and should return an error like -EINVAL.
      
      Fixes: 94160108
      
       ("net/ieee802154: fix uninit value bug in dgram_sendmsg")
      Signed-off-by: default avatarAlexander Aring <aahringo@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1210359a
    • Pavel Begunkov's avatar
      io_uring/af_unix: defer registered files gc to io_uring release · 04df9719
      Pavel Begunkov authored
      [ upstream commit 0091bfc8 ]
      
      Instead of putting io_uring's registered files in unix_gc() we want it
      to be done by io_uring itself. The trick here is to consider io_uring
      registered files for cycle detection but not actually putting them down.
      Because io_uring can't register other ring instances, this will remove
      all refs to the ring file triggering the ->release path and clean up
      with io_ring_ctx_free().
      
      Cc: stable@vger.kernel.org
      Fixes: 6b06314c
      
       ("io_uring: add file set registration")
      Reported-and-tested-by: default avatarDavid Bouman <dbouman03@gmail.com>
      Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: default avatarThadeu Lima de Souza Cascardo <cascardo@canonical.com>
      [axboe: add kerneldoc comment to skb, fold in skb leak fix]
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      04df9719
    • Adrian Hunter's avatar
      perf intel-pt: Fix segfault in intel_pt_print_info() with uClibc · f5dd24a6
      Adrian Hunter authored
      commit 5a3d4707 upstream.
      
      uClibc segfaulted because NULL was passed as the format to fprintf().
      
      That happened because one of the format strings was missing and
      intel_pt_print_info() didn't check that before calling fprintf().
      
      Add the missing format string, and check format is not NULL before calling
      fprintf().
      
      Fixes: 11fa7cb8
      
       ("perf tools: Pass Intel PT information for decoding MTC and CYC")
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20221012082259.22394-2-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>
      f5dd24a6
    • Maxime Ripard's avatar
      clk: bcm2835: Make peripheral PLLC critical · 036b1f3b
      Maxime Ripard authored
      [ Upstream commit 6c542285
      
       ]
      
      When testing for a series affecting the VEC, it was discovered that
      turning off and on the VEC clock is crashing the system.
      
      It turns out that, when disabling the VEC clock, it's the only child of
      the PLLC-per clock which will also get disabled. The source of the crash
      is PLLC-per being disabled.
      
      It's likely that some other device might not take a clock reference that
      it actually needs, but it's unclear which at this point. Let's make
      PLLC-per critical so that we don't have that crash.
      Reported-by: default avatarNoralf Trønnes <noralf@tronnes.org>
      Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
      Link: https://lore.kernel.org/r/20220926084509.12233-1-maxime@cerno.tech
      
      Reviewed-by: default avatarStefan Wahren <stefan.wahren@i2se.com>
      Acked-by: default avatarNoralf Trønnes <noralf@tronnes.org>
      Signed-off-by: default avatarStephen Boyd <sboyd@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      036b1f3b
    • Dongliang Mu's avatar
      usb: idmouse: fix an uninit-value in idmouse_open · 1eae30c0
      Dongliang Mu authored
      [ Upstream commit bce2b053
      
       ]
      
      In idmouse_create_image, if any ftip_command fails, it will
      go to the reset label. However, this leads to the data in
      bulk_in_buffer[HEADER..IMGSIZE] uninitialized. And the check
      for valid image incurs an uninitialized dereference.
      
      Fix this by moving the check before reset label since this
      check only be valid if the data after bulk_in_buffer[HEADER]
      has concrete data.
      
      Note that this is found by KMSAN, so only kernel compilation
      is tested.
      
      Reported-by: syzbot+79832d33eb89fb3cd092@syzkaller.appspotmail.com
      Signed-off-by: default avatarDongliang Mu <mudongliangabcd@gmail.com>
      Link: https://lore.kernel.org/r/20220922134847.1101921-1-dzm91@hust.edu.cn
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1eae30c0
    • Varun Prakash's avatar
      nvmet-tcp: add bounds check on Transfer Tag · 0d150ccd
      Varun Prakash authored
      [ Upstream commit b6a545ff
      
       ]
      
      ttag is used as an index to get cmd in nvmet_tcp_handle_h2c_data_pdu(),
      add a bounds check to avoid out-of-bounds access.
      Signed-off-by: default avatarVarun Prakash <varun@chelsio.com>
      Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0d150ccd
    • Keith Busch's avatar
      nvme: copy firmware_rev on each init · 3a3a8d75
      Keith Busch authored
      [ Upstream commit a8eb6c1b
      
       ]
      
      The firmware revision can change on after a reset so copy the most
      recent info each time instead of just the first time, otherwise the
      sysfs firmware_rev entry may contain stale data.
      Reported-by: default avatarJeff Lien <jeff.lien@wdc.com>
      Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
      Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
      Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
      Reviewed-by: default avatarChao Leng <lengchao@huawei.com>
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3a3a8d75
    • Xiaoke Wang's avatar
      staging: rtl8723bs: fix a potential memory leak in rtw_init_cmd_priv() · e5d8f05e
      Xiaoke Wang authored
      [ Upstream commit 708056fb
      
       ]
      
      In rtw_init_cmd_priv(), if `pcmdpriv->rsp_allocated_buf` is allocated
      in failure, then `pcmdpriv->cmd_allocated_buf` will be not properly
      released. Besides, considering there are only two error paths and the
      first one can directly return, so we do not need implicitly jump to the
      `exit` tag to execute the error handler.
      
      So this patch added `kfree(pcmdpriv->cmd_allocated_buf);` on the error
      path to release the resource and simplified the return logic of
      rtw_init_cmd_priv(). As there is no proper device to test with, no runtime
      testing was performed.
      Signed-off-by: default avatarXiaoke Wang <xkernel.wang@foxmail.com>
      Link: https://lore.kernel.org/r/tencent_2B7931B79BA38E22205C5A09EFDF11E48805@qq.com
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e5d8f05e
    • sunghwan jung's avatar
      Revert "usb: storage: Add quirk for Samsung Fit flash" · 072b5a41
      sunghwan jung authored
      [ Upstream commit ad5dbfc1 ]
      
      This reverts commit 86d92f54
      
      ,
      which fix the timeout issue for "Samsung Fit Flash".
      
      But the commit affects not only "Samsung Fit Flash" but also other usb
      storages that use the same controller and causes severe performance
      regression.
      
       # hdparm -t /dev/sda (without the quirk)
       Timing buffered disk reads: 622 MB in  3.01 seconds = 206.66 MB/sec
      
       # hdparm -t /dev/sda (with the quirk)
       Timing buffered disk reads: 220 MB in  3.00 seconds =  73.32 MB/sec
      
      The commit author mentioned that "Issue was reproduced after device has
      bad block", so this quirk should be applied when we have the timeout
      issue with a device that has bad blocks.
      
      We revert the commit so that we apply this quirk by adding kernel
      paramters using a bootloader or other ways when we really need it,
      without the performance regression with devices that don't have the
      issue.
      Signed-off-by: default avatarsunghwan jung <onenowy@gmail.com>
      Link: https://lore.kernel.org/r/20220913114913.3073-1-onenowy@gmail.com
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      072b5a41
    • Robin Guo's avatar
      usb: musb: Fix musb_gadget.c rxstate overflow bug · d6afcab1
      Robin Guo authored
      [ Upstream commit eea4c860
      
       ]
      
      The usb function device call musb_gadget_queue() adds the passed
      request to musb_ep::req_list,If the (request->length > musb_ep->packet_sz)
      and (is_buffer_mapped(req) return false),the rxstate() will copy all data
      in fifo to request->buf which may cause request->buf out of bounds.
      
      Fix it by add the length check :
      fifocnt = min_t(unsigned, request->length - request->actual, fifocnt);
      Signed-off-by: default avatarRobin Guo <guoweibin@inspur.com>
      Link: https://lore.kernel.org/r/20220906102119.1b071d07a8391ff115e6d1ef@inspur.com
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d6afcab1
    • Jianglei Nie's avatar
      usb: host: xhci: Fix potential memory leak in xhci_alloc_stream_info() · 9fa81cbd
      Jianglei Nie authored
      [ Upstream commit 7e271f42
      
       ]
      
      xhci_alloc_stream_info() allocates stream context array for stream_info
      ->stream_ctx_array with xhci_alloc_stream_ctx(). When some error occurs,
      stream_info->stream_ctx_array is not released, which will lead to a
      memory leak.
      
      We can fix it by releasing the stream_info->stream_ctx_array with
      xhci_free_stream_ctx() on the error path to avoid the potential memory
      leak.
      Signed-off-by: default avatarJianglei Nie <niejianglei2021@163.com>
      Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
      Link: https://lore.kernel.org/r/20220921123450.671459-2-mathias.nyman@linux.intel.com
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9fa81cbd
    • Logan Gunthorpe's avatar
      md/raid5: Wait for MD_SB_CHANGE_PENDING in raid5d · 1c00bb62
      Logan Gunthorpe authored
      [ Upstream commit 5e2cf333 ]
      
      A complicated deadlock exists when using the journal and an elevated
      group_thrtead_cnt. It was found with loop devices, but its not clear
      whether it can be seen with real disks. The deadlock can occur simply
      by writing data with an fio script.
      
      When the deadlock occurs, multiple threads will hang in different ways:
      
       1) The group threads will hang in the blk-wbt code with bios waiting to
          be submitted to the block layer:
      
              io_schedule+0x70/0xb0
              rq_qos_wait+0x153/0x210
              wbt_wait+0x115/0x1b0
              io_schedule+0x70/0xb0
              rq_qos_wait+0x153/0x210
              wbt_wait+0x115/0x1b0
              __rq_qos_throttle+0x38/0x60
              blk_mq_submit_bio+0x589/0xcd0
              wbt_wait+0x115/0x1b0
              __rq_qos_throttle+0x38/0x60
              blk_mq_submit_bio+0x589/0xcd0
              __submit_bio+0xe6/0x100
              submit_bio_noacct_nocheck+0x42e/0x470
              submit_bio_noacct+0x4c2/0xbb0
              ops_run_io+0x46b/0x1a30
              handle_stripe+0xcd3/0x36b0
              handle_active_stripes.constprop.0+0x6f6/0xa60
              raid5_do_work+0x177/0x330
      
          Or:
              io_schedule+0x70/0xb0
              rq_qos_wait+0x153/0x210
              wbt_wait+0x115/0x1b0
              __rq_qos_throttle+0x38/0x60
              blk_mq_submit_bio+0x589/0xcd0
              __submit_bio+0xe6/0x100
              submit_bio_noacct_nocheck+0x42e/0x470
              submit_bio_noacct+0x4c2/0xbb0
              flush_deferred_bios+0x136/0x170
              raid5_do_work+0x262/0x330
      
       2) The r5l_reclaim thread will hang in the same way, submitting a
          bio to the block layer:
      
              io_schedule+0x70/0xb0
              rq_qos_wait+0x153/0x210
              wbt_wait+0x115/0x1b0
              __rq_qos_throttle+0x38/0x60
              blk_mq_submit_bio+0x589/0xcd0
              __submit_bio+0xe6/0x100
              submit_bio_noacct_nocheck+0x42e/0x470
              submit_bio_noacct+0x4c2/0xbb0
              submit_bio+0x3f/0xf0
              md_super_write+0x12f/0x1b0
              md_update_sb.part.0+0x7c6/0xff0
              md_update_sb+0x30/0x60
              r5l_do_reclaim+0x4f9/0x5e0
              r5l_reclaim_thread+0x69/0x30b
      
          However, before hanging, the MD_SB_CHANGE_PENDING flag will be
          set for sb_flags in r5l_write_super_and_discard_space(). This
          flag will never be cleared because the submit_bio() call never
          returns.
      
       3) Due to the MD_SB_CHANGE_PENDING flag being set, handle_stripe()
          will do no processing on any pending stripes and re-set
          STRIPE_HANDLE. This will cause the raid5d thread to enter an
          infinite loop, constantly trying to handle the same stripes
          stuck in the queue.
      
          The raid5d thread has a blk_plug that holds a number of bios
          that are also stuck waiting seeing the thread is in a loop
          that never schedules. These bios have been accounted for by
          blk-wbt thus preventing the other threads above from
          continuing when they try to submit bios. --Deadlock.
      
      To fix this, add the same wait_event() that is used in raid5_do_work()
      to raid5d() such that if MD_SB_CHANGE_PENDING is set, the thread will
      schedule and wait until the flag is cleared. The schedule action will
      flush the plug which will allow the r5l_reclaim thread to continue,
      thus preventing the deadlock.
      
      However, md_check_recovery() calls can also clear MD_SB_CHANGE_PENDING
      from the same thread and can thus deadlock if the thread is put to
      sleep. So avoid waiting if md_check_recovery() is being called in the
      loop.
      
      It's not clear when the deadlock was introduced, but the similar
      wait_event() call in raid5_do_work() was added in 2017 by this
      commit:
      
          16d997b7 ("md/raid5: simplfy delaying of writes while metadata
                         is updated.")
      
      Link: https://lore.kernel.org/r/7f3b87b6-b52a-f737-51d7-a4eec5c44112@deltatee.com
      
      Signed-off-by: default avatarLogan Gunthorpe <logang@deltatee.com>
      Signed-off-by: default avatarSong Liu <song@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1c00bb62
    • Hyunwoo Kim's avatar
      HID: roccat: Fix use-after-free in roccat_read() · e30c3a9a
      Hyunwoo Kim authored
      [ Upstream commit cacdb14b
      
       ]
      
      roccat_report_event() is responsible for registering
      roccat-related reports in struct roccat_device.
      
      int roccat_report_event(int minor, u8 const *data)
      {
      	struct roccat_device *device;
      	struct roccat_reader *reader;
      	struct roccat_report *report;
      	uint8_t *new_value;
      
      	device = devices[minor];
      
      	new_value = kmemdup(data, device->report_size, GFP_ATOMIC);
      	if (!new_value)
      		return -ENOMEM;
      
      	report = &device->cbuf[device->cbuf_end];
      
      	/* passing NULL is safe */
      	kfree(report->value);
      	...
      
      The registered report is stored in the struct roccat_device member
      "struct roccat_report cbuf[ROCCAT_CBUF_SIZE];".
      If more reports are received than the "ROCCAT_CBUF_SIZE" value,
      kfree() the saved report from cbuf[0] and allocates a new reprot.
      Since there is no lock when this kfree() is performed,
      kfree() can be performed even while reading the saved report.
      
      static ssize_t roccat_read(struct file *file, char __user *buffer,
      		size_t count, loff_t *ppos)
      {
      	struct roccat_reader *reader = file->private_data;
      	struct roccat_device *device = reader->device;
      	struct roccat_report *report;
      	ssize_t retval = 0, len;
      	DECLARE_WAITQUEUE(wait, current);
      
      	mutex_lock(&device->cbuf_lock);
      
      	...
      
      	report = &device->cbuf[reader->cbuf_start];
      	/*
      	 * If report is larger than requested amount of data, rest of report
      	 * is lost!
      	 */
      	len = device->report_size > count ? count : device->report_size;
      
      	if (copy_to_user(buffer, report->value, len)) {
      		retval = -EFAULT;
      		goto exit_unlock;
      	}
      	...
      
      The roccat_read() function receives the device->cbuf report and
      delivers it to the user through copy_to_user().
      If the N+ROCCAT_CBUF_SIZE th report is received while copying of
      the Nth report->value is in progress, the pointer that copy_to_user()
      is working on is kfree()ed and UAF read may occur. (race condition)
      
      Since the device node of this driver does not set separate permissions,
      this is not a security vulnerability, but because it is used for
      requesting screen display of profile or dpi settings,
      a user using the roccat device can apply udev to this device node or
      There is a possibility to use it by giving.
      Signed-off-by: default avatarHyunwoo Kim <imv4bel@gmail.com>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e30c3a9a
    • Coly Li's avatar
      bcache: fix set_at_max_writeback_rate() for multiple attached devices · 81247850
      Coly Li authored
      [ Upstream commit d2d05b88
      
       ]
      
      Inside set_at_max_writeback_rate() the calculation in following if()
      check is wrong,
      	if (atomic_inc_return(&c->idle_counter) <
      	    atomic_read(&c->attached_dev_nr) * 6)
      
      Because each attached backing device has its own writeback thread
      running and increasing c->idle_counter, the counter increates much
      faster than expected. The correct calculation should be,
      	(counter / dev_nr) < dev_nr * 6
      which equals to,
      	counter < dev_nr * dev_nr * 6
      
      This patch fixes the above mistake with correct calculation, and helper
      routine idle_counter_exceeded() is added to make code be more clear.
      Reported-by: default avatarMingzhe Zou <mingzhe.zou@easystack.cn>
      Signed-off-by: default avatarColy Li <colyli@suse.de>
      Acked-by: default avatarMingzhe Zou <mingzhe.zou@easystack.cn>
      Link: https://lore.kernel.org/r/20220919161647.81238-6-colyli@suse.de
      
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      81247850
    • Serge Semin's avatar
      ata: libahci_platform: Sanity check the DT child nodes number · 7cfc77f4
      Serge Semin authored
      [ Upstream commit 3c132ea6
      
       ]
      
      Having greater than AHCI_MAX_PORTS (32) ports detected isn't that critical
      from the further AHCI-platform initialization point of view since
      exceeding the ports upper limit will cause allocating more resources than
      will be used afterwards. But detecting too many child DT-nodes doesn't
      seem right since it's very unlikely to have it on an ordinary platform. In
      accordance with the AHCI specification there can't be more than 32 ports
      implemented at least due to having the CAP.NP field of 5 bits wide and the
      PI register of dword size. Thus if such situation is found the DTB must
      have been corrupted and the data read from it shouldn't be reliable. Let's
      consider that as an erroneous situation and halt further resources
      allocation.
      
      Note it's logically more correct to have the nports set only after the
      initialization value is checked for being sane. So while at it let's make
      sure nports is assigned with a correct value.
      Signed-off-by: default avatarSerge Semin <Sergey.Semin@baikalelectronics.ru>
      Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
      Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7cfc77f4
    • Nam Cao's avatar
      staging: vt6655: fix potential memory leak · 16a45e78
      Nam Cao authored
      [ Upstream commit c8ff9153
      
       ]
      
      In function device_init_td0_ring, memory is allocated for member
      td_info of priv->apTD0Rings[i], with i increasing from 0. In case of
      allocation failure, the memory is freed in reversed order, with i
      decreasing to 0. However, the case i=0 is left out and thus memory is
      leaked.
      
      Modify the memory freeing loop to include the case i=0.
      Tested-by: default avatarPhilipp Hortmann <philipp.g.hortmann@gmail.com>
      Signed-off-by: default avatarNam Cao <namcaov@gmail.com>
      Link: https://lore.kernel.org/r/20220909141338.19343-1-namcaov@gmail.com
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      16a45e78
    • Wei Yongjun's avatar
      power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type() · 3376a0cf
      Wei Yongjun authored
      [ Upstream commit 9d47e01b
      
       ]
      
      ADP5061_CHG_STATUS_1_CHG_STATUS is masked with 0x07, which means a length
      of 8, but adp5061_chg_type array size is 4, may end up reading 4 elements
      beyond the end of the adp5061_chg_type[] array.
      Signed-off-by: default avatarWei Yongjun <weiyongjun1@huawei.com>
      Acked-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
      Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3376a0cf
    • Shigeru Yoshida's avatar
      nbd: Fix hung when signal interrupts nbd_start_device_ioctl() · 35759495
      Shigeru Yoshida authored
      [ Upstream commit 1de7c3cf ]
      
      syzbot reported hung task [1].  The following program is a simplified
      version of the reproducer:
      
      int main(void)
      {
      	int sv[2], fd;
      
      	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) < 0)
      		return 1;
      	if ((fd = open("/dev/nbd0", 0)) < 0)
      		return 1;
      	if (ioctl(fd, NBD_SET_SIZE_BLOCKS, 0x81) < 0)
      		return 1;
      	if (ioctl(fd, NBD_SET_SOCK, sv[0]) < 0)
      		return 1;
      	if (ioctl(fd, NBD_DO_IT) < 0)
      		return 1;
      	return 0;
      }
      
      When signal interrupt nbd_start_device_ioctl() waiting the condition
      atomic_read(&config->recv_threads) == 0, the task can hung because it
      waits the completion of the inflight IOs.
      
      This patch fixes the issue by clearing queue, not just shutdown, when
      signal interrupt nbd_start_device_ioctl().
      
      Link: https://syzkaller.appspot.com/bug?id=7d89a3ffacd2b83fdd39549bc4d8e0a89ef21239
      
       [1]
      Reported-by: syzbot+38e6c55d4969a14c1534@syzkaller.appspotmail.com
      Signed-off-by: default avatarShigeru Yoshida <syoshida@redhat.com>
      Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
      Link: https://lore.kernel.org/r/20220907163502.577561-1-syoshida@redhat.com
      
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      35759495
    • Letu Ren's avatar
      scsi: 3w-9xxx: Avoid disabling device if failing to enable it · 22f49d9d
      Letu Ren authored
      [ Upstream commit 7eff437b ]
      
      The original code will "goto out_disable_device" and call
      pci_disable_device() if pci_enable_device() fails. The kernel will generate
      a warning message like "3w-9xxx 0000:00:05.0: disabling already-disabled
      device".
      
      We shouldn't disable a device that failed to be enabled. A simple return is
      fine.
      
      Link: https://lore.kernel.org/r/20220829110115.38789-1-fantasquex@gmail.com
      
      Reported-by: default avatarZheyu Ma <zheyuma97@gmail.com>
      Signed-off-by: default avatarLetu Ren <fantasquex@gmail.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      22f49d9d
    • Quanyang Wang's avatar
      clk: zynqmp: pll: rectify rate rounding in zynqmp_pll_round_rate · 66de9220
      Quanyang Wang authored
      [ Upstream commit 30eaf021
      
       ]
      
      The function zynqmp_pll_round_rate is used to find a most appropriate
      PLL frequency which the hardware can generate according to the desired
      frequency. For example, if the desired frequency is 297MHz, considering
      the limited range from PS_PLL_VCO_MIN (1.5GHz) to PS_PLL_VCO_MAX (3.0GHz)
      of PLL, zynqmp_pll_round_rate should return 1.872GHz (297MHz * 5).
      
      There are two problems with the current code of zynqmp_pll_round_rate:
      
      1) When the rate is below PS_PLL_VCO_MIN, it can't find a correct rate
      when the parameter "rate" is an integer multiple of *prate, in other words,
      if "f" is zero, zynqmp_pll_round_rate won't return a valid frequency which
      is from PS_PLL_VCO_MIN to PS_PLL_VCO_MAX. For example, *prate is 33MHz
      and the rate is 660MHz, zynqmp_pll_round_rate will not boost up rate and
      just return 660MHz, and this will cause clk_calc_new_rates failure since
      zynqmp_pll_round_rate returns an invalid rate out of its boundaries.
      
      2) Even if the rate is higher than PS_PLL_VCO_MIN, there is still a risk
      that zynqmp_pll_round_rate returns an invalid rate because the function
      DIV_ROUND_CLOSEST makes some loss in the fractional part. If the parent
      clock *prate is 33333333Hz and we want to set the PLL rate to 1.5GHz,
      this function will return 1499999985Hz by using the formula below:
          value = *prate * DIV_ROUND_CLOSEST(rate, *prate)).
      This value is also invalid since it's slightly smaller than PS_PLL_VCO_MIN.
      because DIV_ROUND_CLOSEST makes some loss in the fractional part.
      Signed-off-by: default avatarQuanyang Wang <quanyang.wang@windriver.com>
      Link: https://lore.kernel.org/r/20220826142030.213805-1-quanyang.wang@windriver.com
      
      Reviewed-by: default avatarShubhrajyoti Datta <shubhrajyoti.datta@amd.com>
      Signed-off-by: default avatarStephen Boyd <sboyd@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      66de9220
    • Zheyu Ma's avatar
      media: cx88: Fix a null-ptr-deref bug in buffer_prepare() · 9181af2d
      Zheyu Ma authored
      [ Upstream commit 2b064d91
      
       ]
      
      When the driver calls cx88_risc_buffer() to prepare the buffer, the
      function call may fail, resulting in a empty buffer and null-ptr-deref
      later in buffer_queue().
      
      The following log can reveal it:
      
      [   41.822762] general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN PTI
      [   41.824488] KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
      [   41.828027] RIP: 0010:buffer_queue+0xc2/0x500
      [   41.836311] Call Trace:
      [   41.836945]  __enqueue_in_driver+0x141/0x360
      [   41.837262]  vb2_start_streaming+0x62/0x4a0
      [   41.838216]  vb2_core_streamon+0x1da/0x2c0
      [   41.838516]  __vb2_init_fileio+0x981/0xbc0
      [   41.839141]  __vb2_perform_fileio+0xbf9/0x1120
      [   41.840072]  vb2_fop_read+0x20e/0x400
      [   41.840346]  v4l2_read+0x215/0x290
      [   41.840603]  vfs_read+0x162/0x4c0
      
      Fix this by checking the return value of cx88_risc_buffer()
      
      [hverkuil: fix coding style issues]
      Signed-off-by: default avatarZheyu Ma <zheyuma97@gmail.com>
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9181af2d
    • Ian Nam's avatar
      clk: zynqmp: Fix stack-out-of-bounds in strncpy` · 5dbfcf7b
      Ian Nam authored
      [ Upstream commit dd80fb2d
      
       ]
      
      "BUG: KASAN: stack-out-of-bounds in strncpy+0x30/0x68"
      
      Linux-ATF interface is using 16 bytes of SMC payload. In case clock name is
      longer than 15 bytes, string terminated NULL character will not be received
      by Linux. Add explicit NULL character at last byte to fix issues when clock
      name is longer.
      
      This fixes below bug reported by KASAN:
      
       ==================================================================
       BUG: KASAN: stack-out-of-bounds in strncpy+0x30/0x68
       Read of size 1 at addr ffff0008c89a7410 by task swapper/0/1
      
       CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.4.0-00396-g81ef9e7-dirty #3
       Hardware name: Xilinx Versal vck190 Eval board revA (QSPI) (DT)
       Call trace:
        dump_backtrace+0x0/0x1e8
        show_stack+0x14/0x20
        dump_stack+0xd4/0x108
        print_address_description.isra.0+0xbc/0x37c
        __kasan_report+0x144/0x198
        kasan_report+0xc/0x18
        __asan_load1+0x5c/0x68
        strncpy+0x30/0x68
        zynqmp_clock_probe+0x238/0x7b8
        platform_drv_probe+0x6c/0xc8
        really_probe+0x14c/0x418
        driver_probe_device+0x74/0x130
        __device_attach_driver+0xc4/0xe8
        bus_for_each_drv+0xec/0x150
        __device_attach+0x160/0x1d8
        device_initial_probe+0x10/0x18
        bus_probe_device+0xe0/0xf0
        device_add+0x528/0x950
        of_device_add+0x5c/0x80
        of_platform_device_create_pdata+0x120/0x168
        of_platform_bus_create+0x244/0x4e0
        of_platform_populate+0x50/0xe8
        zynqmp_firmware_probe+0x370/0x3a8
        platform_drv_probe+0x6c/0xc8
        really_probe+0x14c/0x418
        driver_probe_device+0x74/0x130
        device_driver_attach+0x94/0xa0
        __driver_attach+0x70/0x108
        bus_for_each_dev+0xe4/0x158
        driver_attach+0x30/0x40
        bus_add_driver+0x21c/0x2b8
        driver_register+0xbc/0x1d0
        __platform_driver_register+0x7c/0x88
        zynqmp_firmware_driver_init+0x1c/0x24
        do_one_initcall+0xa4/0x234
        kernel_init_freeable+0x1b0/0x24c
        kernel_init+0x10/0x110
        ret_from_fork+0x10/0x18
      
       The buggy address belongs to the page:
       page:ffff0008f9be1c88 refcount:0 mapcount:0 mapping:0000000000000000 index:0x0
       raw: 0008d00000000000 ffff0008f9be1c90 ffff0008f9be1c90 0000000000000000
       raw: 0000000000000000 0000000000000000 00000000ffffffff
       page dumped because: kasan: bad access detected
      
       addr ffff0008c89a7410 is located in stack of task swapper/0/1 at offset 112 in frame:
        zynqmp_clock_probe+0x0/0x7b8
      
       this frame has 3 objects:
        [32, 44) 'response'
        [64, 80) 'ret_payload'
        [96, 112) 'name'
      
       Memory state around the buggy address:
        ffff0008c89a7300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        ffff0008c89a7380: 00 00 00 00 f1 f1 f1 f1 00 04 f2 f2 00 00 f2 f2
       >ffff0008c89a7400: 00 00 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00
                                ^
        ffff0008c89a7480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        ffff0008c89a7500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
       ==================================================================
      Signed-off-by: default avatarIan Nam <young.kwan.nam@xilinx.com>
      Signed-off-by: default avatarShubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
      Link: https://lore.kernel.org/r/20220510070154.29528-3-shubhrajyoti.datta@xilinx.com
      
      Acked-by: default avatarMichal Simek <michal.simek@amd.com>
      Signed-off-by: default avatarStephen Boyd <sboyd@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5dbfcf7b
    • Qu Wenruo's avatar
      btrfs: scrub: try to fix super block errors · 715fe157
      Qu Wenruo authored
      [ Upstream commit f9eab5f0
      
       ]
      
      [BUG]
      The following script shows that, although scrub can detect super block
      errors, it never tries to fix it:
      
      	mkfs.btrfs -f -d raid1 -m raid1 $dev1 $dev2
      	xfs_io -c "pwrite 67108864 4k" $dev2
      
      	mount $dev1 $mnt
      	btrfs scrub start -B $dev2
      	btrfs scrub start -Br $dev2
      	umount $mnt
      
      The first scrub reports the super error correctly:
      
        scrub done for f3289218-abd3-41ac-a630-202f766c0859
        Scrub started:    Tue Aug  2 14:44:11 2022
        Status:           finished
        Duration:         0:00:00
        Total to scrub:   1.26GiB
        Rate:             0.00B/s
        Error summary:    super=1
          Corrected:      0
          Uncorrectable:  0
          Unverified:     0
      
      But the second read-only scrub still reports the same super error:
      
        Scrub started:    Tue Aug  2 14:44:11 2022
        Status:           finished
        Duration:         0:00:00
        Total to scrub:   1.26GiB
        Rate:             0.00B/s
        Error summary:    super=1
          Corrected:      0
          Uncorrectable:  0
          Unverified:     0
      
      [CAUSE]
      The comments already shows that super block can be easily fixed by
      committing a transaction:
      
      	/*
      	 * If we find an error in a super block, we just report it.
      	 * They will get written with the next transaction commit
      	 * anyway
      	 */
      
      But the truth is, such assumption is not always true, and since scrub
      should try to repair every error it found (except for read-only scrub),
      we should really actively commit a transaction to fix this.
      
      [FIX]
      Just commit a transaction if we found any super block errors, after
      everything else is done.
      
      We cannot do this just after scrub_supers(), as
      btrfs_commit_transaction() will try to pause and wait for the running
      scrub, thus we can not call it with scrub_lock hold.
      Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
      Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      715fe157
    • Alexander Stein's avatar
      ARM: dts: imx6sx: add missing properties for sram · 8054f824
      Alexander Stein authored
      [ Upstream commit 415432c0
      
       ]
      
      All 3 properties are required by sram.yaml. Fixes the dtbs_check warning:
      sram@900000: '#address-cells' is a required property
      sram@900000: '#size-cells' is a required property
      sram@900000: 'ranges' is a required property
      Signed-off-by: default avatarAlexander Stein <alexander.stein@ew.tq-group.com>
      Signed-off-by: default avatarShawn Guo <shawnguo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      8054f824
    • Alexander Stein's avatar
      ARM: dts: imx6sll: add missing properties for sram · 05f789af
      Alexander Stein authored
      [ Upstream commit 7492a83e
      
       ]
      
      All 3 properties are required by sram.yaml. Fixes the dtbs_check warning:
      sram@900000: '#address-cells' is a required property
      sram@900000: '#size-cells' is a required property
      sram@900000: 'ranges' is a required property
      Signed-off-by: default avatarAlexander Stein <alexander.stein@ew.tq-group.com>
      Signed-off-by: default avatarShawn Guo <shawnguo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      05f789af
    • Alexander Stein's avatar
      ARM: dts: imx6sl: add missing properties for sram · 48d1766b
      Alexander Stein authored
      [ Upstream commit 60c9213a
      
       ]
      
      All 3 properties are required by sram.yaml. Fixes the dtbs_check warning:
      sram@900000: '#address-cells' is a required property
      sram@900000: '#size-cells' is a required property
      sram@900000: 'ranges' is a required property
      Signed-off-by: default avatarAlexander Stein <alexander.stein@ew.tq-group.com>
      Signed-off-by: default avatarShawn Guo <shawnguo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      48d1766b
    • Alexander Stein's avatar
      ARM: dts: imx6qp: add missing properties for sram · ef4a3baf
      Alexander Stein authored
      [ Upstream commit 088fe523
      
       ]
      
      All 3 properties are required by sram.yaml. Fixes the dtbs_check warning:
      sram@940000: '#address-cells' is a required property
      sram@940000: '#size-cells' is a required property
      sram@940000: 'ranges' is a required property
      Signed-off-by: default avatarAlexander Stein <alexander.stein@ew.tq-group.com>
      Signed-off-by: default avatarShawn Guo <shawnguo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ef4a3baf
    • Alexander Stein's avatar
      ARM: dts: imx6dl: add missing properties for sram · ee239c03
      Alexander Stein authored
      [ Upstream commit f5848b95
      
       ]
      
      All 3 properties are required by sram.yaml. Fixes the dtbs_check warning:
      sram@900000: '#address-cells' is a required property
      sram@900000: '#size-cells' is a required property
      sram@900000: 'ranges' is a required property
      Signed-off-by: default avatarAlexander Stein <alexander.stein@ew.tq-group.com>
      Signed-off-by: default avatarShawn Guo <shawnguo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ee239c03
    • Alexander Stein's avatar
      ARM: dts: imx6q: add missing properties for sram · 82e5191b
      Alexander Stein authored
      [ Upstream commit b11d083c
      
       ]
      
      All 3 properties are required by sram.yaml. Fixes the dtbs_check warning:
      sram@900000: '#address-cells' is a required property
      sram@900000: '#size-cells' is a required property
      sram@900000: 'ranges' is a required property
      Signed-off-by: default avatarAlexander Stein <alexander.stein@ew.tq-group.com>
      Signed-off-by: default avatarShawn Guo <shawnguo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      82e5191b
    • Haibo Chen's avatar
      ARM: dts: imx7d-sdb: config the max pressure for tsc2046 · 0b2013ac
      Haibo Chen authored
      [ Upstream commit e7c4ebe2
      
       ]
      
      Use the general touchscreen method to config the max pressure for
      touch tsc2046(data sheet suggest 8 bit pressure), otherwise, for
      ABS_PRESSURE, when config the same max and min value, weston will
      meet the following issue,
      
      [17:19:39.183] event1  - ADS7846 Touchscreen: is tagged by udev as: Touchscreen
      [17:19:39.183] event1  - ADS7846 Touchscreen: kernel bug: device has min == max on ABS_PRESSURE
      [17:19:39.183] event1  - ADS7846 Touchscreen: was rejected
      [17:19:39.183] event1  - not using input device '/dev/input/event1'
      
      This will then cause the APP weston-touch-calibrator can't list touch devices.
      
      root@imx6ul7d:~# weston-touch-calibrator
      could not load cursor 'dnd-move'
      could not load cursor 'dnd-copy'
      could not load cursor 'dnd-none'
      No devices listed.
      
      And accroding to binding Doc, "ti,x-max", "ti,y-max", "ti,pressure-max"
      belong to the deprecated properties, so remove them. Also for "ti,x-min",
      "ti,y-min", "ti,x-plate-ohms", the value set in dts equal to the default
      value in driver, so are redundant, also remove here.
      Signed-off-by: default avatarHaibo Chen <haibo.chen@nxp.com>
      Signed-off-by: default avatarShawn Guo <shawnguo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0b2013ac
    • Richard Acayan's avatar
      mmc: sdhci-msm: add compatible string check for sdm670 · aec01503
      Richard Acayan authored
      [ Upstream commit 4de95950
      
       ]
      
      The Snapdragon 670 has the same quirk as Snapdragon 845 (needing to
      restore the dll config). Add a compatible string check to detect the need
      for this.
      Signed-off-by: default avatarRichard Acayan <mailingradian@gmail.com>
      Reviewed-by: default avatarBhupesh Sharma <bhupesh.sharma@linaro.org>
      Acked-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
      Link: https://lore.kernel.org/r/20220923014322.33620-3-mailingradian@gmail.com
      
      Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      aec01503
    • hongao's avatar
      drm/amdgpu: fix initial connector audio value · e67c2cda
      hongao authored
      [ Upstream commit 4bb71fce
      
       ]
      
      This got lost somewhere along the way, This fixes
      audio not working until set_property was called.
      Signed-off-by: default avatarhongao <hongao@uniontech.com>
      Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e67c2cda