1. 04 Jul, 2024 4 commits
    • Kuniyuki Iwashima's avatar
      selftest: af_unix: Add test case for backtrack after finalising SCC. · 2a79651b
      Kuniyuki Iwashima authored
      syzkaller reported a KMSAN splat in __unix_walk_scc() while backtracking
      edge_stack after finalising SCC.
      
      Let's add a test case exercising the path.
      Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Signed-off-by: default avatarShigeru Yoshida <syoshida@redhat.com>
      Link: https://patch.msgid.link/20240702160428.10153-2-syoshida@redhat.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      2a79651b
    • Shigeru Yoshida's avatar
      af_unix: Fix uninit-value in __unix_walk_scc() · 927fa5b3
      Shigeru Yoshida authored
      KMSAN reported uninit-value access in __unix_walk_scc() [1].
      
      In the list_for_each_entry_reverse() loop, when the vertex's index
      equals it's scc_index, the loop uses the variable vertex as a
      temporary variable that points to a vertex in scc. And when the loop
      is finished, the variable vertex points to the list head, in this case
      scc, which is a local variable on the stack (more precisely, it's not
      even scc and might underflow the call stack of __unix_walk_scc():
      container_of(&scc, struct unix_vertex, scc_entry)).
      
      However, the variable vertex is used under the label prev_vertex. So
      if the edge_stack is not empty and the function jumps to the
      prev_vertex label, the function will access invalid data on the
      stack. This causes the uninit-value access issue.
      
      Fix this by introducing a new temporary variable for the loop.
      
      [1]
      BUG: KMSAN: uninit-value in __unix_walk_scc net/unix/garbage.c:478 [inline]
      BUG: KMSAN: uninit-value in unix_walk_scc net/unix/garbage.c:526 [inline]
      BUG: KMSAN: uninit-value in __unix_gc+0x2589/0x3c20 net/unix/garbage.c:584
       __unix_walk_scc net/unix/garbage.c:478 [inline]
       unix_walk_scc net/unix/garbage.c:526 [inline]
       __unix_gc+0x2589/0x3c20 net/unix/garbage.c:584
       process_one_work kernel/workqueue.c:3231 [inline]
       process_scheduled_works+0xade/0x1bf0 kernel/workqueue.c:3312
       worker_thread+0xeb6/0x15b0 kernel/workqueue.c:3393
       kthread+0x3c4/0x530 kernel/kthread.c:389
       ret_from_fork+0x6e/0x90 arch/x86/kernel/process.c:147
       ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
      
      Uninit was stored to memory at:
       unix_walk_scc net/unix/garbage.c:526 [inline]
       __unix_gc+0x2adf/0x3c20 net/unix/garbage.c:584
       process_one_work kernel/workqueue.c:3231 [inline]
       process_scheduled_works+0xade/0x1bf0 kernel/workqueue.c:3312
       worker_thread+0xeb6/0x15b0 kernel/workqueue.c:3393
       kthread+0x3c4/0x530 kernel/kthread.c:389
       ret_from_fork+0x6e/0x90 arch/x86/kernel/process.c:147
       ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
      
      Local variable entries created at:
       ref_tracker_free+0x48/0xf30 lib/ref_tracker.c:222
       netdev_tracker_free include/linux/netdevice.h:4058 [inline]
       netdev_put include/linux/netdevice.h:4075 [inline]
       dev_put include/linux/netdevice.h:4101 [inline]
       update_gid_event_work_handler+0xaa/0x1b0 drivers/infiniband/core/roce_gid_mgmt.c:813
      
      CPU: 1 PID: 12763 Comm: kworker/u8:31 Not tainted 6.10.0-rc4-00217-g35bb670d #32
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-2.fc40 04/01/2014
      Workqueue: events_unbound __unix_gc
      
      Fixes: 3484f063 ("af_unix: Detect Strongly Connected Components.")
      Reported-by: default avatarsyzkaller <syzkaller@googlegroups.com>
      Signed-off-by: default avatarShigeru Yoshida <syoshida@redhat.com>
      Reviewed-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
      Link: https://patch.msgid.link/20240702160428.10153-1-syoshida@redhat.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      927fa5b3
    • Sam Sun's avatar
      bonding: Fix out-of-bounds read in bond_option_arp_ip_targets_set() · e271ff53
      Sam Sun authored
      In function bond_option_arp_ip_targets_set(), if newval->string is an
      empty string, newval->string+1 will point to the byte after the
      string, causing an out-of-bound read.
      
      BUG: KASAN: slab-out-of-bounds in strlen+0x7d/0xa0 lib/string.c:418
      Read of size 1 at addr ffff8881119c4781 by task syz-executor665/8107
      CPU: 1 PID: 8107 Comm: syz-executor665 Not tainted 6.7.0-rc7 #1
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
      Call Trace:
       <TASK>
       __dump_stack lib/dump_stack.c:88 [inline]
       dump_stack_lvl+0xd9/0x150 lib/dump_stack.c:106
       print_address_description mm/kasan/report.c:364 [inline]
       print_report+0xc1/0x5e0 mm/kasan/report.c:475
       kasan_report+0xbe/0xf0 mm/kasan/report.c:588
       strlen+0x7d/0xa0 lib/string.c:418
       __fortify_strlen include/linux/fortify-string.h:210 [inline]
       in4_pton+0xa3/0x3f0 net/core/utils.c:130
       bond_option_arp_ip_targets_set+0xc2/0x910
      drivers/net/bonding/bond_options.c:1201
       __bond_opt_set+0x2a4/0x1030 drivers/net/bonding/bond_options.c:767
       __bond_opt_set_notify+0x48/0x150 drivers/net/bonding/bond_options.c:792
       bond_opt_tryset_rtnl+0xda/0x160 drivers/net/bonding/bond_options.c:817
       bonding_sysfs_store_option+0xa1/0x120 drivers/net/bonding/bond_sysfs.c:156
       dev_attr_store+0x54/0x80 drivers/base/core.c:2366
       sysfs_kf_write+0x114/0x170 fs/sysfs/file.c:136
       kernfs_fop_write_iter+0x337/0x500 fs/kernfs/file.c:334
       call_write_iter include/linux/fs.h:2020 [inline]
       new_sync_write fs/read_write.c:491 [inline]
       vfs_write+0x96a/0xd80 fs/read_write.c:584
       ksys_write+0x122/0x250 fs/read_write.c:637
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0x40/0x110 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x63/0x6b
      ---[ end trace ]---
      
      Fix it by adding a check of string length before using it.
      
      Fixes: f9de11a1 ("bonding: add ip checks when store ip target")
      Signed-off-by: default avatarYue Sun <samsun1006219@gmail.com>
      Signed-off-by: default avatarSimon Horman <horms@kernel.org>
      Acked-by: default avatarJay Vosburgh <jay.vosburgh@canonical.com>
      Reviewed-by: default avatarHangbin Liu <liuhangbin@gmail.com>
      Link: https://patch.msgid.link/20240702-bond-oob-v6-1-2dfdba195c19@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      e271ff53
    • Radu Rendec's avatar
      net: rswitch: Avoid use-after-free in rswitch_poll() · 9a0c28ef
      Radu Rendec authored
      The use-after-free is actually in rswitch_tx_free(), which is inlined in
      rswitch_poll(). Since `skb` and `gq->skbs[gq->dirty]` are in fact the
      same pointer, the skb is first freed using dev_kfree_skb_any(), then the
      value in skb->len is used to update the interface statistics.
      
      Let's move around the instructions to use skb->len before the skb is
      freed.
      
      This bug is trivial to reproduce using KFENCE. It will trigger a splat
      every few packets. A simple ARP request or ICMP echo request is enough.
      
      Fixes: 271e015b ("net: rswitch: Add unmap_addrs instead of dma address in each desc")
      Signed-off-by: default avatarRadu Rendec <rrendec@redhat.com>
      Reviewed-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
      Reviewed-by: default avatarNiklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
      Link: https://patch.msgid.link/20240702210838.2703228-1-rrendec@redhat.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      9a0c28ef
  2. 03 Jul, 2024 3 commits
    • Furong Xu's avatar
      net: stmmac: enable HW-accelerated VLAN stripping for gmac4 only · 8eb301bd
      Furong Xu authored
      Commit 750011e2 ("net: stmmac: Add support for HW-accelerated VLAN
      stripping") enables MAC level VLAN tag stripping for all MAC cores, but
      leaves set_hw_vlan_mode() and rx_hw_vlan() un-implemented for both gmac
      and xgmac.
      
      On gmac and xgmac, ethtool reports rx-vlan-offload is on, both MAC and
      driver do nothing about VLAN packets actually, although VLAN works well.
      
      Driver level stripping should be used on gmac and xgmac for now.
      
      Fixes: 750011e2 ("net: stmmac: Add support for HW-accelerated VLAN stripping")
      Signed-off-by: default avatarFurong Xu <0x1207@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      8eb301bd
    • Dave Jiang's avatar
      net: ntb_netdev: Move ntb_netdev_rx_handler() to call netif_rx() from __netif_rx() · e15a5d82
      Dave Jiang authored
      The following is emitted when using idxd (DSA) dmanegine as the data
      mover for ntb_transport that ntb_netdev uses.
      
      [74412.546922] BUG: using smp_processor_id() in preemptible [00000000] code: irq/52-idxd-por/14526
      [74412.556784] caller is netif_rx_internal+0x42/0x130
      [74412.562282] CPU: 6 PID: 14526 Comm: irq/52-idxd-por Not tainted 6.9.5 #5
      [74412.569870] Hardware name: Intel Corporation ArcherCity/ArcherCity, BIOS EGSDCRB1.E9I.1752.P05.2402080856 02/08/2024
      [74412.581699] Call Trace:
      [74412.584514]  <TASK>
      [74412.586933]  dump_stack_lvl+0x55/0x70
      [74412.591129]  check_preemption_disabled+0xc8/0xf0
      [74412.596374]  netif_rx_internal+0x42/0x130
      [74412.600957]  __netif_rx+0x20/0xd0
      [74412.604743]  ntb_netdev_rx_handler+0x66/0x150 [ntb_netdev]
      [74412.610985]  ntb_complete_rxc+0xed/0x140 [ntb_transport]
      [74412.617010]  ntb_rx_copy_callback+0x53/0x80 [ntb_transport]
      [74412.623332]  idxd_dma_complete_txd+0xe3/0x160 [idxd]
      [74412.628963]  idxd_wq_thread+0x1a6/0x2b0 [idxd]
      [74412.634046]  irq_thread_fn+0x21/0x60
      [74412.638134]  ? irq_thread+0xa8/0x290
      [74412.642218]  irq_thread+0x1a0/0x290
      [74412.646212]  ? __pfx_irq_thread_fn+0x10/0x10
      [74412.651071]  ? __pfx_irq_thread_dtor+0x10/0x10
      [74412.656117]  ? __pfx_irq_thread+0x10/0x10
      [74412.660686]  kthread+0x100/0x130
      [74412.664384]  ? __pfx_kthread+0x10/0x10
      [74412.668639]  ret_from_fork+0x31/0x50
      [74412.672716]  ? __pfx_kthread+0x10/0x10
      [74412.676978]  ret_from_fork_asm+0x1a/0x30
      [74412.681457]  </TASK>
      
      The cause is due to the idxd driver interrupt completion handler uses
      threaded interrupt and the threaded handler is not hard or soft interrupt
      context. However __netif_rx() can only be called from interrupt context.
      Change the call to netif_rx() in order to allow completion via normal
      context for dmaengine drivers that utilize threaded irq handling.
      
      While the following commit changed from netif_rx() to __netif_rx(),
      baebdf48 ("net: dev: Makes sure netif_rx() can be invoked in any context."),
      the change should've been a noop instead. However, the code precedes this
      fix should've been using netif_rx_ni() or netif_rx_any_context().
      
      Fixes: 548c237c ("net: Add support for NTB virtual ethernet device")
      Reported-by: default avatarJerry Dai <jerry.dai@intel.com>
      Tested-by: default avatarJerry Dai <jerry.dai@intel.com>
      Signed-off-by: default avatarDave Jiang <dave.jiang@intel.com>
      Link: https://patch.msgid.link/20240701181538.3799546-1-dave.jiang@intel.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      e15a5d82
    • Bartosz Golaszewski's avatar
      net: phy: aquantia: add missing include guards · 21934375
      Bartosz Golaszewski authored
      The header is missing the include guards so add them.
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Fixes: fb470f70 ("net: phy: aquantia: add hwmon support")
      Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
      Link: https://patch.msgid.link/20240701080322.9569-1-brgl@bgdev.plSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      21934375
  3. 02 Jul, 2024 9 commits
  4. 01 Jul, 2024 3 commits
  5. 29 Jun, 2024 1 commit
    • Ghadi Elie Rahme's avatar
      bnx2x: Fix multiple UBSAN array-index-out-of-bounds · 13406116
      Ghadi Elie Rahme authored
      Fix UBSAN warnings that occur when using a system with 32 physical
      cpu cores or more, or when the user defines a number of Ethernet
      queues greater than or equal to FP_SB_MAX_E1x using the num_queues
      module parameter.
      
      Currently there is a read/write out of bounds that occurs on the array
      "struct stats_query_entry query" present inside the "bnx2x_fw_stats_req"
      struct in "drivers/net/ethernet/broadcom/bnx2x/bnx2x.h".
      Looking at the definition of the "struct stats_query_entry query" array:
      
      struct stats_query_entry query[FP_SB_MAX_E1x+
               BNX2X_FIRST_QUEUE_QUERY_IDX];
      
      FP_SB_MAX_E1x is defined as the maximum number of fast path interrupts and
      has a value of 16, while BNX2X_FIRST_QUEUE_QUERY_IDX has a value of 3
      meaning the array has a total size of 19.
      Since accesses to "struct stats_query_entry query" are offset-ted by
      BNX2X_FIRST_QUEUE_QUERY_IDX, that means that the total number of Ethernet
      queues should not exceed FP_SB_MAX_E1x (16). However one of these queues
      is reserved for FCOE and thus the number of Ethernet queues should be set
      to [FP_SB_MAX_E1x -1] (15) if FCOE is enabled or [FP_SB_MAX_E1x] (16) if
      it is not.
      
      This is also described in a comment in the source code in
      drivers/net/ethernet/broadcom/bnx2x/bnx2x.h just above the Macro definition
      of FP_SB_MAX_E1x. Below is the part of this explanation that it important
      for this patch
      
      /*
        * The total number of L2 queues, MSIX vectors and HW contexts (CIDs) is
        * control by the number of fast-path status blocks supported by the
        * device (HW/FW). Each fast-path status block (FP-SB) aka non-default
        * status block represents an independent interrupts context that can
        * serve a regular L2 networking queue. However special L2 queues such
        * as the FCoE queue do not require a FP-SB and other components like
        * the CNIC may consume FP-SB reducing the number of possible L2 queues
        *
        * If the maximum number of FP-SB available is X then:
        * a. If CNIC is supported it consumes 1 FP-SB thus the max number of
        *    regular L2 queues is Y=X-1
        * b. In MF mode the actual number of L2 queues is Y= (X-1/MF_factor)
        * c. If the FCoE L2 queue is supported the actual number of L2 queues
        *    is Y+1
        * d. The number of irqs (MSIX vectors) is either Y+1 (one extra for
        *    slow-path interrupts) or Y+2 if CNIC is supported (one additional
        *    FP interrupt context for the CNIC).
        * e. The number of HW context (CID count) is always X or X+1 if FCoE
        *    L2 queue is supported. The cid for the FCoE L2 queue is always X.
        */
      
      However this driver also supports NICs that use the E2 controller which can
      handle more queues due to having more FP-SB represented by FP_SB_MAX_E2.
      Looking at the commits when the E2 support was added, it was originally
      using the E1x parameters: commit f2e0899f ("bnx2x: Add 57712 support").
      Back then FP_SB_MAX_E2 was set to 16 the same as E1x. However the driver
      was later updated to take full advantage of the E2 instead of having it be
      limited to the capabilities of the E1x. But as far as we can tell, the
      array "stats_query_entry query" was still limited to using the FP-SB
      available to the E1x cards as part of an oversignt when the driver was
      updated to take full advantage of the E2, and now with the driver being
      aware of the greater queue size supported by E2 NICs, it causes the UBSAN
      warnings seen in the stack traces below.
      
      This patch increases the size of the "stats_query_entry query" array by
      replacing FP_SB_MAX_E1x with FP_SB_MAX_E2 to be large enough to handle
      both types of NICs.
      
      Stack traces:
      
      UBSAN: array-index-out-of-bounds in
             drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c:1529:11
      index 20 is out of range for type 'stats_query_entry [19]'
      CPU: 12 PID: 858 Comm: systemd-network Not tainted 6.9.0-060900rc7-generic
      	     #202405052133
      Hardware name: HP ProLiant DL360 Gen9/ProLiant DL360 Gen9,
      	       BIOS P89 10/21/2019
      Call Trace:
       <TASK>
       dump_stack_lvl+0x76/0xa0
       dump_stack+0x10/0x20
       __ubsan_handle_out_of_bounds+0xcb/0x110
       bnx2x_prep_fw_stats_req+0x2e1/0x310 [bnx2x]
       bnx2x_stats_init+0x156/0x320 [bnx2x]
       bnx2x_post_irq_nic_init+0x81/0x1a0 [bnx2x]
       bnx2x_nic_load+0x8e8/0x19e0 [bnx2x]
       bnx2x_open+0x16b/0x290 [bnx2x]
       __dev_open+0x10e/0x1d0
      RIP: 0033:0x736223927a0a
      Code: d8 64 89 02 48 c7 c0 ff ff ff ff eb b8 0f 1f 00 f3 0f 1e fa 41 89 ca
            64 8b 04 25 18 00 00 00 85 c0 75 15 b8 2c 00 00 00 0f 05 <48> 3d 00
            f0 ff ff 77 7e c3 0f 1f 44 00 00 41 54 48 83 ec 30 44 89
      RSP: 002b:00007ffc0bb2ada8 EFLAGS: 00000246 ORIG_RAX: 000000000000002c
      RAX: ffffffffffffffda RBX: 0000583df50f9c78 RCX: 0000736223927a0a
      RDX: 0000000000000020 RSI: 0000583df50ee510 RDI: 0000000000000003
      RBP: 0000583df50d4940 R08: 00007ffc0bb2adb0 R09: 0000000000000080
      R10: 0000000000000000 R11: 0000000000000246 R12: 0000583df5103ae0
      R13: 000000000000035a R14: 0000583df50f9c30 R15: 0000583ddddddf00
      </TASK>
      ---[ end trace ]---
      ------------[ cut here ]------------
      UBSAN: array-index-out-of-bounds in
             drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c:1546:11
      index 28 is out of range for type 'stats_query_entry [19]'
      CPU: 12 PID: 858 Comm: systemd-network Not tainted 6.9.0-060900rc7-generic
      	     #202405052133
      Hardware name: HP ProLiant DL360 Gen9/ProLiant DL360 Gen9,
      	       BIOS P89 10/21/2019
      Call Trace:
      <TASK>
      dump_stack_lvl+0x76/0xa0
      dump_stack+0x10/0x20
      __ubsan_handle_out_of_bounds+0xcb/0x110
      bnx2x_prep_fw_stats_req+0x2fd/0x310 [bnx2x]
      bnx2x_stats_init+0x156/0x320 [bnx2x]
      bnx2x_post_irq_nic_init+0x81/0x1a0 [bnx2x]
      bnx2x_nic_load+0x8e8/0x19e0 [bnx2x]
      bnx2x_open+0x16b/0x290 [bnx2x]
      __dev_open+0x10e/0x1d0
      RIP: 0033:0x736223927a0a
      Code: d8 64 89 02 48 c7 c0 ff ff ff ff eb b8 0f 1f 00 f3 0f 1e fa 41 89 ca
            64 8b 04 25 18 00 00 00 85 c0 75 15 b8 2c 00 00 00 0f 05 <48> 3d 00
            f0 ff ff 77 7e c3 0f 1f 44 00 00 41 54 48 83 ec 30 44 89
      RSP: 002b:00007ffc0bb2ada8 EFLAGS: 00000246 ORIG_RAX: 000000000000002c
      RAX: ffffffffffffffda RBX: 0000583df50f9c78 RCX: 0000736223927a0a
      RDX: 0000000000000020 RSI: 0000583df50ee510 RDI: 0000000000000003
      RBP: 0000583df50d4940 R08: 00007ffc0bb2adb0 R09: 0000000000000080
      R10: 0000000000000000 R11: 0000000000000246 R12: 0000583df5103ae0
      R13: 000000000000035a R14: 0000583df50f9c30 R15: 0000583ddddddf00
       </TASK>
      ---[ end trace ]---
      ------------[ cut here ]------------
      UBSAN: array-index-out-of-bounds in
             drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c:1895:8
      index 29 is out of range for type 'stats_query_entry [19]'
      CPU: 13 PID: 163 Comm: kworker/u96:1 Not tainted 6.9.0-060900rc7-generic
      	     #202405052133
      Hardware name: HP ProLiant DL360 Gen9/ProLiant DL360 Gen9,
      	       BIOS P89 10/21/2019
      Workqueue: bnx2x bnx2x_sp_task [bnx2x]
      Call Trace:
       <TASK>
       dump_stack_lvl+0x76/0xa0
       dump_stack+0x10/0x20
       __ubsan_handle_out_of_bounds+0xcb/0x110
       bnx2x_iov_adjust_stats_req+0x3c4/0x3d0 [bnx2x]
       bnx2x_storm_stats_post.part.0+0x4a/0x330 [bnx2x]
       ? bnx2x_hw_stats_post+0x231/0x250 [bnx2x]
       bnx2x_stats_start+0x44/0x70 [bnx2x]
       bnx2x_stats_handle+0x149/0x350 [bnx2x]
       bnx2x_attn_int_asserted+0x998/0x9b0 [bnx2x]
       bnx2x_sp_task+0x491/0x5c0 [bnx2x]
       process_one_work+0x18d/0x3f0
       </TASK>
      ---[ end trace ]---
      
      Fixes: 50f0a562 ("bnx2x: add fcoe statistics")
      Signed-off-by: default avatarGhadi Elie Rahme <ghadi.rahme@canonical.com>
      Cc: stable@vger.kernel.org
      Link: https://patch.msgid.link/20240627111405.1037812-1-ghadi.rahme@canonical.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      13406116
  6. 28 Jun, 2024 20 commits