History

Merge tag 'net-6.17-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net

Pull networking fixes from Paolo Abeni: "Including fixes from Bluetooth, IPsec and CAN. No known regressions at this point. Current release - regressions: - xfrm: xfrm_alloc_spi shouldn't use 0 as SPI Previous releases - regressions: - xfrm: fix offloading of cross-family tunnels - bluetooth: fix several races leading to UaFs - dsa: lantiq_gswip: fix FDB entries creation for the CPU port - eth: - tun: update napi->skb after XDP process - mlx: fix UAF in flow counter release Previous releases - always broken: - core: forbid FDB status change while nexthop is in a group - smc: fix warning in smc_rx_splice() when calling get_page() - can: provide missing ndo_change_mtu(), to prevent buffer overflow. - eth: - i40e: fix VF config validation - broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl" * tag 'net-6.17-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net: (40 commits) octeontx2-pf: Fix potential use after free in otx2_tc_add_flow() net: dsa: lantiq_gswip: suppress -EINVAL errors for bridge FDB entries added to the CPU port net: dsa: lantiq_gswip: move gswip_add_single_port_br() call to port_setup() libie: fix string names for AQ error codes net/mlx5e: Fix missing FEC RS stats for RS_544_514_INTERLEAVED_QUAD net/mlx5: HWS, ignore flow level for multi-dest table net/mlx5: fs, fix UAF in flow counter release selftests: fib_nexthops: Add test cases for FDB status change selftests: fib_nexthops: Fix creation of non-FDB nexthops nexthop: Forbid FDB status change while nexthop is in a group net: allow alloc_skb_with_frags() to use MAX_SKB_FRAGS bnxt_en: correct offset handling for IPv6 destination address ptp: document behavior of PTP_STRICT_FLAGS broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl broadcom: fix support for PTP_PEROUT_DUTY_CYCLE Bluetooth: MGMT: Fix possible UAFs Bluetooth: hci_event: Fix UAF in hci_acl_create_conn_sync Bluetooth: hci_event: Fix UAF in hci_conn_tx_dequeue Bluetooth: hci_sync: Fix hci_resume_advertising_sync Bluetooth: Fix build after header cleanup ...

Linus Torvalds committed 1 year ago

Commit 4ff71af2 parents 93a2744 d9c70e941 files · +548 −201Browse files

Unified · Split

41 files
  1. drivers/bluetooth/Kconfig +6 −0
  2. drivers/bluetooth/hci_uart.h +4 −4
  3. drivers/net/can/rcar/rcar_canfd.c +4 −3
  4. drivers/net/can/spi/hi311x.c +18 −16
  5. drivers/net/can/sun4i_can.c +1 −0
  6. drivers/net/can/usb/etas_es58x/es58x_core.c +2 −1
  7. drivers/net/can/usb/mcba_usb.c +1 −0
  8. drivers/net/can/usb/peak_usb/pcan_usb_core.c +1 −1
  9. drivers/net/dsa/lantiq_gswip.c +16 −5
  10. drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c +1 −1
  11. drivers/net/ethernet/intel/i40e/i40e.h +2 −1
  12. drivers/net/ethernet/intel/i40e/i40e_main.c +22 −4
  13. drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +64 −46
  14. drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h +2 −1
  15. drivers/net/ethernet/intel/libie/adminq.c +1 −1
  16. drivers/net/ethernet/marvell/octeontx2/af/cgx.c +1 −2
  17. drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +1 −1
  18. drivers/net/ethernet/mellanox/mlx5/core/en_stats.c +1 −0
  19. drivers/net/ethernet/mellanox/mlx5/core/fs_core.c +1 −1
  20. drivers/net/ethernet/mellanox/mlx5/core/fs_core.h +1 −0
  21. drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c +22 −3
  22. drivers/net/ethernet/mellanox/mlx5/core/steering/hws/action.c +2 −2
  23. drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c +3 −8
  24. drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws_pools.c +7 −1
  25. drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws.h +1 −2
  26. drivers/net/phy/bcm-phy-ptp.c +2 −4
  27. drivers/net/tun.c +3 −0
  28. include/linux/mlx5/fs.h +2 −0
  29. include/net/bluetooth/hci_core.h +21 −0
  30. include/uapi/linux/ptp_clock.h +3 −0
  31. net/bluetooth/hci_event.c +27 −3
  32. net/bluetooth/hci_sync.c +7 −0
  33. net/bluetooth/mgmt.c +182 −77
  34. net/bluetooth/mgmt_util.c +46 −0
  35. net/bluetooth/mgmt_util.h +3 −0
  36. net/core/skbuff.c +1 −1
  37. net/ipv4/nexthop.c +7 −0
  38. net/smc/smc_loopback.c +9 −5
  39. net/xfrm/xfrm_device.c +1 −1
  40. net/xfrm/xfrm_state.c +3 −0
  41. tools/testing/selftests/net/fib_nexthops.sh +46 −6
