Skip to content
  1. Nov 04, 2022
    • 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.org
      
      
      Signed-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.com
      
      
      Signed-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.net
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      f2c24be5
    • Youlin Li's avatar
      selftests/bpf: Add verifier test for release_reference() · 475244f5
      Youlin Li authored
      
      
      Add a test case to ensure that released pointer registers will not be
      leaked into the map.
      
      Before fix:
      
        ./test_verifier 984
          984/u reference tracking: try to leak released ptr reg FAIL
          Unexpected success to load!
          verification time 67 usec
          stack depth 4
          processed 23 insns (limit 1000000) max_states_per_insn 0 total_states 2
          peak_states 2 mark_read 1
          984/p reference tracking: try to leak released ptr reg OK
          Summary: 1 PASSED, 0 SKIPPED, 1 FAILED
      
      After fix:
      
        ./test_verifier 984
          984/u reference tracking: try to leak released ptr reg OK
          984/p reference tracking: try to leak released ptr reg OK
          Summary: 2 PASSED, 0 SKIPPED, 0 FAILED
      
      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-2-liulin063@gmail.com
      475244f5
    • Youlin Li's avatar
      bpf: Fix wrong reg type conversion in release_reference() · f1db2081
      Youlin Li authored
      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
      f1db2081
    • Linus Torvalds's avatar
      Merge tag 'net-6.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net · 9521c9d6
      Linus Torvalds authored
      Pull networking fixes from Paolo Abeni:
       "Including fixes from bluetooth and netfilter.
      
        Current release - regressions:
      
         - net: several zerocopy flags fixes
      
         - netfilter: fix possible memory leak in nf_nat_init()
      
         - openvswitch: add missing .resv_start_op
      
        Previous releases - regressions:
      
         - neigh: fix null-ptr-deref in neigh_table_clear()
      
         - sched: fix use after free in red_enqueue()
      
         - dsa: fall back to default tagger if we can't load the one from DT
      
         - bluetooth: fix use-after-free in l2cap_conn_del()
      
        Previous releases - always broken:
      
         - netfilter: netlink notifier might race to release objects
      
         - nfc: fix potential memory leak of skb
      
         - bluetooth: fix use-after-free caused by l2cap_reassemble_sdu
      
         - bluetooth: use skb_put to set length
      
         - eth: tun: fix bugs for oversize packet when napi frags enabled
      
         - eth: lan966x: fixes for when MTU is changed
      
         - eth: dwmac-loongson: fix invalid mdio_node"
      
      * tag 'net-6.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net: (53 commits)
        vsock: fix possible infinite sleep in vsock_connectible_wait_data()
        vsock: remove the unused 'wait' in vsock_connectible_recvmsg()
        ipv6: fix WARNING in ip6_route_net_exit_late()
        bridge: Fix flushing of dynamic FDB entries
        net, neigh: Fix null-ptr-deref in neigh_table_clear()
        net/smc: Fix possible leaked pernet namespace in smc_init()
        stmmac: dwmac-loongson: fix invalid mdio_node
        ibmvnic: Free rwi on reset success
        net: mdio: fix undefined behavior in bit shift for __mdiobus_register
        Bluetooth: L2CAP: Fix attempting to access uninitialized memory
        Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm
        Bluetooth: L2CAP: Fix accepting connection request for invalid SPSM
        Bluetooth: hci_conn: Fix not restoring ISO buffer count on disconnect
        Bluetooth: L2CAP: Fix memory leak in vhci_write
        Bluetooth: L2CAP: fix use-after-free in l2cap_conn_del()
        Bluetooth: virtio_bt: Use skb_put to set length
        Bluetooth: hci_conn: Fix CIS connection dst_type handling
        Bluetooth: L2CAP: Fix use-after-free caused by l2cap_reassemble_sdu
        netfilter: ipset: enforce documented limit to prevent allocating huge memory
        isdn: mISDN: netjet: fix wrong check of device registration
        ...
      9521c9d6
    • Linus Torvalds's avatar
      Merge tag 'powerpc-6.1-4' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux · 4d740391
      Linus Torvalds authored
      Pull powerpc fixes from Michael Ellerman:
      
       - Fix an endian thinko in the asm-generic compat_arg_u64() which led to
         syscall arguments being swapped for some compat syscalls.
      
       - Fix syscall wrapper handling of syscalls with 64-bit arguments on
         32-bit kernels, which led to syscall arguments being misplaced.
      
       - A build fix for amdgpu on Book3E with AltiVec disabled.
      
      Thanks to Andreas Schwab, Christian Zigotzky, and Arnd Bergmann.
      
      * tag 'powerpc-6.1-4' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux:
        powerpc/32: Select ARCH_SPLIT_ARG64
        powerpc/32: fix syscall wrappers with 64-bit arguments
        asm-generic: compat: fix compat_arg_u64() and compat_arg_u64_dual()
        powerpc/64e: Fix amdgpu build on Book3E w/o AltiVec
      4d740391
  2. Nov 03, 2022
    • Cong Wang's avatar
      bpf, sock_map: Move cancel_work_sync() out of sock lock · 8bbabb3f
      Cong Wang authored
      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
      8bbabb3f
    • Andrii Nakryiko's avatar
      tools/headers: Pull in stddef.h to uapi to fix BPF selftests build in CI · a778f5d4
      Andrii Nakryiko authored
      With recent sync of linux/in.h tools/include headers are now relying on
      __DECLARE_FLEX_ARRAY macro, which isn't itself defined inside
      tools/include headers anywhere and is instead assumed to be present in
      system-wide UAPI header. This breaks isolated environments that don't
      have kernel UAPI headers installed system-wide, like BPF CI ([0]).
      
      To fix this, bring in include/uapi/linux/stddef.h into tools/include.
      We can't just copy/paste it, though, it has to be processed with
      scripts/headers_install.sh, which has a dependency on scripts/unifdef.
      So the full command to (re-)generate stddef.h for inclusion into
      tools/include directory is:
      
        $ make scripts_unifdef && \
          cp $KBUILD_OUTPUT/scripts/unifdef scripts/ && \
          scripts/headers_install.sh include/uapi/linux/stddef.h tools/include/uapi/linux/stddef.h
      
      This assumes KBUILD_OUTPUT envvar is set and used for out-of-tree builds.
      
        [0] https://github.com/kernel-patches/bpf/actions/runs/3379432493/jobs/5610982609
      
      Fixes: 036b8f5b
      
       ("tools headers uapi: Update linux/in.h copy")
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Cc: Jakub Kicinski <kuba@kernel.org>
      Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
      Link: https://lore.kernel.org/bpf/20221102182517.2675301-2-andrii@kernel.org
      a778f5d4
    • Andrii Nakryiko's avatar
      net/ipv4: Fix linux/in.h header dependencies · aec1dc97
      Andrii Nakryiko authored
      __DECLARE_FLEX_ARRAY is defined in include/uapi/linux/stddef.h but
      doesn't seem to be explicitly included from include/uapi/linux/in.h,
      which breaks BPF selftests builds (once we sync linux/stddef.h into
      tools/include directory in the next patch). Fix this by explicitly
      including linux/stddef.h.
      
      Given this affects BPF CI and bpf tree, targeting this for bpf tree.
      
      Fixes: 5854a09b
      
       ("net/ipv4: Use __DECLARE_FLEX_ARRAY() helper")
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
      Cc: Jakub Kicinski <kuba@kernel.org>
      Link: https://lore.kernel.org/bpf/20221102182517.2675301-1-andrii@kernel.org
      aec1dc97
    • Paolo Abeni's avatar
      Merge branch 'vsock-remove-an-unused-variable-and-fix-infinite-sleep' · 715aee0f
      Paolo Abeni authored
      Dexuan Cui says:
      
      ====================
      vsock: remove an unused variable and fix infinite sleep
      
      Patch 1 removes the unused 'wait' variable.
      Patch 2 fixes an infinite sleep issue reported by a hv_sock user.
      ====================
      
      Link: https://lore.kernel.org/r/20221101021706.26152-1-decui@microsoft.com
      
      
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      715aee0f
    • Dexuan Cui's avatar
      vsock: fix possible infinite sleep in vsock_connectible_wait_data() · 466a8533
      Dexuan Cui authored
      Currently vsock_connectible_has_data() may miss a wakeup operation
      between vsock_connectible_has_data() == 0 and the prepare_to_wait().
      
      Fix the race by adding the process to the wait queue before checking
      vsock_connectible_has_data().
      
      Fixes: b3f7fd54
      
       ("af_vsock: separate wait data loop")
      Signed-off-by: default avatarDexuan Cui <decui@microsoft.com>
      Reviewed-by: default avatarStefano Garzarella <sgarzare@redhat.com>
      Reported-by: default avatarFrédéric Dalleau <frederic.dalleau@docker.com>
      Tested-by: default avatarFrédéric Dalleau <frederic.dalleau@docker.com>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      466a8533
    • Dexuan Cui's avatar
      vsock: remove the unused 'wait' in vsock_connectible_recvmsg() · cf6ff0df
      Dexuan Cui authored
      Remove the unused variable introduced by 19c1b90e.
      
      Fixes: 19c1b90e
      
       ("af_vsock: separate receive data loop")
      Signed-off-by: default avatarDexuan Cui <decui@microsoft.com>
      Reviewed-by: default avatarStefano Garzarella <sgarzare@redhat.com>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      cf6ff0df
    • Zhengchao Shao's avatar
      ipv6: fix WARNING in ip6_route_net_exit_late() · 768b3c74
      Zhengchao Shao authored
      During the initialization of ip6_route_net_init_late(), if file
      ipv6_route or rt6_stats fails to be created, the initialization is
      successful by default. Therefore, the ipv6_route or rt6_stats file
      doesn't be found during the remove in ip6_route_net_exit_late(). It
      will cause WRNING.
      
      The following is the stack information:
      name 'rt6_stats'
      WARNING: CPU: 0 PID: 9 at fs/proc/generic.c:712 remove_proc_entry+0x389/0x460
      Modules linked in:
      Workqueue: netns cleanup_net
      RIP: 0010:remove_proc_entry+0x389/0x460
      PKRU: 55555554
      Call Trace:
      <TASK>
      ops_exit_list+0xb0/0x170
      cleanup_net+0x4ea/0xb00
      process_one_work+0x9bf/0x1710
      worker_thread+0x665/0x1080
      kthread+0x2e4/0x3a0
      ret_from_fork+0x1f/0x30
      </TASK>
      
      Fixes: cdb18761
      
       ("[NETNS][IPV6] route6 - create route6 proc files for the namespace")
      Signed-off-by: default avatarZhengchao Shao <shaozhengchao@huawei.com>
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Link: https://lore.kernel.org/r/20221102020610.351330-1-shaozhengchao@huawei.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      768b3c74
    • Ido Schimmel's avatar
      bridge: Fix flushing of dynamic FDB entries · 628ac04a
      Ido Schimmel authored
      The following commands should result in all the dynamic FDB entries
      being flushed, but instead all the non-local (non-permanent) entries are
      flushed:
      
       # bridge fdb add 00:aa:bb:cc:dd:ee dev dummy1 master static
       # bridge fdb add 00:11:22:33:44:55 dev dummy1 master dynamic
       # ip link set dev br0 type bridge fdb_flush
       # bridge fdb show brport dummy1
       00:00:00:00:00:01 master br0 permanent
       33:33:00:00:00:01 self permanent
       01:00:5e:00:00:01 self permanent
      
      This is because br_fdb_flush() works with FDB flags and not the
      corresponding enumerator values. Fix by passing the FDB flag instead.
      
      After the fix:
      
       # bridge fdb add 00:aa:bb:cc:dd:ee dev dummy1 master static
       # bridge fdb add 00:11:22:33:44:55 dev dummy1 master dynamic
       # ip link set dev br0 type bridge fdb_flush
       # bridge fdb show brport dummy1
       00:aa:bb:cc:dd:ee master br0 static
       00:00:00:00:00:01 master br0 permanent
       33:33:00:00:00:01 self permanent
       01:00:5e:00:00:01 self permanent
      
      Fixes: 1f78ee14
      
       ("net: bridge: fdb: add support for fine-grained flushing")
      Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
      Acked-by: default avatarNikolay Aleksandrov <razor@blackwall.org>
      Link: https://lore.kernel.org/r/20221101185753.2120691-1-idosch@nvidia.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      628ac04a
    • Chen Zhongjin's avatar
      net, neigh: Fix null-ptr-deref in neigh_table_clear() · f8017317
      Chen Zhongjin authored
      When IPv6 module gets initialized but hits an error in the middle,
      kenel panic with:
      
      KASAN: null-ptr-deref in range [0x0000000000000598-0x000000000000059f]
      CPU: 1 PID: 361 Comm: insmod
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)
      RIP: 0010:__neigh_ifdown.isra.0+0x24b/0x370
      RSP: 0018:ffff888012677908 EFLAGS: 00000202
      ...
      Call Trace:
       <TASK>
       neigh_table_clear+0x94/0x2d0
       ndisc_cleanup+0x27/0x40 [ipv6]
       inet6_init+0x21c/0x2cb [ipv6]
       do_one_initcall+0xd3/0x4d0
       do_init_module+0x1ae/0x670
      ...
      Kernel panic - not syncing: Fatal exception
      
      When ipv6 initialization fails, it will try to cleanup and calls:
      
      neigh_table_clear()
        neigh_ifdown(tbl, NULL)
          pneigh_queue_purge(&tbl->proxy_queue, dev_net(dev == NULL))
          # dev_net(NULL) triggers null-ptr-deref.
      
      Fix it by passing NULL to pneigh_queue_purge() in neigh_ifdown() if dev
      is NULL, to make kernel not panic immediately.
      
      Fixes: 66ba215c
      
       ("neigh: fix possible DoS due to net iface start/stop loop")
      Signed-off-by: default avatarChen Zhongjin <chenzhongjin@huawei.com>
      Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
      Reviewed-by: default avatarDenis V. Lunev <den@openvz.org>
      Link: https://lore.kernel.org/r/20221101121552.21890-1-chenzhongjin@huawei.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      f8017317
    • Chen Zhongjin's avatar
      net/smc: Fix possible leaked pernet namespace in smc_init() · 62ff373d
      Chen Zhongjin authored
      In smc_init(), register_pernet_subsys(&smc_net_stat_ops) is called
      without any error handling.
      If it fails, registering of &smc_net_ops won't be reverted.
      And if smc_nl_init() fails, &smc_net_stat_ops itself won't be reverted.
      
      This leaves wild ops in subsystem linkedlist and when another module
      tries to call register_pernet_operations() it triggers page fault:
      
      BUG: unable to handle page fault for address: fffffbfff81b964c
      RIP: 0010:register_pernet_operations+0x1b9/0x5f0
      Call Trace:
        <TASK>
        register_pernet_subsys+0x29/0x40
        ebtables_init+0x58/0x1000 [ebtables]
        ...
      
      Fixes: 194730a9
      
       ("net/smc: Make SMC statistics network namespace aware")
      Signed-off-by: default avatarChen Zhongjin <chenzhongjin@huawei.com>
      Reviewed-by: default avatarTony Lu <tonylu@linux.alibaba.com>
      Reviewed-by: default avatarWenjia Zhang <wenjia@linux.ibm.com>
      Link: https://lore.kernel.org/r/20221101093722.127223-1-chenzhongjin@huawei.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      62ff373d
    • Liu Peibao's avatar
      stmmac: dwmac-loongson: fix invalid mdio_node · 2ae34111
      Liu Peibao authored
      In current code "plat->mdio_node" is always NULL, the mdio
      support is lost as there is no "mdio_bus_data". The original
      driver could work as the "mdio" variable is never set to
      false, which is described in commit <b0e03950> ("stmmac:
      dwmac-loongson: fix uninitialized variable ......"). And
      after this commit merged, the "mdio" variable is always
      false, causing the mdio supoort logic lost.
      
      Fixes: 30bba69d
      
       ("stmmac: pci: Add dwmac support for Loongson")
      Signed-off-by: default avatarLiu Peibao <liupeibao@loongson.cn>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Link: https://lore.kernel.org/r/20221101060218.16453-1-liupeibao@loongson.cn
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      2ae34111
    • Nick Child's avatar
      ibmvnic: Free rwi on reset success · d6dd2fe7
      Nick Child authored
      Free the rwi structure in the event that the last rwi in the list
      processed successfully. The logic in commit 4f408e1f ("ibmvnic:
      retry reset if there are no other resets") introduces an issue that
      results in a 32 byte memory leak whenever the last rwi in the list
      gets processed.
      
      Fixes: 4f408e1f
      
       ("ibmvnic: retry reset if there are no other resets")
      Signed-off-by: default avatarNick Child <nnac123@linux.ibm.com>
      Link: https://lore.kernel.org/r/20221031150642.13356-1-nnac123@linux.ibm.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      d6dd2fe7
    • Gaosheng Cui's avatar
      net: mdio: fix undefined behavior in bit shift for __mdiobus_register · 40e4eb32
      Gaosheng Cui authored
      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 drivers/net/phy/mdio_bus.c:586:27
      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
       __mdiobus_register+0x49d/0x4e0
       fixed_mdio_bus_init+0xd8/0x12d
       do_one_initcall+0x76/0x430
       kernel_init_freeable+0x3b3/0x422
       kernel_init+0x24/0x1e0
       ret_from_fork+0x1f/0x30
       </TASK>
      
      Fixes: 4fd5f812
      
       ("phylib: allow incremental scanning of an mii bus")
      Signed-off-by: default avatarGaosheng Cui <cuigaosheng1@huawei.com>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Link: https://lore.kernel.org/r/20221031132645.168421-1-cuigaosheng1@huawei.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      40e4eb32
    • Jakub Kicinski's avatar
      Merge git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf · dac1dc7e
      Jakub Kicinski authored
      Pablo Neira Ayuso says:
      
      ====================
      Netfilter/IPVS fixes for net
      
      1) netlink socket notifier might win race to release objects that are
         already pending to be released via commit release path, reported by
         syzbot.
      
      2) No need to postpone flow rule release to commit release path, this
         triggered the syzbot report, complementary fix to previous patch.
      
      3) Use explicit signed chars in IPVS to unbreak arm, from Jason A. Donenfeld.
      
      4) Missing check for proc entry creation failure in IPVS, from Zhengchao Shao.
      
      5) Incorrect error path handling when BPF NAT fails to register, from
         Chen Zhongjin.
      
      6) Prevent huge memory allocation in ipset hash types, from Jozsef Kadlecsik.
      
      Except the incorrect BPF NAT error path which is broken in 6.1-rc, anything
      else has been broken for several releases.
      
      * git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf:
        netfilter: ipset: enforce documented limit to prevent allocating huge memory
        netfilter: nf_nat: Fix possible memory leak in nf_nat_init()
        ipvs: fix WARNING in ip_vs_app_net_cleanup()
        ipvs: fix WARNING in __ip_vs_cleanup_batch()
        ipvs: use explicitly signed chars
        netfilter: nf_tables: release flow rule object from commit path
        netfilter: nf_tables: netlink notifier might race to release objects
      ====================
      
      Link: https://lore.kernel.org/r/20221102184659.2502-1-pablo@netfilter.org
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      dac1dc7e
    • Jakub Kicinski's avatar
      Merge tag 'for-net-2022-10-02' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth · ef1fdc93
      Jakub Kicinski authored
      Luiz Augusto von Dentz says:
      
      ====================
      bluetooth 2022-11-02
      
       - Fix memory leak in hci_vhci driver
       - Fix handling of skb on virtio_bt driver
       - Fix accepting connection for invalid L2CAP PSM
       - Fix attemting to access uninitialized memory
       - Fix use-after-free in l2cap_reassemble_sdu
       - Fix use-after-free in l2cap_conn_del
       - Fix handling of destination address type for CIS
       - Fix not restoring ISO buffer count on disconnect
      
      * tag 'for-net-2022-10-02' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth:
        Bluetooth: L2CAP: Fix attempting to access uninitialized memory
        Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm
        Bluetooth: L2CAP: Fix accepting connection request for invalid SPSM
        Bluetooth: hci_conn: Fix not restoring ISO buffer count on disconnect
        Bluetooth: L2CAP: Fix memory leak in vhci_write
        Bluetooth: L2CAP: fix use-after-free in l2cap_conn_del()
        Bluetooth: virtio_bt: Use skb_put to set length
        Bluetooth: hci_conn: Fix CIS connection dst_type handling
        Bluetooth: L2CAP: Fix use-after-free caused by l2cap_reassemble_sdu
      ====================
      
      Link: https://lore.kernel.org/r/20221102235927.3324891-1-luiz.dentz@gmail.com
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      ef1fdc93
    • 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: default avatar <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
    • Soenke Huster's avatar
      Bluetooth: virtio_bt: Use skb_put to set length · 160fbcf3
      Soenke Huster authored
      By using skb_put we ensure that skb->tail is set
      correctly. Currently, skb->tail is always zero, which
      leads to errors, such as the following page fault in
      rfcomm_recv_frame:
      
          BUG: unable to handle page fault for address: ffffed1021de29ff
          #PF: supervisor read access in kernel mode
          #PF: error_code(0x0000) - not-present page
          RIP: 0010:rfcomm_run+0x831/0x4040 (net/bluetooth/rfcomm/core.c:1751)
      
      Fixes: afd2daa2
      
       ("Bluetooth: Add support for virtio transport driver")
      Signed-off-by: default avatarSoenke Huster <soenke.huster@eknoes.de>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      160fbcf3
    • Pauli Virtanen's avatar
      Bluetooth: hci_conn: Fix CIS connection dst_type handling · b36a234d
      Pauli Virtanen authored
      hci_connect_cis and iso_connect_cis call hci_bind_cis inconsistently
      with dst_type being either ISO socket address type or the HCI type, but
      these values cannot be mixed like this. Fix this by using only the HCI
      type.
      
      CIS connection dst_type was also not initialized in hci_bind_cis, even
      though it is used in hci_conn_hash_lookup_cis to find existing
      connections.  Set the value in hci_bind_cis, so that existing CIS
      connections are found e.g. when doing deferred socket connections, also
      when dst_type is not 0 (ADDR_LE_DEV_PUBLIC).
      
      Fixes: 26afbd82
      
       ("Bluetooth: Add initial implementation of CIS connections")
      Signed-off-by: default avatarPauli Virtanen <pav@iki.fi>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      b36a234d
    • Maxim Mikityanskiy's avatar
      Bluetooth: L2CAP: Fix use-after-free caused by l2cap_reassemble_sdu · 3aff8aac
      Maxim Mikityanskiy authored
      Fix the race condition between the following two flows that run in
      parallel:
      
      1. l2cap_reassemble_sdu -> chan->ops->recv (l2cap_sock_recv_cb) ->
         __sock_queue_rcv_skb.
      
      2. bt_sock_recvmsg -> skb_recv_datagram, skb_free_datagram.
      
      An SKB can be queued by the first flow and immediately dequeued and
      freed by the second flow, therefore the callers of l2cap_reassemble_sdu
      can't use the SKB after that function returns. However, some places
      continue accessing struct l2cap_ctrl that resides in the SKB's CB for a
      short time after l2cap_reassemble_sdu returns, leading to a
      use-after-free condition (the stack trace is below, line numbers for
      kernel 5.19.8).
      
      Fix it by keeping a local copy of struct l2cap_ctrl.
      
      BUG: KASAN: use-after-free in l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth
      Read of size 1 at addr ffff88812025f2f0 by task kworker/u17:3/43169
      
      Workqueue: hci0 hci_rx_work [bluetooth]
      Call Trace:
       <TASK>
       dump_stack_lvl (lib/dump_stack.c:107 (discriminator 4))
       print_report.cold (mm/kasan/report.c:314 mm/kasan/report.c:429)
       ? l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth
       kasan_report (mm/kasan/report.c:162 mm/kasan/report.c:493)
       ? l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth
       l2cap_rx_state_recv (net/bluetooth/l2cap_core.c:6906) bluetooth
       l2cap_rx (net/bluetooth/l2cap_core.c:7236 net/bluetooth/l2cap_core.c:7271) bluetooth
       ret_from_fork (arch/x86/entry/entry_64.S:306)
       </TASK>
      
      Allocated by task 43169:
       kasan_save_stack (mm/kasan/common.c:39)
       __kasan_slab_alloc (mm/kasan/common.c:45 mm/kasan/common.c:436 mm/kasan/common.c:469)
       kmem_cache_alloc_node (mm/slab.h:750 mm/slub.c:3243 mm/slub.c:3293)
       __alloc_skb (net/core/skbuff.c:414)
       l2cap_recv_frag (./include/net/bluetooth/bluetooth.h:425 net/bluetooth/l2cap_core.c:8329) bluetooth
       l2cap_recv_acldata (net/bluetooth/l2cap_core.c:8442) bluetooth
       hci_rx_work (net/bluetooth/hci_core.c:3642 net/bluetooth/hci_core.c:3832) bluetooth
       process_one_work (kernel/workqueue.c:2289)
       worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2437)
       kthread (kernel/kthread.c:376)
       ret_from_fork (arch/x86/entry/entry_64.S:306)
      
      Freed by task 27920:
       kasan_save_stack (mm/kasan/common.c:39)
       kasan_set_track (mm/kasan/common.c:45)
       kasan_set_free_info (mm/kasan/generic.c:372)
       ____kasan_slab_free (mm/kasan/common.c:368 mm/kasan/common.c:328)
       slab_free_freelist_hook (mm/slub.c:1780)
       kmem_cache_free (mm/slub.c:3536 mm/slub.c:3553)
       skb_free_datagram (./include/net/sock.h:1578 ./include/net/sock.h:1639 net/core/datagram.c:323)
       bt_sock_recvmsg (net/bluetooth/af_bluetooth.c:295) bluetooth
       l2cap_sock_recvmsg (net/bluetooth/l2cap_sock.c:1212) bluetooth
       sock_read_iter (net/socket.c:1087)
       new_sync_read (./include/linux/fs.h:2052 fs/read_write.c:401)
       vfs_read (fs/read_write.c:482)
       ksys_read (fs/read_write.c:620)
       do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80)
       entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:120)
      
      Link: https://lore.kernel.org/linux-bluetooth/CAKErNvoqga1WcmoR3-0875esY6TVWFQDandbVZncSiuGPBQXLA@mail.gmail.com/T/#u
      Fixes: d2a7ac5d ("Bluetooth: Add the ERTM receive state machine")
      Fixes: 4b51dae9
      
       ("Bluetooth: Add streaming mode receive and incoming packet classifier")
      Signed-off-by: default avatarMaxim Mikityanskiy <maxtram95@gmail.com>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      3aff8aac
    • Linus Torvalds's avatar
      Merge tag 'parisc-for-6.1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux · 8e5423e9
      Linus Torvalds authored
      Pull parisc architecture fixes from Helge Deller:
       "This mostly handles oddities with the serial port 8250_gsc.c driver.
      
        Although the name suggests it's just for serial ports on the GSC bus
        (e.g. in older PA-RISC machines), it handles serial ports on PA-RISC
        PCI devices (e.g. on the SuperIO chip) as well.
      
        Thus this renames the driver to 8250_parisc and fixes the config
        dependencies.
      
        The other change is a cleanup on how the device IDs of devices in a
        PA-RISC machine are shown at startup"
      
      * tag 'parisc-for-6.1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux:
        parisc: Avoid printing the hardware path twice
        parisc: Export iosapic_serial_irq() symbol for serial port driver
        MAINTAINERS: adjust entry after renaming parisc serial driver
        parisc: Use signed char for hardware path in pdc.h
        parisc/serial: Rename 8250_gsc.c to 8250_parisc.c
        parisc: Make 8250_gsc driver dependend on CONFIG_PARISC
      8e5423e9