1. 04 Nov, 2022 15 commits
    • Wang Yufen's avatar
      net: tun: Fix memory leaks of napi_get_frags · 1118b204
      Wang Yufen authored
      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>
      1118b204
    • Ratheesh Kannoth's avatar
      octeontx2-pf: NIX TX overwrites SQ_CTX_HW_S[SQ_INT] · 51afe902
      Ratheesh Kannoth authored
      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>
      51afe902
    • Roger Quadros's avatar
      net: ethernet: ti: am65-cpsw: Fix segmentation fault at module unload · 1a0c016a
      Roger Quadros authored
      Move am65_cpsw_nuss_phylink_cleanup() call to after
      am65_cpsw_nuss_cleanup_ndev() so phylink is still valid
      to prevent the below Segmentation fault on module remove when
      first slave link is up.
      
      [   31.652944] Unable to handle kernel paging request at virtual address 00040008000005f4
      [   31.684627] Mem abort info:
      [   31.687446]   ESR = 0x0000000096000004
      [   31.704614]   EC = 0x25: DABT (current EL), IL = 32 bits
      [   31.720663]   SET = 0, FnV = 0
      [   31.723729]   EA = 0, S1PTW = 0
      [   31.740617]   FSC = 0x04: level 0 translation fault
      [   31.756624] Data abort info:
      [   31.759508]   ISV = 0, ISS = 0x00000004
      [   31.776705]   CM = 0, WnR = 0
      [   31.779695] [00040008000005f4] address between user and kernel address ranges
      [   31.808644] Internal error: Oops: 0000000096000004 [#1] PREEMPT SMP
      [   31.814928] Modules linked in: wlcore_sdio wl18xx wlcore mac80211 libarc4 cfg80211 rfkill crct10dif_ce phy_gmii_sel ti_am65_cpsw_nuss(-) sch_fq_codel ipv6
      [   31.828776] CPU: 0 PID: 1026 Comm: modprobe Not tainted 6.1.0-rc2-00012-gfabfcf7dafdb-dirty #160
      [   31.837547] Hardware name: Texas Instruments AM625 (DT)
      [   31.842760] pstate: 40000005 (nZcv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
      [   31.849709] pc : phy_stop+0x18/0xf8
      [   31.853202] lr : phylink_stop+0x38/0xf8
      [   31.857031] sp : ffff80000a0839f0
      [   31.860335] x29: ffff80000a0839f0 x28: ffff000000de1c80 x27: 0000000000000000
      [   31.867462] x26: 0000000000000000 x25: 0000000000000000 x24: ffff80000a083b98
      [   31.874589] x23: 0000000000000800 x22: 0000000000000001 x21: ffff000001bfba90
      [   31.881715] x20: ffff0000015ee000 x19: 0004000800000200 x18: 0000000000000000
      [   31.888842] x17: ffff800076c45000 x16: ffff800008004000 x15: 000058e39660b106
      [   31.895969] x14: 0000000000000144 x13: 0000000000000144 x12: 0000000000000000
      [   31.903095] x11: 000000000000275f x10: 00000000000009e0 x9 : ffff80000a0837d0
      [   31.910222] x8 : ffff000000de26c0 x7 : ffff00007fbd6540 x6 : ffff00007fbd64c0
      [   31.917349] x5 : ffff00007fbd0b10 x4 : ffff00007fbd0b10 x3 : ffff00007fbd3920
      [   31.924476] x2 : d0a07fcff8b8d500 x1 : 0000000000000000 x0 : 0004000800000200
      [   31.931603] Call trace:
      [   31.934042]  phy_stop+0x18/0xf8
      [   31.937177]  phylink_stop+0x38/0xf8
      [   31.940657]  am65_cpsw_nuss_ndo_slave_stop+0x28/0x1e0 [ti_am65_cpsw_nuss]
      [   31.947452]  __dev_close_many+0xa4/0x140
      [   31.951371]  dev_close_many+0x84/0x128
      [   31.955115]  unregister_netdevice_many+0x130/0x6d0
      [   31.959897]  unregister_netdevice_queue+0x94/0xd8
      [   31.964591]  unregister_netdev+0x24/0x38
      [   31.968504]  am65_cpsw_nuss_cleanup_ndev.isra.0+0x48/0x70 [ti_am65_cpsw_nuss]
      [   31.975637]  am65_cpsw_nuss_remove+0x58/0xf8 [ti_am65_cpsw_nuss]
      
      Cc: <Stable@vger.kernel.org> # v5.18+
      Fixes: e8609e69 ("net: ethernet: ti: am65-cpsw: Convert to PHYLINK")
      Signed-off-by: default avatarRoger Quadros <rogerq@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      1a0c016a
    • David S. Miller's avatar
      Merge branch 'macsec-offload-fixes' · f4e405f5
      David S. Miller authored
      Sabrina Dubroca says:
      
      ====================
      macsec: offload-related fixes
      
      I'm working on a dummy offload for macsec on netdevsim. It just has a
      small SecY and RXSC table so I can trigger failures easily on the
      ndo_* side. It has exposed a couple of issues.
      
      The first patch is a revert of commit c850240b ("net: macsec:
      report real_dev features when HW offloading is enabled"). That commit
      tried to improve the performance of macsec offload by taking advantage
      of some of the NIC's features, but in doing so, broke macsec offload
      when the lower device supports both macsec and ipsec offload, as the
      ipsec offload feature flags were copied from the real device. Since
      the macsec device doesn't provide xdo_* ops, the XFRM core rejects the
      registration of the new macsec device in xfrm_api_check.
      
      I'm working on re-adding those feature flags when offload is
      available, but I haven't fully solved that yet. I think it would be
      safer to do that second part in net-next considering how complex
      feature interactions tend to be.
      
      v2:
       - better describe the issue introduced by commit c850240b (Leon
         Romanovsky)
       - patch #3: drop unnecessary !! (Leon Romanovsky)
      
      v3:
       - patch #3: drop extra newline (Jakub Kicinski)
      ====================
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      f4e405f5
    • Sabrina Dubroca's avatar
      macsec: clear encryption keys from the stack after setting up offload · aaab73f8
      Sabrina Dubroca authored
      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>
      aaab73f8
    • Sabrina Dubroca's avatar
      macsec: fix detection of RXSCs when toggling offloading · 80df4706
      Sabrina Dubroca authored
      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>
      80df4706
    • Sabrina Dubroca's avatar
      macsec: fix secy->n_rx_sc accounting · 73a4b31c
      Sabrina Dubroca authored
      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>
      73a4b31c
    • Sabrina Dubroca's avatar
      macsec: delete new rxsc when offload fails · 93a30947
      Sabrina Dubroca authored
      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>
      93a30947
    • Sabrina Dubroca's avatar
      Revert "net: macsec: report real_dev features when HW offloading is enabled" · 8bcd560a
      Sabrina Dubroca authored
      This reverts commit c850240b.
      
      That commit tried to improve the performance of macsec offload by
      taking advantage of some of the NIC's features, but in doing so, broke
      macsec offload when the lower device supports both macsec and ipsec
      offload, as the ipsec offload feature flags (mainly NETIF_F_HW_ESP)
      were copied from the real device. Since the macsec device doesn't
      provide xdo_* ops, the XFRM core rejects the registration of the new
      macsec device in xfrm_api_check.
      
      Example perf trace when running
        ip link add link eni1np1 type macsec port 4 offload mac
      
          ip   737 [003]   795.477676: probe:xfrm_dev_event__REGISTER      name="macsec0" features=0x1c000080014869
                    xfrm_dev_event+0x3a
                    notifier_call_chain+0x47
                    register_netdevice+0x846
                    macsec_newlink+0x25a
      
          ip   737 [003]   795.477687:   probe:xfrm_dev_event__return      ret=0x8002 (NOTIFY_BAD)
                   notifier_call_chain+0x47
                   register_netdevice+0x846
                   macsec_newlink+0x25a
      
      dev->features includes NETIF_F_HW_ESP (0x04000000000000), so
      xfrm_api_check returns NOTIFY_BAD because we don't have
      dev->xfrmdev_ops on the macsec device.
      
      We could probably propagate GSO and a few other features from the
      lower device, similar to macvlan. This will be done in a future patch.
      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>
      8bcd560a
    • Adrien Thierry's avatar
      selftests/net: give more time to udpgro bg processes to complete startup · cdb525ca
      Adrien Thierry authored
      In some conditions, background processes in udpgro don't have enough
      time to set up the sockets. When foreground processes start, this
      results in the test failing with "./udpgso_bench_tx: sendmsg: Connection
      refused". For instance, this happens from time to time on a Qualcomm
      SA8540P SoC running CentOS Stream 9.
      
      To fix this, increase the time given to background processes to
      complete the startup before foreground processes start.
      Signed-off-by: default avatarAdrien Thierry <athierry@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      cdb525ca
    • Guangbin Huang's avatar
      net: hns3: fix get wrong value of function hclge_get_dscp_prio() · cfdcb075
      Guangbin Huang authored
      As the argument struct hnae3_handle *h of function hclge_get_dscp_prio()
      can be other client registered in hnae3 layer, we need to transform it
      into hnae3_handle of local nic client to get right dscp settings for
      other clients.
      
      Fixes: dfea275e ("net: hns3: optimize converting dscp to priority process of hns3_nic_select_queue()")
      Signed-off-by: default avatarGuangbin Huang <huangguangbin2@huawei.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      cfdcb075
    • Randy Dunlap's avatar
      net: octeontx2-pf: mcs: consider MACSEC setting · 4581dd48
      Randy Dunlap authored
      Fix build errors when MACSEC=m and OCTEONTX2_PF=y by having
      OCTEONTX2_PF depend on MACSEC if it is enabled. By adding
      "|| !MACSEC", this means that MACSEC is not required -- it can
      be disabled for this driver.
      
      drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.o: in function `otx2_remove':
      ../drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c:(.text+0x2fd0): undefined reference to `cn10k_mcs_free'
      mips64-linux-ld: drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.o: in function `otx2_mbox_up_handler_mcs_intr_notify':
      ../drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c:(.text+0x4610): undefined reference to `cn10k_handle_mcs_event'
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Fixes: c54ffc73 ("octeontx2-pf: mcs: Introduce MACSEC hardware offloading")
      Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Cc: Subbaraya Sundeep <sbhatta@marvell.com>
      Cc: Sunil Goutham <sgoutham@marvell.com>
      Cc: Geetha sowjanya <gakula@marvell.com>
      Cc: hariprasad <hkelam@marvell.com>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Eric Dumazet <edumazet@google.com>
      Cc: Jakub Kicinski <kuba@kernel.org>
      Cc: Paolo Abeni <pabeni@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      4581dd48
    • Jakub Kicinski's avatar
      Merge tag 'wireless-2022-11-03' of git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless · 91018bbc
      Jakub Kicinski authored
      Kalle Valo says:
      
      ====================
      wireless fixes for v6.1
      
      Second set of fixes for v6.1. Some fixes to char type usage in
      drivers, memory leaks in the stack and also functionality fixes. The
      rt2x00 char type fix is a larger (but still simple) commit, otherwise
      the fixes are small in size.
      
      * tag 'wireless-2022-11-03' of git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless:
        wifi: ath11k: avoid deadlock during regulatory update in ath11k_regd_update()
        wifi: ath11k: Fix QCN9074 firmware boot on x86
        wifi: mac80211: Set TWT Information Frame Disabled bit as 1
        wifi: mac80211: Fix ack frame idr leak when mesh has no route
        wifi: mac80211: fix general-protection-fault in ieee80211_subif_start_xmit()
        wifi: brcmfmac: Fix potential buffer overflow in brcmf_fweh_event_worker()
        wifi: airo: do not assign -1 to unsigned char
        wifi: mac80211_hwsim: fix debugfs attribute ps with rc table support
        wifi: cfg80211: Fix bitrates overflow issue
        wifi: cfg80211: fix memory leak in query_regdb_file()
        wifi: mac80211: fix memory free error when registering wiphy fail
        wifi: cfg80211: silence a sparse RCU warning
        wifi: rt2x00: use explicitly signed or unsigned types
      ====================
      
      Link: https://lore.kernel.org/r/20221103125315.04E57C433C1@smtp.kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      91018bbc
    • Jiri Benc's avatar
      net: gso: fix panic on frag_list with mixed head alloc types · 9e4b7a99
      Jiri Benc authored
      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.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      9e4b7a99
    • Jakub Kicinski's avatar
      Merge tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf · f2c24be5
      Jakub Kicinski authored
      Daniel Borkmann says:
      
      ====================
      bpf 2022-11-04
      
      We've added 8 non-merge commits during the last 3 day(s) which contain
      a total of 10 files changed, 113 insertions(+), 16 deletions(-).
      
      The main changes are:
      
      1) Fix memory leak upon allocation failure in BPF verifier's stack state
         tracking, from Kees Cook.
      
      2) Fix address leakage when BPF progs release reference to an object,
         from Youlin Li.
      
      3) Fix BPF CI breakage from buggy in.h uapi header dependency,
         from Andrii Nakryiko.
      
      4) Fix bpftool pin sub-command's argument parsing, from Pu Lehui.
      
      5) Fix BPF sockmap lockdep warning by cancelling psock work outside
         of socket lock, from Cong Wang.
      
      6) Follow-up for BPF sockmap to fix sk_forward_alloc accounting,
         from Wang Yufen.
      
      bpf-for-netdev
      
      * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf:
        selftests/bpf: Add verifier test for release_reference()
        bpf: Fix wrong reg type conversion in release_reference()
        bpf, sock_map: Move cancel_work_sync() out of sock lock
        tools/headers: Pull in stddef.h to uapi to fix BPF selftests build in CI
        net/ipv4: Fix linux/in.h header dependencies
        bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE
        bpf, sockmap: Fix the sk->sk_forward_alloc warning of sk_stream_kill_queues
        bpf, verifier: Fix memory leak in array reallocation for stack state
      ====================
      
      Link: https://lore.kernel.org/r/20221104000445.30761-1-daniel@iogearbox.netSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      f2c24be5
  2. 03 Nov, 2022 19 commits
  3. 02 Nov, 2022 6 commits
    • Luiz Augusto von Dentz's avatar
      Bluetooth: L2CAP: Fix attempting to access uninitialized memory · b1a2cd50
      Luiz Augusto von Dentz authored
      On l2cap_parse_conf_req the variable efs is only initialized if
      remote_efs has been set.
      
      CVE: CVE-2022-42895
      CC: stable@vger.kernel.org
      Reported-by: default avatarTamás Koczka <poprdi@google.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Reviewed-by: default avatarTedd Ho-Jeong An <tedd.an@intel.com>
      b1a2cd50
    • Luiz Augusto von Dentz's avatar
      Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm · f937b758
      Luiz Augusto von Dentz authored
      l2cap_global_chan_by_psm shall not return fixed channels as they are not
      meant to be connected by (S)PSM.
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Reviewed-by: default avatarTedd Ho-Jeong An <tedd.an@intel.com>
      f937b758
    • Luiz Augusto von Dentz's avatar
      Bluetooth: L2CAP: Fix accepting connection request for invalid SPSM · 711f8c3f
      Luiz Augusto von Dentz authored
      The Bluetooth spec states that the valid range for SPSM is from
      0x0001-0x00ff so it is invalid to accept values outside of this range:
      
        BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 3, Part A
        page 1059:
        Table 4.15: L2CAP_LE_CREDIT_BASED_CONNECTION_REQ SPSM ranges
      
      CVE: CVE-2022-42896
      CC: stable@vger.kernel.org
      Reported-by: default avatarTamás Koczka <poprdi@google.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Reviewed-by: default avatarTedd Ho-Jeong An <tedd.an@intel.com>
      711f8c3f
    • Luiz Augusto von Dentz's avatar
      Bluetooth: hci_conn: Fix not restoring ISO buffer count on disconnect · 5638d9ea
      Luiz Augusto von Dentz authored
      When disconnecting an ISO link the controller may not generate
      HCI_EV_NUM_COMP_PKTS for unacked packets which needs to be restored in
      hci_conn_del otherwise the host would assume they are still in use and
      would not be able to use all the buffers available.
      
      Fixes: 26afbd82 ("Bluetooth: Add initial implementation of CIS connections")
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Tested-by: default avatarFrédéric Danis <frederic.danis@collabora.com>
      5638d9ea
    • Hawkins Jiawei's avatar
      Bluetooth: L2CAP: Fix memory leak in vhci_write · 7c9524d9
      Hawkins Jiawei authored
      Syzkaller reports a memory leak as follows:
      ====================================
      BUG: memory leak
      unreferenced object 0xffff88810d81ac00 (size 240):
        [...]
        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:
          [<ffffffff838733d9>] __alloc_skb+0x1f9/0x270 net/core/skbuff.c:418
          [<ffffffff833f742f>] alloc_skb include/linux/skbuff.h:1257 [inline]
          [<ffffffff833f742f>] bt_skb_alloc include/net/bluetooth/bluetooth.h:469 [inline]
          [<ffffffff833f742f>] vhci_get_user drivers/bluetooth/hci_vhci.c:391 [inline]
          [<ffffffff833f742f>] vhci_write+0x5f/0x230 drivers/bluetooth/hci_vhci.c:511
          [<ffffffff815e398d>] call_write_iter include/linux/fs.h:2192 [inline]
          [<ffffffff815e398d>] new_sync_write fs/read_write.c:491 [inline]
          [<ffffffff815e398d>] vfs_write+0x42d/0x540 fs/read_write.c:578
          [<ffffffff815e3cdd>] ksys_write+0x9d/0x160 fs/read_write.c:631
          [<ffffffff845e0645>] do_syscall_x64 arch/x86/entry/common.c:50 [inline]
          [<ffffffff845e0645>] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
          [<ffffffff84600087>] entry_SYSCALL_64_after_hwframe+0x63/0xcd
      ====================================
      
      HCI core will uses hci_rx_work() to process frame, which is queued to
      the hdev->rx_q tail in hci_recv_frame() by HCI driver.
      
      Yet the problem is that, HCI core may not free the skb after handling
      ACL data packets. To be more specific, when start fragment does not
      contain the L2CAP length, HCI core just copies skb into conn->rx_skb and
      finishes frame process in l2cap_recv_acldata(), without freeing the skb,
      which triggers the above memory leak.
      
      This patch solves it by releasing the relative skb, after processing
      the above case in l2cap_recv_acldata().
      
      Fixes: 4d7ea8ee ("Bluetooth: L2CAP: Fix handling fragmented length")
      Link: https://lore.kernel.org/all/0000000000000d0b1905e6aaef64@google.com/
      Reported-and-tested-by: syzbot+8f819e36e01022991cfa@syzkaller.appspotmail.com
      Signed-off-by: default avatarHawkins Jiawei <yin31149@gmail.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      7c9524d9
    • Zhengchao Shao's avatar
      Bluetooth: L2CAP: fix use-after-free in l2cap_conn_del() · 0d0e2d03
      Zhengchao Shao authored
      When l2cap_recv_frame() is invoked to receive data, and the cid is
      L2CAP_CID_A2MP, if the channel does not exist, it will create a channel.
      However, after a channel is created, the hold operation of the channel
      is not performed. In this case, the value of channel reference counting
      is 1. As a result, after hci_error_reset() is triggered, l2cap_conn_del()
      invokes the close hook function of A2MP to release the channel. Then
       l2cap_chan_unlock(chan) will trigger UAF issue.
      
      The process is as follows:
      Receive data:
      l2cap_data_channel()
          a2mp_channel_create()  --->channel ref is 2
          l2cap_chan_put()       --->channel ref is 1
      
      Triger event:
          hci_error_reset()
              hci_dev_do_close()
              ...
              l2cap_disconn_cfm()
                  l2cap_conn_del()
                      l2cap_chan_hold()    --->channel ref is 2
                      l2cap_chan_del()     --->channel ref is 1
                      a2mp_chan_close_cb() --->channel ref is 0, release channel
                      l2cap_chan_unlock()  --->UAF of channel
      
      The detailed Call Trace is as follows:
      BUG: KASAN: use-after-free in __mutex_unlock_slowpath+0xa6/0x5e0
      Read of size 8 at addr ffff8880160664b8 by task kworker/u11:1/7593
      Workqueue: hci0 hci_error_reset
      Call Trace:
       <TASK>
       dump_stack_lvl+0xcd/0x134
       print_report.cold+0x2ba/0x719
       kasan_report+0xb1/0x1e0
       kasan_check_range+0x140/0x190
       __mutex_unlock_slowpath+0xa6/0x5e0
       l2cap_conn_del+0x404/0x7b0
       l2cap_disconn_cfm+0x8c/0xc0
       hci_conn_hash_flush+0x11f/0x260
       hci_dev_close_sync+0x5f5/0x11f0
       hci_dev_do_close+0x2d/0x70
       hci_error_reset+0x9e/0x140
       process_one_work+0x98a/0x1620
       worker_thread+0x665/0x1080
       kthread+0x2e4/0x3a0
       ret_from_fork+0x1f/0x30
       </TASK>
      
      Allocated by task 7593:
       kasan_save_stack+0x1e/0x40
       __kasan_kmalloc+0xa9/0xd0
       l2cap_chan_create+0x40/0x930
       amp_mgr_create+0x96/0x990
       a2mp_channel_create+0x7d/0x150
       l2cap_recv_frame+0x51b8/0x9a70
       l2cap_recv_acldata+0xaa3/0xc00
       hci_rx_work+0x702/0x1220
       process_one_work+0x98a/0x1620
       worker_thread+0x665/0x1080
       kthread+0x2e4/0x3a0
       ret_from_fork+0x1f/0x30
      
      Freed by task 7593:
       kasan_save_stack+0x1e/0x40
       kasan_set_track+0x21/0x30
       kasan_set_free_info+0x20/0x30
       ____kasan_slab_free+0x167/0x1c0
       slab_free_freelist_hook+0x89/0x1c0
       kfree+0xe2/0x580
       l2cap_chan_put+0x22a/0x2d0
       l2cap_conn_del+0x3fc/0x7b0
       l2cap_disconn_cfm+0x8c/0xc0
       hci_conn_hash_flush+0x11f/0x260
       hci_dev_close_sync+0x5f5/0x11f0
       hci_dev_do_close+0x2d/0x70
       hci_error_reset+0x9e/0x140
       process_one_work+0x98a/0x1620
       worker_thread+0x665/0x1080
       kthread+0x2e4/0x3a0
       ret_from_fork+0x1f/0x30
      
      Last potentially related work creation:
       kasan_save_stack+0x1e/0x40
       __kasan_record_aux_stack+0xbe/0xd0
       call_rcu+0x99/0x740
       netlink_release+0xe6a/0x1cf0
       __sock_release+0xcd/0x280
       sock_close+0x18/0x20
       __fput+0x27c/0xa90
       task_work_run+0xdd/0x1a0
       exit_to_user_mode_prepare+0x23c/0x250
       syscall_exit_to_user_mode+0x19/0x50
       do_syscall_64+0x42/0x80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      Second to last potentially related work creation:
       kasan_save_stack+0x1e/0x40
       __kasan_record_aux_stack+0xbe/0xd0
       call_rcu+0x99/0x740
       netlink_release+0xe6a/0x1cf0
       __sock_release+0xcd/0x280
       sock_close+0x18/0x20
       __fput+0x27c/0xa90
       task_work_run+0xdd/0x1a0
       exit_to_user_mode_prepare+0x23c/0x250
       syscall_exit_to_user_mode+0x19/0x50
       do_syscall_64+0x42/0x80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd
      
      Fixes: d0be8347 ("Bluetooth: L2CAP: Fix use-after-free caused by l2cap_chan_put")
      Signed-off-by: default avatarZhengchao Shao <shaozhengchao@huawei.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      0d0e2d03