drivers/bluetooth/Kconfig+6−0
@@ -312,7 +312,9 @@ config BT_HCIBCM4377 · 311 unmodified lines
312312
313313 config BT_HCIBPA10X
314314 tristate "HCI BPA10x USB driver"
315+ depends on BT_HCIUART
315316 depends on USB
317+ select BT_HCIUART_H4
316318 help
317319 Bluetooth HCI BPA10x USB driver.
318320 This driver provides support for the Digianswer BPA 100/105 Bluetooth
@@ -437,8 +439,10 @@ config BT_MTKSDIO · 118 unmodified lines
437439
438440 config BT_MTKUART
439441 tristate "MediaTek HCI UART driver"
442+ depends on BT_HCIUART
440443 depends on SERIAL_DEV_BUS
441444 depends on USB || !BT_HCIBTUSB_MTK
445+ select BT_HCIUART_H4
442446 select BT_MTK
443447 help
444448 MediaTek Bluetooth HCI UART driver.
@@ -483,7 +487,9 @@ config BT_VIRTIO · 38 unmodified lines
483487
484488 config BT_NXPUART
485489 tristate "NXP protocol support"
490+ depends on BT_HCIUART
486491 depends on SERIAL_DEV_BUS
492+ select BT_HCIUART_H4
487493 select CRC32
488494 select CRC8
489495 help
drivers/bluetooth/hci_uart.h+4−4
@@ -121,10 +121,6 @@ void hci_uart_set_flow_control(struct hci_uart *hu, bool enable); · 120 unmodified lines
121121 void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed,
122122 unsigned int oper_speed);
123123
124−#ifdef CONFIG_BT_HCIUART_H4
125−int h4_init(void);
126−int h4_deinit(void);
127−
128124 struct h4_recv_pkt {
129125 u8 type; /* Packet type */
130126 u8 hlen; /* Header length */
@@ -162,6 +158,10 @@ struct h4_recv_pkt { · 31 unmodified lines
162158 .lsize = 2, \
163159 .maxlen = HCI_MAX_FRAME_SIZE \
164160
161+#ifdef CONFIG_BT_HCIUART_H4
162+int h4_init(void);
163+int h4_deinit(void);
164+
165165 struct sk_buff *h4_recv_buf(struct hci_dev *hdev, struct sk_buff *skb,
166166 const unsigned char *buffer, int count,
167167 const struct h4_recv_pkt *pkts, int pkts_count);
drivers/net/can/rcar/rcar_canfd.c+4−3
@@ -823,9 +823,6 @@ static int rcar_canfd_reset_controller(struct rcar_canfd_global *gpriv) · 822 unmodified lines
823823 /* Reset Global error flags */
824824 rcar_canfd_write(gpriv->base, RCANFD_GERFL, 0x0);
825825
826− /* Set the controller into appropriate mode */
827− rcar_canfd_set_mode(gpriv);
828−
829826 /* Transition all Channels to reset mode */
830827 for_each_set_bit(ch, &gpriv->channels_mask, gpriv->info->max_channels) {
831828 rcar_canfd_clear_bit(gpriv->base,
@@ -844,6 +841,10 @@ static int rcar_canfd_reset_controller(struct rcar_canfd_global *gpriv) · 12 unmodified lines
844841 return err;
845842 }
846843 }
844+
845+ /* Set the controller into appropriate mode */
846+ rcar_canfd_set_mode(gpriv);
847+
847848 return 0;
848849 }
849850
drivers/net/can/spi/hi311x.c+18−16
@@ -545,8 +545,6 @@ static int hi3110_stop(struct net_device *net) · 544 unmodified lines
545545
546546 priv->force_quit = 1;
547547 free_irq(spi->irq, priv);
548− destroy_workqueue(priv->wq);
549− priv->wq = NULL;
550548
551549 mutex_lock(&priv->hi3110_lock);
552550
@@ -770,34 +768,23 @@ static int hi3110_open(struct net_device *net) · 217 unmodified lines
770768 goto out_close;
771769 }
772770
773− priv->wq = alloc_workqueue("hi3110_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM,
774− 0);
775− if (!priv->wq) {
776− ret = -ENOMEM;
777− goto out_free_irq;
778− }
779− INIT_WORK(&priv->tx_work, hi3110_tx_work_handler);
780− INIT_WORK(&priv->restart_work, hi3110_restart_work_handler);
781−
782771 ret = hi3110_hw_reset(spi);
783772 if (ret)
784− goto out_free_wq;
773+ goto out_free_irq;
785774
786775 ret = hi3110_setup(net);
787776 if (ret)
788− goto out_free_wq;
777+ goto out_free_irq;
789778
790779 ret = hi3110_set_normal_mode(spi);
791780 if (ret)
792− goto out_free_wq;
781+ goto out_free_irq;
793782
794783 netif_wake_queue(net);
795784 mutex_unlock(&priv->hi3110_lock);
796785
797786 return 0;
798787
799− out_free_wq:
800− destroy_workqueue(priv->wq);
801788 out_free_irq:
802789 free_irq(spi->irq, priv);
803790 hi3110_hw_sleep(spi);
@@ -812,6 +799,7 @@ static const struct net_device_ops hi3110_netdev_ops = { · 8 unmodified lines
812799 .ndo_open = hi3110_open,
813800 .ndo_stop = hi3110_stop,
814801 .ndo_start_xmit = hi3110_hard_start_xmit,
802+ .ndo_change_mtu = can_change_mtu,
815803 };
816804
817805 static const struct ethtool_ops hi3110_ethtool_ops = {
@@ -908,6 +896,15 @@ static int hi3110_can_probe(struct spi_device *spi) · 90 unmodified lines
908896 if (ret)
909897 goto out_clk;
910898
899+ priv->wq = alloc_workqueue("hi3110_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM,
900+ 0);
901+ if (!priv->wq) {
902+ ret = -ENOMEM;
903+ goto out_clk;
904+ }
905+ INIT_WORK(&priv->tx_work, hi3110_tx_work_handler);
906+ INIT_WORK(&priv->restart_work, hi3110_restart_work_handler);
907+
911908 priv->spi = spi;
912909 mutex_init(&priv->hi3110_lock);
913910
@@ -943,6 +940,8 @@ static int hi3110_can_probe(struct spi_device *spi) · 29 unmodified lines
943940 return 0;
944941
945942 error_probe:
943+ destroy_workqueue(priv->wq);
944+ priv->wq = NULL;
946945 hi3110_power_enable(priv->power, 0);
947946
948947 out_clk:
@@ -963,6 +962,9 @@ static void hi3110_can_remove(struct spi_device *spi) · 14 unmodified lines
963962
964963 hi3110_power_enable(priv->power, 0);
965964
965+ destroy_workqueue(priv->wq);
966+ priv->wq = NULL;
967+
966968 clk_disable_unprepare(priv->clk);
967969
968970 free_candev(net);
drivers/net/can/sun4i_can.c+1−0
@@ -768,6 +768,7 @@ static const struct net_device_ops sun4ican_netdev_ops = { · 767 unmodified lines
768768 .ndo_open = sun4ican_open,
769769 .ndo_stop = sun4ican_close,
770770 .ndo_start_xmit = sun4ican_start_xmit,
771+ .ndo_change_mtu = can_change_mtu,
771772 };
772773
773774 static const struct ethtool_ops sun4ican_ethtool_ops = {
drivers/net/can/usb/etas_es58x/es58x_core.c+2−1
@@ -7,7 +7,7 @@ · 6 unmodified lines
77 *
88 * Copyright (c) 2019 Robert Bosch Engineering and Business Solutions. All rights reserved.
99 * Copyright (c) 2020 ETAS K.K.. All rights reserved.
10− * Copyright (c) 2020-2022 Vincent Mailhol <mailhol.vincent@wanadoo.fr>
10+ * Copyright (c) 2020-2025 Vincent Mailhol <mailhol@kernel.org>
1111 */
1212
1313 #include <linux/unaligned.h>
@@ -1977,6 +1977,7 @@ static const struct net_device_ops es58x_netdev_ops = { · 1963 unmodified lines
19771977 .ndo_stop = es58x_stop,
19781978 .ndo_start_xmit = es58x_start_xmit,
19791979 .ndo_eth_ioctl = can_eth_ioctl_hwts,
1980+ .ndo_change_mtu = can_change_mtu,
19801981 };
19811982
19821983 static const struct ethtool_ops es58x_ethtool_ops = {
drivers/net/can/usb/mcba_usb.c+1−0
@@ -761,6 +761,7 @@ static const struct net_device_ops mcba_netdev_ops = { · 760 unmodified lines
761761 .ndo_open = mcba_usb_open,
762762 .ndo_stop = mcba_usb_close,
763763 .ndo_start_xmit = mcba_usb_start_xmit,
764+ .ndo_change_mtu = can_change_mtu,
764765 };
765766
766767 static const struct ethtool_ops mcba_ethtool_ops = {
drivers/net/can/usb/peak_usb/pcan_usb_core.c+1−1
@@ -111,7 +111,7 @@ void peak_usb_update_ts_now(struct peak_time_ref *time_ref, u32 ts_now) · 110 unmodified lines
111111 u32 delta_ts = time_ref->ts_dev_2 - time_ref->ts_dev_1;
112112
113113 if (time_ref->ts_dev_2 < time_ref->ts_dev_1)
114− delta_ts &= (1 << time_ref->adapter->ts_used_bits) - 1;
114+ delta_ts &= (1ULL << time_ref->adapter->ts_used_bits) - 1;
115115
116116 time_ref->ts_total += delta_ts;
117117 }
drivers/net/dsa/lantiq_gswip.c+16−5
@@ -685,18 +685,27 @@ static int gswip_add_single_port_br(struct gswip_priv *priv, int port, bool add) · 684 unmodified lines
685685 return 0;
686686 }
687687
688−static int gswip_port_enable(struct dsa_switch *ds, int port,
689− struct phy_device *phydev)
688+static int gswip_port_setup(struct dsa_switch *ds, int port)
690689 {
691690 struct gswip_priv *priv = ds->priv;
692691 int err;
693692
694693 if (!dsa_is_cpu_port(ds, port)) {
695− u32 mdio_phy = 0;
696−
697694 err = gswip_add_single_port_br(priv, port, true);
698695 if (err)
699696 return err;
697+ }
698+
699+ return 0;
700+}
701+
702+static int gswip_port_enable(struct dsa_switch *ds, int port,
703+ struct phy_device *phydev)
704+{
705+ struct gswip_priv *priv = ds->priv;
706+
707+ if (!dsa_is_cpu_port(ds, port)) {
708+ u32 mdio_phy = 0;
700709
701710 if (phydev)
702711 mdio_phy = phydev->mdio.addr & GSWIP_MDIO_PHY_ADDR_MASK;
@@ -1359,8 +1368,9 @@ static int gswip_port_fdb(struct dsa_switch *ds, int port, · 656 unmodified lines
13591368 int i;
13601369 int err;
13611370
1371+ /* Operation not supported on the CPU port, don't throw errors */
13621372 if (!bridge)
1363− return -EINVAL;
1373+ return 0;
13641374
13651375 for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
13661376 if (priv->vlans[i].bridge == bridge) {
@@ -1829,6 +1839,7 @@ static const struct phylink_mac_ops gswip_phylink_mac_ops = { · 462 unmodified lines
18291839 static const struct dsa_switch_ops gswip_xrx200_switch_ops = {
18301840 .get_tag_protocol = gswip_get_tag_protocol,
18311841 .setup = gswip_setup,
1842+ .port_setup = gswip_port_setup,
18321843 .port_enable = gswip_port_enable,
18331844 .port_disable = gswip_port_disable,
18341845 .port_bridge_join = gswip_port_bridge_join,
drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c+1−1
@@ -244,7 +244,7 @@ bnxt_tc_parse_pedit(struct bnxt *bp, struct bnxt_tc_actions *actions, · 243 unmodified lines
244244 offset < offset_of_ip6_daddr + 16) {
245245 actions->nat.src_xlate = false;
246246 idx = (offset - offset_of_ip6_daddr) / 4;
247− actions->nat.l3.ipv6.saddr.s6_addr32[idx] = htonl(val);
247+ actions->nat.l3.ipv6.daddr.s6_addr32[idx] = htonl(val);
248248 } else {
249249 netdev_err(bp->dev,
250250 "%s: IPv6_hdr: Invalid pedit field\n",
drivers/net/ethernet/intel/i40e/i40e.h+2−1
@@ -1278,7 +1278,8 @@ struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi, · 1277 unmodified lines
12781278 const u8 *macaddr);
12791279 int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr);
12801280 bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi);
1281−int i40e_count_filters(struct i40e_vsi *vsi);
1281+int i40e_count_all_filters(struct i40e_vsi *vsi);
1282+int i40e_count_active_filters(struct i40e_vsi *vsi);
12821283 struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr);
12831284 void i40e_vlan_stripping_enable(struct i40e_vsi *vsi);
12841285 static inline bool i40e_is_sw_dcb(struct i40e_pf *pf)
drivers/net/ethernet/intel/i40e/i40e_main.c+22−4
@@ -1243,12 +1243,30 @@ void i40e_update_stats(struct i40e_vsi *vsi) · 1242 unmodified lines
12431243 }
12441244
12451245 /**
1246− * i40e_count_filters - counts VSI mac filters
1246+ * i40e_count_all_filters - counts VSI MAC filters
12471247 * @vsi: the VSI to be searched
12481248 *
1249− * Returns count of mac filters
1250− **/
1251−int i40e_count_filters(struct i40e_vsi *vsi)
1249+ * Return: count of MAC filters in any state.
1250+ */
1251+int i40e_count_all_filters(struct i40e_vsi *vsi)
1252+{
1253+ struct i40e_mac_filter *f;
1254+ struct hlist_node *h;
1255+ int bkt, cnt = 0;
1256+
1257+ hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
1258+ cnt++;
1259+
1260+ return cnt;
1261+}
1262+
1263+/**
1264+ * i40e_count_active_filters - counts VSI MAC filters
1265+ * @vsi: the VSI to be searched
1266+ *
1267+ * Return: count of active MAC filters.
1268+ */
1269+int i40e_count_active_filters(struct i40e_vsi *vsi)
12521270 {
12531271 struct i40e_mac_filter *f;
12541272 struct hlist_node *h;
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c+64−46
@@ -448,7 +448,7 @@ static void i40e_config_irq_link_list(struct i40e_vf *vf, u16 vsi_id, · 447 unmodified lines
448448 (qtype << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
449449 (pf_queue_id << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
450450 BIT(I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) |
451− (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT);
451+ FIELD_PREP(I40E_QINT_RQCTL_ITR_INDX_MASK, itr_idx);
452452 wr32(hw, reg_idx, reg);
453453 }
454454
@@ -653,6 +653,13 @@ static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_id, · 198 unmodified lines
653653
654654 /* only set the required fields */
655655 tx_ctx.base = info->dma_ring_addr / 128;
656+
657+ /* ring_len has to be multiple of 8 */
658+ if (!IS_ALIGNED(info->ring_len, 8) ||
659+ info->ring_len > I40E_MAX_NUM_DESCRIPTORS_XL710) {
660+ ret = -EINVAL;
661+ goto error_context;
662+ }
656663 tx_ctx.qlen = info->ring_len;
657664 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]);
658665 tx_ctx.rdylist_act = 0;
@@ -716,6 +723,13 @@ static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id, · 57 unmodified lines
716723
717724 /* only set the required fields */
718725 rx_ctx.base = info->dma_ring_addr / 128;
726+
727+ /* ring_len has to be multiple of 32 */
728+ if (!IS_ALIGNED(info->ring_len, 32) ||
729+ info->ring_len > I40E_MAX_NUM_DESCRIPTORS_XL710) {
730+ ret = -EINVAL;
731+ goto error_param;
732+ }
719733 rx_ctx.qlen = info->ring_len;
720734
721735 if (info->splithdr_enabled) {
@@ -1450,6 +1464,7 @@ static void i40e_trigger_vf_reset(struct i40e_vf *vf, bool flr) · 728 unmodified lines
14501464 * functions that may still be running at this point.
14511465 */
14521466 clear_bit(I40E_VF_STATE_INIT, &vf->vf_states);
1467+ clear_bit(I40E_VF_STATE_RESOURCES_LOADED, &vf->vf_states);
14531468
14541469 /* In the case of a VFLR, the HW has already reset the VF and we
14551470 * just need to clean up, so don't hit the VFRTRIG register.
@@ -2116,7 +2131,10 @@ static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg) · 660 unmodified lines
21162131 size_t len = 0;
21172132 int ret;
21182133
2119− if (!i40e_sync_vf_state(vf, I40E_VF_STATE_INIT)) {
2134+ i40e_sync_vf_state(vf, I40E_VF_STATE_INIT);
2135+
2136+ if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states) ||
2137+ test_bit(I40E_VF_STATE_RESOURCES_LOADED, &vf->vf_states)) {
21202138 aq_ret = -EINVAL;
21212139 goto err;
21222140 }
@@ -2219,6 +2237,7 @@ static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg) · 96 unmodified lines
22192237 vf->default_lan_addr.addr);
22202238 }
22212239 set_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states);
2240+ set_bit(I40E_VF_STATE_RESOURCES_LOADED, &vf->vf_states);
22222241
22232242 err:
22242243 /* send the response back to the VF */
@@ -2381,7 +2400,7 @@ static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg) · 156 unmodified lines
23812400 }
23822401
23832402 if (vf->adq_enabled) {
2384− if (idx >= ARRAY_SIZE(vf->ch)) {
2403+ if (idx >= vf->num_tc) {
23852404 aq_ret = -ENODEV;
23862405 goto error_param;
23872406 }
@@ -2402,7 +2421,7 @@ static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg) · 14 unmodified lines
24022421 * to its appropriate VSIs based on TC mapping
24032422 */
24042423 if (vf->adq_enabled) {
2405− if (idx >= ARRAY_SIZE(vf->ch)) {
2424+ if (idx >= vf->num_tc) {
24062425 aq_ret = -ENODEV;
24072426 goto error_param;
24082427 }
@@ -2452,8 +2471,10 @@ static int i40e_validate_queue_map(struct i40e_vf *vf, u16 vsi_id, · 43 unmodified lines
24522471 u16 vsi_queue_id, queue_id;
24532472
24542473 for_each_set_bit(vsi_queue_id, &queuemap, I40E_MAX_VSI_QP) {
2455− if (vf->adq_enabled) {
2456− vsi_id = vf->ch[vsi_queue_id / I40E_MAX_VF_VSI].vsi_id;
2474+ u16 idx = vsi_queue_id / I40E_MAX_VF_VSI;
2475+
2476+ if (vf->adq_enabled && idx < vf->num_tc) {
2477+ vsi_id = vf->ch[idx].vsi_id;
24572478 queue_id = (vsi_queue_id % I40E_DEFAULT_QUEUES_PER_VF);
24582479 } else {
24592480 queue_id = vsi_queue_id;
@@ -2841,24 +2862,6 @@ error_param: · 381 unmodified lines
28412862 (u8 *)&stats, sizeof(stats));
28422863 }
28432864
2844−/**
2845− * i40e_can_vf_change_mac
2846− * @vf: pointer to the VF info
2847− *
2848− * Return true if the VF is allowed to change its MAC filters, false otherwise
2849− */
2850−static bool i40e_can_vf_change_mac(struct i40e_vf *vf)
2851−{
2852− /* If the VF MAC address has been set administratively (via the
2853− * ndo_set_vf_mac command), then deny permission to the VF to
2854− * add/delete unicast MAC addresses, unless the VF is trusted
2855− */
2856− if (vf->pf_set_mac && !vf->trusted)
2857− return false;
2858−
2859− return true;
2860−}
2861−
28622865 #define I40E_MAX_MACVLAN_PER_HW 3072
28632866 #define I40E_MAX_MACVLAN_PER_PF(num_ports) (I40E_MAX_MACVLAN_PER_HW / \
28642867 (num_ports))
@@ -2897,8 +2900,10 @@ static inline int i40e_check_vf_permission(struct i40e_vf *vf, · 32 unmodified lines
28972900 struct i40e_pf *pf = vf->pf;
28982901 struct i40e_vsi *vsi = pf->vsi[vf->lan_vsi_idx];
28992902 struct i40e_hw *hw = &pf->hw;
2900− int mac2add_cnt = 0;
2901− int i;
2903+ int i, mac_add_max, mac_add_cnt = 0;
2904+ bool vf_trusted;
2905+
2906+ vf_trusted = test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
29022907
29032908 for (i = 0; i < al->num_elements; i++) {
29042909 struct i40e_mac_filter *f;
@@ -2918,9 +2923,8 @@ static inline int i40e_check_vf_permission(struct i40e_vf *vf, · 13 unmodified lines
29182923 * The VF may request to set the MAC address filter already
29192924 * assigned to it so do not return an error in that case.
29202925 */
2921− if (!i40e_can_vf_change_mac(vf) &&
2922− !is_multicast_ether_addr(addr) &&
2923− !ether_addr_equal(addr, vf->default_lan_addr.addr)) {
2926+ if (!vf_trusted && !is_multicast_ether_addr(addr) &&
2927+ vf->pf_set_mac && !ether_addr_equal(addr, vf->default_lan_addr.addr)) {
29242928 dev_err(&pf->pdev->dev,
29252929 "VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n");
29262930 return -EPERM;
@@ -2929,29 +2933,33 @@ static inline int i40e_check_vf_permission(struct i40e_vf *vf, · 2 unmodified lines
29292933 /*count filters that really will be added*/
29302934 f = i40e_find_mac(vsi, addr);
29312935 if (!f)
2932− ++mac2add_cnt;
2936+ ++mac_add_cnt;
29332937 }
29342938
29352939 /* If this VF is not privileged, then we can't add more than a limited
2936− * number of addresses. Check to make sure that the additions do not
2937− * push us over the limit.
2938− */
2939− if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
2940− if ((i40e_count_filters(vsi) + mac2add_cnt) >
2941− I40E_VC_MAX_MAC_ADDR_PER_VF) {
2942− dev_err(&pf->pdev->dev,
2943− "Cannot add more MAC addresses, VF is not trusted, switch the VF to trusted to add more functionality\n");
2944− return -EPERM;
2945− }
2946− /* If this VF is trusted, it can use more resources than untrusted.
2940+ * number of addresses.
2941+ *
2942+ * If this VF is trusted, it can use more resources than untrusted.
29472943 * However to ensure that every trusted VF has appropriate number of
29482944 * resources, divide whole pool of resources per port and then across
29492945 * all VFs.
29502946 */
2951− } else {
2952− if ((i40e_count_filters(vsi) + mac2add_cnt) >
2953− I40E_VC_MAX_MACVLAN_PER_TRUSTED_VF(pf->num_alloc_vfs,
2954− hw->num_ports)) {
2947+ if (!vf_trusted)
2948+ mac_add_max = I40E_VC_MAX_MAC_ADDR_PER_VF;
2949+ else
2950+ mac_add_max = I40E_VC_MAX_MACVLAN_PER_TRUSTED_VF(pf->num_alloc_vfs, hw->num_ports);
2951+
2952+ /* VF can replace all its filters in one step, in this case mac_add_max
2953+ * will be added as active and another mac_add_max will be in
2954+ * a to-be-removed state. Account for that.
2955+ */
2956+ if ((i40e_count_active_filters(vsi) + mac_add_cnt) > mac_add_max ||
2957+ (i40e_count_all_filters(vsi) + mac_add_cnt) > 2 * mac_add_max) {
2958+ if (!vf_trusted) {
2959+ dev_err(&pf->pdev->dev,
2960+ "Cannot add more MAC addresses, VF is not trusted, switch the VF to trusted to add more functionality\n");
2961+ return -EPERM;
2962+ } else {
29552963 dev_err(&pf->pdev->dev,
29562964 "Cannot add more MAC addresses, trusted VF exhausted it's resources\n");
29572965 return -EPERM;
@@ -3587,7 +3595,7 @@ static int i40e_validate_cloud_filter(struct i40e_vf *vf, · 629 unmodified lines
35873595
35883596 /* action_meta is TC number here to which the filter is applied */
35893597 if (!tc_filter->action_meta ||
3590− tc_filter->action_meta > vf->num_tc) {
3598+ tc_filter->action_meta >= vf->num_tc) {
35913599 dev_info(&pf->pdev->dev, "VF %d: Invalid TC number %u\n",
35923600 vf->vf_id, tc_filter->action_meta);
35933601 goto err;
@@ -3884,6 +3892,8 @@ err: · 290 unmodified lines
38843892 aq_ret);
38853893 }
38863894
3895+#define I40E_MAX_VF_CLOUD_FILTER 0xFF00
3896+
38873897 /**
38883898 * i40e_vc_add_cloud_filter
38893899 * @vf: pointer to the VF info
@@ -3923,6 +3933,14 @@ static int i40e_vc_add_cloud_filter(struct i40e_vf *vf, u8 *msg) · 33 unmodified lines
39233933 goto err_out;
39243934 }
39253935
3936+ if (vf->num_cloud_filters >= I40E_MAX_VF_CLOUD_FILTER) {
3937+ dev_warn(&pf->pdev->dev,
3938+ "VF %d: Max number of filters reached, can't apply cloud filter\n",
3939+ vf->vf_id);
3940+ aq_ret = -ENOSPC;
3941+ goto err_out;
3942+ }
3943+
39263944 cfilter = kzalloc(sizeof(*cfilter), GFP_KERNEL);
39273945 if (!cfilter) {
39283946 aq_ret = -ENOMEM;
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h+2−1
@@ -41,7 +41,8 @@ enum i40e_vf_states { · 40 unmodified lines
4141 I40E_VF_STATE_MC_PROMISC,
4242 I40E_VF_STATE_UC_PROMISC,
4343 I40E_VF_STATE_PRE_ENABLE,
44− I40E_VF_STATE_RESETTING
44+ I40E_VF_STATE_RESETTING,
45+ I40E_VF_STATE_RESOURCES_LOADED,
4546 };
4647
4748 /* VF capabilities */
drivers/net/ethernet/intel/libie/adminq.c+1−1
@@ -6,7 +6,7 @@ · 5 unmodified lines
66
77 static const char * const libie_aq_str_arr[] = {
88 #define LIBIE_AQ_STR(x) \
9− [LIBIE_AQ_RC_##x] = "LIBIE_AQ_RC" #x
9+ [LIBIE_AQ_RC_##x] = "LIBIE_AQ_RC_" #x
1010 LIBIE_AQ_STR(OK),
1111 LIBIE_AQ_STR(EPERM),
1212 LIBIE_AQ_STR(ENOENT),
drivers/net/ethernet/marvell/octeontx2/af/cgx.c+1−2
@@ -21,8 +21,7 @@ · 20 unmodified lines
2121 #include "rvu.h"
2222 #include "lmac_common.h"
2323
24−#define DRV_NAME "Marvell-CGX/RPM"
25−#define DRV_STRING "Marvell CGX/RPM Driver"
24+#define DRV_NAME "Marvell-CGX-RPM"
2625
2726 #define CGX_RX_STAT_GLOBAL_INDEX 9
2827
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c+1−1
@@ -1326,7 +1326,6 @@ static int otx2_tc_add_flow(struct otx2_nic *nic, · 1325 unmodified lines
13261326
13271327 free_leaf:
13281328 otx2_tc_del_from_flow_list(flow_cfg, new_node);
1329− kfree_rcu(new_node, rcu);
13301329 if (new_node->is_act_police) {
13311330 mutex_lock(&nic->mbox.lock);
13321331
@@ -1346,6 +1345,7 @@ free_leaf: · 13 unmodified lines
13461345
13471346 mutex_unlock(&nic->mbox.lock);
13481347 }
1348+ kfree_rcu(new_node, rcu);
13491349
13501350 return rc;
13511351 }
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c+1−0
@@ -1466,6 +1466,7 @@ static void fec_set_block_stats(struct mlx5e_priv *priv, · 1465 unmodified lines
14661466 case MLX5E_FEC_RS_528_514:
14671467 case MLX5E_FEC_RS_544_514:
14681468 case MLX5E_FEC_LLRS_272_257_1:
1469+ case MLX5E_FEC_RS_544_514_INTERLEAVED_QUAD:
14691470 fec_set_rs_stats(fec_stats, out);
14701471 return;
14711472 case MLX5E_FEC_FIRECODE:
drivers/net/ethernet/mellanox/mlx5/core/fs_core.c+1−1
@@ -663,7 +663,7 @@ static void del_sw_hw_rule(struct fs_node *node) · 662 unmodified lines
663663 BIT(MLX5_SET_FTE_MODIFY_ENABLE_MASK_ACTION) |
664664 BIT(MLX5_SET_FTE_MODIFY_ENABLE_MASK_FLOW_COUNTERS);
665665 fte->act_dests.action.action &= ~MLX5_FLOW_CONTEXT_ACTION_COUNT;
666− mlx5_fc_local_destroy(rule->dest_attr.counter);
666+ mlx5_fc_local_put(rule->dest_attr.counter);
667667 goto out;
668668 }
669669
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h+1−0
@@ -343,6 +343,7 @@ struct mlx5_fc { · 342 unmodified lines
343343 enum mlx5_fc_type type;
344344 struct mlx5_fc_bulk *bulk;
345345 struct mlx5_fc_cache cache;
346+ refcount_t fc_local_refcount;
346347 /* last{packets,bytes} are used for calculating deltas since last reading. */
347348 u64 lastpackets;
348349 u64 lastbytes;
drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c+22−3
@@ -562,17 +562,36 @@ mlx5_fc_local_create(u32 counter_id, u32 offset, u32 bulk_size) · 561 unmodified lines
562562 counter->id = counter_id;
563563 fc_bulk->base_id = counter_id - offset;
564564 fc_bulk->fs_bulk.bulk_len = bulk_size;
565+ refcount_set(&fc_bulk->hws_data.hws_action_refcount, 0);
566+ mutex_init(&fc_bulk->hws_data.lock);
565567 counter->bulk = fc_bulk;
568+ refcount_set(&counter->fc_local_refcount, 1);
566569 return counter;
567570 }
568571 EXPORT_SYMBOL(mlx5_fc_local_create);
569572
570573 void mlx5_fc_local_destroy(struct mlx5_fc *counter)
571574 {
572− if (!counter || counter->type != MLX5_FC_TYPE_LOCAL)
573− return;
574−
575575 kfree(counter->bulk);
576576 kfree(counter);
577577 }
578578 EXPORT_SYMBOL(mlx5_fc_local_destroy);
579+
580+void mlx5_fc_local_get(struct mlx5_fc *counter)
581+{
582+ if (!counter || counter->type != MLX5_FC_TYPE_LOCAL)
583+ return;
584+
585+ refcount_inc(&counter->fc_local_refcount);
586+}
587+
588+void mlx5_fc_local_put(struct mlx5_fc *counter)
589+{
590+ if (!counter || counter->type != MLX5_FC_TYPE_LOCAL)
591+ return;
592+
593+ if (!refcount_dec_and_test(&counter->fc_local_refcount))
594+ return;
595+
596+ mlx5_fc_local_destroy(counter);
597+}
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/action.c+2−2
@@ -1360,7 +1360,7 @@ free_action: · 1359 unmodified lines
13601360 struct mlx5hws_action *
13611361 mlx5hws_action_create_dest_array(struct mlx5hws_context *ctx, size_t num_dest,
13621362 struct mlx5hws_action_dest_attr *dests,
1363− bool ignore_flow_level, u32 flags)
1363+ u32 flags)
13641364 {
13651365 struct mlx5hws_cmd_set_fte_dest *dest_list = NULL;
13661366 struct mlx5hws_cmd_ft_create_attr ft_attr = {0};
@@ -1397,7 +1397,7 @@ mlx5hws_action_create_dest_array(struct mlx5hws_context *ctx, size_t num_dest, · 30 unmodified lines
13971397 MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
13981398 dest_list[i].destination_id = dests[i].dest->dest_obj.obj_id;
13991399 fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
1400− fte_attr.ignore_flow_level = ignore_flow_level;
1400+ fte_attr.ignore_flow_level = 1;
14011401 if (dests[i].is_wire_ft)
14021402 last_dest_idx = i;
14031403 break;
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c+3−8
@@ -572,12 +572,12 @@ static void mlx5_fs_put_dest_action_sampler(struct mlx5_fs_hws_context *fs_ctx, · 571 unmodified lines
572572 static struct mlx5hws_action *
573573 mlx5_fs_create_action_dest_array(struct mlx5hws_context *ctx,
574574 struct mlx5hws_action_dest_attr *dests,
575− u32 num_of_dests, bool ignore_flow_level)
575+ u32 num_of_dests)
576576 {
577577 u32 flags = MLX5HWS_ACTION_FLAG_HWS_FDB | MLX5HWS_ACTION_FLAG_SHARED;
578578
579579 return mlx5hws_action_create_dest_array(ctx, num_of_dests, dests,
580− ignore_flow_level, flags);
580+ flags);
581581 }
582582
583583 static struct mlx5hws_action *
@@ -1014,19 +1014,14 @@ static int mlx5_fs_fte_get_hws_actions(struct mlx5_flow_root_namespace *ns, · 430 unmodified lines
10141014 }
10151015 (*ractions)[num_actions++].action = dest_actions->dest;
10161016 } else if (num_dest_actions > 1) {
1017− bool ignore_flow_level;
1018−
10191017 if (num_actions == MLX5_FLOW_CONTEXT_ACTION_MAX ||
10201018 num_fs_actions == MLX5_FLOW_CONTEXT_ACTION_MAX) {
10211019 err = -EOPNOTSUPP;
10221020 goto free_actions;
10231021 }
1024− ignore_flow_level =
1025− !!(fte_action->flags & FLOW_ACT_IGNORE_FLOW_LEVEL);
10261022 tmp_action =
10271023 mlx5_fs_create_action_dest_array(ctx, dest_actions,
1028− num_dest_actions,
1029− ignore_flow_level);
1024+ num_dest_actions);
10301025 if (!tmp_action) {
10311026 err = -EOPNOTSUPP;
10321027 goto free_actions;
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws_pools.c+7−1
@@ -407,15 +407,21 @@ struct mlx5hws_action *mlx5_fc_get_hws_action(struct mlx5hws_context *ctx, · 406 unmodified lines
407407 {
408408 struct mlx5_fs_hws_create_action_ctx create_ctx;
409409 struct mlx5_fc_bulk *fc_bulk = counter->bulk;
410+ struct mlx5hws_action *hws_action;
410411
411412 create_ctx.hws_ctx = ctx;
412413 create_ctx.id = fc_bulk->base_id;
413414 create_ctx.actions_type = MLX5HWS_ACTION_TYP_CTR;
414415
415− return mlx5_fs_get_hws_action(&fc_bulk->hws_data, &create_ctx);
416+ mlx5_fc_local_get(counter);
417+ hws_action = mlx5_fs_get_hws_action(&fc_bulk->hws_data, &create_ctx);
418+ if (!hws_action)
419+ mlx5_fc_local_put(counter);
420+ return hws_action;
416421 }
417422
418423 void mlx5_fc_put_hws_action(struct mlx5_fc *counter)
419424 {
420425 mlx5_fs_put_hws_action(&counter->bulk->hws_data);
426+ mlx5_fc_local_put(counter);
421427 }
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws.h+1−2
@@ -735,7 +735,6 @@ mlx5hws_action_create_push_vlan(struct mlx5hws_context *ctx, u32 flags); · 734 unmodified lines
735735 * @num_dest: The number of dests attributes.
736736 * @dests: The destination array. Each contains a destination action and can
737737 * have additional actions.
738− * @ignore_flow_level: Whether to turn on 'ignore_flow_level' for this dest.
739738 * @flags: Action creation flags (enum mlx5hws_action_flags).
740739 *
741740 * Return: pointer to mlx5hws_action on success NULL otherwise.
@@ -743,7 +742,7 @@ mlx5hws_action_create_push_vlan(struct mlx5hws_context *ctx, u32 flags); · 1 unmodified line
743742 struct mlx5hws_action *
744743 mlx5hws_action_create_dest_array(struct mlx5hws_context *ctx, size_t num_dest,
745744 struct mlx5hws_action_dest_attr *dests,
746− bool ignore_flow_level, u32 flags);
745+ u32 flags);
747746
748747 /**
749748 * mlx5hws_action_create_insert_header - Create insert header action.
drivers/net/phy/bcm-phy-ptp.c+2−4
@@ -597,10 +597,6 @@ static int bcm_ptp_perout_locked(struct bcm_ptp_private *priv, · 596 unmodified lines
597597
598598 period = BCM_MAX_PERIOD_8NS; /* write nonzero value */
599599
600− /* Reject unsupported flags */
601− if (req->flags & ~PTP_PEROUT_DUTY_CYCLE)
602− return -EOPNOTSUPP;
603−
604600 if (req->flags & PTP_PEROUT_DUTY_CYCLE)
605601 pulse = ktime_to_ns(ktime_set(req->on.sec, req->on.nsec));
606602 else
@@ -741,6 +737,8 @@ static const struct ptp_clock_info bcm_ptp_clock_info = { · 134 unmodified lines
741737 .n_pins = 1,
742738 .n_per_out = 1,
743739 .n_ext_ts = 1,
740+ .supported_perout_flags = PTP_PEROUT_DUTY_CYCLE,
741+ .supported_extts_flags = PTP_STRICT_FLAGS | PTP_RISING_EDGE,
744742 };
745743
746744 static void bcm_ptp_txtstamp(struct mii_timestamper *mii_ts,
drivers/net/tun.c+3−0
@@ -1875,6 +1875,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, · 1874 unmodified lines
18751875 local_bh_enable();
18761876 goto unlock_frags;
18771877 }
1878+
1879+ if (frags && skb != tfile->napi.skb)
1880+ tfile->napi.skb = skb;
18781881 }
18791882 rcu_read_unlock();
18801883 local_bh_enable();
include/linux/mlx5/fs.h+2−0
@@ -308,6 +308,8 @@ struct mlx5_fc *mlx5_fc_create(struct mlx5_core_dev *dev, bool aging); · 307 unmodified lines
308308 void mlx5_fc_destroy(struct mlx5_core_dev *dev, struct mlx5_fc *counter);
309309 struct mlx5_fc *mlx5_fc_local_create(u32 counter_id, u32 offset, u32 bulk_size);
310310 void mlx5_fc_local_destroy(struct mlx5_fc *counter);
311+void mlx5_fc_local_get(struct mlx5_fc *counter);
312+void mlx5_fc_local_put(struct mlx5_fc *counter);
311313 u64 mlx5_fc_query_lastuse(struct mlx5_fc *counter);
312314 void mlx5_fc_query_cached(struct mlx5_fc *counter,
313315 u64 *bytes, u64 *packets, u64 *lastuse);
include/net/bluetooth/hci_core.h+21−0
@@ -1245,6 +1245,27 @@ static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev, · 1244 unmodified lines
12451245 return NULL;
12461246 }
12471247
1248+static inline struct hci_conn *hci_conn_hash_lookup_role(struct hci_dev *hdev,
1249+ __u8 type, __u8 role,
1250+ bdaddr_t *ba)
1251+{
1252+ struct hci_conn_hash *h = &hdev->conn_hash;
1253+ struct hci_conn *c;
1254+
1255+ rcu_read_lock();
1256+
1257+ list_for_each_entry_rcu(c, &h->list, list) {
1258+ if (c->type == type && c->role == role && !bacmp(&c->dst, ba)) {
1259+ rcu_read_unlock();
1260+ return c;
1261+ }
1262+ }
1263+
1264+ rcu_read_unlock();
1265+
1266+ return NULL;
1267+}
1268+
12481269 static inline struct hci_conn *hci_conn_hash_lookup_le(struct hci_dev *hdev,
12491270 bdaddr_t *ba,
12501271 __u8 ba_type)
include/uapi/linux/ptp_clock.h+3−0
@@ -37,6 +37,9 @@ · 36 unmodified lines
3737
3838 /*
3939 * flag fields valid for the new PTP_EXTTS_REQUEST2 ioctl.
40+ *
41+ * Note: PTP_STRICT_FLAGS is always enabled by the kernel for
42+ * PTP_EXTTS_REQUEST2 regardless of whether it is set by userspace.
4043 */
4144 #define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FEATURE | \
4245 PTP_RISING_EDGE | \
net/bluetooth/hci_event.c+27−3
@@ -3087,8 +3087,18 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data, · 3086 unmodified lines
30873087
30883088 hci_dev_lock(hdev);
30893089
3090+ /* Check for existing connection:
3091+ *
3092+ * 1. If it doesn't exist then it must be receiver/slave role.
3093+ * 2. If it does exist confirm that it is connecting/BT_CONNECT in case
3094+ * of initiator/master role since there could be a collision where
3095+ * either side is attempting to connect or something like a fuzzing
3096+ * testing is trying to play tricks to destroy the hcon object before
3097+ * it even attempts to connect (e.g. hcon->state == BT_OPEN).
3098+ */
30903099 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
3091− if (!conn) {
3100+ if (!conn ||
3101+ (conn->role == HCI_ROLE_MASTER && conn->state != BT_CONNECT)) {
30923102 /* In case of error status and there is no connection pending
30933103 * just unlock as there is nothing to cleanup.
30943104 */
@@ -4391,6 +4401,8 @@ static void hci_num_comp_pkts_evt(struct hci_dev *hdev, void *data, · 1296 unmodified lines
43914401
43924402 bt_dev_dbg(hdev, "num %d", ev->num);
43934403
4404+ hci_dev_lock(hdev);
4405+
43944406 for (i = 0; i < ev->num; i++) {
43954407 struct hci_comp_pkts_info *info = &ev->handles[i];
43964408 struct hci_conn *conn;
@@ -4472,6 +4484,8 @@ static void hci_num_comp_pkts_evt(struct hci_dev *hdev, void *data, · 75 unmodified lines
44724484 }
44734485
44744486 queue_work(hdev->workqueue, &hdev->tx_work);
4487+
4488+ hci_dev_unlock(hdev);
44754489 }
44764490
44774491 static void hci_mode_change_evt(struct hci_dev *hdev, void *data,
@@ -5634,8 +5648,18 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, · 1156 unmodified lines
56345648 */
56355649 hci_dev_clear_flag(hdev, HCI_LE_ADV);
56365650
5637− conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, bdaddr);
5638− if (!conn) {
5651+ /* Check for existing connection:
5652+ *
5653+ * 1. If it doesn't exist then use the role to create a new object.
5654+ * 2. If it does exist confirm that it is connecting/BT_CONNECT in case
5655+ * of initiator/master role since there could be a collision where
5656+ * either side is attempting to connect or something like a fuzzing
5657+ * testing is trying to play tricks to destroy the hcon object before
5658+ * it even attempts to connect (e.g. hcon->state == BT_OPEN).
5659+ */
5660+ conn = hci_conn_hash_lookup_role(hdev, LE_LINK, role, bdaddr);
5661+ if (!conn ||
5662+ (conn->role == HCI_ROLE_MASTER && conn->state != BT_CONNECT)) {
56395663 /* In case of error status and there is no connection pending
56405664 * just unlock as there is nothing to cleanup.
56415665 */
net/bluetooth/hci_sync.c+7−0
@@ -2594,6 +2594,13 @@ static int hci_resume_advertising_sync(struct hci_dev *hdev) · 2593 unmodified lines
25942594 hci_remove_ext_adv_instance_sync(hdev, adv->instance,
25952595 NULL);
25962596 }
2597+
2598+ /* If current advertising instance is set to instance 0x00
2599+ * then we need to re-enable it.
2600+ */
2601+ if (!hdev->cur_adv_instance)
2602+ err = hci_enable_ext_advertising_sync(hdev,
2603+ hdev->cur_adv_instance);
25972604 } else {
25982605 /* Schedule for most recent instance to be restarted and begin
25992606 * the software rotation loop
net/bluetooth/mgmt.c+182−77
@@ -1323,8 +1323,7 @@ static void mgmt_set_powered_complete(struct hci_dev *hdev, void *data, int err) · 1322 unmodified lines
13231323 struct mgmt_mode *cp;
13241324
13251325 /* Make sure cmd still outstanding. */
1326− if (err == -ECANCELED ||
1327− cmd != pending_find(MGMT_OP_SET_POWERED, hdev))
1326+ if (err == -ECANCELED || !mgmt_pending_valid(hdev, cmd))
13281327 return;
13291328
13301329 cp = cmd->param;
@@ -1351,23 +1350,29 @@ static void mgmt_set_powered_complete(struct hci_dev *hdev, void *data, int err) · 20 unmodified lines
13511350 mgmt_status(err));
13521351 }
13531352
1354− mgmt_pending_remove(cmd);
1353+ mgmt_pending_free(cmd);
13551354 }
13561355
13571356 static int set_powered_sync(struct hci_dev *hdev, void *data)
13581357 {
13591358 struct mgmt_pending_cmd *cmd = data;
1360− struct mgmt_mode *cp;
1359+ struct mgmt_mode cp;
1360+
1361+ mutex_lock(&hdev->mgmt_pending_lock);
13611362
13621363 /* Make sure cmd still outstanding. */
1363− if (cmd != pending_find(MGMT_OP_SET_POWERED, hdev))
1364+ if (!__mgmt_pending_listed(hdev, cmd)) {
1365+ mutex_unlock(&hdev->mgmt_pending_lock);
13641366 return -ECANCELED;
1367+ }
13651368
1366− cp = cmd->param;
1369+ memcpy(&cp, cmd->param, sizeof(cp));
1370+
1371+ mutex_unlock(&hdev->mgmt_pending_lock);
13671372
13681373 BT_DBG("%s", hdev->name);
13691374
1370− return hci_set_powered_sync(hdev, cp->val);
1375+ return hci_set_powered_sync(hdev, cp.val);
13711376 }
13721377
13731378 static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data,
@@ -1516,8 +1521,7 @@ static void mgmt_set_discoverable_complete(struct hci_dev *hdev, void *data, · 142 unmodified lines
15161521 bt_dev_dbg(hdev, "err %d", err);
15171522
15181523 /* Make sure cmd still outstanding. */
1519− if (err == -ECANCELED ||
1520− cmd != pending_find(MGMT_OP_SET_DISCOVERABLE, hdev))
1524+ if (err == -ECANCELED || !mgmt_pending_valid(hdev, cmd))
15211525 return;
15221526
15231527 hci_dev_lock(hdev);
@@ -1539,12 +1543,15 @@ static void mgmt_set_discoverable_complete(struct hci_dev *hdev, void *data, · 15 unmodified lines
15391543 new_settings(hdev, cmd->sk);
15401544
15411545 done:
1542− mgmt_pending_remove(cmd);
1546+ mgmt_pending_free(cmd);
15431547 hci_dev_unlock(hdev);
15441548 }
15451549
15461550 static int set_discoverable_sync(struct hci_dev *hdev, void *data)
15471551 {
1552+ if (!mgmt_pending_listed(hdev, data))
1553+ return -ECANCELED;
1554+
15481555 BT_DBG("%s", hdev->name);
15491556
15501557 return hci_update_discoverable_sync(hdev);
@@ -1691,8 +1698,7 @@ static void mgmt_set_connectable_complete(struct hci_dev *hdev, void *data, · 140 unmodified lines
16911698 bt_dev_dbg(hdev, "err %d", err);
16921699
16931700 /* Make sure cmd still outstanding. */
1694− if (err == -ECANCELED ||
1695− cmd != pending_find(MGMT_OP_SET_CONNECTABLE, hdev))
1701+ if (err == -ECANCELED || !mgmt_pending_valid(hdev, cmd))
16961702 return;
16971703
16981704 hci_dev_lock(hdev);
@@ -1707,7 +1713,7 @@ static void mgmt_set_connectable_complete(struct hci_dev *hdev, void *data, · 8 unmodified lines
17071713 new_settings(hdev, cmd->sk);
17081714
17091715 done:
1710− mgmt_pending_remove(cmd);
1716+ mgmt_pending_free(cmd);
17111717
17121718 hci_dev_unlock(hdev);
17131719 }
@@ -1743,6 +1749,9 @@ static int set_connectable_update_settings(struct hci_dev *hdev, · 29 unmodified lines
17431749
17441750 static int set_connectable_sync(struct hci_dev *hdev, void *data)
17451751 {
1752+ if (!mgmt_pending_listed(hdev, data))
1753+ return -ECANCELED;
1754+
17461755 BT_DBG("%s", hdev->name);
17471756
17481757 return hci_update_connectable_sync(hdev);
@@ -1919,14 +1928,17 @@ static void set_ssp_complete(struct hci_dev *hdev, void *data, int err) · 170 unmodified lines
19191928 {
19201929 struct cmd_lookup match = { NULL, hdev };
19211930 struct mgmt_pending_cmd *cmd = data;
1922− struct mgmt_mode *cp = cmd->param;
1923− u8 enable = cp->val;
1931+ struct mgmt_mode *cp;
1932+ u8 enable;
19241933 bool changed;
19251934
19261935 /* Make sure cmd still outstanding. */
1927− if (err == -ECANCELED || cmd != pending_find(MGMT_OP_SET_SSP, hdev))
1936+ if (err == -ECANCELED || !mgmt_pending_valid(hdev, cmd))
19281937 return;
19291938
1939+ cp = cmd->param;
1940+ enable = cp->val;
1941+
19301942 if (err) {
19311943 u8 mgmt_err = mgmt_status(err);
19321944
@@ -1935,8 +1947,7 @@ static void set_ssp_complete(struct hci_dev *hdev, void *data, int err) · 2 unmodified lines
19351947 new_settings(hdev, NULL);
19361948 }
19371949
1938− mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, true,
1939− cmd_status_rsp, &mgmt_err);
1950+ mgmt_cmd_status(cmd->sk, cmd->hdev->id, cmd->opcode, mgmt_err);
19401951 return;
19411952 }
19421953
@@ -1946,7 +1957,7 @@ static void set_ssp_complete(struct hci_dev *hdev, void *data, int err) · 3 unmodified lines
19461957 changed = hci_dev_test_and_clear_flag(hdev, HCI_SSP_ENABLED);
19471958 }
19481959
1949− mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, true, settings_rsp, &match);
1960+ settings_rsp(cmd, &match);
19501961
19511962 if (changed)
19521963 new_settings(hdev, match.sk);
@@ -1960,14 +1971,25 @@ static void set_ssp_complete(struct hci_dev *hdev, void *data, int err) · 7 unmodified lines
19601971 static int set_ssp_sync(struct hci_dev *hdev, void *data)
19611972 {
19621973 struct mgmt_pending_cmd *cmd = data;
1963− struct mgmt_mode *cp = cmd->param;
1974+ struct mgmt_mode cp;
19641975 bool changed = false;
19651976 int err;
19661977
1967− if (cp->val)
1978+ mutex_lock(&hdev->mgmt_pending_lock);
1979+
1980+ if (!__mgmt_pending_listed(hdev, cmd)) {
1981+ mutex_unlock(&hdev->mgmt_pending_lock);
1982+ return -ECANCELED;
1983+ }
1984+
1985+ memcpy(&cp, cmd->param, sizeof(cp));
1986+
1987+ mutex_unlock(&hdev->mgmt_pending_lock);
1988+
1989+ if (cp.val)
19681990 changed = !hci_dev_test_and_set_flag(hdev, HCI_SSP_ENABLED);
19691991
1970− err = hci_write_ssp_mode_sync(hdev, cp->val);
1992+ err = hci_write_ssp_mode_sync(hdev, cp.val);
19711993
19721994 if (!err && changed)
19731995 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED);
@@ -2060,32 +2082,50 @@ static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) · 86 unmodified lines
20602082
20612083 static void set_le_complete(struct hci_dev *hdev, void *data, int err)
20622084 {
2085+ struct mgmt_pending_cmd *cmd = data;
20632086 struct cmd_lookup match = { NULL, hdev };
20642087 u8 status = mgmt_status(err);
20652088
20662089 bt_dev_dbg(hdev, "err %d", err);
20672090
2068− if (status) {
2069− mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, true, cmd_status_rsp,
2070− &status);
2091+ if (err == -ECANCELED || !mgmt_pending_valid(hdev, data))
20712092 return;
2093+
2094+ if (status) {
2095+ mgmt_cmd_status(cmd->sk, cmd->hdev->id, cmd->opcode, status);
2096+ goto done;
20722097 }
20732098
2074− mgmt_pending_foreach(MGMT_OP_SET_LE, hdev, true, settings_rsp, &match);
2099+ settings_rsp(cmd, &match);
20752100
20762101 new_settings(hdev, match.sk);
20772102
20782103 if (match.sk)
20792104 sock_put(match.sk);
2105+
2106+done:
2107+ mgmt_pending_free(cmd);
20802108 }
20812109
20822110 static int set_le_sync(struct hci_dev *hdev, void *data)
20832111 {
20842112 struct mgmt_pending_cmd *cmd = data;
2085− struct mgmt_mode *cp = cmd->param;
2086− u8 val = !!cp->val;
2113+ struct mgmt_mode cp;
2114+ u8 val;
20872115 int err;
20882116
2117+ mutex_lock(&hdev->mgmt_pending_lock);
2118+
2119+ if (!__mgmt_pending_listed(hdev, cmd)) {
2120+ mutex_unlock(&hdev->mgmt_pending_lock);
2121+ return -ECANCELED;
2122+ }
2123+
2124+ memcpy(&cp, cmd->param, sizeof(cp));
2125+ val = !!cp.val;
2126+
2127+ mutex_unlock(&hdev->mgmt_pending_lock);
2128+
20892129 if (!val) {
20902130 hci_clear_adv_instance_sync(hdev, NULL, 0x00, true);
20912131
@@ -2127,7 +2167,12 @@ static void set_mesh_complete(struct hci_dev *hdev, void *data, int err) · 35 unmodified lines
21272167 {
21282168 struct mgmt_pending_cmd *cmd = data;
21292169 u8 status = mgmt_status(err);
2130− struct sock *sk = cmd->sk;
2170+ struct sock *sk;
2171+
2172+ if (err == -ECANCELED || !mgmt_pending_valid(hdev, cmd))
2173+ return;
2174+
2175+ sk = cmd->sk;
21312176
21322177 if (status) {
21332178 mgmt_pending_foreach(MGMT_OP_SET_MESH_RECEIVER, hdev, true,
@@ -2142,24 +2187,37 @@ static void set_mesh_complete(struct hci_dev *hdev, void *data, int err) · 8 unmodified lines
21422187 static int set_mesh_sync(struct hci_dev *hdev, void *data)
21432188 {
21442189 struct mgmt_pending_cmd *cmd = data;
2145− struct mgmt_cp_set_mesh *cp = cmd->param;
2146− size_t len = cmd->param_len;
2190+ struct mgmt_cp_set_mesh cp;
2191+ size_t len;
2192+
2193+ mutex_lock(&hdev->mgmt_pending_lock);
2194+
2195+ if (!__mgmt_pending_listed(hdev, cmd)) {
2196+ mutex_unlock(&hdev->mgmt_pending_lock);
2197+ return -ECANCELED;
2198+ }
2199+
2200+ memcpy(&cp, cmd->param, sizeof(cp));
2201+
2202+ mutex_unlock(&hdev->mgmt_pending_lock);
2203+
2204+ len = cmd->param_len;
21472205
21482206 memset(hdev->mesh_ad_types, 0, sizeof(hdev->mesh_ad_types));
21492207
2150− if (cp->enable)
2208+ if (cp.enable)
21512209 hci_dev_set_flag(hdev, HCI_MESH);
21522210 else
21532211 hci_dev_clear_flag(hdev, HCI_MESH);
21542212
2155− hdev->le_scan_interval = __le16_to_cpu(cp->period);
2156− hdev->le_scan_window = __le16_to_cpu(cp->window);
2213+ hdev->le_scan_interval = __le16_to_cpu(cp.period);
2214+ hdev->le_scan_window = __le16_to_cpu(cp.window);
21572215
2158− len -= sizeof(*cp);
2216+ len -= sizeof(cp);
21592217
21602218 /* If filters don't fit, forward all adv pkts */
21612219 if (len <= sizeof(hdev->mesh_ad_types))
2162− memcpy(hdev->mesh_ad_types, cp->ad_types, len);
2220+ memcpy(hdev->mesh_ad_types, cp.ad_types, len);
21632221
21642222 hci_update_passive_scan_sync(hdev);
21652223 return 0;
@@ -3867,15 +3925,16 @@ static int name_changed_sync(struct hci_dev *hdev, void *data) · 1701 unmodified lines
38673925 static void set_name_complete(struct hci_dev *hdev, void *data, int err)
38683926 {
38693927 struct mgmt_pending_cmd *cmd = data;
3870− struct mgmt_cp_set_local_name *cp = cmd->param;
3928+ struct mgmt_cp_set_local_name *cp;
38713929 u8 status = mgmt_status(err);
38723930
38733931 bt_dev_dbg(hdev, "err %d", err);
38743932
3875− if (err == -ECANCELED ||
3876− cmd != pending_find(MGMT_OP_SET_LOCAL_NAME, hdev))
3933+ if (err == -ECANCELED || !mgmt_pending_valid(hdev, cmd))
38773934 return;
38783935
3936+ cp = cmd->param;
3937+
38793938 if (status) {
38803939 mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME,
38813940 status);
@@ -3887,16 +3946,27 @@ static void set_name_complete(struct hci_dev *hdev, void *data, int err) · 5 unmodified lines
38873946 hci_cmd_sync_queue(hdev, name_changed_sync, NULL, NULL);
38883947 }
38893948
3890− mgmt_pending_remove(cmd);
3949+ mgmt_pending_free(cmd);
38913950 }
38923951
38933952 static int set_name_sync(struct hci_dev *hdev, void *data)
38943953 {
38953954 struct mgmt_pending_cmd *cmd = data;
3896− struct mgmt_cp_set_local_name *cp = cmd->param;
3955+ struct mgmt_cp_set_local_name cp;
3956+
3957+ mutex_lock(&hdev->mgmt_pending_lock);
3958+
3959+ if (!__mgmt_pending_listed(hdev, cmd)) {
3960+ mutex_unlock(&hdev->mgmt_pending_lock);
3961+ return -ECANCELED;
3962+ }
3963+
3964+ memcpy(&cp, cmd->param, sizeof(cp));
3965+
3966+ mutex_unlock(&hdev->mgmt_pending_lock);
38973967
38983968 if (lmp_bredr_capable(hdev)) {
3899− hci_update_name_sync(hdev, cp->name);
3969+ hci_update_name_sync(hdev, cp.name);
39003970 hci_update_eir_sync(hdev);
39013971 }
39023972
@@ -4048,12 +4118,10 @@ int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip) · 145 unmodified lines
40484118 static void set_default_phy_complete(struct hci_dev *hdev, void *data, int err)
40494119 {
40504120 struct mgmt_pending_cmd *cmd = data;
4051− struct sk_buff *skb = cmd->skb;
4121+ struct sk_buff *skb;
40524122 u8 status = mgmt_status(err);
40534123
4054− if (err == -ECANCELED ||
4055− cmd != pending_find(MGMT_OP_SET_PHY_CONFIGURATION, hdev))
4056− return;
4124+ skb = cmd->skb;
40574125
40584126 if (!status) {
40594127 if (!skb)
@@ -4080,7 +4148,7 @@ static void set_default_phy_complete(struct hci_dev *hdev, void *data, int err) · 20 unmodified lines
40804148 if (skb && !IS_ERR(skb))
40814149 kfree_skb(skb);
40824150
4083− mgmt_pending_remove(cmd);
4151+ mgmt_pending_free(cmd);
40844152 }
40854153
40864154 static int set_default_phy_sync(struct hci_dev *hdev, void *data)
@@ -4088,7 +4156,9 @@ static int set_default_phy_sync(struct hci_dev *hdev, void *data) · 1 unmodified line
40884156 struct mgmt_pending_cmd *cmd = data;
40894157 struct mgmt_cp_set_phy_configuration *cp = cmd->param;
40904158 struct hci_cp_le_set_default_phy cp_phy;
4091− u32 selected_phys = __le32_to_cpu(cp->selected_phys);
4159+ u32 selected_phys;
4160+
4161+ selected_phys = __le32_to_cpu(cp->selected_phys);
40924162
40934163 memset(&cp_phy, 0, sizeof(cp_phy));
40944164
@@ -4228,7 +4298,7 @@ static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev, · 133 unmodified lines
42284298 goto unlock;
42294299 }
42304300
4231− cmd = mgmt_pending_add(sk, MGMT_OP_SET_PHY_CONFIGURATION, hdev, data,
4301+ cmd = mgmt_pending_new(sk, MGMT_OP_SET_PHY_CONFIGURATION, hdev, data,
42324302 len);
42334303 if (!cmd)
42344304 err = -ENOMEM;
@@ -5189,7 +5259,17 @@ static void mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev, · 954 unmodified lines
51895259 {
51905260 struct mgmt_rp_add_adv_patterns_monitor rp;
51915261 struct mgmt_pending_cmd *cmd = data;
5192− struct adv_monitor *monitor = cmd->user_data;
5262+ struct adv_monitor *monitor;
5263+
5264+ /* This is likely the result of hdev being closed and mgmt_index_removed
5265+ * is attempting to clean up any pending command so
5266+ * hci_adv_monitors_clear is about to be called which will take care of
5267+ * freeing the adv_monitor instances.
5268+ */
5269+ if (status == -ECANCELED && !mgmt_pending_valid(hdev, cmd))
5270+ return;
5271+
5272+ monitor = cmd->user_data;
51935273
51945274 hci_dev_lock(hdev);
51955275
@@ -5215,9 +5295,20 @@ static void mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev, · 19 unmodified lines
52155295 static int mgmt_add_adv_patterns_monitor_sync(struct hci_dev *hdev, void *data)
52165296 {
52175297 struct mgmt_pending_cmd *cmd = data;
5218− struct adv_monitor *monitor = cmd->user_data;
5298+ struct adv_monitor *mon;
5299+
5300+ mutex_lock(&hdev->mgmt_pending_lock);
5301+
5302+ if (!__mgmt_pending_listed(hdev, cmd)) {
5303+ mutex_unlock(&hdev->mgmt_pending_lock);
5304+ return -ECANCELED;
5305+ }
5306+
5307+ mon = cmd->user_data;
5308+
5309+ mutex_unlock(&hdev->mgmt_pending_lock);
52195310
5220− return hci_add_adv_monitor(hdev, monitor);
5311+ return hci_add_adv_monitor(hdev, mon);
52215312 }
52225313
52235314 static int __add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev,
@@ -5484,7 +5575,8 @@ unlock: · 260 unmodified lines
54845575 status);
54855576 }
54865577
5487−static void read_local_oob_data_complete(struct hci_dev *hdev, void *data, int err)
5578+static void read_local_oob_data_complete(struct hci_dev *hdev, void *data,
5579+ int err)
54885580 {
54895581 struct mgmt_rp_read_local_oob_data mgmt_rp;
54905582 size_t rp_size = sizeof(mgmt_rp);
@@ -5504,7 +5596,8 @@ static void read_local_oob_data_complete(struct hci_dev *hdev, void *data, int e · 13 unmodified lines
55045596 bt_dev_dbg(hdev, "status %d", status);
55055597
55065598 if (status) {
5507− mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA, status);
5599+ mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_READ_LOCAL_OOB_DATA,
5600+ status);
55085601 goto remove;
55095602 }
55105603
@@ -5786,17 +5879,12 @@ static void start_discovery_complete(struct hci_dev *hdev, void *data, int err) · 275 unmodified lines
57865879
57875880 bt_dev_dbg(hdev, "err %d", err);
57885881
5789− if (err == -ECANCELED)
5790− return;
5791−
5792− if (cmd != pending_find(MGMT_OP_START_DISCOVERY, hdev) &&
5793− cmd != pending_find(MGMT_OP_START_LIMITED_DISCOVERY, hdev) &&
5794− cmd != pending_find(MGMT_OP_START_SERVICE_DISCOVERY, hdev))
5882+ if (err == -ECANCELED || !mgmt_pending_valid(hdev, cmd))
57955883 return;
57965884
57975885 mgmt_cmd_complete(cmd->sk, cmd->hdev->id, cmd->opcode, mgmt_status(err),
57985886 cmd->param, 1);
5799− mgmt_pending_remove(cmd);
5887+ mgmt_pending_free(cmd);
58005888
58015889 hci_discovery_set_state(hdev, err ? DISCOVERY_STOPPED:
58025890 DISCOVERY_FINDING);
@@ -5804,6 +5892,9 @@ static void start_discovery_complete(struct hci_dev *hdev, void *data, int err) · 1 unmodified line
58045892
58055893 static int start_discovery_sync(struct hci_dev *hdev, void *data)
58065894 {
5895+ if (!mgmt_pending_listed(hdev, data))
5896+ return -ECANCELED;
5897+
58075898 return hci_start_discovery_sync(hdev);
58085899 }
58095900
@@ -6009,15 +6100,14 @@ static void stop_discovery_complete(struct hci_dev *hdev, void *data, int err) · 199 unmodified lines
60096100 {
60106101 struct mgmt_pending_cmd *cmd = data;
60116102
6012− if (err == -ECANCELED ||
6013− cmd != pending_find(MGMT_OP_STOP_DISCOVERY, hdev))
6103+ if (err == -ECANCELED || !mgmt_pending_valid(hdev, cmd))
60146104 return;
60156105
60166106 bt_dev_dbg(hdev, "err %d", err);
60176107
60186108 mgmt_cmd_complete(cmd->sk, cmd->hdev->id, cmd->opcode, mgmt_status(err),
60196109 cmd->param, 1);
6020− mgmt_pending_remove(cmd);
6110+ mgmt_pending_free(cmd);
60216111
60226112 if (!err)
60236113 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
@@ -6025,6 +6115,9 @@ static void stop_discovery_complete(struct hci_dev *hdev, void *data, int err) · 1 unmodified line
60256115
60266116 static int stop_discovery_sync(struct hci_dev *hdev, void *data)
60276117 {
6118+ if (!mgmt_pending_listed(hdev, data))
6119+ return -ECANCELED;
6120+
60286121 return hci_stop_discovery_sync(hdev);
60296122 }
60306123
@@ -6234,14 +6327,18 @@ static void enable_advertising_instance(struct hci_dev *hdev, int err) · 203 unmodified lines
62346327
62356328 static void set_advertising_complete(struct hci_dev *hdev, void *data, int err)
62366329 {
6330+ struct mgmt_pending_cmd *cmd = data;
62376331 struct cmd_lookup match = { NULL, hdev };
62386332 u8 instance;
62396333 struct adv_info *adv_instance;
62406334 u8 status = mgmt_status(err);
62416335
6336+ if (err == -ECANCELED || !mgmt_pending_valid(hdev, data))
6337+ return;
6338+
62426339 if (status) {
6243− mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, true,
6244− cmd_status_rsp, &status);
6340+ mgmt_cmd_status(cmd->sk, cmd->hdev->id, cmd->opcode, status);
6341+ mgmt_pending_free(cmd);
62456342 return;
62466343 }
62476344
@@ -6250,8 +6347,7 @@ static void set_advertising_complete(struct hci_dev *hdev, void *data, int err) · 2 unmodified lines
62506347 else
62516348 hci_dev_clear_flag(hdev, HCI_ADVERTISING);
62526349
6253− mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev, true, settings_rsp,
6254− &match);
6350+ settings_rsp(cmd, &match);
62556351
62566352 new_settings(hdev, match.sk);
62576353
@@ -6283,10 +6379,23 @@ static void set_advertising_complete(struct hci_dev *hdev, void *data, int err) · 25 unmodified lines
62836379 static int set_adv_sync(struct hci_dev *hdev, void *data)
62846380 {
62856381 struct mgmt_pending_cmd *cmd = data;
6286− struct mgmt_mode *cp = cmd->param;
6287− u8 val = !!cp->val;
6382+ struct mgmt_mode cp;
6383+ u8 val;
62886384
6289− if (cp->val == 0x02)
6385+ mutex_lock(&hdev->mgmt_pending_lock);
6386+
6387+ if (!__mgmt_pending_listed(hdev, cmd)) {
6388+ mutex_unlock(&hdev->mgmt_pending_lock);
6389+ return -ECANCELED;
6390+ }
6391+
6392+ memcpy(&cp, cmd->param, sizeof(cp));
6393+
6394+ mutex_unlock(&hdev->mgmt_pending_lock);
6395+
6396+ val = !!cp.val;
6397+
6398+ if (cp.val == 0x02)
62906399 hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE);
62916400 else
62926401 hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE);
@@ -8039,10 +8148,6 @@ static void read_local_oob_ext_data_complete(struct hci_dev *hdev, void *data, · 1746 unmodified lines
80398148 u8 status = mgmt_status(err);
80408149 u16 eir_len;
80418150
8042− if (err == -ECANCELED ||
8043− cmd != pending_find(MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev))
8044− return;
8045−
80468151 if (!status) {
80478152 if (!skb)
80488153 status = MGMT_STATUS_FAILED;
@@ -8149,7 +8254,7 @@ done: · 100 unmodified lines
81498254 kfree_skb(skb);
81508255
81518256 kfree(mgmt_rp);
8152− mgmt_pending_remove(cmd);
8257+ mgmt_pending_free(cmd);
81538258 }
81548259
81558260 static int read_local_ssp_oob_req(struct hci_dev *hdev, struct sock *sk,
@@ -8158,7 +8263,7 @@ static int read_local_ssp_oob_req(struct hci_dev *hdev, struct sock *sk, · 2 unmodified lines
81588263 struct mgmt_pending_cmd *cmd;
81598264 int err;
81608265
8161− cmd = mgmt_pending_add(sk, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev,
8266+ cmd = mgmt_pending_new(sk, MGMT_OP_READ_LOCAL_OOB_EXT_DATA, hdev,
81628267 cp, sizeof(*cp));
81638268 if (!cmd)
81648269 return -ENOMEM;
net/bluetooth/mgmt_util.c+46−0
@@ -320,6 +320,52 @@ void mgmt_pending_remove(struct mgmt_pending_cmd *cmd) · 319 unmodified lines
320320 mgmt_pending_free(cmd);
321321 }
322322
323+bool __mgmt_pending_listed(struct hci_dev *hdev, struct mgmt_pending_cmd *cmd)
324+{
325+ struct mgmt_pending_cmd *tmp;
326+
327+ lockdep_assert_held(&hdev->mgmt_pending_lock);
328+
329+ if (!cmd)
330+ return false;
331+
332+ list_for_each_entry(tmp, &hdev->mgmt_pending, list) {
333+ if (cmd == tmp)
334+ return true;
335+ }
336+
337+ return false;
338+}
339+
340+bool mgmt_pending_listed(struct hci_dev *hdev, struct mgmt_pending_cmd *cmd)
341+{
342+ bool listed;
343+
344+ mutex_lock(&hdev->mgmt_pending_lock);
345+ listed = __mgmt_pending_listed(hdev, cmd);
346+ mutex_unlock(&hdev->mgmt_pending_lock);
347+
348+ return listed;
349+}
350+
351+bool mgmt_pending_valid(struct hci_dev *hdev, struct mgmt_pending_cmd *cmd)
352+{
353+ bool listed;
354+
355+ if (!cmd)
356+ return false;
357+
358+ mutex_lock(&hdev->mgmt_pending_lock);
359+
360+ listed = __mgmt_pending_listed(hdev, cmd);
361+ if (listed)
362+ list_del(&cmd->list);
363+
364+ mutex_unlock(&hdev->mgmt_pending_lock);
365+
366+ return listed;
367+}
368+
323369 void mgmt_mesh_foreach(struct hci_dev *hdev,
324370 void (*cb)(struct mgmt_mesh_tx *mesh_tx, void *data),
325371 void *data, struct sock *sk)
net/bluetooth/mgmt_util.h+3−0
@@ -65,6 +65,9 @@ struct mgmt_pending_cmd *mgmt_pending_new(struct sock *sk, u16 opcode, · 64 unmodified lines
6565 void *data, u16 len);
6666 void mgmt_pending_free(struct mgmt_pending_cmd *cmd);
6767 void mgmt_pending_remove(struct mgmt_pending_cmd *cmd);
68+bool __mgmt_pending_listed(struct hci_dev *hdev, struct mgmt_pending_cmd *cmd);
69+bool mgmt_pending_listed(struct hci_dev *hdev, struct mgmt_pending_cmd *cmd);
70+bool mgmt_pending_valid(struct hci_dev *hdev, struct mgmt_pending_cmd *cmd);
6871 void mgmt_mesh_foreach(struct hci_dev *hdev,
6972 void (*cb)(struct mgmt_mesh_tx *mesh_tx, void *data),
7073 void *data, struct sock *sk);
net/core/skbuff.c+1−1
@@ -6667,7 +6667,7 @@ struct sk_buff *alloc_skb_with_frags(unsigned long header_len, · 6666 unmodified lines
66676667 return NULL;
66686668
66696669 while (data_len) {
6670− if (nr_frags == MAX_SKB_FRAGS - 1)
6670+ if (nr_frags == MAX_SKB_FRAGS)
66716671 goto failure;
66726672 while (order && PAGE_ALIGN(data_len) < (PAGE_SIZE << order))
66736673 order--;
net/ipv4/nexthop.c+7−0
@@ -2399,6 +2399,13 @@ static int replace_nexthop_single(struct net *net, struct nexthop *old, · 2398 unmodified lines
23992399 return -EINVAL;
24002400 }
24012401
2402+ if (!list_empty(&old->grp_list) &&
2403+ rtnl_dereference(new->nh_info)->fdb_nh !=
2404+ rtnl_dereference(old->nh_info)->fdb_nh) {
2405+ NL_SET_ERR_MSG(extack, "Cannot change nexthop FDB status while in a group");
2406+ return -EINVAL;
2407+ }
2408+
24022409 err = call_nexthop_notifiers(net, NEXTHOP_EVENT_REPLACE, new, extack);
24032410 if (err)
24042411 return err;
net/smc/smc_loopback.c+9−5
@@ -56,6 +56,7 @@ static int smc_lo_register_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb, · 55 unmodified lines
5656 {
5757 struct smc_lo_dmb_node *dmb_node, *tmp_node;
5858 struct smc_lo_dev *ldev = smcd->priv;
59+ struct folio *folio;
5960 int sba_idx, rc;
6061
6162 /* check space for new dmb */
@@ -74,13 +75,16 @@ static int smc_lo_register_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb, · 12 unmodified lines
7475
7576 dmb_node->sba_idx = sba_idx;
7677 dmb_node->len = dmb->dmb_len;
77− dmb_node->cpu_addr = kzalloc(dmb_node->len, GFP_KERNEL |
78− __GFP_NOWARN | __GFP_NORETRY |
79− __GFP_NOMEMALLOC);
80− if (!dmb_node->cpu_addr) {
78+
79+ /* not critical; fail under memory pressure and fallback to TCP */
80+ folio = folio_alloc(GFP_KERNEL | __GFP_NOWARN | __GFP_NOMEMALLOC |
81+ __GFP_NORETRY | __GFP_ZERO,
82+ get_order(dmb_node->len));
83+ if (!folio) {
8184 rc = -ENOMEM;
8285 goto err_node;
8386 }
87+ dmb_node->cpu_addr = folio_address(folio);
8488 dmb_node->dma_addr = SMC_DMA_ADDR_INVALID;
8589 refcount_set(&dmb_node->refcnt, 1);
8690
@@ -122,7 +126,7 @@ static void __smc_lo_unregister_dmb(struct smc_lo_dev *ldev, · 35 unmodified lines
122126 write_unlock_bh(&ldev->dmb_ht_lock);
123127
124128 clear_bit(dmb_node->sba_idx, ldev->sba_idx_mask);
125− kvfree(dmb_node->cpu_addr);
129+ folio_put(virt_to_folio(dmb_node->cpu_addr));
126130 kfree(dmb_node);
127131
128132 if (atomic_dec_and_test(&ldev->dmb_cnt))
net/xfrm/xfrm_device.c+1−1
@@ -438,7 +438,7 @@ ok: · 437 unmodified lines
438438
439439 check_tunnel_size = x->xso.type == XFRM_DEV_OFFLOAD_PACKET &&
440440 x->props.mode == XFRM_MODE_TUNNEL;
441− switch (x->props.family) {
441+ switch (x->inner_mode.family) {
442442 case AF_INET:
443443 /* Check for IPv4 options */
444444 if (ip_hdr(skb)->ihl != 5)
net/xfrm/xfrm_state.c+3−0
@@ -2583,6 +2583,8 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high, · 2582 unmodified lines
25832583
25842584 for (h = 0; h < range; h++) {
25852585 u32 spi = (low == high) ? low : get_random_u32_inclusive(low, high);
2586+ if (spi == 0)
2587+ goto next;
25862588 newspi = htonl(spi);
25872589
25882590 spin_lock_bh(&net->xfrm.xfrm_state_lock);
@@ -2598,6 +2600,7 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high, · 9 unmodified lines
25982600 xfrm_state_put(x0);
25992601 spin_unlock_bh(&net->xfrm.xfrm_state_lock);
26002602
2603+next:
26012604 if (signal_pending(current)) {
26022605 err = -ERESTARTSYS;
26032606 goto unlock;
tools/testing/selftests/net/fib_nexthops.sh+46−6
@@ -467,8 +467,8 @@ ipv6_fdb_grp_fcnal() · 466 unmodified lines
467467 log_test $? 0 "Get Fdb nexthop group by id"
468468
469469 # fdb nexthop group can only contain fdb nexthops
470− run_cmd "$IP nexthop add id 63 via 2001:db8:91::4"
471− run_cmd "$IP nexthop add id 64 via 2001:db8:91::5"
470+ run_cmd "$IP nexthop add id 63 via 2001:db8:91::4 dev veth1"
471+ run_cmd "$IP nexthop add id 64 via 2001:db8:91::5 dev veth1"
472472 run_cmd "$IP nexthop add id 103 group 63/64 fdb"
473473 log_test $? 2 "Fdb Nexthop group with non-fdb nexthops"
474474
@@ -494,6 +494,26 @@ ipv6_fdb_grp_fcnal() · 19 unmodified lines
494494 run_cmd "$IP nexthop add id 69 encap mpls 101 via 2001:db8:91::8 dev veth1 fdb"
495495 log_test $? 2 "Fdb Nexthop with encap"
496496
497+ # Replace FDB nexthop to non-FDB and vice versa
498+ run_cmd "$IP nexthop add id 70 via 2001:db8:91::2 fdb"
499+ run_cmd "$IP nexthop replace id 70 via 2001:db8:91::2 dev veth1"
500+ log_test $? 0 "Replace FDB nexthop to non-FDB nexthop"
501+ run_cmd "$IP nexthop replace id 70 via 2001:db8:91::2 fdb"
502+ log_test $? 0 "Replace non-FDB nexthop to FDB nexthop"
503+
504+ # Replace FDB nexthop address while in a group
505+ run_cmd "$IP nexthop add id 71 group 70 fdb"
506+ run_cmd "$IP nexthop replace id 70 via 2001:db8:91::3 fdb"
507+ log_test $? 0 "Replace FDB nexthop address while in a group"
508+
509+ # Cannot replace FDB nexthop to non-FDB and vice versa while in a group
510+ run_cmd "$IP nexthop replace id 70 via 2001:db8:91::2 dev veth1"
511+ log_test $? 2 "Replace FDB nexthop to non-FDB nexthop while in a group"
512+ run_cmd "$IP nexthop add id 72 via 2001:db8:91::2 dev veth1"
513+ run_cmd "$IP nexthop add id 73 group 72"
514+ run_cmd "$IP nexthop replace id 72 via 2001:db8:91::2 fdb"
515+ log_test $? 2 "Replace non-FDB nexthop to FDB nexthop while in a group"
516+
497517 run_cmd "$IP link add name vx10 type vxlan id 1010 local 2001:db8:91::9 remote 2001:db8:91::10 dstport 4789 nolearning noudpcsum tos inherit ttl 100"
498518 run_cmd "$BRIDGE fdb add 02:02:00:00:00:13 dev vx10 nhid 102 self"
499519 log_test $? 0 "Fdb mac add with nexthop group"
@@ -547,15 +567,15 @@ ipv4_fdb_grp_fcnal() · 47 unmodified lines
547567 log_test $? 0 "Get Fdb nexthop group by id"
548568
549569 # fdb nexthop group can only contain fdb nexthops
550− run_cmd "$IP nexthop add id 14 via 172.16.1.2"
551− run_cmd "$IP nexthop add id 15 via 172.16.1.3"
570+ run_cmd "$IP nexthop add id 14 via 172.16.1.2 dev veth1"
571+ run_cmd "$IP nexthop add id 15 via 172.16.1.3 dev veth1"
552572 run_cmd "$IP nexthop add id 103 group 14/15 fdb"
553573 log_test $? 2 "Fdb Nexthop group with non-fdb nexthops"
554574
555575 # Non fdb nexthop group can not contain fdb nexthops
556576 run_cmd "$IP nexthop add id 16 via 172.16.1.2 fdb"
557577 run_cmd "$IP nexthop add id 17 via 172.16.1.3 fdb"
558− run_cmd "$IP nexthop add id 104 group 14/15"
578+ run_cmd "$IP nexthop add id 104 group 16/17"
559579 log_test $? 2 "Non-Fdb Nexthop group with fdb nexthops"
560580
561581 # fdb nexthop cannot have blackhole
@@ -574,6 +594,26 @@ ipv4_fdb_grp_fcnal() · 12 unmodified lines
574594 run_cmd "$IP nexthop add id 17 encap mpls 101 via 172.16.1.2 dev veth1 fdb"
575595 log_test $? 2 "Fdb Nexthop with encap"
576596
597+ # Replace FDB nexthop to non-FDB and vice versa
598+ run_cmd "$IP nexthop add id 18 via 172.16.1.2 fdb"
599+ run_cmd "$IP nexthop replace id 18 via 172.16.1.2 dev veth1"
600+ log_test $? 0 "Replace FDB nexthop to non-FDB nexthop"
601+ run_cmd "$IP nexthop replace id 18 via 172.16.1.2 fdb"
602+ log_test $? 0 "Replace non-FDB nexthop to FDB nexthop"
603+
604+ # Replace FDB nexthop address while in a group
605+ run_cmd "$IP nexthop add id 19 group 18 fdb"
606+ run_cmd "$IP nexthop replace id 18 via 172.16.1.3 fdb"
607+ log_test $? 0 "Replace FDB nexthop address while in a group"
608+
609+ # Cannot replace FDB nexthop to non-FDB and vice versa while in a group
610+ run_cmd "$IP nexthop replace id 18 via 172.16.1.2 dev veth1"
611+ log_test $? 2 "Replace FDB nexthop to non-FDB nexthop while in a group"
612+ run_cmd "$IP nexthop add id 20 via 172.16.1.2 dev veth1"
613+ run_cmd "$IP nexthop add id 21 group 20"
614+ run_cmd "$IP nexthop replace id 20 via 172.16.1.2 fdb"
615+ log_test $? 2 "Replace non-FDB nexthop to FDB nexthop while in a group"
616+
577617 run_cmd "$IP link add name vx10 type vxlan id 1010 local 10.0.0.1 remote 10.0.0.2 dstport 4789 nolearning noudpcsum tos inherit ttl 100"
578618 run_cmd "$BRIDGE fdb add 02:02:00:00:00:13 dev vx10 nhid 102 self"
579619 log_test $? 0 "Fdb mac add with nexthop group"
@@ -582,7 +622,7 @@ ipv4_fdb_grp_fcnal() · 2 unmodified lines
582622 run_cmd "$BRIDGE fdb add 02:02:00:00:00:14 dev vx10 nhid 12 self"
583623 log_test $? 255 "Fdb mac add with nexthop"
584624
585− run_cmd "$IP ro add 172.16.0.0/22 nhid 15"
625+ run_cmd "$IP ro add 172.16.0.0/22 nhid 16"
586626 log_test $? 2 "Route add with fdb nexthop"
587627
588628 run_cmd "$IP ro add 172.16.0.0/22 nhid 103"