Skip to content
  1. Nov 16, 2022
    • Zhengchao Shao's avatar
      net: lapbether: fix issue of invalid opcode in lapbeth_open() · 4689bd3a
      Zhengchao Shao authored
      [ Upstream commit 3faf7e14 ]
      
      If lapb_register() failed when lapb device goes to up for the first time,
      the NAPI is not disabled. As a result, the invalid opcode issue is
      reported when the lapb device goes to up for the second time.
      
      The stack info is as follows:
      [ 1958.311422][T11356] kernel BUG at net/core/dev.c:6442!
      [ 1958.312206][T11356] invalid opcode: 0000 [#1] PREEMPT SMP KASAN
      [ 1958.315979][T11356] RIP: 0010:napi_enable+0x16a/0x1f0
      [ 1958.332310][T11356] Call Trace:
      [ 1958.332817][T11356]  <TASK>
      [ 1958.336135][T11356]  lapbeth_open+0x18/0x90
      [ 1958.337446][T11356]  __dev_open+0x258/0x490
      [ 1958.341672][T11356]  __dev_change_flags+0x4d4/0x6a0
      [ 1958.345325][T11356]  dev_change_flags+0x93/0x160
      [ 1958.346027][T11356]  devinet_ioctl+0x1276/0x1bf0
      [ 1958.346738][T11356]  inet_ioctl+0x1c8/0x2d0
      [ 1958.349638][T11356]  sock_ioctl+0x5d1/0x750
      [ 1958.356059][T11356]  __x64_sys_ioctl+0x3ec/0x1790
      [ 1958.365594][T11356]  do_syscall_64+0x35/0x80
      [ 1958.366239][T11356]  entry_SYSCALL_64_after_hwframe+0x46/0xb0
      [ 1958.377381][T11356]  </TASK>
      
      Fixes: 514e1150
      
       ("net: x25: Queue received packets in the drivers instead of per-CPU queues")
      Signed-off-by: default avatarZhengchao Shao <shaozhengchao@huawei.com>
      Link: https://lore.kernel.org/r/20221107011445.207372-1-shaozhengchao@huawei.com
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4689bd3a
    • Yang Yingliang's avatar
      dmaengine: ti: k3-udma-glue: fix memory leak when register device fail · 1dd27541
      Yang Yingliang authored
      [ Upstream commit ac2b9f34 ]
      
      If device_register() fails, it should call put_device() to give
      up reference, the name allocated in dev_set_name() can be freed
      in callback function kobject_cleanup().
      
      Fixes: 5b65781d
      
       ("dmaengine: ti: k3-udma-glue: Add support for K3 PKTDMA")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Acked-by: default avatarPeter Ujfalusi <peter.ujfalusi@gmail.com>
      Link: https://lore.kernel.org/r/20221020062827.2914148-1-yangyingliang@huawei.com
      Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1dd27541
    • Christophe JAILLET's avatar
      dmaengine: mv_xor_v2: Fix a resource leak in mv_xor_v2_remove() · 992e966c
      Christophe JAILLET authored
      [ Upstream commit 081195d1 ]
      
      A clk_prepare_enable() call in the probe is not balanced by a corresponding
      clk_disable_unprepare() in the remove function.
      
      Add the missing call.
      
      Fixes: 3cd2c313
      
       ("dmaengine: mv_xor_v2: Fix clock resource by adding a register clock")
      Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
      Link: https://lore.kernel.org/r/e9e3837a680c9bd2438e4db2b83270c6c052d005.1666640987.git.christophe.jaillet@wanadoo.fr
      Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      992e966c
    • Doug Brown's avatar
      dmaengine: pxa_dma: use platform_get_irq_optional · 9766af75
      Doug Brown authored
      [ Upstream commit b3d726cb ]
      
      The first IRQ is required, but IRQs 1 through (nb_phy_chans - 1) are
      optional, because on some platforms (e.g. PXA168) there is a single IRQ
      shared between all channels.
      
      This change inhibits a flood of "IRQ index # not found" messages at
      startup. Tested on a PXA168-based device.
      
      Fixes: 7723f4c5
      
       ("driver core: platform: Add an error message to platform_get_irq*()")
      Signed-off-by: default avatarDoug Brown <doug@schmorgal.com>
      Link: https://lore.kernel.org/r/20220906000709.52705-1-doug@schmorgal.com
      Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      9766af75
    • Xin Long's avatar
      tipc: fix the msg->req tlv len check in tipc_nl_compat_name_table_dump_header · 301caa06
      Xin Long authored
      [ Upstream commit 1c075b19 ]
      
      This is a follow-up for commit 974cb0e3
      
       ("tipc: fix uninit-value
      in tipc_nl_compat_name_table_dump") where it should have type casted
      sizeof(..) to int to work when TLV_GET_DATA_LEN() returns a negative
      value.
      
      syzbot reported a call trace because of it:
      
        BUG: KMSAN: uninit-value in ...
         tipc_nl_compat_name_table_dump+0x841/0xea0 net/tipc/netlink_compat.c:934
         __tipc_nl_compat_dumpit+0xab2/0x1320 net/tipc/netlink_compat.c:238
         tipc_nl_compat_dumpit+0x991/0xb50 net/tipc/netlink_compat.c:321
         tipc_nl_compat_recv+0xb6e/0x1640 net/tipc/netlink_compat.c:1324
         genl_family_rcv_msg_doit net/netlink/genetlink.c:731 [inline]
         genl_family_rcv_msg net/netlink/genetlink.c:775 [inline]
         genl_rcv_msg+0x103f/0x1260 net/netlink/genetlink.c:792
         netlink_rcv_skb+0x3a5/0x6c0 net/netlink/af_netlink.c:2501
         genl_rcv+0x3c/0x50 net/netlink/genetlink.c:803
         netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline]
         netlink_unicast+0xf3b/0x1270 net/netlink/af_netlink.c:1345
         netlink_sendmsg+0x1288/0x1440 net/netlink/af_netlink.c:1921
         sock_sendmsg_nosec net/socket.c:714 [inline]
         sock_sendmsg net/socket.c:734 [inline]
      
      Reported-by: default avatar <syzbot+e5dbaaa238680ce206ea@syzkaller.appspotmail.com>
      Fixes: 974cb0e3
      
       ("tipc: fix uninit-value in tipc_nl_compat_name_table_dump")
      Signed-off-by: default avatarXin Long <lucien.xin@gmail.com>
      Link: https://lore.kernel.org/r/ccd6a7ea801b15aec092c3b532a883b4c5708695.1667594933.git.lucien.xin@gmail.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      301caa06
    • YueHaibing's avatar
      net: broadcom: Fix BCMGENET Kconfig · 6a264203
      YueHaibing authored
      [ Upstream commit 8d820bc9 ]
      
      While BCMGENET select BROADCOM_PHY as y, but PTP_1588_CLOCK_OPTIONAL is m,
      kconfig warning and build errors:
      
      WARNING: unmet direct dependencies detected for BROADCOM_PHY
        Depends on [m]: NETDEVICES [=y] && PHYLIB [=y] && PTP_1588_CLOCK_OPTIONAL [=m]
        Selected by [y]:
        - BCMGENET [=y] && NETDEVICES [=y] && ETHERNET [=y] && NET_VENDOR_BROADCOM [=y] && HAS_IOMEM [=y] && ARCH_BCM2835 [=y]
      
      drivers/net/phy/broadcom.o: In function `bcm54xx_suspend':
      broadcom.c:(.text+0x6ac): undefined reference to `bcm_ptp_stop'
      drivers/net/phy/broadcom.o: In function `bcm54xx_phy_probe':
      broadcom.c:(.text+0x784): undefined reference to `bcm_ptp_probe'
      drivers/net/phy/broadcom.o: In function `bcm54xx_config_init':
      broadcom.c:(.text+0xd4c): undefined reference to `bcm_ptp_config_init'
      
      Fixes: 99addbe3
      
       ("net: broadcom: Select BROADCOM_PHY for BCMGENET")
      Signed-off-by: default avatarYueHaibing <yuehaibing@huawei.com>
      Acked-by: default avatarFlorian Fainelli <f.fainelli@broadcom.com>
      Link: https://lore.kernel.org/r/20221105090245.8508-1-yuehaibing@huawei.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6a264203
    • Rasmus Villemoes's avatar
      net: stmmac: dwmac-meson8b: fix meson8b_devm_clk_prepare_enable() · e7871b9a
      Rasmus Villemoes authored
      [ Upstream commit ed4314f7 ]
      
      There are two problems with meson8b_devm_clk_prepare_enable(),
      introduced in commit a54dc4a4 ("net: stmmac: dwmac-meson8b:
      Make the clock enabling code re-usable"):
      
      - It doesn't pass the clk argument, but instead always the
        rgmii_tx_clk of the device.
      
      - It silently ignores the return value of devm_add_action_or_reset().
      
      The former didn't become an actual bug until another user showed up in
      the next commit 9308c476 ("net: stmmac: dwmac-meson8b: add support
      for the RX delay configuration"). The latter means the callers could
      end up with the clock not actually prepared/enabled.
      
      Fixes: a54dc4a4
      
       ("net: stmmac: dwmac-meson8b: Make the clock enabling code re-usable")
      Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
      Reviewed-by: default avatarMartin Blumenstingl <martin.blumenstingl@googlemail.com>
      Link: https://lore.kernel.org/r/20221104083004.2212520-1-linux@rasmusvillemoes.dk
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e7871b9a
    • Zhengchao Shao's avatar
      can: af_can: fix NULL pointer dereference in can_rx_register() · 261178a1
      Zhengchao Shao authored
      [ Upstream commit 8aa59e35 ]
      
      It causes NULL pointer dereference when testing as following:
      (a) use syscall(__NR_socket, 0x10ul, 3ul, 0) to create netlink socket.
      (b) use syscall(__NR_sendmsg, ...) to create bond link device and vxcan
          link device, and bind vxcan device to bond device (can also use
          ifenslave command to bind vxcan device to bond device).
      (c) use syscall(__NR_socket, 0x1dul, 3ul, 1) to create CAN socket.
      (d) use syscall(__NR_bind, ...) to bind the bond device to CAN socket.
      
      The bond device invokes the can-raw protocol registration interface to
      receive CAN packets. However, ml_priv is not allocated to the dev,
      dev_rcv_lists is assigned to NULL in can_rx_register(). In this case,
      it will occur the NULL pointer dereference issue.
      
      The following is the stack information:
      BUG: kernel NULL pointer dereference, address: 0000000000000008
      PGD 122a4067 P4D 122a4067 PUD 1223c067 PMD 0
      Oops: 0000 [#1] PREEMPT SMP
      RIP: 0010:can_rx_register+0x12d/0x1e0
      Call Trace:
      <TASK>
      raw_enable_filters+0x8d/0x120
      raw_enable_allfilters+0x3b/0x130
      raw_bind+0x118/0x4f0
      __sys_bind+0x163/0x1a0
      __x64_sys_bind+0x1e/0x30
      do_syscall_64+0x35/0x80
      entry_SYSCALL_64_after_hwframe+0x63/0xcd
      </TASK>
      
      Fixes: 4e096a18
      
       ("net: introduce CAN specific pointer in the struct net_device")
      Signed-off-by: default avatarZhengchao Shao <shaozhengchao@huawei.com>
      Reviewed-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Link: https://lore.kernel.org/all/20221028085650.170470-1-shaozhengchao@huawei.com
      Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      261178a1
    • Alexander Potapenko's avatar
      ipv6: addrlabel: fix infoleak when sending struct ifaddrlblmsg to network · 2acb2779
      Alexander Potapenko authored
      [ Upstream commit c23fb2c8
      
       ]
      
      When copying a `struct ifaddrlblmsg` to the network, __ifal_reserved
      remained uninitialized, resulting in a 1-byte infoleak:
      
        BUG: KMSAN: kernel-network-infoleak in __netdev_start_xmit ./include/linux/netdevice.h:4841
         __netdev_start_xmit ./include/linux/netdevice.h:4841
         netdev_start_xmit ./include/linux/netdevice.h:4857
         xmit_one net/core/dev.c:3590
         dev_hard_start_xmit+0x1dc/0x800 net/core/dev.c:3606
         __dev_queue_xmit+0x17e8/0x4350 net/core/dev.c:4256
         dev_queue_xmit ./include/linux/netdevice.h:3009
         __netlink_deliver_tap_skb net/netlink/af_netlink.c:307
         __netlink_deliver_tap+0x728/0xad0 net/netlink/af_netlink.c:325
         netlink_deliver_tap net/netlink/af_netlink.c:338
         __netlink_sendskb net/netlink/af_netlink.c:1263
         netlink_sendskb+0x1d9/0x200 net/netlink/af_netlink.c:1272
         netlink_unicast+0x56d/0xf50 net/netlink/af_netlink.c:1360
         nlmsg_unicast ./include/net/netlink.h:1061
         rtnl_unicast+0x5a/0x80 net/core/rtnetlink.c:758
         ip6addrlbl_get+0xfad/0x10f0 net/ipv6/addrlabel.c:628
         rtnetlink_rcv_msg+0xb33/0x1570 net/core/rtnetlink.c:6082
        ...
        Uninit was created at:
         slab_post_alloc_hook+0x118/0xb00 mm/slab.h:742
         slab_alloc_node mm/slub.c:3398
         __kmem_cache_alloc_node+0x4f2/0x930 mm/slub.c:3437
         __do_kmalloc_node mm/slab_common.c:954
         __kmalloc_node_track_caller+0x117/0x3d0 mm/slab_common.c:975
         kmalloc_reserve net/core/skbuff.c:437
         __alloc_skb+0x27a/0xab0 net/core/skbuff.c:509
         alloc_skb ./include/linux/skbuff.h:1267
         nlmsg_new ./include/net/netlink.h:964
         ip6addrlbl_get+0x490/0x10f0 net/ipv6/addrlabel.c:608
         rtnetlink_rcv_msg+0xb33/0x1570 net/core/rtnetlink.c:6082
         netlink_rcv_skb+0x299/0x550 net/netlink/af_netlink.c:2540
         rtnetlink_rcv+0x26/0x30 net/core/rtnetlink.c:6109
         netlink_unicast_kernel net/netlink/af_netlink.c:1319
         netlink_unicast+0x9ab/0xf50 net/netlink/af_netlink.c:1345
         netlink_sendmsg+0xebc/0x10f0 net/netlink/af_netlink.c:1921
        ...
      
      This patch ensures that the reserved field is always initialized.
      
      Reported-by: default avatar <syzbot+3553517af6020c4f2813f1003fe76ef3cbffe98d@syzkaller.appspotmail.com>
      Fixes: 2a8cc6c8
      
       ("[IPV6] ADDRCONF: Support RFC3484 configurable address selection policy table.")
      Signed-off-by: default avatarAlexander Potapenko <glider@google.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2acb2779
    • Lu Wei's avatar
      tcp: prohibit TCP_REPAIR_OPTIONS if data was already sent · 13ecaa68
      Lu Wei authored
      [ Upstream commit 0c175da7 ]
      
      If setsockopt with option name of TCP_REPAIR_OPTIONS and opt_code
      of TCPOPT_SACK_PERM is called to enable sack after data is sent
      and dupacks are received , it will trigger a warning in function
      tcp_verify_left_out() as follows:
      
      ============================================
      WARNING: CPU: 8 PID: 0 at net/ipv4/tcp_input.c:2132
      tcp_timeout_mark_lost+0x154/0x160
      tcp_enter_loss+0x2b/0x290
      tcp_retransmit_timer+0x50b/0x640
      tcp_write_timer_handler+0x1c8/0x340
      tcp_write_timer+0xe5/0x140
      call_timer_fn+0x3a/0x1b0
      __run_timers.part.0+0x1bf/0x2d0
      run_timer_softirq+0x43/0xb0
      __do_softirq+0xfd/0x373
      __irq_exit_rcu+0xf6/0x140
      
      The warning is caused in the following steps:
      1. a socket named socketA is created
      2. socketA enters repair mode without build a connection
      3. socketA calls connect() and its state is changed to TCP_ESTABLISHED
         directly
      4. socketA leaves repair mode
      5. socketA calls sendmsg() to send data, packets_out and sack_outs(dup
         ack receives) increase
      6. socketA enters repair mode again
      7. socketA calls setsockopt with TCPOPT_SACK_PERM to enable sack
      8. retransmit timer expires, it calls tcp_timeout_mark_lost(), lost_out
         increases
      9. sack_outs + lost_out > packets_out triggers since lost_out and
         sack_outs increase repeatly
      
      In function tcp_timeout_mark_lost(), tp->sacked_out will be cleared if
      Step7 not happen and the warning will not be triggered. As suggested by
      Denis and Eric, TCP_REPAIR_OPTIONS should be prohibited if data was
      already sent.
      
      socket-tcp tests in CRIU has been tested as follows:
      $ sudo ./test/zdtm.py run -t zdtm/static/socket-tcp*  --keep-going \
             --ignore-taint
      
      socket-tcp* represent all socket-tcp tests in test/zdtm/static/.
      
      Fixes: b139ba4e
      
       ("tcp: Repair connection-time negotiated parameters")
      Signed-off-by: default avatarLu Wei <luwei32@huawei.com>
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      13ecaa68
    • Yuan Can's avatar
      drm/vc4: Fix missing platform_unregister_drivers() call in vc4_drm_register() · bc79cb9f
      Yuan Can authored
      [ Upstream commit cf53db76 ]
      
      A problem about modprobe vc4 failed is triggered with the following log
      given:
      
       [  420.327987] Error: Driver 'vc4_hvs' is already registered, aborting...
       [  420.333904] failed to register platform driver vc4_hvs_driver [vc4]: -16
       modprobe: ERROR: could not insert 'vc4': Device or resource busy
      
      The reason is that vc4_drm_register() returns platform_driver_register()
      directly without checking its return value, if platform_driver_register()
      fails, it returns without unregistering all the vc4 drivers, resulting the
      vc4 can never be installed later.
      A simple call graph is shown as below:
      
       vc4_drm_register()
         platform_register_drivers() # all vc4 drivers are registered
         platform_driver_register()
           driver_register()
             bus_add_driver()
               priv = kzalloc(...) # OOM happened
         # return without unregister drivers
      
      Fixing this problem by checking the return value of
      platform_driver_register() and do platform_unregister_drivers() if
      error happened.
      
      Fixes: c8b75bca
      
       ("drm/vc4: Add KMS support for Raspberry Pi.")
      Signed-off-by: default avatarYuan Can <yuancan@huawei.com>
      Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
      Link: https://patchwork.freedesktop.org/patch/msgid/20221103014705.109322-1-yuancan@huawei.com
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      bc79cb9f
    • HW He's avatar
      net: wwan: mhi: fix memory leak in mhi_mbim_dellink · 2845bc90
      HW He authored
      [ Upstream commit 668205b9 ]
      
      MHI driver registers network device without setting the
      needs_free_netdev flag, and does NOT call free_netdev() when
      unregisters network device, which causes a memory leak.
      
      This patch sets needs_free_netdev to true when registers
      network device, which makes netdev subsystem call free_netdev()
      automatically after unregister_netdevice().
      
      Fixes: aa730a99
      
       ("net: wwan: Add MHI MBIM network driver")
      Signed-off-by: default avatarHW He <hw.he@mediatek.com>
      Signed-off-by: default avatarZhaoping Shu <zhaoping.shu@mediatek.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2845bc90
    • HW He's avatar
      net: wwan: iosm: fix memory leak in ipc_wwan_dellink · 2ce2348c
      HW He authored
      [ Upstream commit f25caaca ]
      
      IOSM driver registers network device without setting the
      needs_free_netdev flag, and does NOT call free_netdev() when
      unregisters network device, which causes a memory leak.
      
      This patch sets needs_free_netdev to true when registers
      network device, which makes netdev subsystem call free_netdev()
      automatically after unregister_netdevice().
      
      Fixes: 2a54f2c7
      
       ("net: iosm: net driver")
      Signed-off-by: default avatarHW He <hw.he@mediatek.com>
      Reviewed-by: default avatarLoic Poulain <loic.poulain@linaro.org>
      Signed-off-by: default avatarZhaoping Shu <zhaoping.shu@mediatek.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2ce2348c
    • Zhengchao Shao's avatar
      hamradio: fix issue of dev reference count leakage in bpq_device_event() · 7b6bc50f
      Zhengchao Shao authored
      [ Upstream commit 85cbaf03 ]
      
      When following tests are performed, it will cause dev reference counting
      leakage.
      a)ip link add bond2 type bond mode balance-rr
      b)ip link set bond2 up
      c)ifenslave -f bond2 rose1
      d)ip link del bond2
      
      When new bond device is created, the default type of the bond device is
      ether. And the bond device is up, bpq_device_event() receives the message
      and creates a new bpq device. In this case, the reference count value of
      dev is hold once. But after "ifenslave -f bond2 rose1" command is
      executed, the type of the bond device is changed to rose. When the bond
      device is unregistered, bpq_device_event() will not put the dev reference
      count.
      
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      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>
      7b6bc50f
    • Zhengchao Shao's avatar
      net: lapbether: fix issue of dev reference count leakage in lapbeth_device_event() · f59adebb
      Zhengchao Shao authored
      [ Upstream commit 531705a7 ]
      
      When following tests are performed, it will cause dev reference counting
      leakage.
      a)ip link add bond2 type bond mode balance-rr
      b)ip link set bond2 up
      c)ifenslave -f bond2 rose1
      d)ip link del bond2
      
      When new bond device is created, the default type of the bond device is
      ether. And the bond device is up, lapbeth_device_event() receives the
      message and creates a new lapbeth device. In this case, the reference
      count value of dev is hold once. But after "ifenslave -f bond2 rose1"
      command is executed, the type of the bond device is changed to rose. When
      the bond device is unregistered, lapbeth_device_event() will not put the
      dev reference count.
      
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      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>
      f59adebb
    • Nico Boehr's avatar
      KVM: s390: pv: don't allow userspace to set the clock under PV · 119407dc
      Nico Boehr authored
      [ Upstream commit 6973091d ]
      
      When running under PV, the guest's TOD clock is under control of the
      ultravisor and the hypervisor isn't allowed to change it. Hence, don't
      allow userspace to change the guest's TOD clock by returning
      -EOPNOTSUPP.
      
      When userspace changes the guest's TOD clock, KVM updates its
      kvm.arch.epoch field and, in addition, the epoch field in all state
      descriptions of all VCPUs.
      
      But, under PV, the ultravisor will ignore the epoch field in the state
      description and simply overwrite it on next SIE exit with the actual
      guest epoch. This leads to KVM having an incorrect view of the guest's
      TOD clock: it has updated its internal kvm.arch.epoch field, but the
      ultravisor ignores the field in the state description.
      
      Whenever a guest is now waiting for a clock comparator, KVM will
      incorrectly calculate the time when the guest should wake up, possibly
      causing the guest to sleep for much longer than expected.
      
      With this change, kvm_s390_set_tod() will now take the kvm->lock to be
      able to call kvm_s390_pv_is_protected(). Since kvm_s390_set_tod_clock()
      also takes kvm->lock, use __kvm_s390_set_tod_clock() instead.
      
      The function kvm_s390_set_tod_clock is now unused, hence remove it.
      Update the documentation to indicate the TOD clock attr calls can now
      return -EOPNOTSUPP.
      
      Fixes: 0f303504
      
       ("KVM: s390: protvirt: Do only reset registers that are accessible")
      Reported-by: default avatarMarc Hartmayer <mhartmay@linux.ibm.com>
      Signed-off-by: default avatarNico Boehr <nrb@linux.ibm.com>
      Reviewed-by: default avatarClaudio Imbrenda <imbrenda@linux.ibm.com>
      Reviewed-by: default avatarJanosch Frank <frankja@linux.ibm.com>
      Link: https://lore.kernel.org/r/20221011160712.928239-2-nrb@linux.ibm.com
      Message-Id: <20221011160712.928239-2-nrb@linux.ibm.com>
      Signed-off-by: default avatarJanosch Frank <frankja@linux.ibm.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      119407dc
    • John Thomson's avatar
      phy: ralink: mt7621-pci: add sentinel to quirks table · 500bcd3a
      John Thomson authored
      [ Upstream commit 819b885c ]
      
      With mt7621 soc_dev_attr fixed to register the soc as a device,
      kernel will experience an oops in soc_device_match_attr
      
      This quirk test was introduced in the staging driver in
      commit 9445ccb3 ("staging: mt7621-pci-phy: add quirks for 'E2'
      revision using 'soc_device_attribute'"). The staging driver was removed,
      and later re-added in commit d87da323 ("phy: ralink: Add PHY driver
      for MT7621 PCIe PHY") for kernel 5.11
      
      Link: https://lore.kernel.org/lkml/26ebbed1-0fe9-4af9-8466-65f841d0b382@app.fastmail.com
      Fixes: d87da323
      
       ("phy: ralink: Add PHY driver for MT7621 PCIe PHY")
      Signed-off-by: default avatarJohn Thomson <git@johnthomson.fastmail.com.au>
      Acked-by: default avatarSergio Paracuellos <sergio.paracuellos@gmail.com>
      Link: https://lore.kernel.org/r/20221104205242.3440388-2-git@johnthomson.fastmail.com.au
      Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      500bcd3a
    • Gaosheng Cui's avatar
      capabilities: fix undefined behavior in bit shift for CAP_TO_MASK · 151dc808
      Gaosheng Cui authored
      [ Upstream commit 46653972 ]
      
      Shifting signed 32-bit value by 31 bits is undefined, so changing
      significant bit to unsigned. The UBSAN warning calltrace like below:
      
      UBSAN: shift-out-of-bounds in security/commoncap.c:1252:2
      left shift of 1 by 31 places cannot be represented in type 'int'
      Call Trace:
       <TASK>
       dump_stack_lvl+0x7d/0xa5
       dump_stack+0x15/0x1b
       ubsan_epilogue+0xe/0x4e
       __ubsan_handle_shift_out_of_bounds+0x1e7/0x20c
       cap_task_prctl+0x561/0x6f0
       security_task_prctl+0x5a/0xb0
       __x64_sys_prctl+0x61/0x8f0
       do_syscall_64+0x58/0x80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
       </TASK>
      
      Fixes: e338d263
      
       ("Add 64-bit capability support to the kernel")
      Signed-off-by: default avatarGaosheng Cui <cuigaosheng1@huawei.com>
      Acked-by: default avatarAndrew G. Morgan <morgan@kernel.org>
      Reviewed-by: default avatarSerge Hallyn <serge@hallyn.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      151dc808
    • Sean Anderson's avatar
      net: fman: Unregister ethernet device on removal · 435c7ddf
      Sean Anderson authored
      [ Upstream commit b7cbc674 ]
      
      When the mac device gets removed, it leaves behind the ethernet device.
      This will result in a segfault next time the ethernet device accesses
      mac_dev. Remove the ethernet device when we get removed to prevent
      this. This is not completely reversible, since some resources aren't
      cleaned up properly, but that can be addressed later.
      
      Fixes: 39339616
      
       ("fsl/fman: Add FMan MAC driver")
      Signed-off-by: default avatarSean Anderson <sean.anderson@seco.com>
      Link: https://lore.kernel.org/r/20221103182831.2248833-1-sean.anderson@seco.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      435c7ddf
    • Alex Barba's avatar
      bnxt_en: fix potentially incorrect return value for ndo_rx_flow_steer · 3a504d6d
      Alex Barba authored
      [ Upstream commit 02597d39 ]
      
      In the bnxt_en driver ndo_rx_flow_steer returns '0' whenever an entry
      that we are attempting to steer is already found.  This is not the
      correct behavior.  The return code should be the value/index that
      corresponds to the entry.  Returning zero all the time causes the
      RFS records to be incorrect unless entry '0' is the correct one.  As
      flows migrate to different cores this can create entries that are not
      correct.
      
      Fixes: c0c050c5
      
       ("bnxt_en: New Broadcom ethernet driver.")
      Reported-by: default avatarAkshay Navgire <anavgire@purestorage.com>
      Signed-off-by: default avatarAlex Barba <alex.barba@broadcom.com>
      Signed-off-by: default avatarAndy Gospodarek <gospo@broadcom.com>
      Signed-off-by: default avatarMichael Chan <michael.chan@broadcom.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3a504d6d
    • Michael Chan's avatar
      bnxt_en: Fix possible crash in bnxt_hwrm_set_coal() · ac257c43
      Michael Chan authored
      [ Upstream commit 6d81ea37 ]
      
      During the error recovery sequence, the rtnl_lock is not held for the
      entire duration and some datastructures may be freed during the sequence.
      Check for the BNXT_STATE_OPEN flag instead of netif_running() to ensure
      that the device is fully operational before proceeding to reconfigure
      the coalescing settings.
      
      This will fix a possible crash like this:
      
      BUG: unable to handle kernel NULL pointer dereference at 0000000000000000
      PGD 0 P4D 0
      Oops: 0000 [#1] SMP NOPTI
      CPU: 10 PID: 181276 Comm: ethtool Kdump: loaded Tainted: G          IOE    --------- -  - 4.18.0-348.el8.x86_64 #1
      Hardware name: Dell Inc. PowerEdge R740/0F9N89, BIOS 2.3.10 08/15/2019
      RIP: 0010:bnxt_hwrm_set_coal+0x1fb/0x2a0 [bnxt_en]
      Code: c2 66 83 4e 22 08 66 89 46 1c e8 10 cb 00 00 41 83 c6 01 44 39 b3 68 01 00 00 0f 8e a3 00 00 00 48 8b 93 c8 00 00 00 49 63 c6 <48> 8b 2c c2 48 8b 85 b8 02 00 00 48 85 c0 74 2e 48 8b 74 24 08 f6
      RSP: 0018:ffffb11c8dcaba50 EFLAGS: 00010246
      RAX: 0000000000000000 RBX: ffff8d168a8b0ac0 RCX: 00000000000000c5
      RDX: 0000000000000000 RSI: ffff8d162f72c000 RDI: ffff8d168a8b0b28
      RBP: 0000000000000000 R08: b6e1f68a12e9a7eb R09: 0000000000000000
      R10: 0000000000000001 R11: 0000000000000037 R12: ffff8d168a8b109c
      R13: ffff8d168a8b10aa R14: 0000000000000000 R15: ffffffffc01ac4e0
      FS:  00007f3852e4c740(0000) GS:ffff8d24c0080000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 0000000000000000 CR3: 000000041b3ee003 CR4: 00000000007706e0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      PKRU: 55555554
      Call Trace:
       ethnl_set_coalesce+0x3ce/0x4c0
       genl_family_rcv_msg_doit.isra.15+0x10f/0x150
       genl_family_rcv_msg+0xb3/0x160
       ? coalesce_fill_reply+0x480/0x480
       genl_rcv_msg+0x47/0x90
       ? genl_family_rcv_msg+0x160/0x160
       netlink_rcv_skb+0x4c/0x120
       genl_rcv+0x24/0x40
       netlink_unicast+0x196/0x230
       netlink_sendmsg+0x204/0x3d0
       sock_sendmsg+0x4c/0x50
       __sys_sendto+0xee/0x160
       ? syscall_trace_enter+0x1d3/0x2c0
       ? __audit_syscall_exit+0x249/0x2a0
       __x64_sys_sendto+0x24/0x30
       do_syscall_64+0x5b/0x1a0
       entry_SYSCALL_64_after_hwframe+0x65/0xca
      RIP: 0033:0x7f38524163bb
      
      Fixes: 2151fe08
      
       ("bnxt_en: Handle RESET_NOTIFY async event from firmware.")
      Reviewed-by: default avatarSomnath Kotur <somnath.kotur@broadcom.com>
      Signed-off-by: default avatarMichael Chan <michael.chan@broadcom.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ac257c43
    • Wang Yufen's avatar
      net: tun: Fix memory leaks of napi_get_frags · d7569302
      Wang Yufen authored
      [ Upstream commit 1118b204 ]
      
      kmemleak reports after running test_progs:
      
      unreferenced object 0xffff8881b1672dc0 (size 232):
        comm "test_progs", pid 394388, jiffies 4354712116 (age 841.975s)
        hex dump (first 32 bytes):
          e0 84 d7 a8 81 88 ff ff 80 2c 67 b1 81 88 ff ff  .........,g.....
          00 40 c5 9b 81 88 ff ff 00 00 00 00 00 00 00 00  .@..............
        backtrace:
          [<00000000c8f01748>] napi_skb_cache_get+0xd4/0x150
          [<0000000041c7fc09>] __napi_build_skb+0x15/0x50
          [<00000000431c7079>] __napi_alloc_skb+0x26e/0x540
          [<000000003ecfa30e>] napi_get_frags+0x59/0x140
          [<0000000099b2199e>] tun_get_user+0x183d/0x3bb0 [tun]
          [<000000008a5adef0>] tun_chr_write_iter+0xc0/0x1b1 [tun]
          [<0000000049993ff4>] do_iter_readv_writev+0x19f/0x320
          [<000000008f338ea2>] do_iter_write+0x135/0x630
          [<000000008a3377a4>] vfs_writev+0x12e/0x440
          [<00000000a6b5639a>] do_writev+0x104/0x280
          [<00000000ccf065d8>] do_syscall_64+0x3b/0x90
          [<00000000d776e329>] entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      The issue occurs in the following scenarios:
      tun_get_user()
        napi_gro_frags()
          napi_frags_finish()
            case GRO_NORMAL:
              gro_normal_one()
                list_add_tail(&skb->list, &napi->rx_list);
                <-- While napi->rx_count < READ_ONCE(gro_normal_batch),
                <-- gro_normal_list() is not called, napi->rx_list is not empty
        <-- not ask to complete the gro work, will cause memory leaks in
        <-- following tun_napi_del()
      ...
      tun_napi_del()
        netif_napi_del()
          __netif_napi_del()
          <-- &napi->rx_list is not empty, which caused memory leaks
      
      To fix, add napi_complete() after napi_gro_frags().
      
      Fixes: 90e33d45
      
       ("tun: enable napi_gro_frags() for TUN/TAP driver")
      Signed-off-by: default avatarWang Yufen <wangyufen@huawei.com>
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d7569302
    • Ratheesh Kannoth's avatar
      octeontx2-pf: NIX TX overwrites SQ_CTX_HW_S[SQ_INT] · 430d1f49
      Ratheesh Kannoth authored
      [ Upstream commit 51afe902 ]
      
      In scenarios where multiple errors have occurred
      for a SQ before SW starts handling error interrupt,
      SQ_CTX[OP_INT] may get overwritten leading to
      NIX_LF_SQ_OP_INT returning incorrect value.
      To workaround this read LMT, MNQ and SQ individual
      error status registers to determine the cause of error.
      
      Fixes: 4ff7d148
      
       ("octeontx2-pf: Error handling support")
      Signed-off-by: default avatarRatheesh Kannoth <rkannoth@marvell.com>
      Reviewed-by: default avatarSunil Kovvuri Goutham <sgoutham@marvell.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      430d1f49
    • Geetha sowjanya's avatar
      octeontx2-pf: Use hardware register for CQE count · ec0db818
      Geetha sowjanya authored
      [ Upstream commit af3826db
      
       ]
      
      Current driver uses software CQ head pointer to poll on CQE
      header in memory to determine if CQE is valid. Software needs
      to make sure, that the reads of the CQE do not get re-ordered
      so much that it ends up with an inconsistent view of the CQE.
      To ensure that DMB barrier after read to first CQE cacheline
      and before reading of the rest of the CQE is needed.
      But having barrier for every CQE read will impact the performance,
      instead use hardware CQ head and tail pointers to find the
      valid number of CQEs.
      
      Signed-off-by: default avatarGeetha sowjanya <gakula@marvell.com>
      Signed-off-by: default avatarSunil Kovvuri Goutham <sgoutham@marvell.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Stable-dep-of: 51afe902
      
       ("octeontx2-pf: NIX TX overwrites SQ_CTX_HW_S[SQ_INT]")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ec0db818
    • Sabrina Dubroca's avatar
      macsec: clear encryption keys from the stack after setting up offload · b89a0d88
      Sabrina Dubroca authored
      [ Upstream commit aaab73f8 ]
      
      macsec_add_rxsa and macsec_add_txsa copy the key to an on-stack
      offloading context to pass it to the drivers, but leaves it there when
      it's done. Clear it with memzero_explicit as soon as it's not needed
      anymore.
      
      Fixes: 3cf3227a
      
       ("net: macsec: hardware offloading infrastructure")
      Signed-off-by: default avatarSabrina Dubroca <sd@queasysnail.net>
      Reviewed-by: default avatarAntoine Tenart <atenart@kernel.org>
      Reviewed-by: default avatarLeon Romanovsky <leonro@nvidia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      b89a0d88
    • Sabrina Dubroca's avatar
      macsec: fix detection of RXSCs when toggling offloading · eeba7f07
      Sabrina Dubroca authored
      [ Upstream commit 80df4706 ]
      
      macsec_is_configured incorrectly uses secy->n_rx_sc to check if some
      RXSCs exist. secy->n_rx_sc only counts the number of active RXSCs, but
      there can also be inactive SCs as well, which may be stored in the
      driver (in case we're disabling offloading), or would have to be
      pushed to the device (in case we're trying to enable offloading).
      
      As long as RXSCs active on creation and never turned off, the issue is
      not visible.
      
      Fixes: dcb780fb
      
       ("net: macsec: add nla support for changing the offloading selection")
      Signed-off-by: default avatarSabrina Dubroca <sd@queasysnail.net>
      Reviewed-by: default avatarAntoine Tenart <atenart@kernel.org>
      Reviewed-by: default avatarLeon Romanovsky <leonro@nvidia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      eeba7f07
    • Sabrina Dubroca's avatar
      macsec: fix secy->n_rx_sc accounting · 3070a880
      Sabrina Dubroca authored
      [ Upstream commit 73a4b31c ]
      
      secy->n_rx_sc is supposed to be the number of _active_ rxsc's within a
      secy. This is then used by macsec_send_sci to help decide if we should
      add the SCI to the header or not.
      
      This logic is currently broken when we create a new RXSC and turn it
      off at creation, as create_rx_sc always sets ->active to true (and
      immediately uses that to increment n_rx_sc), and only later
      macsec_add_rxsc sets rx_sc->active.
      
      Fixes: c09440f7
      
       ("macsec: introduce IEEE 802.1AE driver")
      Signed-off-by: default avatarSabrina Dubroca <sd@queasysnail.net>
      Reviewed-by: default avatarAntoine Tenart <atenart@kernel.org>
      Reviewed-by: default avatarLeon Romanovsky <leonro@nvidia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      3070a880
    • Sabrina Dubroca's avatar
      macsec: delete new rxsc when offload fails · e957555a
      Sabrina Dubroca authored
      [ Upstream commit 93a30947 ]
      
      Currently we get an inconsistent state:
       - netlink returns the error to userspace
       - the RXSC is installed but not offloaded
      
      Then the device could get confused when we try to add an RXSA, because
      the RXSC isn't supposed to exist.
      
      Fixes: 3cf3227a
      
       ("net: macsec: hardware offloading infrastructure")
      Signed-off-by: default avatarSabrina Dubroca <sd@queasysnail.net>
      Reviewed-by: default avatarAntoine Tenart <atenart@kernel.org>
      Reviewed-by: default avatarLeon Romanovsky <leonro@nvidia.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e957555a
    • Jiri Benc's avatar
      net: gso: fix panic on frag_list with mixed head alloc types · ad25a115
      Jiri Benc authored
      [ Upstream commit 9e4b7a99 ]
      
      Since commit 3dcbdb13 ("net: gso: Fix skb_segment splat when
      splitting gso_size mangled skb having linear-headed frag_list"), it is
      allowed to change gso_size of a GRO packet. However, that commit assumes
      that "checking the first list_skb member suffices; i.e if either of the
      list_skb members have non head_frag head, then the first one has too".
      
      It turns out this assumption does not hold. We've seen BUG_ON being hit
      in skb_segment when skbs on the frag_list had differing head_frag with
      the vmxnet3 driver. This happens because __netdev_alloc_skb and
      __napi_alloc_skb can return a skb that is page backed or kmalloced
      depending on the requested size. As the result, the last small skb in
      the GRO packet can be kmalloced.
      
      There are three different locations where this can be fixed:
      
      (1) We could check head_frag in GRO and not allow GROing skbs with
          different head_frag. However, that would lead to performance
          regression on normal forward paths with unmodified gso_size, where
          !head_frag in the last packet is not a problem.
      
      (2) Set a flag in bpf_skb_net_grow and bpf_skb_net_shrink indicating
          that NETIF_F_SG is undesirable. That would need to eat a bit in
          sk_buff. Furthermore, that flag can be unset when all skbs on the
          frag_list are page backed. To retain good performance,
          bpf_skb_net_grow/shrink would have to walk the frag_list.
      
      (3) Walk the frag_list in skb_segment when determining whether
          NETIF_F_SG should be cleared. This of course slows things down.
      
      This patch implements (3). To limit the performance impact in
      skb_segment, the list is walked only for skbs with SKB_GSO_DODGY set
      that have gso_size changed. Normal paths thus will not hit it.
      
      We could check only the last skb but since we need to walk the whole
      list anyway, let's stay on the safe side.
      
      Fixes: 3dcbdb13
      
       ("net: gso: Fix skb_segment splat when splitting gso_size mangled skb having linear-headed frag_list")
      Signed-off-by: default avatarJiri Benc <jbenc@redhat.com>
      Reviewed-by: default avatarWillem de Bruijn <willemb@google.com>
      Link: https://lore.kernel.org/r/e04426a6a91baf4d1081e1b478c82b5de25fdf21.1667407944.git.jbenc@redhat.com
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ad25a115
    • Youlin Li's avatar
      bpf: Fix wrong reg type conversion in release_reference() · 466ce46f
      Youlin Li authored
      [ Upstream commit f1db2081 ]
      
      Some helper functions will allocate memory. To avoid memory leaks, the
      verifier requires the eBPF program to release these memories by calling
      the corresponding helper functions.
      
      When a resource is released, all pointer registers corresponding to the
      resource should be invalidated. The verifier use release_references() to
      do this job, by apply  __mark_reg_unknown() to each relevant register.
      
      It will give these registers the type of SCALAR_VALUE. A register that
      will contain a pointer value at runtime, but of type SCALAR_VALUE, which
      may allow the unprivileged user to get a kernel pointer by storing this
      register into a map.
      
      Using __mark_reg_not_init() while NOT allow_ptr_leaks can mitigate this
      problem.
      
      Fixes: fd978bf7
      
       ("bpf: Add reference tracking to verifier")
      Signed-off-by: default avatarYoulin Li <liulin063@gmail.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20221103093440.3161-1-liulin063@gmail.com
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      466ce46f
    • Kumar Kartikeya Dwivedi's avatar
      bpf: Add helper macro bpf_for_each_reg_in_vstate · 35d8130f
      Kumar Kartikeya Dwivedi authored
      [ Upstream commit b239da34
      
       ]
      
      For a lot of use cases in future patches, we will want to modify the
      state of registers part of some same 'group' (e.g. same ref_obj_id). It
      won't just be limited to releasing reference state, but setting a type
      flag dynamically based on certain actions, etc.
      
      Hence, we need a way to easily pass a callback to the function that
      iterates over all registers in current bpf_verifier_state in all frames
      upto (and including) the curframe.
      
      While in C++ we would be able to easily use a lambda to pass state and
      the callback together, sadly we aren't using C++ in the kernel. The next
      best thing to avoid defining a function for each case seems like
      statement expressions in GNU C. The kernel already uses them heavily,
      hence they can passed to the macro in the style of a lambda. The
      statement expression will then be substituted in the for loop bodies.
      
      Variables __state and __reg are set to current bpf_func_state and reg
      for each invocation of the expression inside the passed in verifier
      state.
      
      Then, convert mark_ptr_or_null_regs, clear_all_pkt_pointers,
      release_reference, find_good_pkt_pointers, find_equal_scalars to
      use bpf_for_each_reg_in_vstate.
      
      Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
      Link: https://lore.kernel.org/r/20220904204145.3089-16-memxor@gmail.com
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Stable-dep-of: f1db2081
      
       ("bpf: Fix wrong reg type conversion in release_reference()")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      35d8130f
    • Cong Wang's avatar
      bpf, sock_map: Move cancel_work_sync() out of sock lock · 61274498
      Cong Wang authored
      [ Upstream commit 8bbabb3f ]
      
      Stanislav reported a lockdep warning, which is caused by the
      cancel_work_sync() called inside sock_map_close(), as analyzed
      below by Jakub:
      
      psock->work.func = sk_psock_backlog()
        ACQUIRE psock->work_mutex
          sk_psock_handle_skb()
            skb_send_sock()
              __skb_send_sock()
                sendpage_unlocked()
                  kernel_sendpage()
                    sock->ops->sendpage = inet_sendpage()
                      sk->sk_prot->sendpage = tcp_sendpage()
                        ACQUIRE sk->sk_lock
                          tcp_sendpage_locked()
                        RELEASE sk->sk_lock
        RELEASE psock->work_mutex
      
      sock_map_close()
        ACQUIRE sk->sk_lock
        sk_psock_stop()
          sk_psock_clear_state(psock, SK_PSOCK_TX_ENABLED)
          cancel_work_sync()
            __cancel_work_timer()
              __flush_work()
                // wait for psock->work to finish
        RELEASE sk->sk_lock
      
      We can move the cancel_work_sync() out of the sock lock protection,
      but still before saved_close() was called.
      
      Fixes: 799aa7f9
      
       ("skmsg: Avoid lock_sock() in sk_psock_backlog()")
      Reported-by: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarCong Wang <cong.wang@bytedance.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Tested-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
      Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Acked-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
      Link: https://lore.kernel.org/bpf/20221102043417.279409-1-xiyou.wangcong@gmail.com
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      61274498
    • John Fastabend's avatar
      bpf: Fix sockmap calling sleepable function in teardown path · 32b5dd03
      John Fastabend authored
      [ Upstream commit 697fb80a ]
      
      syzbot reproduced the bug ...
      
       BUG: sleeping function called from invalid context at kernel/workqueue.c:3010
      
      ... with the following stack trace fragment ...
      
       start_flush_work kernel/workqueue.c:3010 [inline]
       __flush_work+0x109/0xb10 kernel/workqueue.c:3074
       __cancel_work_timer+0x3f9/0x570 kernel/workqueue.c:3162
       sk_psock_stop+0x4cb/0x630 net/core/skmsg.c:802
       sock_map_destroy+0x333/0x760 net/core/sock_map.c:1581
       inet_csk_destroy_sock+0x196/0x440 net/ipv4/inet_connection_sock.c:1130
       __tcp_close+0xd5b/0x12b0 net/ipv4/tcp.c:2897
       tcp_close+0x29/0xc0 net/ipv4/tcp.c:2909
      
      ... introduced by d8616ee2. Do a quick trace of the code path and the
      bug is obvious:
      
         inet_csk_destroy_sock(sk)
           sk_prot->destroy(sk);      <--- sock_map_destroy
              sk_psock_stop(, true);   <--- true so cancel workqueue
                cancel_work_sync()     <--- splat, because *_bh_disable()
      
      We can not call cancel_work_sync() from inside destroy path. So mark
      the sk_psock_stop call to skip this cancel_work_sync(). This will avoid
      the BUG, but means we may run sk_psock_backlog after or during the
      destroy op. We zapped the ingress_skb queue in sk_psock_stop (safe to
      do with local_bh_disable) so its empty and the sk_psock_backlog work
      item will not find any pkts to process here. However, because we are
      not going to wait for it or clear its ->state its possible it kicks off
      or is already running. This should be 'safe' up until psock drops its
      refcnt to psock->sk. The sock_put() that drops this reference is only
      done at psock destroy time from sk_psock_destroy(). This is done through
      workqueue when sk_psock_drop() is called on psock refnt reaches 0.
      And importantly sk_psock_destroy() does a cancel_work_sync(). So trivial
      fix works.
      
      I've had hit or miss luck reproducing this caught it once or twice with
      the provided reproducer when running with many runners. However, syzkaller
      is very good at reproducing so relying on syzkaller to verify fix.
      
      Fixes: d8616ee2
      
       ("bpf, sockmap: Fix sk->sk_forward_alloc warn_on in sk_stream_kill_queues")
      Reported-by: default avatar <syzbot+140186ceba0c496183bc@syzkaller.appspotmail.com>
      Suggested-by: default avatarHillf Danton <hdanton@sina.com>
      Signed-off-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Cc: Wang Yufen <wangyufen@huawei.com>
      Link: https://lore.kernel.org/bpf/20220628035803.317876-1-john.fastabend@gmail.com
      Stable-dep-of: 8bbabb3f
      
       ("bpf, sock_map: Move cancel_work_sync() out of sock lock")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      32b5dd03
    • Wang Yufen's avatar
      bpf, sockmap: Fix sk->sk_forward_alloc warn_on in sk_stream_kill_queues · e9915581
      Wang Yufen authored
      [ Upstream commit d8616ee2
      
       ]
      
      During TCP sockmap redirect pressure test, the following warning is triggered:
      
      WARNING: CPU: 3 PID: 2145 at net/core/stream.c:205 sk_stream_kill_queues+0xbc/0xd0
      CPU: 3 PID: 2145 Comm: iperf Kdump: loaded Tainted: G        W         5.10.0+ #9
      Call Trace:
       inet_csk_destroy_sock+0x55/0x110
       inet_csk_listen_stop+0xbb/0x380
       tcp_close+0x41b/0x480
       inet_release+0x42/0x80
       __sock_release+0x3d/0xa0
       sock_close+0x11/0x20
       __fput+0x9d/0x240
       task_work_run+0x62/0x90
       exit_to_user_mode_prepare+0x110/0x120
       syscall_exit_to_user_mode+0x27/0x190
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      The reason we observed is that:
      
      When the listener is closing, a connection may have completed the three-way
      handshake but not accepted, and the client has sent some packets. The child
      sks in accept queue release by inet_child_forget()->inet_csk_destroy_sock(),
      but psocks of child sks have not released.
      
      To fix, add sock_map_destroy to release psocks.
      
      Signed-off-by: default avatarWang Yufen <wangyufen@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Acked-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
      Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Link: https://lore.kernel.org/bpf/20220524075311.649153-1-wangyufen@huawei.com
      Stable-dep-of: 8bbabb3f
      
       ("bpf, sock_map: Move cancel_work_sync() out of sock lock")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      e9915581
    • Yang Yingliang's avatar
      HID: hyperv: fix possible memory leak in mousevsc_probe() · 5ad95d71
      Yang Yingliang authored
      [ Upstream commit b5bcb94b ]
      
      If hid_add_device() returns error, it should call hid_destroy_device()
      to free hid_dev which is allocated in hid_allocate_device().
      
      Fixes: 74c4fb05
      
       ("HID: hv_mouse: Properly add the hid device")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Reviewed-by: default avatarWei Liu <wei.liu@kernel.org>
      Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5ad95d71
    • Pu Lehui's avatar
      bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE · 6dcdd1b6
      Pu Lehui authored
      [ Upstream commit 34de8e6e ]
      
      When using bpftool to pin {PROG, MAP, LINK} without FILE,
      segmentation fault will occur. The reson is that the lack
      of FILE will cause strlen to trigger NULL pointer dereference.
      The corresponding stacktrace is shown below:
      
      do_pin
        do_pin_any
          do_pin_fd
            mount_bpffs_for_pin
              strlen(name) <- NULL pointer dereference
      
      Fix it by adding validation to the common process.
      
      Fixes: 75a1e792
      
       ("tools: bpftool: Allow all prog/map handles for pinning objects")
      Signed-off-by: default avatarPu Lehui <pulehui@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Reviewed-by: default avatarQuentin Monnet <quentin@isovalent.com>
      Link: https://lore.kernel.org/bpf/20221102084034.3342995-1-pulehui@huaweicloud.com
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      6dcdd1b6
    • Howard Hsu's avatar
      wifi: mac80211: Set TWT Information Frame Disabled bit as 1 · 2fc90224
      Howard Hsu authored
      [ Upstream commit 30ac96f7 ]
      
      The TWT Information Frame Disabled bit of control field of TWT Setup
      frame shall be set to 1 since handling TWT Information frame is not
      supported by current mac80211 implementation.
      
      Fixes: f5a4c24e
      
       ("mac80211: introduce individual TWT support in AP mode")
      Signed-off-by: default avatarHoward Hsu <howard-yh.hsu@mediatek.com>
      Link: https://lore.kernel.org/r/20221027015653.1448-1-howard-yh.hsu@mediatek.com
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2fc90224
    • Wang Yufen's avatar
      bpf, sockmap: Fix the sk->sk_forward_alloc warning of sk_stream_kill_queues · 95adbd2a
      Wang Yufen authored
      [ Upstream commit 8ec95b94 ]
      
      When running `test_sockmap` selftests, the following warning appears:
      
        WARNING: CPU: 2 PID: 197 at net/core/stream.c:205 sk_stream_kill_queues+0xd3/0xf0
        Call Trace:
        <TASK>
        inet_csk_destroy_sock+0x55/0x110
        tcp_rcv_state_process+0xd28/0x1380
        ? tcp_v4_do_rcv+0x77/0x2c0
        tcp_v4_do_rcv+0x77/0x2c0
        __release_sock+0x106/0x130
        __tcp_close+0x1a7/0x4e0
        tcp_close+0x20/0x70
        inet_release+0x3c/0x80
        __sock_release+0x3a/0xb0
        sock_close+0x14/0x20
        __fput+0xa3/0x260
        task_work_run+0x59/0xb0
        exit_to_user_mode_prepare+0x1b3/0x1c0
        syscall_exit_to_user_mode+0x19/0x50
        do_syscall_64+0x48/0x90
        entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      The root case is in commit 84472b43 ("bpf, sockmap: Fix more uncharged
      while msg has more_data"), where I used msg->sg.size to replace the tosend,
      causing breakage:
      
        if (msg->apply_bytes && msg->apply_bytes < tosend)
          tosend = psock->apply_bytes;
      
      Fixes: 84472b43
      
       ("bpf, sockmap: Fix more uncharged while msg has more_data")
      Reported-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
      Signed-off-by: default avatarWang Yufen <wangyufen@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Acked-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
      Link: https://lore.kernel.org/bpf/1667266296-8794-1-git-send-email-wangyufen@huawei.com
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      95adbd2a
    • Kees Cook's avatar
      bpf, verifier: Fix memory leak in array reallocation for stack state · 06615967
      Kees Cook authored
      [ Upstream commit 42378a9c ]
      
      If an error (NULL) is returned by krealloc(), callers of realloc_array()
      were setting their allocation pointers to NULL, but on error krealloc()
      does not touch the original allocation. This would result in a memory
      resource leak. Instead, free the old allocation on the error handling
      path.
      
      The memory leak information is as follows as also reported by Zhengchao:
      
        unreferenced object 0xffff888019801800 (size 256):
        comm "bpf_repo", pid 6490, jiffies 4294959200 (age 17.170s)
        hex dump (first 32 bytes):
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
          00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        backtrace:
          [<00000000b211474b>] __kmalloc_node_track_caller+0x45/0xc0
          [<0000000086712a0b>] krealloc+0x83/0xd0
          [<00000000139aab02>] realloc_array+0x82/0xe2
          [<00000000b1ca41d1>] grow_stack_state+0xfb/0x186
          [<00000000cd6f36d2>] check_mem_access.cold+0x141/0x1341
          [<0000000081780455>] do_check_common+0x5358/0xb350
          [<0000000015f6b091>] bpf_check.cold+0xc3/0x29d
          [<000000002973c690>] bpf_prog_load+0x13db/0x2240
          [<00000000028d1644>] __sys_bpf+0x1605/0x4ce0
          [<00000000053f29bd>] __x64_sys_bpf+0x75/0xb0
          [<0000000056fedaf5>] do_syscall_64+0x35/0x80
          [<000000002bd58261>] entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      Fixes: c69431aa
      
       ("bpf: verifier: Improve function state reallocation")
      Reported-by: default avatarZhengchao Shao <shaozhengchao@huawei.com>
      Reported-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Reviewed-by: default avatarBill Wendling <morbo@google.com>
      Cc: Lorenz Bauer <oss@lmb.io>
      Link: https://lore.kernel.org/bpf/20221029025433.2533810-1-keescook@chromium.org
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      06615967
    • Srinivas Kandagatla's avatar
      soundwire: qcom: check for outanding writes before doing a read · 4335a82c
      Srinivas Kandagatla authored
      [ Upstream commit 49a46731 ]
      
      Reading will increase the fifo count, so check for outstanding cmd wrt.
      write fifo depth to avoid overflow as read will also increase
      write fifo cnt.
      
      Fixes: a661308c
      
       ("soundwire: qcom: wait for fifo space to be available before read/write")
      Signed-off-by: default avatarSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
      Link: https://lore.kernel.org/r/20221026110210.6575-3-srinivas.kandagatla@linaro.org
      Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      4335a82c