From 45a25a1bfd267d9e420119a48e5291d7882395df Mon Sep 17 00:00:00 2001 From: Joas Antonio dos Santos Date: Tue, 10 Nov 2026 03:55:41 +0000 Subject: [PATCH 001/117] Bluetooth: hci_qca: clear qca_memdump when discarding dump packets qca_controller_memdump() frees qca_memdump when a memdump packet with a non-zero sequence number arrives while QCA_MEMDUMP_COLLECTION is not set, but leaves qca->qca_memdump pointing at the freed object. The next run of the work reads the stale pointer into its local variable, skips the allocation and uses the freed memory. Another packet with a non-zero sequence number frees it a second time, and a packet with sequence number 0 writes ram_dump_size, current_seq_no and received_dump into it. The original code cleared the pointer here; the assignment was dropped when the condition was changed to test QCA_MEMDUMP_COLLECTION. All other places that free the structure clear the pointer. A controller that sends two memdump events without a leading sequence number 0 can trigger a use-after-free or double free of a kmalloc object. Found by LLM-assisted source review. Fixes: 06d3fdfcdf5c ("Bluetooth: hci_qca: Add qcom devcoredump support") Cc: stable@vger.kernel.org Signed-off-by: Joas Antonio dos Santos Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_qca.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index d96ae0fc2b2e..dfaf4861f498 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -1132,6 +1132,7 @@ static void qca_controller_memdump(struct work_struct *work) if (!test_bit(QCA_MEMDUMP_COLLECTION, &qca->flags)) { bt_dev_err(hu->hdev, "QCA: Discarding other packets"); kfree(qca_memdump); + qca->qca_memdump = NULL; kfree_skb(skb); mutex_unlock(&qca->hci_memdump_lock); return; From a57a255ce204b51327ac4e840a7726b0ab9a1942 Mon Sep 17 00:00:00 2001 From: Shuai Zhang Date: Tue, 10 Nov 2026 17:29:28 +0800 Subject: [PATCH 002/117] Bluetooth: hci_qca: Reopen the UART after enabling QCA2066 QCA2066 does not reopen the UART after the controller is enabled, which causes RX/TX out-of-sync errors. The UART has to be reopened once the controller is powered on. qca_regulator_init() already enables the controller and then reopens the UART, but QCA2066 does not go through it. QCA2066 was added with its own SoC type and handled in the default case. Let QCA2066 go through qca_regulator_init() as well, and handle it in the other places that check the SoC type in the same way. This also applies the baudrate switching, flow control, shutdown and probe handling of those chips to QCA2066. btqca.c checks the SoC type in the same way, so the firmware version is also shown in the log. Signed-off-by: Shuai Zhang Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btqca.c | 1 + drivers/bluetooth/hci_qca.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/drivers/bluetooth/btqca.c b/drivers/bluetooth/btqca.c index 60735b70d89a..9f54e33e4250 100644 --- a/drivers/bluetooth/btqca.c +++ b/drivers/bluetooth/btqca.c @@ -983,6 +983,7 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, switch (soc_type) { case QCA_WCN3991: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: /* get fw build info */ diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index dfaf4861f498..f10edada9512 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -1387,6 +1387,7 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate) case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: usleep_range(1000, 10000); @@ -1474,6 +1475,7 @@ static int qca_check_speeds(struct hci_uart *hu) case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: if (!qca_get_speed(hu, QCA_INIT_SPEED) && @@ -1517,6 +1519,7 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type) case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: hci_uart_set_flow_control(hu, true); @@ -1552,6 +1555,7 @@ error: case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: hci_uart_set_flow_control(hu, false); @@ -1868,6 +1872,7 @@ static int qca_power_on(struct hci_dev *hdev) case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: ret = qca_regulator_init(hu); @@ -1990,6 +1995,7 @@ retry: case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: if (qcadev && qcadev->bdaddr_property_broken) @@ -2023,6 +2029,7 @@ retry: case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: break; @@ -2285,6 +2292,7 @@ static void qca_power_off(struct hci_uart *hu) break; case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: gpiod_set_value_cansleep(qcadev->bt_en, 0); msleep(100); @@ -2439,6 +2447,7 @@ static int qca_serdev_probe(struct serdev_device *serdev) case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: qcadev->bt_power = devm_kzalloc(&serdev->dev, @@ -2458,6 +2467,7 @@ static int qca_serdev_probe(struct serdev_device *serdev) case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: if (!device_property_present(&serdev->dev, "enable-gpios")) { @@ -2501,6 +2511,7 @@ static int qca_serdev_probe(struct serdev_device *serdev) if (!qcadev->bt_en && (data->soc_type == QCA_WCN6750 || + data->soc_type == QCA_QCA2066 || data->soc_type == QCA_WCN6855 || data->soc_type == QCA_WCN7850)) power_ctrl_enabled = false; @@ -2509,6 +2520,7 @@ static int qca_serdev_probe(struct serdev_device *serdev) GPIOD_IN); if (IS_ERR(qcadev->sw_ctrl) && (data->soc_type == QCA_WCN6750 || + data->soc_type == QCA_QCA2066 || data->soc_type == QCA_WCN6855 || data->soc_type == QCA_WCN7850)) { dev_err(&serdev->dev, "failed to acquire SW_CTRL gpio\n"); @@ -2593,6 +2605,7 @@ static void qca_serdev_remove(struct serdev_device *serdev) case QCA_WCN3991: case QCA_WCN3998: case QCA_WCN6750: + case QCA_QCA2066: case QCA_WCN6855: case QCA_WCN7850: if (power->vregs_on) From 45e28b01e4d06282d03f08888f09722709d4b552 Mon Sep 17 00:00:00 2001 From: Shuai Zhang Date: Tue, 10 Nov 2026 17:29:29 +0800 Subject: [PATCH 003/117] Bluetooth: hci_qca: Don't use the serdev port after a failed reopen If serdev_device_open() fails in qca_port_reopen(), qca_regulator_init() or the qca_setup() retry path, the port is left closed but HCI_UART_PROTO_READY stays set. The error reaches qca_setup(), whose retry loop calls serdev_device_close() again, and hci_uart_close() or hci_uart_unregister_device() close it once more later. The HCI core also calls hci_uart_flush() from hci_dev_close_sync() before hdev->close(), which writes to the closed port. serdev_device_close() and serdev_device_write_flush() have no "not open" check. ttyport_open() clears serport->tty when it fails, so both end up passing NULL to the tty layer, and the runtime PM usage count is dropped once too often. Keep HCI_UART_PROTO_READY in sync with the port state in hci_qca: clear it when the port is closed, set it only after a successful open, and only call serdev_device_close() when it was set. hci_uart_open() already treats the flag as "port is open" and reopens the port when it is clear, so the next power on recovers. Make hci_uart_flush() skip the port flush when the flag is clear, as it already does for the proto flush. Signed-off-by: Shuai Zhang Reviewed-by: Bartosz Golaszewski Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_qca.c | 33 +++++++++++++++++++++++++++------ drivers/bluetooth/hci_serdev.c | 6 ++++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index f10edada9512..d693e2842725 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -1755,6 +1755,27 @@ static bool qca_wakeup(struct hci_dev *hdev) return wakeup; } +static void qca_port_close(struct hci_uart *hu) +{ + /* HCI_UART_PROTO_READY tracks whether the port is open, so a port + * left closed by a failed qca_port_open() is not closed again by + * hci_uart_close() or hci_uart_unregister_device(). + */ + if (test_and_clear_bit(HCI_UART_PROTO_READY, &hu->flags)) + serdev_device_close(hu->serdev); +} + +static int qca_port_open(struct hci_uart *hu) +{ + int ret; + + ret = serdev_device_open(hu->serdev); + if (!ret) + set_bit(HCI_UART_PROTO_READY, &hu->flags); + + return ret; +} + static int qca_port_reopen(struct hci_uart *hu) { int ret; @@ -1764,8 +1785,8 @@ static int qca_port_reopen(struct hci_uart *hu) * Without this, we will have RTS and CTS synchronization * issues. */ - serdev_device_close(hu->serdev); - ret = serdev_device_open(hu->serdev); + qca_port_close(hu); + ret = qca_port_open(hu); if (ret) { bt_dev_err(hu->hdev, "failed to open port"); return ret; @@ -1789,12 +1810,12 @@ static int qca_regulator_init(struct hci_uart *hu) qcadev = serdev_device_get_drvdata(hu->serdev); if (!qcadev->bt_power->vregs_on) { - serdev_device_close(hu->serdev); + qca_port_close(hu); ret = qca_regulator_enable(qcadev); if (ret) return ret; - ret = serdev_device_open(hu->serdev); + ret = qca_port_open(hu); if (ret) { bt_dev_err(hu->hdev, "failed to open port"); return ret; @@ -2073,8 +2094,8 @@ out: if (retries < MAX_INIT_RETRIES) { bt_dev_warn(hdev, "Retry BT power ON:%d", retries); if (hu->serdev) { - serdev_device_close(hu->serdev); - ret = serdev_device_open(hu->serdev); + qca_port_close(hu); + ret = qca_port_open(hu); if (ret) { bt_dev_err(hdev, "failed to open port"); return ret; diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c index 48ba017e219b..d2c48df34199 100644 --- a/drivers/bluetooth/hci_serdev.c +++ b/drivers/bluetooth/hci_serdev.c @@ -101,11 +101,13 @@ static int hci_uart_flush(struct hci_dev *hdev) kfree_skb(hu->tx_skb); hu->tx_skb = NULL; } + if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) + return 0; + /* Flush any pending characters in the driver and discipline. */ serdev_device_write_flush(hu->serdev); - if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) - hu->proto->flush(hu); + hu->proto->flush(hu); return 0; } From 4728474344793dd67956e03a2cb244b71383ef7c Mon Sep 17 00:00:00 2001 From: Xu Rao Date: Tue, 10 Nov 2026 11:07:56 +0800 Subject: [PATCH 004/117] Bluetooth: MGMT: Fix runtime config status opcode The Set Default Runtime Configuration command uses opcode 0x004e, but set_def_runtime_config() reports its invalid-parameter status with the Set Default System Configuration opcode, 0x004c. A management client that matches Command Status events to its pending request by opcode therefore cannot associate the response with the request it sent. Runtime configuration parameters are not implemented, so the command still returns MGMT_STATUS_INVALID_PARAMS. Use MGMT_OP_SET_DEF_RUNTIME_CONFIG for the status event so the response identifies the command that was actually handled. Fixes: aececa645dc7 ("Bluetooth: mgmt: Add commands for runtime configuration") Signed-off-by: Xu Rao Cc: stable@vger.kernel.org Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/mgmt_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bluetooth/mgmt_config.c b/net/bluetooth/mgmt_config.c index fdcc752c6f13..6a617656bfbe 100644 --- a/net/bluetooth/mgmt_config.c +++ b/net/bluetooth/mgmt_config.c @@ -362,6 +362,6 @@ int set_def_runtime_config(struct sock *sk, struct hci_dev *hdev, void *data, { bt_dev_dbg(hdev, "sock %p", sk); - return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEF_SYSTEM_CONFIG, + return mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_DEF_RUNTIME_CONFIG, MGMT_STATUS_INVALID_PARAMS); } From 1645edfa8c29e43239cca615cefcb19959d3aa36 Mon Sep 17 00:00:00 2001 From: Joas Antonio dos Santos Date: Tue, 10 Nov 2026 03:26:03 +0000 Subject: [PATCH 005/117] Bluetooth: L2CAP: validate MPS and MTU in ECRED connection response l2cap_ecred_conn_rsp() stores the MTU and MPS from the peer without checking them against the minimums required for enhanced credit based channels. The other LE and ECRED handlers (l2cap_le_connect_req(), l2cap_le_connect_rsp(), l2cap_ecred_conn_req(), l2cap_ecred_reconf_req()) all reject values below the minimum. With an MPS below L2CAP_SDULEN_SIZE, the pdu_len computation in l2cap_segment_le_sdu() wraps: pdu_len = chan->remote_mps - L2CAP_SDULEN_SIZE; pdu_len is then clamped to the SDU length, which l2cap_chan_send() has already limited to chan->omtu, so nothing is over-allocated and there is no memory safety issue. The result is that the whole SDU is sent as a single PDU, larger than the MPS the peer announced, and a channel is established with parameters the specification does not allow. Apply the same L2CAP_ECRED_MIN_MTU / L2CAP_ECRED_MIN_MPS checks that l2cap_ecred_conn_req() uses and drop the channel when the response carries smaller values. Found by LLM-assisted manual code review. Fixes: 15f02b910562 ("Bluetooth: L2CAP: Add initial code for Enhanced Credit Based Mode") Signed-off-by: Joas Antonio dos Santos Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 7dcb0586a10b..0398cc5a2dc0 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -5701,6 +5701,16 @@ static inline int l2cap_ecred_conn_rsp(struct l2cap_conn *conn, break; } + /* + * Validate MPS and MTU per BT Core Spec + * Vol 3 Part A Sec 10.2 + */ + if (mtu < L2CAP_ECRED_MIN_MTU || + mps < L2CAP_ECRED_MIN_MPS) { + l2cap_chan_del(chan, ECONNREFUSED); + break; + } + chan->ident = 0; chan->dcid = dcid; chan->omtu = mtu; From d9a1bd14caf5d235499319f7aee9e641c12d90a9 Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Sat, 24 Oct 2026 23:27:49 +0800 Subject: [PATCH 006/117] Bluetooth: hci_conn: Initialize the device before hash insertion An hci_conn must have an initialized embedded device before an RCU reader can acquire a reference to it. __hci_conn_add() instead adds the connection to conn_hash before hci_conn_init_sysfs() calls device_initialize(). Holding hdev->lock during creation does not exclude hci_disconnect_all_sync(), which looks up the connection and calls hci_conn_get() under RCU without that lock. When a new incoming ACL request overlaps controller poweroff before the connection is registered in sysfs, the separate event and request workqueues can execute this sequence: 1. The event worker holds hdev->lock and publishes a new connection in __hci_conn_add(), before device_initialize(). 2. The request worker finds that connection under RCU, calls hci_conn_get() and leaves its RCU read-side critical section. 3. The event worker runs hci_conn_init_sysfs(), sets BT_CONNECT in hci_conn_request_evt() and releases hdev->lock. 4. The request worker calls hci_abort_conn_sync(), which acquires hdev->lock and reaches hci_conn_failed(), hci_conn_del() and hci_conn_del_sysfs() to delete the pending connection. 5. After abort returns, the request worker calls hci_conn_put(). device_initialize() resets the kobject reference count to one, discarding the walker's premature get. If no other device references exist, deletion of the unregistered device drops that one reference and bt_link_release() frees the hci_conn. The walker's trailing put then accesses the freed kobject, as shown by the KASAN report below. The RCU grace period in hci_conn_hash_del() cannot preserve the walker after it has left its read-side critical section. Initialize the device before hci_conn_hash_add() publishes the connection. The existing RCU publication then makes the initialized device visible to readers, so the walker takes a valid reference that survives deletion until its matching put. KASAN report as below: ================================================================== BUG: KASAN: slab-use-after-free in kobject_put+0x4f3/0x610 Read of size 1 at addr ffff88811e6fcd2c by task kworker/u17:0/559 Workqueue: hci0 hci_cmd_sync_work Call Trace: dump_stack_lvl+0x93/0xd0 print_report+0xce/0x630 ? kobject_put+0x4f3/0x610 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? kobject_put+0x4f3/0x610 kasan_report+0xe0/0x110 ? kobject_put+0x4f3/0x610 ? hci_disconnect_all_sync.constprop.0+0xd8/0x520 kobject_put+0x4f3/0x610 ? hci_disconnect_all_sync.constprop.0+0xd8/0x520 put_device+0x24/0x30 hci_disconnect_all_sync.constprop.0+0x176/0x520 ? hci_disconnect_all_sync.constprop.0+0xcd/0x520 ? __pfx_hci_disconnect_all_sync.constprop.0+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 hci_set_powered_sync+0x48f/0x680 ? __pfx_hci_set_powered_sync+0x10/0x10 ? __pfx___mutex_unlock_slowpath+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 set_powered_sync+0xaa/0x150 hci_cmd_sync_work+0x1b3/0x450 ? srso_alias_return_thunk+0x5/0xfbef5 process_one_work+0x908/0x19c0 ? __pfx_process_one_work+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 ? srso_alias_return_thunk+0x5/0xfbef5 worker_thread+0x65c/0xe40 ? __pfx_worker_thread+0x10/0x10 kthread+0x34f/0x460 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x659/0x940 ? __pfx_ret_from_fork+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __switch_to+0x74f/0xf80 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 Allocated by task 561: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 __kmalloc_cache_noprof+0x251/0x610 __hci_conn_add+0x10c/0x1f70 hci_conn_add_unset+0x72/0x120 hci_conn_request_evt+0xb2b/0xd40 hci_event_packet+0x894/0xc70 hci_rx_work+0x367/0xf00 process_one_work+0x908/0x19c0 worker_thread+0x65c/0xe40 kthread+0x34f/0x460 ret_from_fork+0x659/0x940 ret_from_fork_asm+0x1a/0x30 Freed by task 559: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 kfree+0x307/0x580 bt_link_release+0x4a/0xb0 device_release+0xd7/0x280 kobject_put+0x1ad/0x610 put_device+0x24/0x30 hci_conn_del_sysfs+0x15d/0x190 hci_conn_del+0x684/0x1100 hci_abort_conn_sync+0x7d6/0xae0 hci_disconnect_all_sync.constprop.0+0x164/0x520 hci_set_powered_sync+0x48f/0x680 set_powered_sync+0xaa/0x150 hci_cmd_sync_work+0x1b3/0x450 process_one_work+0x908/0x19c0 worker_thread+0x65c/0xe40 kthread+0x34f/0x460 ret_from_fork+0x659/0x940 ret_from_fork_asm+0x1a/0x30 The buggy address belongs to the object at ffff88811e6fc000 which belongs to the cache kmalloc-8k of size 8192 The buggy address is located 3372 bytes inside of freed 8192-byte region [ffff88811e6fc000, ffff88811e6fe000) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x11e6f8 head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x200000000000040(head|node=0|zone=2) page_type: f5(slab) raw: 0200000000000040 ffff888100043180 dead000000000122 0000000000000000 raw: 0000000000000000 0000000000020002 00000000f5000000 0000000000000000 head: 0200000000000040 ffff888100043180 dead000000000122 0000000000000000 head: 0000000000000000 0000000000020002 00000000f5000000 0000000000000000 head: 0200000000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff88811e6fcc00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88811e6fcc80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff88811e6fcd00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff88811e6fcd80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88811e6fce00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== Fixes: 94d9ba9f9888 ("Bluetooth: hci_sync: Fix UAF in hci_disconnect_all_sync") Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_conn.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index eebd73988bf6..c468a9332e05 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1166,6 +1166,9 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, hci_dev_hold(hdev); + /* Initialize the device before publishing it to RCU readers. */ + hci_conn_init_sysfs(conn); + hci_conn_hash_add(hdev, conn); /* The SCO and eSCO connections will only be notified when their @@ -1177,7 +1180,6 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, hdev->notify(hdev, HCI_NOTIFY_CONN_ADD); } - hci_conn_init_sysfs(conn); return conn; } From 58d8a0955065fb00824865dca5b573a1becbb1ca Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Sun, 25 Oct 2026 00:15:17 +0800 Subject: [PATCH 007/117] Bluetooth: vhci: Flush suspend work after removing debugfs The VHCI controller must remain alive until suspend_work finishes. vhci_release() flushes the work before removing the force_suspend debugfs entry, so an active writer can queue work after that flush. A force_suspend write changing the suspend state can overlap the last close of /dev/vhci as follows: /dev/vhci close Debugfs writer Suspend worker --------------- -------------- -------------- vhci_release() force_suspend_write() flush_work() returns [not queued yet] schedule_work() --> hci_suspend_dev() check powered check !HCI_UNREGISTER hci_suspend_sync() unlock(req_lock) vhci_debugfs_remove() wait for writer hci_unregister_dev() hci_free_dev() drop last reference free hdev hci_clear_wake_reason() lock freed mutex use-after-free The controller locks serialize state access but do not retain the allocation. Unregister drains HCI-owned work, but does not cover VHCI's suspend_work on the system workqueue. Flush suspend_work again after removing the debugfs entries and before unregistering the controller. Removal waits for active writers and prevents new callbacks, so the second flush drains all remaining work while the controller and driver data are still alive. Retain the initial flush to preserve the existing teardown order. Runtime testing of this change was not performed. KASAN report as below: ================================================================== BUG: KASAN: use-after-free in __mutex_lock+0x1e68/0x2590 Read of size 8 at addr ffff8881011b80b0 by task kworker/0:0/9 Workqueue: events vhci_suspend_work Call Trace: dump_stack_lvl+0x93/0xd0 print_report+0xce/0x630 ? __mutex_lock+0x1e68/0x2590 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? __mutex_lock+0x1e68/0x2590 kasan_report+0xe0/0x110 ? __mutex_lock+0x1e68/0x2590 __mutex_lock+0x1e68/0x2590 ? hci_suspend_dev+0x1ff/0x650 ? srso_alias_return_thunk+0x5/0xfbef5 ? mark_held_locks+0x40/0x70 ? _raw_spin_unlock_irqrestore+0x44/0x60 ? srso_alias_return_thunk+0x5/0xfbef5 ? lockdep_hardirqs_on_prepare+0xea/0x1a0 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx___mutex_lock+0x10/0x10 ? _raw_spin_unlock_irqrestore+0x44/0x60 ? srso_alias_return_thunk+0x5/0xfbef5 ? pmbd_gate_site_armed+0x31/0x1c0 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_pmbd_probe_hit_cookie+0x10/0x10 ? hci_suspend_dev+0x1ff/0x650 hci_suspend_dev+0x1ff/0x650 vhci_suspend_work+0xa5/0x190 process_one_work+0x908/0x19c0 ? __pfx_process_one_work+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 ? srso_alias_return_thunk+0x5/0xfbef5 worker_thread+0x65c/0xe40 ? __pfx_worker_thread+0x10/0x10 kthread+0x34f/0x460 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x659/0x940 ? __pfx_ret_from_fork+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __switch_to+0x74f/0xf80 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff8881011b9040 pfn:0x1011b8 flags: 0x200000000000000(node=0|zone=2) raw: 0200000000000000 ffffea0004073308 ffff88818863f180 0000000000000000 raw: ffff8881011b9040 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff8881011b7f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffff8881011b8000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff >ffff8881011b8080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ^ ffff8881011b8100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ffff8881011b8180: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ================================================================== Fixes: d16e6d19ccc6 ("Bluetooth: hci_vhci: Fix calling hci_{suspend,resume}_dev") Assisted-by: LLM Signed-off-by: Cen Zhang Tested-by: Chad Aldreda Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_vhci.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c index 8f7db0102b25..bedba3c140ac 100644 --- a/drivers/bluetooth/hci_vhci.c +++ b/drivers/bluetooth/hci_vhci.c @@ -701,6 +701,8 @@ static int vhci_release(struct inode *inode, struct file *file) if (hdev) { if (!IS_ERR_OR_NULL(hdev->debugfs)) vhci_debugfs_remove(hdev); + /* Drain work queued by the last force_suspend writers. */ + flush_work(&data->suspend_work); hci_unregister_dev(hdev); hci_free_dev(hdev); } From f8ba3e2e82f06cbd469d6ee249fbf86c138247c9 Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Sat, 24 Oct 2026 23:28:23 +0800 Subject: [PATCH 008/117] Bluetooth: vhci: Serialize packet reception with device creation The hci_dev passed to hci_recv_frame() must stay alive until the receive operation finishes. __vhci_create_device() stores data->hdev before hci_register_dev() and frees the device if registration fails. vhci_get_user() checks and uses that pointer without taking the open_mutex held by the creator or a device reference. An incoming packet write can overlap the delayed default-create work scheduled by vhci_open(). If registration fails before acquiring the registration reference, the following order is possible: Default-create work Packet write vhci_create_device() mutex_lock(open_mutex) data->hdev = hdev vhci_get_user() load data->hdev hci_register_dev() fails hci_free_dev(hdev) bt_host_release(): kfree(hdev) data->hdev = NULL mutex_unlock(open_mutex) hci_recv_frame(hdev, skb) read hdev->flags The packet retains the pointer before the final put and reads flags after the allocation is freed. The HCI_UP/HCI_INIT test therefore accesses freed memory before it can reject the packet. Hold open_mutex from the packet-side pointer check until hci_recv_frame() returns. Creation and its error cleanup already hold this mutex, so the writer waits until they finish and cannot retain a failed device allocation. Release the mutex on the missing-device error path too. KASAN report as below: BUG: KASAN: use-after-free in hci_recv_frame+0x4e/0x7e0 Read of size 8 at addr ffff888107034138 by task python3/500 Call Trace: dump_stack_lvl+0x93/0xd0 print_report+0xce/0x630 ? hci_recv_frame+0x4e/0x7e0 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? hci_recv_frame+0x4e/0x7e0 kasan_report+0xe0/0x110 ? hci_recv_frame+0x4e/0x7e0 kasan_check_range+0x105/0x1b0 hci_recv_frame+0x4e/0x7e0 vhci_write+0x35a/0x4c0 vfs_write+0x637/0x1010 ? __pfx_vhci_write+0x10/0x10 ? __might_fault+0xdd/0x190 ? __pfx_vfs_write+0x10/0x10 ? __pfx_hrtimer_wakeup+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? common_nsleep_timens+0xa8/0x160 ksys_write+0x111/0x200 ? __pfx_ksys_write+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? restore_fpregs_from_fpstate+0x55/0x100 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff888107036a40 pfn:0x107034 flags: 0x200000000000000(node=0|zone=2) raw: 0200000000000000 ffffea00041c0308 ffff8881887bf180 0000000000000000 raw: ffff888107036a40 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff888107034000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ffff888107034080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff >ffff888107034100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ^ ffff888107034180: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ffff888107034200: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ================================================================== Fixes: 23424c0d3169 ("Bluetooth: Add support creating virtual AMP controllers") Assisted-by: LLM Signed-off-by: Cen Zhang Tested-by: Chad Aldreda Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_vhci.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c index bedba3c140ac..7fec02705e58 100644 --- a/drivers/bluetooth/hci_vhci.c +++ b/drivers/bluetooth/hci_vhci.c @@ -524,7 +524,9 @@ static inline ssize_t vhci_get_user(struct vhci_data *data, case HCI_ACLDATA_PKT: case HCI_SCODATA_PKT: case HCI_ISODATA_PKT: + mutex_lock(&data->open_mutex); if (!data->hdev) { + mutex_unlock(&data->open_mutex); kfree_skb(skb); return -ENODEV; } @@ -532,6 +534,7 @@ static inline ssize_t vhci_get_user(struct vhci_data *data, hci_skb_pkt_type(skb) = pkt_type; ret = hci_recv_frame(data->hdev, skb); + mutex_unlock(&data->open_mutex); break; case HCI_VENDOR_PKT: From df33621e70363df4d6963ad5ff19a3ae740c7703 Mon Sep 17 00:00:00 2001 From: Cen Zhang Date: Sun, 25 Oct 2026 00:35:21 +0800 Subject: [PATCH 009/117] Bluetooth: L2CAP: Protect the receive reject-list lookup Reject-list entries must remain alive throughout a lookup. Management updates the list under hdev->lock, but l2cap_recv_frame() traverses it under conn->lock after l2cap_recv_acldata() has released hdev->lock. An established LE connection can still receive ACL data after its peer has been added to the reject list. If a management socket unblocks that peer during the receive-side lookup, the following ordering is possible: HCI receive Management l2cap_recv_acldata() release hdev->lock acquire conn->lock l2cap_recv_frame() lookup selects entry unblock_device() acquire hdev->lock hci_bdaddr_list_del() unlink and kfree(entry) read entry->bdaddr_type Management does not take conn->lock, so deletion can free the selected entry before the lookup reads its fields. This causes a use-after-free read in hci_bdaddr_list_lookup(). Compute the reject decision under the existing device lock in l2cap_recv_acldata() and pass only the boolean to l2cap_recv_frame(). For pending receive data, take the snapshot in l2cap_conn_ready() and l2cap_security_cfm(), which already hold hdev->lock. Publish it under conn->lock before queuing the worker on the existing device workqueue: HCI callback Pending RX worker hold hdev->lock acquire conn->lock lookup reject list save boolean; queue work release conn->lock acquire conn->lock consume boolean drain pending frames The snapshot belongs to the scheduled batch. A subsequent scheduling callback refreshes it under both locks, including when queue_work() coalesces with already pending work. No reject-list pointer survives the lookup, and the worker reads the boolean under conn->lock. Taking the device lock in the worker would deadlock against l2cap_conn_del(), which holds it while cancelling the work synchronously. A failed trylock followed by immediate self-requeue would instead keep retrying without a delay and extend a concurrent workqueue drain. Keep the lookup in the scheduling callbacks so the worker needs neither the device lock nor a retry. Skip scheduling when pending_rx is empty. KASAN report as below: ================================================================== BUG: KASAN: slab-use-after-free in hci_bdaddr_list_lookup+0x145/0x160 Read of size 1 at addr ffff88810cba64d6 by task kworker/u17:0/493 Workqueue: hci0 hci_rx_work Call Trace: dump_stack_lvl+0x93/0xd0 print_report+0xce/0x630 ? hci_bdaddr_list_lookup+0x145/0x160 ? srso_alias_return_thunk+0x5/0xfbef5 ? __virt_addr_valid+0x20d/0x410 ? hci_bdaddr_list_lookup+0x145/0x160 kasan_report+0xe0/0x110 ? hci_bdaddr_list_lookup+0x145/0x160 hci_bdaddr_list_lookup+0x145/0x160 l2cap_recv_frame+0x865/0x8830 ? srso_alias_return_thunk+0x5/0xfbef5 ? __mutex_lock+0x182c/0x2590 ? __pfx_l2cap_recv_frame+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? find_held_lock+0x2b/0x80 ? l2cap_recv_acldata+0x1eb/0x10e0 ? __pfx___mutex_lock+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __mutex_unlock_slowpath+0x147/0x920 ? __pfx_l2cap_conn_hold_unless_zero+0x10/0x10 ? __pfx_hci_conn_enter_active_mode+0x10/0x10 ? l2cap_recv_acldata+0x13d/0x10e0 ? srso_alias_return_thunk+0x5/0xfbef5 l2cap_recv_acldata+0xe9f/0x10e0 ? srso_alias_return_thunk+0x5/0xfbef5 hci_rx_work+0x5a6/0xf00 ? srso_alias_return_thunk+0x5/0xfbef5 process_one_work+0x908/0x19c0 ? __pfx_process_one_work+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 ? srso_alias_return_thunk+0x5/0xfbef5 worker_thread+0x65c/0xe40 ? __pfx_worker_thread+0x10/0x10 kthread+0x34f/0x460 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x659/0x940 ? __pfx_ret_from_fork+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __switch_to+0x74f/0xf80 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 Allocated by task 604: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 __kmalloc_cache_noprof+0x251/0x610 hci_bdaddr_list_add+0xdf/0x2c0 block_device+0x112/0x260 hci_sock_sendmsg+0x128b/0x22e0 sock_write_iter+0x4c0/0x550 do_iter_readv_writev+0x59c/0x860 vfs_writev+0x30e/0xc10 do_writev+0x241/0x2f0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 606: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x5f/0x80 kfree+0x307/0x580 hci_bdaddr_list_del+0x1a9/0x2a0 unblock_device+0x112/0x260 hci_sock_sendmsg+0x128b/0x22e0 sock_write_iter+0x4c0/0x550 do_iter_readv_writev+0x59c/0x860 vfs_writev+0x30e/0xc10 do_writev+0x241/0x2f0 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the object at ffff88810cba64c0 which belongs to the cache kmalloc-32 of size 32 The buggy address is located 22 bytes inside of freed 32-byte region [ffff88810cba64c0, ffff88810cba64e0) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10cba6 flags: 0x200000000000000(node=0|zone=2) page_type: f5(slab) raw: 0200000000000000 ffff888100042780 dead000000000100 dead000000000122 raw: 0000000000000000 0000000000400040 00000000f5000000 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff88810cba6380: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc ffff88810cba6400: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc >ffff88810cba6480: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc ^ ffff88810cba6500: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc ffff88810cba6580: fa fb fb fb fc fc fc fc fa fb fb fb fc fc fc fc ================================================================== Fixes: cc8dba2bc302 ("Bluetooth: Block ATT connection on LE when device is blocked") Assisted-by: LLM Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/l2cap.h | 1 + net/bluetooth/l2cap_core.c | 61 +++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index 2a05bda8ab43..bb2839972cf3 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -636,6 +636,7 @@ struct l2cap_conn { struct sk_buff_head pending_rx; struct work_struct pending_rx_work; + bool pending_rx_blocked __guarded_by(&lock); struct delayed_work id_addr_timer; diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 0398cc5a2dc0..486b968143d3 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -1747,10 +1747,40 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn) } } -static void l2cap_conn_ready(struct l2cap_conn *conn) +static bool l2cap_is_blocked(struct hci_conn *hcon) + __must_hold(&hcon->hdev->lock) { + /* Since we can't actively block incoming LE connections we must + * at least ensure that we ignore incoming data from them. + */ + return hcon->type == LE_LINK && + hci_bdaddr_list_lookup(&hcon->hdev->reject_list, &hcon->dst, + bdaddr_dst_type(hcon)); +} + +static void l2cap_queue_pending_rx(struct hci_conn *hcon) + __must_hold(&hcon->hdev->lock) +{ + struct l2cap_conn *conn = hcon->l2cap_data; + + mutex_lock(&conn->lock); + + if (!skb_queue_empty(&conn->pending_rx)) { + /* Teardown holds hdev->lock while cancelling the worker. + * Pass the decision under conn->lock to avoid that lock. + */ + conn->pending_rx_blocked = l2cap_is_blocked(hcon); + queue_work(hcon->hdev->workqueue, &conn->pending_rx_work); + } + + mutex_unlock(&conn->lock); +} + +static void l2cap_conn_ready(struct hci_conn *hcon) + __must_hold(&hcon->hdev->lock) +{ + struct l2cap_conn *conn = hcon->l2cap_data; struct l2cap_chan *chan; - struct hci_conn *hcon = conn->hcon; BT_DBG("conn %p", conn); @@ -1782,7 +1812,7 @@ static void l2cap_conn_ready(struct l2cap_conn *conn) if (hcon->type == LE_LINK) l2cap_le_conn_ready(conn); - queue_work(hcon->hdev->workqueue, &conn->pending_rx_work); + l2cap_queue_pending_rx(hcon); } /* Notify sockets that we cannot guaranty reliability anymore */ @@ -7391,7 +7421,8 @@ free_skb: kfree_skb(skb); } -static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb) +static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb, + bool blocked) __must_hold(&conn->lock) { struct l2cap_hdr *lh = (void *) skb->data; @@ -7418,12 +7449,7 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb) return; } - /* Since we can't actively block incoming LE connections we must - * at least ensure that we ignore incoming data from them. - */ - if (hcon->type == LE_LINK && - hci_bdaddr_list_lookup(&hcon->hdev->reject_list, &hcon->dst, - bdaddr_dst_type(hcon))) { + if (blocked) { kfree_skb(skb); return; } @@ -7471,7 +7497,7 @@ static void process_pending_rx(struct work_struct *work) */ while (!test_bit(HCI_CONN_ENC_KEY_SIZE_PEND, conn->hcon->flags) && (skb = skb_dequeue(&conn->pending_rx))) - l2cap_recv_frame(conn, skb); + l2cap_recv_frame(conn, skb, conn->pending_rx_blocked); mutex_unlock(&conn->lock); } @@ -7923,7 +7949,7 @@ next: mutex_unlock(&conn->lock); - l2cap_conn_ready(conn); + l2cap_conn_ready(hcon); } int l2cap_disconn_ind(struct hci_conn *hcon) @@ -8062,8 +8088,7 @@ static void l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt) mutex_unlock(&conn->lock); /* Process data held back while the encryption key size was read */ - if (!skb_queue_empty(&conn->pending_rx)) - queue_work(hcon->hdev->workqueue, &conn->pending_rx_work); + l2cap_queue_pending_rx(hcon); } /* Append fragment into frame respecting the maximum len of rx_skb */ @@ -8152,6 +8177,7 @@ int l2cap_recv_acldata(struct hci_dev *hdev, u16 handle, { struct hci_conn *hcon; struct l2cap_conn *conn; + bool blocked; int len; /* Lock hdev for hci_conn, and race on l2cap_data vs. l2cap_conn_del */ @@ -8174,6 +8200,7 @@ int l2cap_recv_acldata(struct hci_dev *hdev, u16 handle, conn = l2cap_conn_add(hcon); conn = l2cap_conn_hold_unless_zero(conn); + blocked = l2cap_is_blocked(hcon); hcon = NULL; hci_dev_unlock(hdev); @@ -8210,7 +8237,7 @@ int l2cap_recv_acldata(struct hci_dev *hdev, u16 handle, if (len == skb->len) { /* Complete frame received */ - l2cap_recv_frame(conn, skb); + l2cap_recv_frame(conn, skb, blocked); goto unlock; } @@ -8234,7 +8261,7 @@ int l2cap_recv_acldata(struct hci_dev *hdev, u16 handle, * setting the socket unreliable. */ skb->len = len; - l2cap_recv_frame(conn, skb); + l2cap_recv_frame(conn, skb, blocked); l2cap_conn_unreliable(conn, ECOMM); goto unlock; } @@ -8284,7 +8311,7 @@ int l2cap_recv_acldata(struct hci_dev *hdev, u16 handle, */ struct sk_buff *rx_skb = conn->rx_skb; conn->rx_skb = NULL; - l2cap_recv_frame(conn, rx_skb); + l2cap_recv_frame(conn, rx_skb, blocked); } break; } From daf949c968d485badd6c1fc5b6965ea8175e7dda Mon Sep 17 00:00:00 2001 From: Weihong Guan Date: Wed, 11 Nov 2026 16:51:30 +0000 Subject: [PATCH 010/117] Bluetooth: hci_sync: Set random address on the set's handle When the controller supports a single advertising set, hci_add_adv_instance() gives instance 1 handle 0x00, and the parameters, data and enable commands for an instance use adv->handle. LE Set Advertising Set Random Address, from hci_set_adv_set_random_addr_sync(), still sends the instance number, 0x01, a set the controller doesn't have, so an instance using a random address, such as a non-connectable one, never starts: $ btmgmt add-adv -d 0A09434841445654455354 1 Add Advertising failed with status 0x0d (Invalid Parameters) < HCI Command: LE Set Extended Advertising Parameters Handle: 0x00 < HCI Command: LE Set Extended Advertising Data Handle: 0x00 < HCI Command: LE Set Advertising Set Random Address Advertising handle: 0x01 Send the instance's handle, looked up with hdev->lock held. hci_cc_le_set_adv_set_random_addr() records the address in the instance numbered as the handle and leaves handle 0x00 alone, as that handle's address is hdev->random_addr for instance 0. Instance 1's address on handle 0x00 would then go unrecorded, and its RPA timer never start, so record it in hci_set_adv_set_random_addr_sync() once the command succeeds, as the completion does for the other handles. Fixes: e77f43d531af ("Bluetooth: hci_core: Fix not handling hdev->le_num_of_adv_sets=1") Assisted-by: Claude:claude-opus-5.5 Signed-off-by: Weihong Guan Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 9213e3ef9f26..320c5ba0d555 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -1258,6 +1258,8 @@ static int hci_set_adv_set_random_addr_sync(struct hci_dev *hdev, u8 instance, bdaddr_t *random_addr) { struct hci_cp_le_set_adv_set_rand_addr cp; + struct adv_info *adv; + u8 handle = instance; int err; if (!instance) { @@ -1269,15 +1271,46 @@ static int hci_set_adv_set_random_addr_sync(struct hci_dev *hdev, u8 instance, err = hci_set_random_addr_sync(hdev, random_addr); if (err) return err; + } else { + hci_dev_lock(hdev); + adv = hci_find_adv_instance(hdev, instance); + if (adv) + handle = adv->handle; + hci_dev_unlock(hdev); } memset(&cp, 0, sizeof(cp)); - cp.handle = instance; + cp.handle = handle; bacpy(&cp.bdaddr, random_addr); - return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR, - sizeof(cp), &cp, HCI_CMD_TIMEOUT); + err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR, + sizeof(cp), &cp, HCI_CMD_TIMEOUT); + if (err || handle == instance) + return err; + + /* hci_cc_le_set_adv_set_random_addr() records the address of the + * instance numbered as the handle, and leaves handle 0x00 to + * hdev->random_addr, so record it here for an instance using another + * handle: instance 1 on handle 0x00, on a controller supporting a + * single advertising set. + */ + hci_dev_lock(hdev); + + adv = hci_find_adv_instance(hdev, instance); + if (adv) { + bacpy(&adv->random_addr, random_addr); + if (!bacmp(&hdev->rpa, random_addr)) { + adv->rpa_expired = false; + queue_delayed_work(hdev->workqueue, + &adv->rpa_expired_cb, + secs_to_jiffies(hdev->rpa_timeout)); + } + } + + hci_dev_unlock(hdev); + + return 0; } static int From e7e877bf658acd15fc7dda1bff3e66d0fa69a061 Mon Sep 17 00:00:00 2001 From: Weihong Guan Date: Wed, 11 Nov 2026 16:51:31 +0000 Subject: [PATCH 011/117] Bluetooth: hci_sync: Remove an advertising set by its handle When the controller supports a single advertising set, hci_add_adv_instance() gives instance 1 handle 0x00, but hci_remove_ext_adv_instance_sync() sends the instance number as the handle of LE Remove Advertising Set, so removing instance 1 fails: $ btmgmt rm-adv 1 Remove Advertising failed with status 0x03 (Failed) < HCI Command: LE Remove Advertising Set Handle: 1 > HCI Event: Command Complete Status: Unknown Advertising Identifier (0x42) Send the instance's handle, looked up with hdev->lock held. Two more things follow from the instance and the handle differing: - hci_cc_le_remove_adv_set() removes the instance numbered as the handle it sent, which for handle 0x00 is instance 0, so instance 1 would stay in hdev->adv_instances with its RPA timer running, and no MGMT_EV_ADVERTISING_REMOVED. The completion can't tell instance 1 from instance 0, which the MGMT Set Advertising path removes on the same handle, so remove instance 1 in hci_remove_ext_adv_instance_sync() once the command succeeds. - While Global Advertising is on, it owns handle 0x00 (adv_overridden_by_global()), and the set may be enabled for it, so the controller would refuse to remove it, with Command Disallowed. Remove only the instance then, leaving the set to Global Advertising. Fixes: e77f43d531af ("Bluetooth: hci_core: Fix not handling hdev->le_num_of_adv_sets=1") Assisted-by: Claude:claude-opus-5.5 Signed-off-by: Weihong Guan Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 55 +++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 320c5ba0d555..d4a4f49df5ac 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -2110,6 +2110,9 @@ int hci_enable_advertising(struct hci_dev *hdev) int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance, struct sock *sk) { + struct adv_info *adv = NULL; + u8 handle = instance; + bool global = false; int err; if (!ext_adv_capable(hdev)) @@ -2119,13 +2122,53 @@ int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance, if (err) return err; - /* If request specifies an instance that doesn't exist, fail */ - if (instance > 0 && !hci_find_adv_instance(hdev, instance)) - return -EINVAL; + if (instance) { + hci_dev_lock(hdev); - return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_REMOVE_ADV_SET, - sizeof(instance), &instance, 0, - HCI_CMD_TIMEOUT, sk); + adv = hci_find_adv_instance(hdev, instance); + if (adv) { + handle = adv->handle; + + /* An instance sharing handle 0x00 with Global + * Advertising doesn't own the set while Global + * Advertising is on, and the set may still be enabled + * for it, which the controller would refuse to remove. + */ + global = !handle && + (hci_dev_test_flag(hdev, HCI_ADVERTISING) || + hci_dev_test_flag(hdev, HCI_LE_ADV_0)); + } + + hci_dev_unlock(hdev); + + /* If request specifies an instance that doesn't exist, fail */ + if (!adv) + return -EINVAL; + } + + if (!global) { + err = __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_REMOVE_ADV_SET, + sizeof(handle), &handle, 0, + HCI_CMD_TIMEOUT, sk); + if (err) + return err; + } + + /* hci_cc_le_remove_adv_set() removes the instance numbered as the + * handle it sent, so remove here an instance using another handle: + * instance 1 on handle 0x00, on a controller supporting a single + * advertising set. The completion can't tell it from instance 0. + */ + if (handle != instance) { + hci_dev_lock(hdev); + + if (!hci_remove_adv_instance(hdev, instance)) + mgmt_advertising_removed(sk, hdev, instance); + + hci_dev_unlock(hdev); + } + + return 0; } int hci_le_terminate_big_sync(struct hci_dev *hdev, u8 handle, u8 reason) From 8b1eff978e66efb5ed66b79591851203d05ab303 Mon Sep 17 00:00:00 2001 From: Weihong Guan Date: Wed, 11 Nov 2026 16:51:32 +0000 Subject: [PATCH 012/117] Bluetooth: hci_core: Add hci_free_adv_instance() hci_remove_adv_instance() looks the instance up by its number and then frees it. A caller that already holds the instance, found some other way, has to look it up again by number to remove it. Split the freeing into hci_free_adv_instance(), which takes the instance itself, and have hci_remove_adv_instance() call it after the lookup. No functional change. Suggested-by: Luiz Augusto von Dentz Assisted-by: Claude:claude-opus-5.5 Signed-off-by: Weihong Guan Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_core.c | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 6fb713d5e4be..fd4da751a24f 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1972,6 +1972,7 @@ struct adv_info *hci_add_per_instance(struct hci_dev *hdev, u8 instance, u8 sid, int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance, u16 adv_data_len, u8 *adv_data, u16 scan_rsp_len, u8 *scan_rsp_data); +void hci_free_adv_instance(struct hci_dev *hdev, struct adv_info *adv_instance); int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance); void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired); u32 hci_adv_instance_flags(struct hci_dev *hdev, u8 instance); diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index c97aec3caba0..846e6eb2d1bc 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1610,17 +1610,11 @@ struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance) } /* This function requires the caller holds hdev->lock */ -int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance) +void hci_free_adv_instance(struct hci_dev *hdev, struct adv_info *adv_instance) { - struct adv_info *adv_instance; + BT_DBG("%s removing %dMR", hdev->name, adv_instance->instance); - adv_instance = hci_find_adv_instance(hdev, instance); - if (!adv_instance) - return -ENOENT; - - BT_DBG("%s removing %dMR", hdev->name, instance); - - if (hdev->cur_adv_instance == instance) { + if (hdev->cur_adv_instance == adv_instance->instance) { if (hdev->adv_instance_timeout) { cancel_delayed_work(&hdev->adv_instance_expire); hdev->adv_instance_timeout = false; @@ -1634,6 +1628,18 @@ int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance) kfree(adv_instance); hdev->adv_instance_cnt--; +} + +/* This function requires the caller holds hdev->lock */ +int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance) +{ + struct adv_info *adv_instance; + + adv_instance = hci_find_adv_instance(hdev, instance); + if (!adv_instance) + return -ENOENT; + + hci_free_adv_instance(hdev, adv_instance); return 0; } From 4dce35adafb5d258a58788c0282a0dd43e7ccd73 Mon Sep 17 00:00:00 2001 From: Weihong Guan Date: Wed, 11 Nov 2026 16:51:33 +0000 Subject: [PATCH 013/117] Bluetooth: hci_event: Find the owner of a terminated adv set hci_le_ext_adv_term_evt() looks the instance up by the event's handle, but when the controller supports a single advertising set, hci_add_adv_instance() gives instance 1 handle 0x00, which is also the handle of Global Advertising. For instance 1 the event then finds no instance, and: - a connection from it gets hdev->random_addr as its responder address, rather than the instance's random address, which SMP then checks against; - the connection stores handle 0x00 in conn->adv_instance, which is later restored as hdev->cur_adv_instance, so after the disconnection instance 0 is re-enabled rather than instance 1; - when the set terminates with an error, instance 0 is removed rather than instance 1, so instance 1 stays with no MGMT_EV_ADVERTISING_REMOVED. Find the instance owning the set: for handle 0x00 the instance enabled on it, as hci_le_ext_adv_set_enabled() tracks, and use its instance number and random address. On an error, free the instance found with hci_free_adv_instance() rather than looking it up again. Global Advertising, and any other handle, are handled as before. Fixes: e77f43d531af ("Bluetooth: hci_core: Fix not handling hdev->le_num_of_adv_sets=1") Assisted-by: Claude:claude-opus-5.5 Signed-off-by: Weihong Guan Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_event.c | 42 +++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 5e6b25eb5053..10c8b7b8e329 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -6158,6 +6158,26 @@ static void hci_le_pa_sync_lost_evt(struct hci_dev *hdev, void *data, hci_dev_unlock(hdev); } +/* The instance advertising on the set identified by handle. Handle 0x00 may + * be shared by Global Advertising and an instance, e.g. instance 1 when the + * controller supports a single advertising set, in which case the instance + * enabled on it, if any, owns the set (see hci_le_ext_adv_set_enabled()). + */ +static struct adv_info *hci_le_ext_adv_owner(struct hci_dev *hdev, u8 handle) +{ + struct adv_info *adv; + + if (handle) + return hci_find_adv_instance(hdev, handle); + + list_for_each_entry(adv, &hdev->adv_instances, list) { + if (!adv->handle && adv->enabled) + return adv; + } + + return NULL; +} + static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data, struct sk_buff *skb) { @@ -6181,15 +6201,18 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data, hci_dev_lock(hdev); - adv = hci_find_adv_instance(hdev, ev->handle); + adv = hci_le_ext_adv_owner(hdev, ev->handle); if (ev->status) { + u8 instance; + if (!adv) goto unlock; /* Remove advertising as it has been terminated */ - hci_remove_adv_instance(hdev, ev->handle); - mgmt_advertising_removed(NULL, hdev, ev->handle); + instance = adv->instance; + hci_free_adv_instance(hdev, adv); + mgmt_advertising_removed(NULL, hdev, instance); list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { if (adv->enabled) @@ -6206,22 +6229,19 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data, conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->conn_handle)); if (conn) { - /* Store handle in the connection so the correct advertising - * instance can be re-enabled when disconnected. + /* Store the instance in the connection so the correct + * advertising instance can be re-enabled when disconnected. */ - conn->adv_instance = ev->handle; + conn->adv_instance = adv ? adv->instance : ev->handle; if (hdev->adv_addr_type != ADDR_LE_DEV_RANDOM || bacmp(&conn->resp_addr, BDADDR_ANY)) goto unlock; - if (!ev->handle) { - bacpy(&conn->resp_addr, &hdev->random_addr); - goto unlock; - } - if (adv) bacpy(&conn->resp_addr, &adv->random_addr); + else if (!ev->handle) + bacpy(&conn->resp_addr, &hdev->random_addr); } unlock: From fd038b82c71baa8dfb80e1781e53c0dbbda84e70 Mon Sep 17 00:00:00 2001 From: Chun-Yi Lee Date: Wed, 11 Nov 2026 17:45:18 +0800 Subject: [PATCH 014/117] Bluetooth: SMP: Fail if local and remote public key X coords match The commit 6d19628f539f ("Bluetooth: SMP: Fail if remote and local public keys are identical") patch be introduced since v5.13. Looks this patch can handle the CVE-2021-37577 issue. However, it only checks if the full 64-byte public key (X and Y coordinates) is identical, which is insufficient. In CVE-2021-37577: Bluetooth LE and BR/EDR Secure Connections pairing and Secure Simple Pairing using the Passkey entry protocol in Bluetooth Core Specifications 2.1 through 5.3 may permit an unauthenticated man-in-the-middle attacker to identify the Passkey used during pairing by reflection of a crafted public key with the same X coordinate as the offered public key and by reflection of the authentication evidence of the initiating device, potentially permitting this attacker to complete authenticated pairing with the responding device using the correct Passkey for the pairing session. This is a related issue to CVE-2020-26558. Furthermore, according to the Bluetooth Core Specification, the remote and local public keys should not have the same X coordinate: Bluetooth Core Specification Version: v5.4 (7.1 PHASE 1: PUBLIC KEY EXCHANGE) "If the two public keys have the same X coordinate and neither is the debug key (see [Vol 4] Part E, Section 7.6.4), each device should fail the pairing process." Bluetooth Core Specification Version: v6.0 (7.1 Phase 1: Public key exchange) "If the two public keys have the same X coordinate and neither is the debug key (see [Vol 4] Part E, Section 7.6.4), each device shall fail the pairing process." To ensure both initiator and responder roles strictly enforce this rule: - In smp_cmd_public_key(), restrict the check for the initiator to compare only the 32-byte X coordinate of the public keys rather than the full 64 bytes. - In sc_send_public_key(), add the corresponding check for the responder to verify that the 32-byte X coordinate of remote_pk does not match local_pk before transmitting its own public key. This makes the validation compliant with the specification and mitigates CVE-2021-37577 across both pairing roles. Fixes: 6d19628f539f ("Bluetooth: SMP: Fail if remote and local public keys are identical") Link: https://nvd.nist.gov/vuln/detail/cve-2021-37577 Signed-off-by: Chun-Yi Lee Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/smp.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index b7015e37e1f1..6ccb38b1d56d 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c @@ -1898,6 +1898,16 @@ static u8 sc_send_public_key(struct smp_chan *smp) } done: + /* Check if remote and local public keys are the same and debug key is + * not in use. + */ + if (!test_bit(SMP_FLAG_DEBUG_KEY, &smp->flags) && + !test_bit(SMP_FLAG_INITIATOR, &smp->flags) && + !crypto_memneq(smp->remote_pk, smp->local_pk, 32)) { + bt_dev_err(hdev, "Remote and local public keys are identical"); + return SMP_DHKEY_CHECK_FAILED; + } + SMP_DBG("Local Public Key X: %32phN", smp->local_pk); SMP_DBG("Local Public Key Y: %32phN", smp->local_pk + 32); @@ -2749,7 +2759,8 @@ static int smp_cmd_public_key(struct l2cap_conn *conn, struct sk_buff *skb) * not in use. */ if (!test_bit(SMP_FLAG_DEBUG_KEY, &smp->flags) && - !crypto_memneq(key, smp->local_pk, 64)) { + test_bit(SMP_FLAG_INITIATOR, &smp->flags) && + !crypto_memneq(key, smp->local_pk, 32)) { bt_dev_err(hdev, "Remote and local public keys are identical"); return SMP_DHKEY_CHECK_FAILED; } From 1752a2c40059f845123946e01646b8a1798eeea4 Mon Sep 17 00:00:00 2001 From: Chandrashekar Devegowda Date: Wed, 11 Nov 2026 19:48:22 +0530 Subject: [PATCH 015/117] Bluetooth: btintel_pcie: Fix SCP DBGC base address BTINTEL_PCIE_DBGC_BASE_ADDR_SCP was entered as 0xf0d5d500 by mistake when the define was added. The base of the SCP debug controller is 0xf0d5d400, as documented in the Intel SCP SAS document, so the value is one register row too high. The status and wrap-around registers derived from it at offsets 0x1C and 0x2C therefore point at the wrong addresses, and the debug buffer status and wrap-around state read while dumping SCP debug traces are incorrect. Use 0xf0d5d400 so that the derived offsets land on the intended registers. Tested on an SCP platform by triggering a firmware exception and collecting the resulting devcoredump. With the corrected base address, the debug buffer status and wrap-around registers read back valid values and the DRAM monitor buffers in the dump are decoded correctly; with the old address they are read from the wrong registers. Fixes: e43b33bf8d67 ("Bluetooth: btintel_pcie: Load IOSF debug regs by controller variant") Signed-off-by: Chandrashekar Devegowda Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel_pcie.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/bluetooth/btintel_pcie.h b/drivers/bluetooth/btintel_pcie.h index 3030b4e8b750..5f315ebb4123 100644 --- a/drivers/bluetooth/btintel_pcie.h +++ b/drivers/bluetooth/btintel_pcie.h @@ -72,7 +72,7 @@ #define BTINTEL_PCIE_DBGC_CUR_DBGBUFF_STATUS (BTINTEL_PCIE_DBGC_BASE_ADDR + 0x1C) #define BTINTEL_PCIE_DBGC_DBGBUFF_WRAP_ARND (BTINTEL_PCIE_DBGC_BASE_ADDR + 0x2C) -#define BTINTEL_PCIE_DBGC_BASE_ADDR_SCP (0xf0d5d500) +#define BTINTEL_PCIE_DBGC_BASE_ADDR_SCP (0xf0d5d400) #define BTINTEL_PCIE_DBGC_CUR_DBGBUFF_STATUS_SCP (BTINTEL_PCIE_DBGC_BASE_ADDR_SCP + 0x1C) #define BTINTEL_PCIE_DBGC_DBGBUFF_WRAP_ARND_SCP (BTINTEL_PCIE_DBGC_BASE_ADDR_SCP + 0x2C) #define BTINTEL_PCIE_DBGC_ALLOCATION_OFFSET 0x100 From f3183d7ad10120437bcc3f4a751cd256ba69793f Mon Sep 17 00:00:00 2001 From: Weihong Guan Date: Thu, 12 Nov 2026 03:34:28 +0000 Subject: [PATCH 016/117] Bluetooth: hci_sync: Drop the command's sk reference hci_cmd_sync_alloc() takes a reference on the sk a command is sent for (sock_hold()), and hci_cmd_sync_complete() means to drop it, but looks for the sk in the response skb, which never carries one. The reference is never dropped: every command sent with an sk leaks it, and with it the sk and a reference on the bluetooth module. The commands sent with an sk are LE Remove Advertising Set and LE Clear Advertising Sets, for MGMT's Remove Advertising and the instance removals, and Read Local OOB (Extended) Data. After each, the module's refcnt stays one higher with no socket left open, and the module can't be unloaded until a reboot. Drop the reference from the request command, hdev->req_skb, before freeing it. Fixes: cba6b758711c ("Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 2") Assisted-by: Claude:claude-opus-5.5 Signed-off-by: Weihong Guan Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index d4a4f49df5ac..e771f0f2f308 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -31,21 +31,23 @@ static void hci_cmd_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode, hdev->req_result = result; WRITE_ONCE(hdev->req_status, HCI_REQ_DONE); - /* Free the request command so it is not used as response */ + /* Free the request command so it is not used as response, and drop + * the reference hci_cmd_sync_alloc() took on its sk, if set: the + * response skb doesn't carry it. + */ hci_dev_lock(hdev); + if (hdev->req_skb) { + struct sock *sk = hci_skb_sk(hdev->req_skb); + + if (sk) + sock_put(sk); + } kfree_skb(hdev->req_skb); hdev->req_skb = NULL; hci_dev_unlock(hdev); - if (skb) { - struct sock *sk = hci_skb_sk(skb); - - /* Drop sk reference if set */ - if (sk) - sock_put(sk); - + if (skb) hdev->req_rsp = skb_get(skb); - } wake_up_interruptible(&hdev->req_wait_q); } From 3b069de8a5d688c7e8381b99d6cdb7467fcae0de Mon Sep 17 00:00:00 2001 From: Amir Abudubai Date: Wed, 11 Nov 2026 15:49:05 -0600 Subject: [PATCH 017/117] Bluetooth: L2CAP: Fix size check for receive buffer space Check that available receive space covers a full MTU-sized SDU and its overhead, rather than just the overhead. Otherwise, credits can be exhausted before an SDU is completed. This could result in a deadlock under some configurations and SDU combinations. This follows the SDU-sized credit policy from commit 96cd8eaa131f ("Bluetooth: L2CAP: Derive rx credits from MTU and MPS"). Clarify the comment by replacing "packet" with "SDU". Fixes: ce60b9231b66 ("Bluetooth: compute LE flow credits based on recvbuf space") Signed-off-by: Amir Abudubai Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_sock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index e5c15c083c1a..304ebafdfeaa 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1229,11 +1229,11 @@ static void l2cap_publish_rx_avail(struct l2cap_chan *chan) /* Correct available memory by estimated sk_buff overhead. * This is significant due to small transfer sizes. However, accept - * at least one full packet if receive space is non-zero. + * at least one full SDU if receive space is non-zero. */ expected_skbs = DIV_ROUND_UP(avail, chan->mps); skb_overhead = expected_skbs * sizeof(struct sk_buff); - if (skb_overhead < avail) + if (avail - skb_overhead >= chan->imtu + L2CAP_SDULEN_SIZE) l2cap_chan_rx_avail(chan, avail - skb_overhead); else l2cap_chan_rx_avail(chan, -1); From ad3bee5c582e95754ac483f00dbeed882b9eb5dc Mon Sep 17 00:00:00 2001 From: Keegan Freyhof Date: Tue, 10 Nov 2026 09:49:42 -0800 Subject: [PATCH 018/117] bnxt_en: Map HWRM_ERR_CODE_PF_UNAVAILABLE to -ECOMM The current use of -ENODEV for both PCI being disabled and FW's HWRM_ERR_CODE_PF_UNAVAILABLE errors makes it impossible for the caller to distinguish between the 2 errors. As a result, a disabled VF device will cause the driver to pointlessly retry setting L2 filters believing that the PF is down. Fix it by using -ECOMM instead for HWRM_ERR_CODE_PF_UNAVAILABLE which means that the FW is failing the command on the VF because the PF is down. This new -ECOMM error code which is more accurate will now propagate to userspace instead of -ENODEV on some VF failure paths when the PF is down. Fixes: 662c9b22f5b5 ("bnxt_en: improve VF error messages when PF is unavailable") Reviewed-by: Kalesh AP Signed-off-by: Keegan Freyhof Signed-off-by: Michael Chan Link: https://patch.msgid.link/20261110174943.2106347-2-michael.chan@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 14 +++++++------- drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c | 4 +++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 6846a27bfef4..82b44e7362cc 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -11318,7 +11318,7 @@ static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init) /* Filter for default vnic 0 */ rc = bnxt_hwrm_set_vnic_filter(bp, 0, 0, bp->dev->dev_addr); if (rc) { - if (BNXT_VF(bp) && rc == -ENODEV) + if (rc == -ECOMM) netdev_err(bp->dev, "Cannot configure L2 filter while PF is unavailable\n"); else netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc); @@ -12476,7 +12476,7 @@ int bnxt_update_link(struct bnxt *bp, bool chng_link_state) rc = hwrm_req_send(bp, req); if (rc) { hwrm_req_drop(bp, req); - if (BNXT_VF(bp) && rc == -ENODEV) { + if (rc == -ECOMM) { netdev_warn(bp->dev, "Cannot obtain link state while PF unavailable.\n"); rc = 0; } @@ -13953,7 +13953,7 @@ static int bnxt_cfg_rx_mode(struct bnxt *bp, struct netdev_hw_addr_list *uc, for (i = 1, off = 0; i < vnic->uc_filter_count; i++, off += ETH_ALEN) { rc = bnxt_hwrm_set_vnic_filter(bp, 0, i, vnic->uc_list + off); if (rc) { - if (BNXT_VF(bp) && rc == -ENODEV) { + if (rc == -ECOMM) { netdev_warn(bp->dev, "Cannot configure L2 filters while PF is unavailable, will retry\n"); rc = -EAGAIN; } else if (rc == -EAGAIN) { @@ -17003,7 +17003,7 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh) } rc = __bnxt_reserve_rings(bp); - if (rc && rc != -ENODEV) + if (rc && rc != -ECOMM) netdev_warn(bp->dev, "Unable to reserve tx rings\n"); bnxt_adj_tx_rings(bp); @@ -17013,7 +17013,7 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh) /* Rings may have been trimmed, re-reserve the trimmed rings. */ if (bnxt_need_reserve_rings(bp)) { rc = __bnxt_reserve_rings(bp); - if (rc && rc != -ENODEV) + if (rc && rc != -ECOMM) netdev_warn(bp->dev, "2nd rings reservation failed.\n"); bnxt_adj_tx_rings(bp); } @@ -17039,7 +17039,7 @@ static int bnxt_init_dflt_ring_mode(struct bnxt *bp) bnxt_clear_int_mode(bp); rc = bnxt_set_dflt_rings(bp, true); if (rc) { - if (BNXT_VF(bp) && rc == -ENODEV) + if (rc == -ECOMM) netdev_err(bp->dev, "Cannot configure VF rings while PF is unavailable.\n"); else netdev_err(bp->dev, "Not enough rings available.\n"); @@ -17417,7 +17417,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) bnxt_aux_devices_init(bp); rc = bnxt_set_dflt_rings(bp, true); if (rc) { - if (BNXT_VF(bp) && rc == -ENODEV) { + if (rc == -ECOMM) { netdev_err(bp->dev, "Cannot configure VF rings while PF is unavailable.\n"); } else { netdev_err(bp->dev, "Not enough rings available.\n"); diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c index 5bfabdca7d0e..de02d1baa751 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c @@ -360,7 +360,7 @@ static int __hwrm_to_stderr(u32 hwrm_err) case HWRM_ERR_CODE_CMD_NOT_SUPPORTED: return -EOPNOTSUPP; case HWRM_ERR_CODE_PF_UNAVAILABLE: - return -ENODEV; + return -ECOMM; default: return -EIO; } @@ -716,6 +716,8 @@ exit: * ENOMEM: HWRM has no buffers. * EAGAIN: HWRM busy or reset in progress. * EOPNOTSUPP: Invalid request type. + * ENODEV: PCI device is disabled. + * ECOMM: The parent PF is unavailable when issued on VFs. * EIO: Any other error. * Error handling is orthogonal to request ownership. An unowned request will * still be consumed on error. If the caller owns the request, then the caller From 5ab726ff726b76b12f0594657ca5f49ba74d3241 Mon Sep 17 00:00:00 2001 From: Keegan Freyhof Date: Tue, 10 Nov 2026 09:49:43 -0800 Subject: [PATCH 019/117] bnxt_en: Wait for the PF in bnxt_resume() When bnxt_resume() is called on a VF with the PF running in the same kernel, the initial FW message may timeout if the PF has not been initialized. Use the more appropriate bnxt_hwrm_poll() with the silent flag to suppress warning messages and loop up to 10 times if the error code warrants additional polling. This initial polling is done without the rtnl_lock() to allow the PF running in the same kernel (which will also require the rtnl_lock) to finish its initialization. This fixes a failure found in the lab when running system hibernate on a BCM57608 NIC with 64 VFs created. The FW version is 238.1.59.0. bnxt_en 0000:23:08.5 eno4v5: hwrm req_type 0x0 seq id 0xb0 error 0xa bnxt_en 0000:23:08.5: PM: dpm_run_callback(): pci_pm_restore returns -19 bnxt_en 0000:23:08.5: PM: failed to restore async: error -19 bnxt_en 0000:23:08.3 eno4v3: hwrm req_type 0x0 seq id 0xb0 error 0xa bnxt_en 0000:23:08.4 eno4v4: hwrm req_type 0x0 seq id 0xb0 error 0xa bnxt_en 0000:23:08.7 eno4v7: hwrm req_type 0x0 seq id 0xb0 error 0xa bnxt_en 0000:23:08.3: PM: dpm_run_callback(): pci_pm_restore returns -19 bnxt_en 0000:23:08.4: PM: dpm_run_callback(): pci_pm_restore returns -19 Tested on dual-port BCM57608 with 64 VFs on each port. The polling loop provides adequate margins. Fixes: f65a2044a8c9 ("bnxt_en: Add suspend/resume callbacks.") Reviewed-by: Pavan Chebbi Signed-off-by: Keegan Freyhof Signed-off-by: Michael Chan Link: https://patch.msgid.link/20261110174943.2106347-3-michael.chan@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 37 ++++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 82b44e7362cc..e78cf7ad3cbc 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -17573,21 +17573,50 @@ static int bnxt_suspend(struct device *device) return rc; } +#define BNXT_RESUME_MAX_RETRY 10 + static int bnxt_resume(struct device *device) { struct net_device *dev = dev_get_drvdata(device); struct bnxt *bp = netdev_priv(dev); - int rc = 0; + int i, rc; - rtnl_lock(); - netdev_lock(dev); rc = pci_enable_device(bp->pdev); if (rc) { netdev_err(dev, "Cannot re-enable PCI device during resume, err = %d\n", rc); - goto resume_exit; + return rc; } pci_set_master(bp->pdev); + if (BNXT_VF(bp)) { + for (i = 0; i < BNXT_RESUME_MAX_RETRY; i++) { + rc = bnxt_hwrm_poll(bp); + if (rc != -EAGAIN && rc != -EBUSY && rc != -ECOMM) + break; + + /* Wait briefly for -EAGAIN (FW busy), a bit longer for + * -ECOMM (PF down) to allow the PF to fully initialize. + * For -EBUSY, the message typically has timed out, so + * try again immediately. + */ + if (i < BNXT_RESUME_MAX_RETRY - 1) { + if (rc == -EAGAIN) + msleep(250); + else if (rc == -ECOMM) + msleep(750); + } + } + if (rc) { + netdev_err(dev, + "Firmware not responding during resume, rc = %d\n", + rc); + return -ENODEV; + } + } + + rtnl_lock(); + netdev_lock(dev); + if (bnxt_hwrm_ver_get(bp)) { rc = -ENODEV; goto resume_exit; From 29dfa436bc488056a84ee423ba82336db453e2a6 Mon Sep 17 00:00:00 2001 From: Vladimir Petrzhikovskii Date: Tue, 10 Nov 2026 16:38:27 +0100 Subject: [PATCH 020/117] virtio_net: check RX buffer length before DMA sync An RX queue that uses the DMA API (rq->use_page_pool_dma, for example with VIRTIO_F_ACCESS_PLATFORM) syncs each received buffer with page_pool_dma_sync_for_cpu() using the length the device wrote to the used ring, and checks that length against the posted buffer only after the sync. With SWIOTLB bouncing (swiotlb=force, or a confidential-computing guest), the sync copies from the shared bounce buffer into the guest's private page, so an oversized length also copies the bytes the device wrote past the posted buffer over the neighbouring page pool fragments. The later check drops the packet, but the copy has already happened. A malicious device, such as a host the confidential guest does not trust, can overwrite guest kernel memory next to an RX buffer with bytes it chooses, which is enough to take an unprivileged guest process to root. Check the length before the sync in the per-fragment loops. receive_buf() has to sync the header before the length check, because the mergeable error path reads num_buffers from it, so limit that sync to the posted length. A device that reports correct lengths sees no change. The driver has synced with the device's length since commit 295525e29a5b ("virtio_net: merge dma operations when filling mergeable buffers"), at first in virtnet_rq_unmap(). Commit 24fbd3967f3f ("virtio_net: add page_pool support for buffer allocation") moved the sync to the page_pool call sites that this patch changes, so the patch applies to v7.1 and later. Older kernels need a separate backport that limits the sync in virtnet_rq_unmap(). Found by an LLM code review agent auditing users of the DMA API; the fix and this changelog were also written with an LLM coding assistant and reviewed by us. Reproduced in QEMU with swiotlb=force and iommu_platform=on, a test-only device change that reports a used length 64 bytes past the posted buffer and writes a marker there, and a guest kprobe module that reads the buffer after the sync: without this patch the marker reaches the guest page for small and mergeable buffers; with it the packets are dropped and counted in rx_length_errors. The virtio_net selftest basic_features.sh passes with and without mergeable buffers. Fixes: 295525e29a5b ("virtio_net: merge dma operations when filling mergeable buffers") Cc: stable@vger.kernel.org Co-developed-by: Nikolai Kalinin Signed-off-by: Nikolai Kalinin Signed-off-by: Vladimir Petrzhikovskii Link: https://patch.msgid.link/20261110-b4-virtionet-rxlen-v2-1-6ec5aa0edf9f@dfb.sh Signed-off-by: Jakub Kicinski --- drivers/net/virtio_net.c | 63 +++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index ed20e76fbc4c..28b84de86153 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -792,19 +792,32 @@ static unsigned int mergeable_ctx_to_truesize(void *mrg_ctx) return (unsigned long)mrg_ctx & ((1 << MRG_CTX_HEADER_SHIFT) - 1); } -static int check_mergeable_len(struct net_device *dev, void *mrg_ctx, - unsigned int len) +/* Length of the mergeable buffer that add_recvbuf_mergeable() posted. */ +static unsigned int mergeable_ctx_to_buflen(void *mrg_ctx) { - unsigned int headroom, tailroom, room, truesize; + unsigned int headroom, tailroom, room; - truesize = mergeable_ctx_to_truesize(mrg_ctx); headroom = mergeable_ctx_to_headroom(mrg_ctx); tailroom = headroom ? sizeof(struct skb_shared_info) : 0; room = SKB_DATA_ALIGN(headroom + tailroom); - if (len > truesize - room) { - pr_debug("%s: rx error: len %u exceeds truesize %lu\n", - dev->name, len, (unsigned long)(truesize - room)); + return mergeable_ctx_to_truesize(mrg_ctx) - room; +} + +/* Length of the small buffer that add_recvbuf_small() posts. */ +static unsigned int small_buflen(const struct virtnet_info *vi) +{ + return vi->hdr_len + GOOD_PACKET_LEN; +} + +static int check_mergeable_len(struct net_device *dev, void *mrg_ctx, + unsigned int len) +{ + unsigned int buflen = mergeable_ctx_to_buflen(mrg_ctx); + + if (len > buflen) { + pr_debug("%s: rx error: len %u exceeds buffer length %u\n", + dev->name, len, buflen); DEV_STATS_INC(dev, rx_length_errors); return -1; } @@ -1797,15 +1810,15 @@ static struct page *xdp_linearize_page(struct net_device *dev, p = virt_to_head_page(buf); off = buf - page_address(p); - if (rq->use_page_pool_dma) - page_pool_dma_sync_for_cpu(rq->page_pool, p, - off, buflen); - if (check_mergeable_len(dev, ctx, buflen)) { page_pool_put_page(rq->page_pool, p, -1, true); goto err_buf; } + if (rq->use_page_pool_dma) + page_pool_dma_sync_for_cpu(rq->page_pool, p, + off, buflen); + /* guard against a misconfigured or uncooperative backend that * is sending packet larger than the MTU. */ @@ -2165,15 +2178,15 @@ static int virtnet_build_xdp_buff_mrg(struct net_device *dev, page = virt_to_head_page(buf); offset = buf - page_address(page); - if (rq->use_page_pool_dma) - page_pool_dma_sync_for_cpu(rq->page_pool, page, - offset, len); - if (check_mergeable_len(dev, ctx, len)) { page_pool_put_page(rq->page_pool, page, -1, true); goto err; } + if (rq->use_page_pool_dma) + page_pool_dma_sync_for_cpu(rq->page_pool, page, + offset, len); + truesize = mergeable_ctx_to_truesize(ctx); xdp_frags_truesz += truesize; @@ -2446,15 +2459,15 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, u64_stats_add(&stats->bytes, len); page = virt_to_head_page(buf); + if (check_mergeable_len(dev, ctx, len)) + goto err_skb; + if (rq->use_page_pool_dma) { offset = buf - page_address(page); page_pool_dma_sync_for_cpu(rq->page_pool, page, offset, len); } - if (check_mergeable_len(dev, ctx, len)) - goto err_skb; - truesize = mergeable_ctx_to_truesize(ctx); curr_skb = virtnet_skb_append_frag(rq, head_skb, curr_skb, page, buf, len, truesize); @@ -2574,12 +2587,22 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, /* Sync the memory before touching anything through buf, * unless virtio core did it already. + * + * len comes from the device and is checked against the buffer + * only later, so never sync past the buffer posted to the device. + * The sync still covers the header, which receive_buf() and the + * mergeable drop path read. Big buffers never come from the page + * pool, so a buffer here is either mergeable or small. */ if (rq->use_page_pool_dma) { struct page *page = virt_to_head_page(buf); int offset = buf - page_address(page); + unsigned int buflen = vi->mergeable_rx_bufs ? + mergeable_ctx_to_buflen(ctx) : + small_buflen(vi); - page_pool_dma_sync_for_cpu(rq->page_pool, page, offset, len); + page_pool_dma_sync_for_cpu(rq->page_pool, page, offset, + min(len, buflen)); } /* About the flags below: @@ -2655,7 +2678,7 @@ static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq, buf += VIRTNET_RX_PAD + xdp_headroom; ctx = mergeable_len_to_ctx(alloc_len, xdp_headroom); - err = virtnet_rq_submit(rq, buf, vi->hdr_len + GOOD_PACKET_LEN, ctx, gfp); + err = virtnet_rq_submit(rq, buf, small_buflen(vi), ctx, gfp); if (err < 0) page_pool_put_page(rq->page_pool, virt_to_head_page(buf), -1, false); From aa40afa831ebfe45e40a23721711059f2ac584d4 Mon Sep 17 00:00:00 2001 From: Hyunwoo Kim Date: Tue, 10 Nov 2026 23:04:44 +0900 Subject: [PATCH 021/117] tcp: fix NULL pointer dereference when restarting a Fast Open listener When a valid RST is received for a Fast Open child accepted before the three-way handshake completes, reqsk_fastopen_remove() adds the request_sock to the listener's RST list if the listener is in TCP_LISTEN. An application can call shutdown(SHUT_RD) on a listener socket. inet_csk_listen_stop() checks rskq_rst_head without holding fastopenq.lock. If rskq_rst_head is NULL, it does not acquire the lock and therefore does not synchronize with an insertion by reqsk_fastopen_remove() after that function has passed the TCP_LISTEN check. The more likely outcome of this race, even without a subsequent listen(), is a leak. If reqsk_fastopen_remove() inserts a request_sock after inet_csk_listen_stop() observes an empty list and returns, the request_sock is stranded in rskq_rst_head and keeps a reference on the listener. The socket is already in TCP_CLOSE, so a subsequent close() does not call inet_csk_listen_stop() again. If listen() is called again on the same socket before the delayed list insertion, the insertion can overlap the queue initialization in reqsk_queue_alloc(). If it occurs after rskq_rst_head is set to NULL but before rskq_rst_tail is set to NULL, rskq_rst_head points to the request_sock while rskq_rst_tail is NULL. When a valid RST is later received for another accepted Fast Open child, rskq_rst_head is not NULL, so reqsk_fastopen_remove() attempts to write the request_sock pointer to rskq_rst_tail->dl_next while rskq_rst_tail is NULL. KASAN reports: BUG: KASAN: null-ptr-deref in reqsk_fastopen_remove+0x147/0x210 Write of size 8 at addr 0000000000000088 by task swapper/3/0 ... Call Trace: ... reqsk_fastopen_remove+0x147/0x210 tcp_check_req+0xa70/0x1060 ... tcp_rcv_state_process+0x1cb/0x2ae0 ... tcp_v4_do_rcv+0x1fe/0x740 tcp_v4_rcv+0x1744/0x2070 ... ip_protocol_deliver_rcu+0x5c/0x280 ip_local_deliver_finish+0x171/0x330 ip_local_deliver+0x107/0x370 ... To widen the race window, the issue was reproduced after adding mdelay(3000) immediately after reqsk_fastopen_remove() checks that the listener is in TCP_LISTEN and immediately after reqsk_queue_alloc() sets rskq_rst_head to NULL. Make inet_csk_listen_stop() acquire fastopenq.lock regardless of the value of rskq_rst_head and detach the list while holding the lock. With this synchronization, reqsk_fastopen_remove() either inserts the request_sock before inet_csk_listen_stop() acquires the lock, in which case inet_csk_listen_stop() reclaims it, or sees that the listener is not in TCP_LISTEN and does not insert anything. Fixes: 0536fcc039a8 ("tcp: prepare fastopen code for upcoming listener changes") Cc: stable@vger.kernel.org Signed-off-by: Hyunwoo Kim Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/avMkfJrXhCFXn8M_@v4bel Signed-off-by: Jakub Kicinski --- net/ipv4/inet_connection_sock.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 6c079929e06f..ca3057192e6d 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1533,17 +1533,15 @@ skip_child_forget: if (!has_current_bpf_ctx()) cond_resched(); } - if (queue->fastopenq.rskq_rst_head) { - /* Free all the reqs queued in rskq_rst_head. */ - spin_lock_bh(&queue->fastopenq.lock); - req = queue->fastopenq.rskq_rst_head; - queue->fastopenq.rskq_rst_head = NULL; - spin_unlock_bh(&queue->fastopenq.lock); - while (req != NULL) { - next = req->dl_next; - reqsk_put(req); - req = next; - } + /* Free all the reqs queued in rskq_rst_head. */ + spin_lock_bh(&queue->fastopenq.lock); + req = queue->fastopenq.rskq_rst_head; + queue->fastopenq.rskq_rst_head = NULL; + spin_unlock_bh(&queue->fastopenq.lock); + while (req != NULL) { + next = req->dl_next; + reqsk_put(req); + req = next; } WARN_ON_ONCE(sk->sk_ack_backlog); } From 5ae07c10854f7ac38da02e8313a59dfcfeb44a61 Mon Sep 17 00:00:00 2001 From: Julian Anastasov Date: Mon, 5 Oct 2026 13:06:17 +0000 Subject: [PATCH 022/117] ipvs: fix problems during connection deletion Sashiko reports for problem when deleting connections. If connection timer expires, its callback can not be concurrently running but if connection is deleted the callback can be running on another CPU even after all references are released. Before now we continued with the connection freeing, risking the callback to access the deleted connection after it is freed. As ip_vs_conn_del() runs under RCU lock there is no risk for accessing a connection freed by concurrent timer callback. As Sashiko warns, the risk is present if normal connection expires and tries to delete its cp->control chain with ip_vs_conn_del_put() without holding a RCU read lock. It is evident that as the pending timer and the running timer callback do not hold reference for the connection, there are races which is difficult to avoid. Change the connection refcounting as follows: * the connection hashing does not take reference anymore * new connection handoffs its reference to the timer if started in __ip_vs_conn_put_timer(), to hold it while it is pending. * if user finds connection in hash table it gets reference and can handoff this reference to the pending timer if this timer is started in __ip_vs_conn_put_timer(), otherwise puts its reference if the timer was already pending which is the common case. * the pending timer handoffs its reference to the running timer callback implicitly. By this way, the timer callback in the common case has the last reference. In rare cases, while the timer callback is running and before it changes refcnt from 1 to 0, other users can get reference and to handoff it again to the pending timer they arm. In this case, the expiration is deferred for later time. As result, cp->refcnt accounts all current connection users and the pending and running timer. Two paths can try to delete the connection: the normal expiration path and ip_vs_conn_del() if it successfully steals the connection reference from the pending timer. refcount_dec_if_one() will tell us if we were the last active user with no packets accessing the connection and no pending/running timers. Change ip_vs_conn_unlink() to directly unhash the connection because when we are the last user the connection's forwarding method can not change. Use smp_acquire__after_ctrl_dep() after refcount_dec_if_one() and before reading the connection fields. ip_vs_conn_expire() does not need to call timer_delete() anymore because the pending timer is already accounted in refcnt. Add explicit rcu_read_lock() while deleting the cp->control chain to protect from concurrent timer callback for ct to expire it before us and to cause use-after-free. During such races, try to keep 0 in cp->timeout as it is a request for deleting our cp->control chain immediately. Make sure we do not send timeout 0 (seconds) in the v1 sync message because the backup server will select some large default value which is not desired for small timeouts. Remove the smp_mb__before_atomic() call from __ip_vs_conn_put(), it is from the atomic_dec() era, now refcount_dec() has RELEASE semantics. Link: https://sashiko.dev/#/patchset/cover.1789435989.git.zihanx%40nebusec.ai Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1790266803.git.zihanx%40nebusec.ai Fixes: f9200a52eedf ("ipvs: avoid expiring many connections from timer") Signed-off-by: Julian Anastasov Signed-off-by: Pablo Neira Ayuso --- include/net/ip_vs.h | 1 - net/netfilter/ipvs/ip_vs_conn.c | 99 ++++++++++++++++++--------------- net/netfilter/ipvs/ip_vs_sync.c | 2 +- 3 files changed, 55 insertions(+), 47 deletions(-) diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h index 9a83bff32569..97097d60d1c4 100644 --- a/include/net/ip_vs.h +++ b/include/net/ip_vs.h @@ -1685,7 +1685,6 @@ static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp) /* put back the conn without restarting its timer */ static inline void __ip_vs_conn_put(struct ip_vs_conn *cp) { - smp_mb__before_atomic(); refcount_dec(&cp->refcnt); } void ip_vs_conn_put(struct ip_vs_conn *cp); diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c index 94f25fb7d87e..86c5e6c7b5af 100644 --- a/net/netfilter/ipvs/ip_vs_conn.c +++ b/net/netfilter/ipvs/ip_vs_conn.c @@ -293,7 +293,6 @@ static inline int ip_vs_conn_hash(struct ip_vs_conn *cp) cp->flags |= IP_VS_CONN_F_HASHED; WRITE_ONCE(cp->hn0.hash_key, hash_key); WRITE_ONCE(cp->hn1.hash_key, hash_key2); - refcount_inc(&cp->refcnt); hlist_bl_add_head_rcu(&cp->hn0.node, head); if (use2) hlist_bl_add_head_rcu(&cp->hn1.node, head2); @@ -319,11 +318,27 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp) struct hlist_bl_head *head, *head2; u32 hash_key, hash_key2; struct ip_vs_rht *t; - bool ret = false; bool use2; + /* No more users and no running/pending timer except us? */ + if (!refcount_dec_if_one(&cp->refcnt)) + return false; + + /* The ONE_PACKET connection is special: + * - the flag is present only for normal connections, not for templates + * - its timer is never started + * - it is never hashed, so you can not find it and delete it + * - it is not synced + * - it has only one user + * - it is freed after use immediately + */ if (cp->flags & IP_VS_CONN_F_ONE_PACKET) - return refcount_dec_if_one(&cp->refcnt); + return true; + + /* Add the needed ACQUIRE barrier between the above + * refcount_dec_if_one() call and the read of cp fields + */ + smp_acquire__after_ctrl_dep(); rcu_read_lock(); local_bh_disable(); @@ -337,15 +352,11 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp) false /* new_hash2 */, &head, &head2); if (cp->flags & IP_VS_CONN_F_HASHED) { - /* Decrease refcnt and unlink conn only if we are last user */ - if (use2 == ip_vs_conn_use_hash2(cp) && - refcount_dec_if_one(&cp->refcnt)) { - hlist_bl_del_rcu(&cp->hn0.node); - if (use2) - hlist_bl_del_rcu(&cp->hn1.node); - cp->flags &= ~IP_VS_CONN_F_HASHED; - ret = true; - } + /* Unlink conn as we are the last user */ + hlist_bl_del_rcu(&cp->hn0.node); + if (use2) + hlist_bl_del_rcu(&cp->hn1.node); + cp->flags &= ~IP_VS_CONN_F_HASHED; } conn_tab_unlock(head, head2); @@ -353,7 +364,7 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp) local_bh_enable(); rcu_read_unlock(); - return ret; + return true; } @@ -621,9 +632,12 @@ static void __ip_vs_conn_put_timer(struct ip_vs_conn *cp) { unsigned long t = (cp->flags & IP_VS_CONN_F_ONE_PACKET) ? 0 : cp->timeout; - mod_timer(&cp->timer, jiffies+t); - __ip_vs_conn_put(cp); + /* Handoff our reference to the timer if it was just armed, + * put the reference if timer was already pending. + */ + if (mod_timer(&cp->timer, jiffies + t)) + __ip_vs_conn_put(cp); } void ip_vs_conn_put(struct ip_vs_conn *cp) @@ -1322,9 +1336,18 @@ static void ip_vs_conn_rcu_free(struct rcu_head *head) kmem_cache_free(ip_vs_conn_cachep, cp); } -/* Try to delete connection while not holding reference */ +/* Try to delete connection while not holding reference. + * It can be called concurrently and always under RCU lock + * to protect from connection deletion from others. + * Used when we need to remove the connection immediately + * and without overloading the timer processing. + * OTOH, we use ip_vs_conn_expire_now() when we prefer to + * leave the current context (packet processing) and to + * remove the connection from timer. + */ static void ip_vs_conn_del(struct ip_vs_conn *cp) { + /* Steal reference from the pending timer */ if (timer_delete(&cp->timer)) { /* Drop cp->control chain too */ if (cp->control) @@ -1333,20 +1356,11 @@ static void ip_vs_conn_del(struct ip_vs_conn *cp) } } -/* Try to delete connection while holding reference */ -static void ip_vs_conn_del_put(struct ip_vs_conn *cp) -{ - if (timer_delete(&cp->timer)) { - /* Drop cp->control chain too */ - if (cp->control) - cp->timeout = 0; - __ip_vs_conn_put(cp); - ip_vs_conn_expire(&cp->timer); - } else { - __ip_vs_conn_put(cp); - } -} - +/* Connection is removed in the following steps: + * - timer expires (with ref) or connection is deleted (with stolen ref) + * - there should be no more users except us (pending/running timer, + * n_control>0 or refcnt>1) + */ static void ip_vs_conn_expire(struct timer_list *t) { struct ip_vs_conn *cp = timer_container_of(cp, t, timer); @@ -1362,23 +1376,18 @@ static void ip_vs_conn_expire(struct timer_list *t) if (likely(ip_vs_conn_unlink(cp))) { struct ip_vs_conn *ct = cp->control; - /* delete the timer if it is activated by other users */ - timer_delete(&cp->timer); - /* does anybody control me? */ if (ct) { - bool has_ref = !cp->timeout && __ip_vs_conn_get(ct); - + rcu_read_lock(); ip_vs_control_del(cp); /* Drop CTL or non-assured TPL if not used anymore */ - if (has_ref && !atomic_read(&ct->n_control) && + if (!cp->timeout && !atomic_read(&ct->n_control) && (!(ct->flags & IP_VS_CONN_F_TEMPLATE) || !(ct->state & IP_VS_CTPL_S_ASSURED))) { IP_VS_DBG(4, "drop controlling connection\n"); - ip_vs_conn_del_put(ct); - } else if (has_ref) { - __ip_vs_conn_put(ct); + ip_vs_conn_del(ct); } + rcu_read_unlock(); } if ((cp->flags & IP_VS_CONN_F_NFCT) && @@ -1413,8 +1422,8 @@ static void ip_vs_conn_expire(struct timer_list *t) refcount_read(&cp->refcnt), atomic_read(&cp->n_control)); - refcount_inc(&cp->refcnt); - cp->timeout = 60*HZ; + if (cp->timeout || atomic_read(&cp->n_control)) + cp->timeout = 60 * HZ; if (ipvs->sync_state & IP_VS_STATE_MASTER) ip_vs_sync_conn(ipvs, cp, sysctl_sync_threshold(ipvs)); @@ -1432,7 +1441,7 @@ static void ip_vs_conn_expire(struct timer_list *t) void ip_vs_conn_expire_now(struct ip_vs_conn *cp) { /* Using mod_timer_pending will ensure the timer is not - * modified after the final timer_delete in ip_vs_conn_expire. + * started without giving it new reference. */ if (timer_pending(&cp->timer) && time_after(cp->timer.expires, jiffies)) @@ -1500,9 +1509,9 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af, spin_lock_init(&cp->lock); /* - * Set the entry is referenced by the current thread before hashing - * it in the table, so that other thread run ip_vs_random_dropentry - * but cannot drop this entry. + * Set the entry as referenced by the current thread before starting + * the timer and giving it our reference to allow other threads to + * run ip_vs_random_dropentry() or any deletion method safely. */ refcount_set(&cp->refcnt, 1); diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c index 157f5c8361ab..1caacf419af9 100644 --- a/net/netfilter/ipvs/ip_vs_sync.c +++ b/net/netfilter/ipvs/ip_vs_sync.c @@ -732,7 +732,7 @@ sloop: s->v4.vport = cp->vport; s->v4.dport = cp->dport; s->v4.fwmark = htonl(cp->fwmark); - s->v4.timeout = htonl(cp->timeout / HZ); + s->v4.timeout = htonl(max(1UL, cp->timeout / HZ)); m->nr_conns++; #ifdef CONFIG_IP_VS_IPV6 From d4e4cd04de2c47ed05f837a26edd20c56be3f097 Mon Sep 17 00:00:00 2001 From: Zihan Xi Date: Mon, 5 Oct 2026 13:06:18 +0000 Subject: [PATCH 023/117] ipvs: avoid stack overflow from recursive connection expiration When a controlled IPVS connection expires, its controller may be expired synchronously if it has no remaining controlled connections. A chain of controlled connections can then recurse through ip_vs_conn_expire() and exhaust the kernel stack during namespace cleanup. Continue expiration with the controller after the current connection has been fully cleaned up instead of calling ip_vs_conn_del() recursively. Keep the expiration walk under RCU, preserve the immediate-drop timeout for a controller with its own controller, and switch to deletion mode before the next iteration. This keeps controlled-connection cleanup synchronous while using one stack frame for the whole chain. The timer callback race during connection deletion is handled by the preceding connection-deletion fix. This patch depends on "ipvs: fix problems during connection deletion" to protect the iterative controller cleanup from the timer callback race. Fixes: f9200a52eedf ("ipvs: avoid expiring many connections from timer") Cc: stable@vger.kernel.org Reported-by: Vega Co-developed-by: Luxing Yin Signed-off-by: Luxing Yin Signed-off-by: Zihan Xi Signed-off-by: Julian Anastasov Signed-off-by: Pablo Neira Ayuso --- net/netfilter/ipvs/ip_vs_conn.c | 40 ++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c index 86c5e6c7b5af..27db8d558a03 100644 --- a/net/netfilter/ipvs/ip_vs_conn.c +++ b/net/netfilter/ipvs/ip_vs_conn.c @@ -1336,9 +1336,23 @@ static void ip_vs_conn_rcu_free(struct rcu_head *head) kmem_cache_free(ip_vs_conn_cachep, cp); } -/* Try to delete connection while not holding reference. +/* Try to steal the reference from the pending timer. * It can be called concurrently and always under RCU lock * to protect from connection deletion from others. + */ +static bool ip_vs_conn_del_reference(struct ip_vs_conn *cp) +{ + /* Steal reference from the pending timer */ + if (!timer_delete(&cp->timer)) + return false; + + /* Drop cp->control chain too */ + if (cp->control) + cp->timeout = 0; + return true; +} + +/* Try to delete connection while not holding reference. * Used when we need to remove the connection immediately * and without overloading the timer processing. * OTOH, we use ip_vs_conn_expire_now() when we prefer to @@ -1347,13 +1361,8 @@ static void ip_vs_conn_rcu_free(struct rcu_head *head) */ static void ip_vs_conn_del(struct ip_vs_conn *cp) { - /* Steal reference from the pending timer */ - if (timer_delete(&cp->timer)) { - /* Drop cp->control chain too */ - if (cp->control) - cp->timeout = 0; + if (ip_vs_conn_del_reference(cp)) ip_vs_conn_expire(&cp->timer); - } } /* Connection is removed in the following steps: @@ -1366,6 +1375,9 @@ static void ip_vs_conn_expire(struct timer_list *t) struct ip_vs_conn *cp = timer_container_of(cp, t, timer); struct netns_ipvs *ipvs = cp->ipvs; + rcu_read_lock(); + +repeat: /* * do I control anybody? */ @@ -1375,19 +1387,18 @@ static void ip_vs_conn_expire(struct timer_list *t) /* Unlink conn if not referenced anymore */ if (likely(ip_vs_conn_unlink(cp))) { struct ip_vs_conn *ct = cp->control; + bool next = false; /* does anybody control me? */ if (ct) { - rcu_read_lock(); ip_vs_control_del(cp); /* Drop CTL or non-assured TPL if not used anymore */ if (!cp->timeout && !atomic_read(&ct->n_control) && (!(ct->flags & IP_VS_CONN_F_TEMPLATE) || !(ct->state & IP_VS_CTPL_S_ASSURED))) { IP_VS_DBG(4, "drop controlling connection\n"); - ip_vs_conn_del(ct); + next = ip_vs_conn_del_reference(ct); } - rcu_read_unlock(); } if ((cp->flags & IP_VS_CONN_F_NFCT) && @@ -1414,7 +1425,11 @@ static void ip_vs_conn_expire(struct timer_list *t) else call_rcu(&cp->rcu_head, ip_vs_conn_rcu_free); atomic_dec(&ipvs->conn_count); - return; + if (next) { + cp = ct; + goto repeat; + } + goto out; } expire_later: @@ -1429,6 +1444,9 @@ static void ip_vs_conn_expire(struct timer_list *t) ip_vs_sync_conn(ipvs, cp, sysctl_sync_threshold(ipvs)); __ip_vs_conn_put_timer(cp); + +out: + rcu_read_unlock(); } /* Modify timer, so that it expires as soon as possible. From a107e150e105836bb5349cdee14541d4995009ea Mon Sep 17 00:00:00 2001 From: Zihan Xi Date: Mon, 5 Oct 2026 13:06:19 +0000 Subject: [PATCH 024/117] ipvs: reject FTP control ports as data ports The FTP helper must not treat a configured control port as a data port. Accepting such a port can leave IPVS connections in a state that leads to recursive expiration and kernel stack exhaustion. Reject zero and configured control ports before creating passive data connections. For active mode, reject a zero client port and a derived data port that is itself a configured control port. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Reported-by: Vega Co-developed-by: Luxing Yin Signed-off-by: Luxing Yin Signed-off-by: Zihan Xi Signed-off-by: Julian Anastasov Signed-off-by: Pablo Neira Ayuso --- net/netfilter/ipvs/ip_vs_ftp.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c index 9e3e005a8263..4822a1a75212 100644 --- a/net/netfilter/ipvs/ip_vs_ftp.c +++ b/net/netfilter/ipvs/ip_vs_ftp.c @@ -62,6 +62,17 @@ static unsigned short ports[IP_VS_APP_MAX_PORTS] = {21, 0}; module_param_array(ports, ushort, &ports_count, 0444); MODULE_PARM_DESC(ports, "Ports to monitor for FTP control commands"); +static bool is_control_port(u16 port) +{ + unsigned int i; + + for (i = 0; i < ports_count; i++) { + if (ports[i] == port) + return true; + } + return false; +} + static char *ip_vs_ftp_data_ptr(struct sk_buff *skb, struct ip_vs_iphdr *ipvsh) { @@ -319,6 +330,10 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp, return 1; } + /* Do not redirect data to control ports */ + if (!port || is_control_port(ntohs(port))) + return 0; + /* Now update or create a connection entry for it */ { struct ip_vs_conn_param p; @@ -529,6 +544,9 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp, return 1; } + if (!port || is_control_port(ntohs(cp->vport) - 1)) + return 0; + /* Passive mode off */ cp->app_data = (void *) IP_VS_FTP_ACTIVE; From 4656934d460da68382cf91766a1ff2d0610554ae Mon Sep 17 00:00:00 2001 From: Theodor Arsenij Larionov Trichkine Date: Thu, 15 Oct 2026 23:09:02 +0300 Subject: [PATCH 025/117] ipvs: ftp: skip conntrack templates in ip_vs_ftp_out A CT target hooked after conntrack attaches its template to a packet that conntrack left without an entry. On an IPVS FTP PASV/EPSV reply, ip_vs_ftp_out() then mangles with the template and creates an expectation with the template as master. Deleting the CT rule frees the template and leaves the expectation, so a later expectation flush reads freed memory: BUG: KASAN: slab-use-after-free in nf_ct_unlink_expect_report Reachable with CAP_NET_ADMIN in a user namespace. Skip templates, as nft_ct and nfnetlink_queue do. Fixes: f4bc17cdd205 ("ipvs: netfilter connection tracking changes") Cc: stable@vger.kernel.org Signed-off-by: Theodor Arsenij Larionov Trichkine Acked-by: Julian Anastasov Signed-off-by: Pablo Neira Ayuso --- net/netfilter/ipvs/ip_vs_ftp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c index 4822a1a75212..44de99f4d187 100644 --- a/net/netfilter/ipvs/ip_vs_ftp.c +++ b/net/netfilter/ipvs/ip_vs_ftp.c @@ -383,7 +383,7 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp, buf_len = strlen(buf); ct = nf_ct_get(skb, &ctinfo); - if (ct) { + if (ct && !nf_ct_is_template(ct)) { bool mangled; /* If mangling fails this function will return 0 From f3aff3d80b5793dbec1ad4081e2f3bb40aff5fd3 Mon Sep 17 00:00:00 2001 From: Julian Anastasov Date: Mon, 2 Nov 2026 10:07:27 +0200 Subject: [PATCH 026/117] ipvs: update flags and seqs in backup server under lock Sashiko reports that we modify the conn flags and seq values in the backup server without holding cp->lock. The same is true for other fields such as state, old_state and timeout which are modified by protocols under lock. Extend the locked region in ip_vs_proc_conn() to update the fields atomically. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260927220816.268206-1-pablo%40netfilter.org Signed-off-by: Julian Anastasov Signed-off-by: Pablo Neira Ayuso --- net/netfilter/ipvs/ip_vs_sync.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c index 1caacf419af9..ba2fa1f9d08e 100644 --- a/net/netfilter/ipvs/ip_vs_sync.c +++ b/net/netfilter/ipvs/ip_vs_sync.c @@ -850,6 +850,7 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa unsigned long timeout, __u32 fwmark, struct ip_vs_sync_conn_options *opt) { + struct ip_vs_conn *cp_new = NULL; struct ip_vs_dest *dest; struct ip_vs_conn *cp; @@ -891,9 +892,6 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa flags &= IP_VS_CONN_F_BACKUP_UPD_MASK; flags |= cp->flags & ~IP_VS_CONN_F_BACKUP_UPD_MASK; cp->flags = flags; - spin_unlock_bh(&cp->lock); - if (!dest) - ip_vs_try_bind_dest(cp); } else { /* * Find the appropriate destination for the connection. @@ -920,6 +918,8 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa } if (!(flags & IP_VS_CONN_F_TEMPLATE)) kfree(param->pe_data); + cp_new = cp; + spin_lock_bh(&cp->lock); } if (opt) { @@ -951,6 +951,9 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa else cp->timeout = (3*60*HZ); } + spin_unlock_bh(&cp->lock); + if (!dest && !cp_new) + ip_vs_try_bind_dest(cp); ip_vs_conn_put(cp); } From aa9afc79f57ba5ef4385aa85cfb7dd50d5c484f6 Mon Sep 17 00:00:00 2001 From: Julian Anastasov Date: Mon, 2 Nov 2026 10:07:28 +0200 Subject: [PATCH 027/117] ipvs: read flags and seqs in master atomically After we fixed the double read of cp->flags in the master with commit 3e3fe49e8678 ("ipvs: fix buffer overflow when sending sync messages") Sashiko reports that we should also read the cp->flags and the seqs atomically. So if the SEQ_MASK is set, re-read the flags and the seqs under cp->lock to provide a snapshot when sending the sync message. Fixes: 3e3fe49e8678 ("ipvs: fix buffer overflow when sending sync messages") Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260927220816.268206-1-pablo%40netfilter.org Signed-off-by: Julian Anastasov Signed-off-by: Pablo Neira Ayuso --- net/netfilter/ipvs/ip_vs_sync.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c index ba2fa1f9d08e..f11c59eca553 100644 --- a/net/netfilter/ipvs/ip_vs_sync.c +++ b/net/netfilter/ipvs/ip_vs_sync.c @@ -539,6 +539,7 @@ set: static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts) { + struct ip_vs_sync_conn_options opts; struct ip_vs_sync_mesg_v0 *m; struct ip_vs_sync_conn_v0 *s; struct ip_vs_sync_buff *buff; @@ -557,6 +558,14 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, if (!ip_vs_sync_conn_needed(ipvs, cp, pkts)) return; + if (flags & IP_VS_CONN_F_SEQ_MASK) { + /* Take atomic snapshot of flags and seqs */ + spin_lock_bh(&cp->lock); + flags = cp->flags; + memcpy(&opts, &cp->sync_conn_opt, sizeof(opts)); + spin_unlock_bh(&cp->lock); + } + spin_lock_bh(&ipvs->sync_buff_lock); if (!(ipvs->sync_state & IP_VS_STATE_MASTER)) { spin_unlock_bh(&ipvs->sync_buff_lock); @@ -604,7 +613,7 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, if (seq_mask) { struct ip_vs_sync_conn_options *opt = (struct ip_vs_sync_conn_options *)&s[1]; - memcpy(opt, &cp->sync_conn_opt, sizeof(*opt)); + memcpy(opt, &opts, sizeof(*opt)); } m->nr_conns++; @@ -630,6 +639,7 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, */ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts) { + struct ip_vs_sync_conn_options opts; struct ip_vs_sync_mesg *m; union ip_vs_sync_conn *s; struct ip_vs_sync_buff *buff; @@ -651,6 +661,13 @@ sloop: if (!ip_vs_sync_conn_needed(ipvs, cp, pkts)) goto control; flags = READ_ONCE(cp->flags); + if (flags & IP_VS_CONN_F_SEQ_MASK) { + /* Take atomic snapshot of flags and seqs */ + spin_lock_bh(&cp->lock); + flags = cp->flags; + memcpy(&opts, &cp->sync_conn_opt, sizeof(opts)); + spin_unlock_bh(&cp->lock); + } /* Sanity checks */ pe_name_len = 0; @@ -752,9 +769,9 @@ sloop: if (seq_mask) { *(p++) = IPVS_OPT_SEQ_DATA; *(p++) = sizeof(struct ip_vs_sync_conn_options); - hton_seq(&cp->in_seq, (struct ip_vs_seq *)p); + hton_seq(&opts.in_seq, (struct ip_vs_seq *)p); p += sizeof(struct ip_vs_seq); - hton_seq(&cp->out_seq, (struct ip_vs_seq *)p); + hton_seq(&opts.out_seq, (struct ip_vs_seq *)p); p += sizeof(struct ip_vs_seq); } /* Handle pe data */ From 567ca80d77baf4c9ab635865375956084c8bb52a Mon Sep 17 00:00:00 2001 From: Julian Anastasov Date: Mon, 2 Nov 2026 10:28:14 +0200 Subject: [PATCH 028/117] ipvs: honor the overload state and do not enter it forever Sashiko warns that we may enter the dest overload state forever if setting the u_threshold to 1 races with the ip_vs_unbind_dest() call for the last connection for dest. The problem is that we prefer ip_vs_unbind_dest() to avoid using locks while reading the threshold. To avoid the race, add a smp_mb() in __ip_vs_dest_update_overload() that is paired with the atomic_fetch_dec() in ip_vs_unbind_dest() which allows to re-read the totalconns and to leave the overload state if we are below l_threshold_val. Also, remove the overload parameter from ip_vs_dest_update_overload() because we just need to know the current state while deciding which threshold ranges to use. This ip_vs_dest_is_overloaded() check can be in __ip_vs_dest_update_overload() instead. To avoid ip_vs_bind_dest() to enter lock just to initialize u_threshold_val to INT_MAX, do it in ip_vs_new_dest(). The LBLC and LBLCR schedulers do not honor the global overload state for cached dests, so add a ip_vs_dest_is_overloaded() check for the situations where we may fallback from overloaded dest (LBLC and LBLCR) or when we hit a cached dest (LBLC). Also, move the ip_vs_dest_set_min() call in LBLCR after the ip_vs_dest_set_erase() call that removes the most-loaded server because due to races we may work with dest that is in process of removing, i.e. ip_vs_dest_set_min() and ip_vs_dest_set_max() may return same dest. Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019150249.1879516-2-pablo%40netfilter.org Fixes: 3ba20137287f ("ipvs: fix more races around the overload flag") Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Julian Anastasov Signed-off-by: Pablo Neira Ayuso --- include/net/ip_vs.h | 2 +- net/netfilter/ipvs/ip_vs_conn.c | 4 ++-- net/netfilter/ipvs/ip_vs_ctl.c | 30 ++++++++++++++++++------------ net/netfilter/ipvs/ip_vs_lblc.c | 8 +++++--- net/netfilter/ipvs/ip_vs_lblcr.c | 13 +++++++------ 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h index 97097d60d1c4..c1f7a3f144f1 100644 --- a/include/net/ip_vs.h +++ b/include/net/ip_vs.h @@ -1922,7 +1922,7 @@ static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest) kfree(dest); } -void ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload); +void ip_vs_dest_update_overload(struct ip_vs_dest *dest); /* Check if dest is in overloaded state */ static inline bool ip_vs_dest_is_overloaded(const struct ip_vs_dest *dest) diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c index 27db8d558a03..66fcdc00ef37 100644 --- a/net/netfilter/ipvs/ip_vs_conn.c +++ b/net/netfilter/ipvs/ip_vs_conn.c @@ -1168,7 +1168,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest) atomic_inc(&dest->activeconns); tc = atomic_inc_return(&dest->totalconns); if (tc >= READ_ONCE(dest->u_threshold_val)) - ip_vs_dest_update_overload(dest, true); + ip_vs_dest_update_overload(dest); } else { /* It is a persistent connection/template, so increase the persistent connection counter */ @@ -1261,7 +1261,7 @@ static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp) atomic_dec(&dest->activeconns); tc = atomic_fetch_dec(&dest->totalconns); if (tc <= READ_ONCE(dest->l_threshold_val)) - ip_vs_dest_update_overload(dest, false); + ip_vs_dest_update_overload(dest); } else { /* It is a persistent connection/template, so decrease the persistent connection counter */ diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c index ce9fe20d6106..5868adda6ed6 100644 --- a/net/netfilter/ipvs/ip_vs_ctl.c +++ b/net/netfilter/ipvs/ip_vs_ctl.c @@ -1304,12 +1304,12 @@ void ip_vs_stats_free(struct ip_vs_stats *stats) } } -/* Update overload flag based on number of dest conns and lower/upper +/* Update overload state based on number of dest conns and lower/upper * connection thresholds: - * - conns reach u_threshold and exceed it: set the flag - * - conns go below l_threshold (or 75% of u_threshold): clear the flag + * - conns reach u_threshold and exceed it: set the overload state + * - conns go below l_threshold (or 75% of u_threshold): clear the state */ -static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload) +static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest) { int conns; u32 l, u; @@ -1320,10 +1320,18 @@ static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload) /* Low threshold defaults to 75% of upper threshold */ l = READ_ONCE(dest->l_threshold) ? : (u - (u >> 2)); conns = atomic_read(&dest->totalconns); - if (conns >= (overload ? l : u)) { + if (conns >= (ip_vs_dest_is_overloaded(dest) ? l : u)) { WRITE_ONCE(dest->u_threshold_val, INT_MAX); WRITE_ONCE(dest->l_threshold_val, l); - return; + /* Commit thresholds before repeating the check, + * it is paired with atomic_fetch_dec() in + * ip_vs_unbind_dest() to avoid entering the + * overload state forever. + */ + smp_mb(); + conns = atomic_read(&dest->totalconns); + if (conns >= l) + return; } } @@ -1331,10 +1339,10 @@ static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload) WRITE_ONCE(dest->l_threshold_val, 0); } -void ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload) +void ip_vs_dest_update_overload(struct ip_vs_dest *dest) { spin_lock_bh(&dest->dst_lock); - __ip_vs_dest_update_overload(dest, overload); + __ip_vs_dest_update_overload(dest); spin_unlock_bh(&dest->dst_lock); } @@ -1406,13 +1414,10 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest, if (READ_ONCE(dest->u_threshold) != udest->u_threshold || READ_ONCE(dest->l_threshold) != udest->l_threshold) { - bool overload; - spin_lock_bh(&dest->dst_lock); WRITE_ONCE(dest->u_threshold, udest->u_threshold); WRITE_ONCE(dest->l_threshold, udest->l_threshold); - overload = ip_vs_dest_is_overloaded(dest); - __ip_vs_dest_update_overload(dest, overload); + __ip_vs_dest_update_overload(dest); spin_unlock_bh(&dest->dst_lock); } @@ -1477,6 +1482,7 @@ ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest) if (ret < 0) goto err_stats; + dest->u_threshold_val = INT_MAX; dest->af = udest->af; dest->protocol = svc->protocol; dest->vaddr = svc->addr; diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c index e1111c3b2721..f5ce1f2afb86 100644 --- a/net/netfilter/ipvs/ip_vs_lblc.c +++ b/net/netfilter/ipvs/ip_vs_lblc.c @@ -467,10 +467,11 @@ is_overloaded(struct ip_vs_dest *dest, struct ip_vs_service *svc) struct ip_vs_dest *d; list_for_each_entry_rcu(d, &svc->destinations, n_list) { - if (atomic_read(&d->activeconns)*2 - < atomic_read(&d->weight)) { + if (ip_vs_dest_is_overloaded(d)) + continue; + if (atomic_read(&d->activeconns) * 2 < + atomic_read(&d->weight)) return 1; - } } } return 0; @@ -507,6 +508,7 @@ ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, dest = en->dest; if ((dest->cflags & IP_VS_DEST_CF_AVAILABLE) && + !ip_vs_dest_is_overloaded(dest) && atomic_read(&dest->weight) > 0 && !is_overloaded(dest, svc)) goto out; } diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c index dfb5bf83750d..4046608922e7 100644 --- a/net/netfilter/ipvs/ip_vs_lblcr.c +++ b/net/netfilter/ipvs/ip_vs_lblcr.c @@ -630,10 +630,11 @@ is_overloaded(struct ip_vs_dest *dest, struct ip_vs_service *svc) struct ip_vs_dest *d; list_for_each_entry_rcu(d, &svc->destinations, n_list) { - if (atomic_read(&d->activeconns)*2 - < atomic_read(&d->weight)) { + if (ip_vs_dest_is_overloaded(d)) + continue; + if (atomic_read(&d->activeconns) * 2 < + atomic_read(&d->weight)) return 1; - } } } return 0; @@ -658,9 +659,6 @@ ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, if (en) { en->lastuse = jiffies; - /* Get the least loaded destination */ - dest = ip_vs_dest_set_min(&en->set); - /* More than one destination + enough time passed by, cleanup */ if (atomic_read(&en->set.size) > 1 && time_after(jiffies, en->set.lastmod + @@ -676,6 +674,9 @@ ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, spin_unlock_bh(&svc->sched_lock); } + /* Get the least loaded destination */ + dest = ip_vs_dest_set_min(&en->set); + /* If the destination is not overloaded, use it */ if (dest && !is_overloaded(dest, svc)) goto out; From 1d1e8bc81f790a48cd643b1b1762de43334d4f14 Mon Sep 17 00:00:00 2001 From: Axel Mierczuk Date: Tue, 3 Nov 2026 11:57:45 -0500 Subject: [PATCH 029/117] ipvs: validate cport in received sync records Local templates have cport 0 and IP_VS_CONN_F_NO_CPORT clear, so ip_vs_conn_in_get() cannot match them. A template received over the unauthenticated sync protocol with a nonzero cport can reach the protocol state machine. Before template state validation, this could cause out-of-bounds reads, crashes and kernel data leaks. Ordinary records with cport 0 and IP_VS_CONN_F_NO_CPORT clear, or with a nonzero cport and IP_VS_CONN_F_NO_CPORT set, create connections that incoming lookups cannot match. The latter also keeps the cport-zero fallback in ip_vs_conn_in_get() enabled. Reject all three cases. Continue accepting ordinary connections with cport 0 and IP_VS_CONN_F_NO_CPORT. The companion commit f96e91748f63 ("ipvs: filter some flags received in the backup server") rejects template records carrying IP_VS_CONN_F_NO_CPORT. Fixes: 87375ab47cd0 ("[IPVS]: ip_vs_ftp breaks connections using persistence") Cc: stable@vger.kernel.org Suggested-by: Julian Anastasov Signed-off-by: Axel Mierczuk Acked-by: Julian Anastasov Signed-off-by: Pablo Neira Ayuso --- net/netfilter/ipvs/ip_vs_sync.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c index f11c59eca553..7e562e745ab5 100644 --- a/net/netfilter/ipvs/ip_vs_sync.c +++ b/net/netfilter/ipvs/ip_vs_sync.c @@ -871,6 +871,25 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa struct ip_vs_dest *dest; struct ip_vs_conn *cp; + /* Templates require cport 0. Ordinary connections require + * NO_CPORT exactly when cport is 0. + */ + if (flags & IP_VS_CONN_F_TEMPLATE) { + if (param->cport) { + IP_VS_DBG(2, "BACKUP, template with cport dropped\n"); + kfree(param->pe_data); + return; + } + } else if (!param->cport && !(flags & IP_VS_CONN_F_NO_CPORT)) { + IP_VS_DBG(2, "BACKUP, conn without cport dropped\n"); + kfree(param->pe_data); + return; + } else if (param->cport && (flags & IP_VS_CONN_F_NO_CPORT)) { + IP_VS_DBG(2, "BACKUP, conn with cport and NO_CPORT dropped\n"); + kfree(param->pe_data); + return; + } + if (!(flags & IP_VS_CONN_F_TEMPLATE)) { cp = ip_vs_conn_in_get(param); if (cp && ((cp->dport != dport) || From 5c8d6e2596e0935e2ace0b94e86ffb99e8434cd9 Mon Sep 17 00:00:00 2001 From: Axel Mierczuk Date: Tue, 3 Nov 2026 11:57:46 -0500 Subject: [PATCH 030/117] ipvs: skip cport 0 connections in ip_vs_conn_out_get() ip_vs_conn_out_get() does not filter templates. A template with cport 0 is matched by a packet sent to client port 0 that traverses the out hook, and handle_response() then runs ip_vs_set_state() and the timeout update on a connection that must never see packets. A backup server receives such templates over the unauthenticated sync protocol. An ordinary connection scheduled for a client that uses source port 0 has cport 0 as well and is matched the same way. Apply the rule used by __ip_vs_conn_in_get(): a lookup for client port 0 matches only connections flagged IP_VS_CONN_F_NO_CPORT, which still wait for their cport, and a lookup for a nonzero client port matches only connections without this flag. Test p->vport, which was already compared with cp->cport, instead of reading cp->cport again. ip_vs_ftp_out() relies on the first case: it looks up the data connection with client port 0 to find the IP_VS_CONN_F_NO_CPORT entry created for an earlier PASV or EPSV reply. That lookup keeps working. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Suggested-by: Julian Anastasov Signed-off-by: Axel Mierczuk Signed-off-by: Pablo Neira Ayuso --- net/netfilter/ipvs/ip_vs_conn.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c index 66fcdc00ef37..83d8a9153a34 100644 --- a/net/netfilter/ipvs/ip_vs_conn.c +++ b/net/netfilter/ipvs/ip_vs_conn.c @@ -590,6 +590,8 @@ struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p) ip_vs_addr_equal(p->af, p->vaddr, &cp->caddr) && ip_vs_addr_equal(p->af, p->caddr, saddr) && + (!p->vport ^ + (!(cp->flags & IP_VS_CONN_F_NO_CPORT))) && p->protocol == cp->protocol) { if (__ip_vs_conn_get(cp)) goto out; From 7439e0fed91f55e4b48b9e725ad60575cb881d09 Mon Sep 17 00:00:00 2001 From: Julian Anastasov Date: Fri, 6 Nov 2026 01:15:34 +0200 Subject: [PATCH 031/117] ipvs: do not create conns from packets with port 0 We should disallow normal connections with cport 0 to be created from packets by the scheduler (from clients) or by ip_vs_new_conn_out (from real servers) because later such traffic can not hit the connection due to the NO_CPORT requirement. As result, it can lead to duplicate connection for every packet. Do the same for vport 0. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Link: https://sashiko.dev/#/patchset/20261104201530.147292-1-ja%40ssi.bg Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261103140308.591690-3-pablo%40netfilter.org Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260925141115.16126-1-axel.mierczuk%401password.com Signed-off-by: Julian Anastasov Signed-off-by: Pablo Neira Ayuso --- net/netfilter/ipvs/ip_vs_core.c | 3 ++- net/netfilter/ipvs/ip_vs_proto_sctp.c | 7 +++++++ net/netfilter/ipvs/ip_vs_proto_tcp.c | 7 +++++++ net/netfilter/ipvs/ip_vs_proto_udp.c | 6 ++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c index 8a3c880fdb26..f3eb72e95024 100644 --- a/net/netfilter/ipvs/ip_vs_core.c +++ b/net/netfilter/ipvs/ip_vs_core.c @@ -1305,6 +1305,7 @@ static inline bool is_new_conn_expected(const struct ip_vs_conn *cp, * In fwmark-VS actual vaddr and vport are unknown to IPVS * 2) Real Server and Virtual Service were NOT configured without port: * This is to allow match of different VS to the same RS ip-addr + * 3) Client port is not 0 */ struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc, struct ip_vs_dest *dest, @@ -1328,7 +1329,7 @@ struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc, /* check pre-requisites are satisfied */ if (svc->fwmark) return NULL; - if (!vport || !dport) + if (!vport || !dport || !cport) return NULL; /* for persistent service first create connection template */ diff --git a/net/netfilter/ipvs/ip_vs_proto_sctp.c b/net/netfilter/ipvs/ip_vs_proto_sctp.c index fb8af6b15a39..cb34bcceb4f6 100644 --- a/net/netfilter/ipvs/ip_vs_proto_sctp.c +++ b/net/netfilter/ipvs/ip_vs_proto_sctp.c @@ -30,6 +30,7 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, sch = skb_header_pointer(skb, iph->len + sizeof(_sctph), sizeof(_schunkh), &_schunkh); if (sch) { + /* Accept packet without scheduling? */ if (sch->type == SCTP_CID_ABORT || !(sysctl_sloppy_sctp(ipvs) || sch->type == SCTP_CID_INIT)) @@ -56,6 +57,12 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, if (svc) { int ignored; + /* Do not create connection for port 0 */ + if (!ports[0] || !ports[1]) { + *verdict = NF_DROP; + return 0; + } + if (ip_vs_todrop(ipvs)) { /* * It seems that we are very loaded. diff --git a/net/netfilter/ipvs/ip_vs_proto_tcp.c b/net/netfilter/ipvs/ip_vs_proto_tcp.c index fec0e8b47b71..25d4576d0e12 100644 --- a/net/netfilter/ipvs/ip_vs_proto_tcp.c +++ b/net/netfilter/ipvs/ip_vs_proto_tcp.c @@ -48,6 +48,7 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, if (likely(!ip_vs_iph_icmp(iph))) { th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph); if (th) { + /* Accept packet without scheduling? */ if (th->rst || !(sysctl_sloppy_tcp(ipvs) || th->syn)) return 1; ports = &th->source; @@ -74,6 +75,12 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, if (svc) { int ignored; + /* Do not create connection for port 0 */ + if (!ports[0] || !ports[1]) { + *verdict = NF_DROP; + return 0; + } + if (ip_vs_todrop(ipvs)) { /* * It seems that we are very loaded. diff --git a/net/netfilter/ipvs/ip_vs_proto_udp.c b/net/netfilter/ipvs/ip_vs_proto_udp.c index f32785682402..ab3ab9524168 100644 --- a/net/netfilter/ipvs/ip_vs_proto_udp.c +++ b/net/netfilter/ipvs/ip_vs_proto_udp.c @@ -62,6 +62,12 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb, if (svc) { int ignored; + /* Do not create connection for port 0 */ + if (!ports[0] || !ports[1]) { + *verdict = NF_DROP; + return 0; + } + if (ip_vs_todrop(ipvs)) { /* * It seems that we are very loaded. From 5367e14e92bbb0779612d36cce7c6e95d3bc5e68 Mon Sep 17 00:00:00 2001 From: Darong Lu Date: Mon, 9 Nov 2026 10:06:47 +0800 Subject: [PATCH 032/117] ipvs: wait grace period before reusing destinations An IPVS destination can be removed from a service and immediately reused from dest_trash before an RCU grace period has elapsed. Reusing its n_list or d_list can make existing readers follow links into another service or real-server hash chain. The grace-period cookie is also saved when a live destination is unhashed for an edit and consumed when it is rehashed. Describe rcu_state as the cookie for an unlink, covering both trash and rehash cases. When a destination is retrieved from dest_trash, ip_vs_add_dest() currently restarts its estimator before waiting for the grace period. If the estimator was on a tick chain, ip_vs_stop_estimator() removed est->list with hlist_del_rcu(), so an estimator kthread can still be traversing that node. ip_vs_start_estimator() rewrites the node on its temporary list on success, or initializes it on failure, before the current wait. A reader can then follow the changed link or stop traversing the chain early. Wait immediately after retrieving the destination, before starting its estimator. The conditional grace-period wait then covers the destination list, real-server hash and estimator list on both estimator success and failure paths. Fixes: bcbde4c0a755 ("ipvs: make the service replacement more robust") Cc: stable@vger.kernel.org Reported-by: Vega Reported-by: Darong Lu Co-developed-by: Jiayuan Chen Signed-off-by: Jiayuan Chen Signed-off-by: Darong Lu Signed-off-by: Ren Wei Signed-off-by: Julian Anastasov Signed-off-by: Pablo Neira Ayuso --- include/net/ip_vs.h | 4 +- net/netfilter/ipvs/ip_vs_ctl.c | 110 ++++++++++++++++++++++++++------- 2 files changed, 91 insertions(+), 23 deletions(-) diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h index c1f7a3f144f1..8dc80d5d42dc 100644 --- a/include/net/ip_vs.h +++ b/include/net/ip_vs.h @@ -1021,7 +1021,9 @@ struct ip_vs_dest { struct rcu_head rcu_head; struct list_head t_list; /* in dest_trash */ - unsigned int in_rs_table:1; /* we are in rs_table */ + unsigned long rcu_state; /* GP cookie on unlink (trash or rehash) */ + unsigned int in_rs_table:1, /* we are in rs_table */ + need_gp:1; /* Need GP on rehash */ }; /* The scheduler object */ diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c index 5868adda6ed6..be818bf7d380 100644 --- a/net/netfilter/ipvs/ip_vs_ctl.c +++ b/net/netfilter/ipvs/ip_vs_ctl.c @@ -64,7 +64,8 @@ int ip_vs_get_debug_level(void) /* Protos */ -static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup); +static void __ip_vs_del_service(struct ip_vs_service *svc, + struct list_head *dest_trash, bool cleanup); #ifdef CONFIG_IP_VS_IPV6 @@ -918,6 +919,11 @@ static void ip_vs_rs_hash(struct netns_ipvs *ipvs, struct ip_vs_dest *dest) */ hash = ip_vs_rs_hashkey(dest->af, &dest->addr, port); + /* Need RCU grace period when rehashing */ + if (dest->need_gp) { + cond_synchronize_rcu(dest->rcu_state); + dest->need_gp = 0; + } hlist_add_head_rcu(&dest->d_list, &ipvs->rs_table[hash]); dest->in_rs_table = 1; } @@ -1111,6 +1117,8 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af, struct ip_vs_dest *dest; struct netns_ipvs *ipvs = svc->ipvs; + lockdep_assert_held(&ipvs->service_mutex); + /* * Find the destination in trash */ @@ -1144,24 +1152,57 @@ out: return dest; } -/* Put destination in trash */ -static void ip_vs_trash_put_dest(struct netns_ipvs *ipvs, +/* Add destination in temp list for trash */ +static void ip_vs_trash_add_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest, unsigned long istart, - bool cleanup) + struct list_head *dest_trash) { - spin_lock_bh(&ipvs->dest_trash_lock); IP_VS_DBG_BUF(3, "Moving dest %s:%u into trash, dest->refcnt=%d\n", IP_VS_DBG_ADDR(dest->af, &dest->addr), ntohs(dest->port), refcount_read(&dest->refcnt)); + /* dest lives in trash with reference */ + list_add(&dest->t_list, dest_trash); + dest->idle_start = istart; +} + +/* Put destinations in trash */ +static void ip_vs_trash_put_dests(struct netns_ipvs *ipvs, + struct list_head *dest_trash, bool cleanup) +{ + spin_lock_bh(&ipvs->dest_trash_lock); if (list_empty(&ipvs->dest_trash) && !cleanup) mod_timer(&ipvs->dest_trash_timer, jiffies + (IP_VS_DEST_TRASH_PERIOD >> 1)); - /* dest lives in trash with reference */ - list_add(&dest->t_list, &ipvs->dest_trash); - dest->idle_start = istart; + list_splice(dest_trash, &ipvs->dest_trash); spin_unlock_bh(&ipvs->dest_trash_lock); } +/* Put destination back in trash */ +static void ip_vs_trash_put_back(struct netns_ipvs *ipvs, + struct ip_vs_dest *dest) +{ + LIST_HEAD(dest_trash); + + ip_vs_trash_add_dest(ipvs, dest, dest->idle_start, &dest_trash); + ip_vs_trash_put_dests(ipvs, &dest_trash, false); +} + +/* Put destinations in trash and save the RCU state */ +static void ip_vs_trash_save_dests(struct netns_ipvs *ipvs, + struct list_head *dest_trash, bool cleanup) +{ + struct ip_vs_dest *dest; + unsigned long rcu_state; + + if (!list_empty(dest_trash)) { + /* Remember when dests were removed and added to dest_trash */ + rcu_state = get_state_synchronize_rcu(); + list_for_each_entry(dest, dest_trash, t_list) + dest->rcu_state = rcu_state; + ip_vs_trash_put_dests(ipvs, dest_trash, cleanup); + } +} + static void ip_vs_dest_rcu_free(struct rcu_head *head) { struct ip_vs_dest *dest; @@ -1377,8 +1418,16 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest, if ((udest->conn_flags & IP_VS_CONN_F_FWD_MASK) != IP_VS_DFWD_METHOD(dest) || udest->tun_type != dest->tun_type || - udest->tun_port != dest->tun_port) + udest->tun_port != dest->tun_port) { + bool unlinked = dest->in_rs_table; + ip_vs_rs_unhash(dest); + if (unlinked) { + dest->rcu_state = get_state_synchronize_rcu(); + /* Need grace period in this or next dest update */ + dest->need_gp = 1; + } + } /* set the tunnel info */ dest->tun_type = udest->tun_type; @@ -1562,6 +1611,11 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest) dest = ip_vs_trash_get_dest(svc, udest->af, &daddr, dport); if (dest != NULL) { + /* Readers may still follow the n_list, d_list or estimator list + * links. Wait before reusing any of them. + */ + cond_synchronize_rcu(dest->rcu_state); + IP_VS_DBG_BUF(3, "Get destination %s:%u from trash, " "dest->refcnt=%d, service %u/%s:%u\n", IP_VS_DBG_ADDR(udest->af, &daddr), ntohs(dport), @@ -1572,11 +1626,14 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest) ret = ip_vs_start_estimator(svc->ipvs, &dest->stats); /* On error put back dest into the trash */ - if (ret < 0) - ip_vs_trash_put_dest(svc->ipvs, dest, dest->idle_start, - false); - else + if (ret < 0) { + ip_vs_trash_put_back(svc->ipvs, dest); + } else { + /* need_gp matters only on dest edit, reinit it */ + dest->need_gp = 0; + __ip_vs_update_dest(svc, dest, udest, 1); + } } else { /* * Allocate and initialize the dest structure @@ -1640,7 +1697,7 @@ ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest) * Delete a destination (must be already unlinked from the service) */ static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest, - bool cleanup) + struct list_head *dest_trash, bool cleanup) { ip_vs_stop_estimator(ipvs, &dest->stats); @@ -1649,7 +1706,7 @@ static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest, */ ip_vs_rs_unhash(dest); - ip_vs_trash_put_dest(ipvs, dest, 0, cleanup); + ip_vs_trash_add_dest(ipvs, dest, 0, dest_trash); /* Queue up delayed work to expire all no destination connections. * No-op when CONFIG_SYSCTL is disabled. @@ -1699,6 +1756,7 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest) { struct ip_vs_dest *dest; __be16 dport = udest->port; + LIST_HEAD(dest_trash); /* We use function that requires RCU lock */ rcu_read_lock(); @@ -1718,7 +1776,9 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest) /* * Delete the destination */ - __ip_vs_del_dest(svc->ipvs, dest, false); + __ip_vs_del_dest(svc->ipvs, dest, &dest_trash, false); + + ip_vs_trash_save_dests(svc->ipvs, &dest_trash, false); return 0; } @@ -2063,7 +2123,8 @@ out: * - The service must be unlinked, unlocked and not referenced! * - We are called under _bh lock */ -static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup) +static void __ip_vs_del_service(struct ip_vs_service *svc, + struct list_head *dest_trash, bool cleanup) { struct ip_vs_dest *dest, *nxt; struct ip_vs_scheduler *old_sched; @@ -2097,7 +2158,7 @@ static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup) */ list_for_each_entry_safe(dest, nxt, &svc->destinations, n_list) { __ip_vs_unlink_dest(svc, dest, 0); - __ip_vs_del_dest(svc->ipvs, dest, cleanup); + __ip_vs_del_dest(svc->ipvs, dest, dest_trash, cleanup); } /* @@ -2120,7 +2181,8 @@ static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup) /* * Unlink a service from list and try to delete it if its refcnt reached 0 */ -static void ip_vs_unlink_service(struct ip_vs_service *svc, bool cleanup) +static void ip_vs_unlink_service(struct ip_vs_service *svc, + struct list_head *dest_trash, bool cleanup) { ip_vs_unregister_conntrack(svc); /* Hold svc to avoid double release from dest_trash */ @@ -2130,7 +2192,7 @@ static void ip_vs_unlink_service(struct ip_vs_service *svc, bool cleanup) */ ip_vs_svc_unhash(svc); - __ip_vs_del_service(svc, cleanup); + __ip_vs_del_service(svc, dest_trash, cleanup); } /* @@ -2140,12 +2202,14 @@ static int ip_vs_del_service(struct ip_vs_service *svc) { struct netns_ipvs *ipvs; struct ip_vs_rht *t, *p; + LIST_HEAD(dest_trash); int ns; if (svc == NULL) return -EEXIST; ipvs = svc->ipvs; - ip_vs_unlink_service(svc, false); + ip_vs_unlink_service(svc, &dest_trash, false); + ip_vs_trash_save_dests(ipvs, &dest_trash, false); /* Drop the table if no more services */ ns = ip_vs_get_num_services(ipvs); @@ -2196,6 +2260,7 @@ static int ip_vs_flush(struct netns_ipvs *ipvs, bool cleanup) struct hlist_bl_node *ne; struct hlist_bl_node *e; struct ip_vs_rht *t, *p; + LIST_HEAD(dest_trash); /* Stop the resizer and drop the tables */ if (!test_and_set_bit(IP_VS_WORK_SVC_NORESIZE, &ipvs->work_flags)) @@ -2205,8 +2270,9 @@ static int ip_vs_flush(struct netns_ipvs *ipvs, bool cleanup) if (ip_vs_get_num_services(ipvs)) { ip_vs_rht_walk_buckets(ipvs->svc_table, head) { hlist_bl_for_each_entry_safe(svc, e, ne, head, s_list) - ip_vs_unlink_service(svc, cleanup); + ip_vs_unlink_service(svc, &dest_trash, cleanup); } + ip_vs_trash_save_dests(ipvs, &dest_trash, cleanup); } /* Unregister the hash table and release it after RCU grace period */ From 76248359ac32e97cd7d1bd55a4c94a2ad4009871 Mon Sep 17 00:00:00 2001 From: Piyus Kedia Date: Thu, 12 Nov 2026 23:08:12 +0530 Subject: [PATCH 033/117] Bluetooth: L2CAP: clear the SDU before the receive callback l2cap_ecred_data_rcv() completes a reassembled SDU by calling l2cap_ecred_recv() with chan->sdu still set, and only clears the reassembly state after it returns: if (chan->sdu->len == chan->sdu_len) { err = l2cap_ecred_recv(chan, chan->sdu); if (!err) { chan->sdu = NULL; ... l2cap_ecred_recv() hands the SDU to the channel's receive callback, which takes ownership of it on success, and then updates the credits: err = chan->ops->recv(chan, skb); ... l2cap_chan_le_send_credits(chan); l2cap_chan_le_send_credits() calls l2cap_le_rx_credits(), which reads size_t sdu_len = chan->sdu ? chan->sdu->len : 0; so between the callback consuming the skb and the assignment above, chan->sdu is a dangling pointer that is dereferenced. For the 6LoWPAN channel the callback frees the skb outright - chan_recv_cb() -> recv_pkt() ends in consume_skb(skb) and returns NET_RX_SUCCESS - so the read is a straightforward use-after-free that KASAN reports: BUG: KASAN: slab-use-after-free in l2cap_le_rx_credits net/bluetooth/l2cap_core.c:576 [inline] BUG: KASAN: slab-use-after-free in l2cap_chan_le_send_credits+0xa8/0x3e0 net/bluetooth/l2cap_core.c:6811 Read of size 4 at addr ffff88800e134070 by task kworker/u21:2/11352 Workqueue: hci0 hci_rx_work l2cap_le_rx_credits net/bluetooth/l2cap_core.c:576 [inline] l2cap_chan_le_send_credits+0xa8/0x3e0 net/bluetooth/l2cap_core.c:6811 l2cap_ecred_recv+0x63/0x120 net/bluetooth/l2cap_core.c:6873 l2cap_ecred_data_rcv net/bluetooth/l2cap_core.c:6976 [inline] l2cap_data_channel net/bluetooth/l2cap_core.c:7028 [inline] l2cap_recv_frame+0x6c3c/0x9650 net/bluetooth/l2cap_core.c:7162 l2cap_recv_acldata+0x6fd/0xe60 net/bluetooth/l2cap_core.c:7902 hci_acldata_packet net/bluetooth/hci_core.c:3865 [inline] hci_rx_work+0x3c0/0xbe0 net/bluetooth/hci_core.c:4092 Freed by task 11352: recv_pkt net/bluetooth/6lowpan.c chan_recv_cb+0x88/0x150 net/bluetooth/6lowpan.c:367 l2cap_ecred_recv+0x61/0x160 net/bluetooth/l2cap_core.c:6864 The buggy address belongs to the object at ffff88800e134000 which belongs to the cache skbuff_head_cache of size 240 The buggy address is located 112 bytes inside of freed 240-byte region Offset 112 is sk_buff.len. Only a multi-frame SDU is affected: the single-frame path already calls l2cap_ecred_recv() with chan->sdu NULL, so l2cap_le_rx_credits() reads a zero sdu_len there. l2cap_reassemble_sdu() completes a segmented SDU the same way and has the same defect. On an ERTM or streaming channel l2cap_sock_recv_cb() calls l2cap_publish_rx_avail(), which reaches l2cap_chan_le_send_credits() through l2cap_chan_rx_avail(), and that function evaluates u16 return_credits = l2cap_le_rx_credits(chan); in its initializer - before the mode test that makes the rest of it a no-op for a non-LE channel. So chan->sdu is dereferenced on that path too, and the result is discarded. What makes it a use-after-free rather than a stale read is a consumer that frees the skb from another thread: BNEP's session kthread takes it off the socket with a lockless skb_dequeue() (net/bluetooth/bnep/core.c:530, freed at :533) and never takes the socket lock, so lock_sock() is no defence. Fix both sites. Clear the reassembly state before handing the SDU to the callback, which makes the fragmented path behave like the single-frame one, and free the SDU on the spot if the callback refused it - the error path's kfree_skb(chan->sdu) used to do that, and the callbacks leave the skb to the caller when they fail. Clearing it first is also the arithmetically correct input, not merely a safe one. l2cap_le_rx_credits() subtracts sdu_len from chan->rx_avail because a partially reassembled SDU will claim that much receive buffer once it completes: if (chan->rx_avail <= sdu_len) return 0; return DIV_ROUND_UP(chan->rx_avail - sdu_len, chan->mps); A completed SDU is no longer waiting for that space. If the callback queued it, l2cap_sock_recv_cb() has already called l2cap_publish_rx_avail(), which recomputes rx_avail from sk_rcvbuf - sk_rmem_alloc with that skb included in sk_rmem_alloc; if the callback consumed it, as the 6LoWPAN one does, it occupies nothing at all. Either way the reassembly buffer is empty, so zero is the right sdu_len, and a NULL chan->sdu is how l2cap_le_rx_credits() expresses that - the same value l2cap_le_flowctl_init() depends on when it seeds chan->rx_credits on an idle channel. Carrying the old length into the calculation instead would subtract the SDU a second time and under-grant credits on every delivery, and once rx_avail fell to the size of one SDU the channel would be granted none at all. Per Documentation/process/generated-content.rst: the use-after-free was found by an AI-driven fuzzing harness built on syzkaller, developed jointly by Kapil Vaswani and myself, which drove a virtual HCI controller and a 6LoWPAN channel under KASAN on x86_64. The root-cause analysis, this changelog and the patch were written with the assistance of a large language model over an extended session, and reviewed by hand; the before/after testing below the --- was run by us. Fixes: ce60b9231b66 ("Bluetooth: compute LE flow credits based on recvbuf space") Signed-off-by: Kapil Vaswani Signed-off-by: Piyus Kedia Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 53 ++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 486b968143d3..4ee1e62ded7e 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -6226,6 +6226,7 @@ static void append_skb_frag(struct sk_buff *skb, struct sk_buff *new_frag, static int l2cap_reassemble_sdu(struct l2cap_chan *chan, struct sk_buff *skb, struct l2cap_ctrl *control) { + struct sk_buff *sdu; int err = -EINVAL; switch (control->sar) { @@ -6286,15 +6287,25 @@ static int l2cap_reassemble_sdu(struct l2cap_chan *chan, struct sk_buff *skb, if (chan->sdu->len != chan->sdu_len) break; - err = chan->ops->recv(chan, chan->sdu); + /* Reassembly complete. Hand the SDU over before the + * callback, for the reason given in l2cap_ecred_data_rcv(): + * the callback takes ownership and may free it, while + * l2cap_chan_rx_avail() -> l2cap_chan_le_send_credits() reads + * chan->sdu->len on the way out - it does so before the mode + * test that makes the rest of that function a no-op here. + * Return directly, since the state this leaves is what the + * trailing error block would otherwise set again. + */ + sdu = chan->sdu; + chan->sdu = NULL; + chan->sdu_last_frag = NULL; + chan->sdu_len = 0; - if (!err) { - /* Reassembly complete */ - chan->sdu = NULL; - chan->sdu_last_frag = NULL; - chan->sdu_len = 0; - } - break; + err = chan->ops->recv(chan, sdu); + if (err) + kfree_skb(sdu); + + return err; } if (err) { @@ -7285,12 +7296,26 @@ static int l2cap_ecred_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb) skb = NULL; if (chan->sdu->len == chan->sdu_len) { - err = l2cap_ecred_recv(chan, chan->sdu); - if (!err) { - chan->sdu = NULL; - chan->sdu_last_frag = NULL; - chan->sdu_len = 0; - } + struct sk_buff *sdu = chan->sdu; + + /* The receive callback takes ownership of a reassembled SDU and + * may free it, while l2cap_ecred_recv() goes on to update the + * credits - which reads chan->sdu->len. Drop the reassembly + * state before handing the SDU over, and release it here if the + * callback refused it, so that it is still freed exactly once. + * The reassembly state is already clear at that point, so + * return instead of falling into the failed: block, whose + * kfree_skb(chan->sdu) would have nothing left to free. + */ + chan->sdu = NULL; + chan->sdu_last_frag = NULL; + chan->sdu_len = 0; + + err = l2cap_ecred_recv(chan, sdu); + if (err) + kfree_skb(sdu); + + return 0; } failed: From 0d8f6981f55e28d8fac703bbd0e29bd9496c8b5b Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 13 Nov 2026 11:15:44 -0500 Subject: [PATCH 034/117] Bluetooth: 6lowpan: Always consume the skb in chan_recv_cb The l2cap_chan_ops recv callback takes ownership of the skb on success and leaves it to the caller on failure. chan_recv_cb() violates this: when recv_pkt() fails it returns -EAGAIN even though skb_share_check() may already have dropped the caller's reference to a shared skb and replaced it with a clone. The L2CAP caller then calls kfree_skb() on the original skb, over-releasing it, while the clone is leaked. Make recv_pkt() free the skb on its drop path and have chan_recv_cb() always consume the skb and return 0, including the lookup failures, so the caller never frees it again. A dropped packet is accounted in rx_dropped and no longer reported as a receive error to L2CAP. Fixes: 11e3ff707278 ("6lowpan: Use skb_cow in IPHC decompression.") Assisted-by: OpenCode:claude-sonnet-5.5 Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/6lowpan.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c index 8c51c20f6c4b..68ca2f49dadc 100644 --- a/net/bluetooth/6lowpan.c +++ b/net/bluetooth/6lowpan.c @@ -345,6 +345,7 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev, return NET_RX_SUCCESS; drop: + kfree_skb(skb); dev->stats.rx_dropped++; return NET_RX_DROP; } @@ -356,21 +357,26 @@ static int chan_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb) struct lowpan_peer *peer; int err; + /* The skb is always consumed, so never return an error that would + * make the caller free it again. + */ peer = lookup_peer(chan->conn); if (!peer) - return -ENOENT; + goto drop; dev = lookup_dev(chan->conn); if (!dev || !dev->netdev) - return -ENOENT; + goto drop; err = recv_pkt(skb, dev->netdev, peer); - if (err) { + if (err) BT_DBG("recv pkt %d", err); - err = -EAGAIN; - } - return err; + return 0; + +drop: + kfree_skb(skb); + return 0; } static int setup_header(struct sk_buff *skb, struct net_device *netdev, From ce09d8c13a15fe881d0a04c91979dcdf45ed9543 Mon Sep 17 00:00:00 2001 From: Henry Martin Date: Wed, 11 Nov 2026 16:23:13 +0800 Subject: [PATCH 035/117] sctp: fix skb_over_panic when adding addresses with a pending delete of another family sctp_make_asconf_update_ip() accounts for a pending DEL_IP parameter by reusing the length of the address being added. The write-back side instead serializes the pending address itself, with its own address family. If the pending delete is IPv6 (20-byte parameter) while the added addresses are IPv4 (8-byte), the chunk is allocated 12 bytes short and sctp_addto_chunk() writes past the end of the skb. E.g. on mainline (05441d697f7f): skbuff: skb_over_panic: text:ffffffff84859c77 len:392 put:20 tail:0x188 end:0x180 dev: kernel BUG at net/core/skbuff.c:215! CPU: 0 UID: 1000 PID: 379 Comm: poc_sctp Call Trace: skb_panic skb_put sctp_addto_chunk sctp_make_asconf_update_ip sctp_send_asconf_add_ip sctp_setsockopt_bindx __x64_sys_setsockopt Requires addip enabled on the endpoint (net.sctp.addip_enable=1). Account for the pending delete with its own address family, as the write-back side already does. This issue was discovered by an LLM code scanner. Cc: stable@vger.kernel.org Fixes: 8a07eb0a50ae ("sctp: Add ASCONF operation on the single-homed host") Signed-off-by: Henry Martin Acked-by: Xin Long Link: https://patch.msgid.link/20261111082313.1606366-1-bsdhenrymartin@gmail.com Signed-off-by: Jakub Kicinski --- net/sctp/sm_make_chunk.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index 15c2d87575a8..ba0474c2a0bc 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -2870,7 +2870,6 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc, int addr_param_len = 0; union sctp_addr *addr; int totallen = 0, i; - int del_pickup = 0; struct sctp_af *af; void *addr_buf; @@ -2885,16 +2884,21 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc, totallen += addr_param_len; addr_buf += af->sockaddr_len; - if (asoc->asconf_addr_del_pending && !del_pickup) { - /* reuse the parameter length from the same scope one */ - totallen += paramlen; - totallen += addr_param_len; - del_pickup = 1; + } - pr_debug("%s: picked same-scope del_pending addr, " - "totallen for all addresses is %d\n", - __func__, totallen); - } + if (asoc->asconf_addr_del_pending) { + /* The DEL_IP parameter is serialized from the pending address + * itself below; account for its own address family, which may + * differ from the added ones. + */ + addr = asoc->asconf_addr_del_pending; + af = sctp_get_af_specific(addr->v4.sin_family); + totallen += paramlen; + totallen += af->to_addr_param(addr, &addr_param); + + pr_debug("%s: picked del_pending addr, " + "totallen for all addresses is %d\n", + __func__, totallen); } /* Create an asconf chunk with the required length. */ @@ -2917,7 +2921,7 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc, addr_buf += af->sockaddr_len; } - if (flags == SCTP_PARAM_ADD_IP && del_pickup) { + if (flags == SCTP_PARAM_ADD_IP && asoc->asconf_addr_del_pending) { addr = asoc->asconf_addr_del_pending; af = sctp_get_af_specific(addr->v4.sin_family); addr_param_len = af->to_addr_param(addr, &addr_param); From 4cad287cb13c1fc32e4afa590e4148fa288d5741 Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Wed, 11 Nov 2026 10:54:27 +0100 Subject: [PATCH 036/117] net: stmmac: re-base EST after PTP settime64 stmmac_set_time() initializes the PTP clock through stmmac_init_systime() (TSINIT) while holding only ptp_lock. It neither takes est_lock nor disables and re-bases EST around the step, unlike stmmac_adjust_time(), which performs TSUPDT through stmmac_adjust_systime() under est_lock. Both operations change the PHC system time, so both invalidate the absolute EST base time. With settime64, a concurrent tc_taprio_configure() can read the pre-step clock through gettimex64() and program EST with a base time that is already stale once TSINIT lands. Separately, a taprio offload installed before the clock_settime() is never re-based and keeps running with its old base time until taprio is reconfigured. Take est_lock for the whole disable/step/reprogram sequence, as stmmac_adjust_time() does: disable EST before initializing the clock and call __stmmac_setup_est() afterwards so the base time is recomputed from the reserved taprio base time and the new clock. This keeps the established est_lock -> ptp_lock ordering: stmmac_init_systime() only uses readl_poll_timeout_atomic() under ptp_lock, and __stmmac_setup_est() takes ptp_lock through gettimex64(). Fixes: b60189e0392f ("net: stmmac: Integrate EST with TAPRIO scheduler API") Signed-off-by: Lorenzo Bianconi Reviewed-by: Nicolai Buchwitz Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20261111-stmmac_set_time-est_lock-v1-1-da1554f233e6@oss.qualcomm.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c index 31a66e855d6b..6370bdc6c58b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c @@ -129,10 +129,19 @@ static int stmmac_set_time(struct ptp_clock_info *ptp, container_of(ptp, struct stmmac_priv, ptp_clock_ops); unsigned long flags; + mutex_lock(&priv->est_lock); + if (priv->est && priv->est->enable) + stmmac_est_configure(priv, priv, priv->est, + priv->plat->clk_ptp_rate, false); + write_lock_irqsave(&priv->ptp_lock, flags); stmmac_init_systime(priv, priv->ptpaddr, ts->tv_sec, ts->tv_nsec); write_unlock_irqrestore(&priv->ptp_lock, flags); + if (priv->est && priv->est->enable) + __stmmac_setup_est(priv); + mutex_unlock(&priv->est_lock); + return 0; } From 1b02f90976d4bdf8c67d19dadf31b4bba05eb66f Mon Sep 17 00:00:00 2001 From: Joas Antonio dos Santos Date: Thu, 12 Nov 2026 16:23:27 +0000 Subject: [PATCH 037/117] net: usb: smsc75xx: reject frames without a full header and FCS smsc75xx_rx_fixup() takes the frame length from the RX command word supplied by the device and strips the FCS by using "size - 4" for the allocation, skb_put() and memcpy() of each frame that is not the last one in the URB. The length is only checked against an upper bound and against skb->len, so a device can report a length field of 2..5, which gives a size of 0..3 after RXW_PADDING is subtracted. size is a u32, so "size - 4" then wraps to 0xfffffffc..0xffffffff. __netdev_alloc_skb() adds NET_SKB_PAD to the unsigned length, which wraps back to a small value and the allocation succeeds. skb_put() adds the length to the 32-bit skb->tail and skb->len, which also wrap, so the skb_over_panic() check does not fire. The following memcpy() then tries to copy almost 4 GiB from the URB buffer into that small allocation and writes far beyond it. A malicious or malfunctioning USB device can use this to corrupt kernel memory or crash the machine. A frame that holds an FCS but less than an Ethernet header is not valid either. usbnet drops it when it is the last frame in the URB, but the other frames go straight to usbnet_skb_return(), where eth_type_trans() reads an Ethernet header that was never copied into the new skb. Reject frames that are too short to hold an Ethernet header and an FCS, which covers both cases with one check. The driver does not set FLAG_RX_ASSEMBLE, so usbnet already counts rx_errors when smsc75xx_rx_fixup() returns 0. Also count rx_length_errors for these frames, as usbnet does for the short frames it drops itself. Found by LLM-assisted source review. Fixes: 1b3b2d9e772b ("net: usb: smsc75xx: stop lying about skb->truesize") Cc: stable@vger.kernel.org Signed-off-by: Joas Antonio dos Santos Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261112-smsc75xx-rx-fcs-v3-1-6ad0378d0384@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/usb/smsc75xx.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c index 6f72a3f15907..d1eca6bf7770 100644 --- a/drivers/net/usb/smsc75xx.c +++ b/drivers/net/usb/smsc75xx.c @@ -2217,6 +2217,14 @@ static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) return 0; } + if (unlikely(size < ETH_HLEN + ETH_FCS_LEN)) { + netif_dbg(dev, rx_err, dev->net, + "size err rx_cmd_a=0x%08x\n", + rx_cmd_a); + dev->net->stats.rx_length_errors++; + return 0; + } + /* last frame in this batch */ if (skb->len == size) { smsc75xx_rx_csum_offload(dev, skb, rx_cmd_a, From f675070191f202010b010160b509a543dd232ae6 Mon Sep 17 00:00:00 2001 From: Juan Agustin Niccolini Date: Wed, 11 Nov 2026 12:47:03 -0500 Subject: [PATCH 038/117] tcp: Fix the SO_REUSEPORT bind cache admitting a conflicting socket When the port is in the FASTREUSEPORT_STRICT state, inet_csk_get_port() skips the bind conflict check if sk_reuseport_match() finds the new socket's address covered by the socket cached in tb->fast_*. This is only safe if both sockets match on everything inet_bind_conflict() reads. The cache misses some of it: - It does not record sk_bound_dev_if or sk_reuse. - It records the family and IPV6_V6ONLY but never compares them with the new socket, so a cached v6only [::] (or 0.0.0.0) socket covers a dual-stack [::] socket. As a result, an unprivileged user can bind and listen on a port that another user is listening on, for example a dual-stack [::] socket on top of a 0.0.0.0 listener: victim: bind(0.0.0.0:P), listen() attacker: SO_REUSEPORT + IPV6_V6ONLY, bind([::]:P) /* fills cache */ attacker: SO_REUSEPORT, bind([::]:P), listen() /* should fail */ Only take the fast path when the new socket matches the cached one in family, IPV6_V6ONLY, bound device and SO_REUSEADDR. Identical SO_REUSEPORT listeners, the workload this cache was added for, still skip the scan (binding 16384 of them: 9.80 ms before, 9.86 ms after, 5874 ms with the full check every time). Fixes: 637bc8bbe6c0 ("inet: reset tb->fastreuseport when adding a reuseport sk") Cc: stable@vger.kernel.org Signed-off-by: Juan Agustin Niccolini Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20261111174704.24312-2-juanagusnicco@gmail.com Signed-off-by: Jakub Kicinski --- include/net/inet_hashtables.h | 2 ++ net/ipv4/inet_connection_sock.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h index 6e2fe186d0dc..44b7e39a1245 100644 --- a/include/net/inet_hashtables.h +++ b/include/net/inet_hashtables.h @@ -87,6 +87,8 @@ struct inet_bind_bucket { __be32 fast_rcv_saddr; unsigned short fast_sk_family; bool fast_ipv6_only; + unsigned char fast_sk_reuse; + int fast_bound_dev_if; struct hlist_node node; struct hlist_head bhash2; struct rcu_head rcu; diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index ca3057192e6d..d1c864b4252f 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -420,13 +420,18 @@ static inline int sk_reuseport_match(struct inet_bind_bucket *tb, return 0; if (!uid_eq(tb->fastuid, sk_uid(sk))) return 0; - /* We only need to check the rcv_saddr if this tb was once marked + /* We only need to check the fast_* fields if this tb was once marked * without fastreuseport and then was reset, as we can only know that - * the fast_*rcv_saddr doesn't have any conflicts with the socks on the - * owners list. + * the socket they describe doesn't have any conflicts with the socks + * on the owners list. */ if (tb->fastreuseport == FASTREUSEPORT_ANY) return 1; + if (tb->fast_sk_family != sk->sk_family || + tb->fast_ipv6_only != ipv6_only_sock(sk) || + tb->fast_bound_dev_if != sk->sk_bound_dev_if || + tb->fast_sk_reuse != sk->sk_reuse) + return 0; #if IS_ENABLED(CONFIG_IPV6) if (tb->fast_sk_family == AF_INET6) return ipv6_rcv_saddr_equal(&tb->fast_v6_rcv_saddr, @@ -455,6 +460,8 @@ void inet_csk_update_fastreuse(const struct sock *sk, tb->fast_rcv_saddr = sk->sk_rcv_saddr; tb->fast_ipv6_only = ipv6_only_sock(sk); tb->fast_sk_family = sk->sk_family; + tb->fast_sk_reuse = sk->sk_reuse; + tb->fast_bound_dev_if = sk->sk_bound_dev_if; #if IS_ENABLED(CONFIG_IPV6) tb->fast_v6_rcv_saddr = sk->sk_v6_rcv_saddr; #endif @@ -482,6 +489,8 @@ void inet_csk_update_fastreuse(const struct sock *sk, tb->fast_rcv_saddr = sk->sk_rcv_saddr; tb->fast_ipv6_only = ipv6_only_sock(sk); tb->fast_sk_family = sk->sk_family; + tb->fast_sk_reuse = sk->sk_reuse; + tb->fast_bound_dev_if = sk->sk_bound_dev_if; #if IS_ENABLED(CONFIG_IPV6) tb->fast_v6_rcv_saddr = sk->sk_v6_rcv_saddr; #endif From 540410997a7da285994280097219a38c5d786473 Mon Sep 17 00:00:00 2001 From: Juan Agustin Niccolini Date: Wed, 11 Nov 2026 12:47:04 -0500 Subject: [PATCH 039/117] selftests: net: Add SO_REUSEPORT bind cache test to bind_wildcard.c Add a test for the bug fixed by "tcp: Fix the SO_REUSEPORT bind cache admitting a conflicting socket". With a 0.0.0.0 listener on the port, a v6only [::] SO_REUSEPORT socket fills the bind cache, and a dual-stack [::] SO_REUSEPORT socket must then fail to bind with EADDRINUSE. Without the fix: # RUN global.reuseport_v6only_cache ... # bind_wildcard.c:860:reuseport_v6only_cache:Expected ret (0) == -1 (-1) # reuseport_v6only_cache: Test terminated by assertion # FAIL global.reuseport_v6only_cache not ok 1 global.reuseport_v6only_cache With it: # RUN global.reuseport_v6only_cache ... # OK global.reuseport_v6only_cache ok 1 global.reuseport_v6only_cache Signed-off-by: Juan Agustin Niccolini Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20261111174704.24312-3-juanagusnicco@gmail.com Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/bind_wildcard.c | 54 +++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tools/testing/selftests/net/bind_wildcard.c b/tools/testing/selftests/net/bind_wildcard.c index be3298c791b2..334a0cf87edf 100644 --- a/tools/testing/selftests/net/bind_wildcard.c +++ b/tools/testing/selftests/net/bind_wildcard.c @@ -811,4 +811,58 @@ TEST_F(bind_wildcard, reuseport) bind_socket(_metadata, self, variant, i, SO_REUSEPORT); } +/* The SO_REUSEPORT bind cache (tb->fast_*) filled by a v6only [::] socket + * must not let a dual-stack [::] socket skip the conflict check against a + * 0.0.0.0 listener. + */ +TEST(reuseport_v6only_cache) +{ + struct sockaddr_in6 addr6 = { + .sin6_family = AF_INET6, + .sin6_addr = in6addr_any, + }; + struct sockaddr_in addr4 = { + .sin_family = AF_INET, + .sin_addr.s_addr = htonl(INADDR_ANY), + }; + socklen_t addrlen; + int fd[3], ret; + int on = 1; + + ASSERT_EQ(unshare(CLONE_NEWNET), 0); + + /* bind(0.0.0.0:P), listen() */ + fd[0] = socket(AF_INET, SOCK_STREAM, 0); + ASSERT_GT(fd[0], 0); + ASSERT_EQ(bind(fd[0], (struct sockaddr *)&addr4, sizeof(addr4)), 0); + ASSERT_EQ(listen(fd[0], 1), 0); + + addrlen = sizeof(addr4); + ASSERT_EQ(getsockname(fd[0], (struct sockaddr *)&addr4, &addrlen), 0); + addr6.sin6_port = addr4.sin_port; + + /* SO_REUSEPORT + IPV6_V6ONLY, bind([::]:P) fills the cache. */ + fd[1] = socket(AF_INET6, SOCK_STREAM, 0); + ASSERT_GT(fd[1], 0); + ret = setsockopt(fd[1], SOL_IPV6, IPV6_V6ONLY, &on, sizeof(on)); + ASSERT_EQ(ret, 0); + ret = setsockopt(fd[1], SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on)); + ASSERT_EQ(ret, 0); + ASSERT_EQ(bind(fd[1], (struct sockaddr *)&addr6, sizeof(addr6)), 0); + + /* SO_REUSEPORT, bind([::]:P) conflicts with 0.0.0.0:P. */ + fd[2] = socket(AF_INET6, SOCK_STREAM, 0); + ASSERT_GT(fd[2], 0); + ret = setsockopt(fd[2], SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on)); + ASSERT_EQ(ret, 0); + + ret = bind(fd[2], (struct sockaddr *)&addr6, sizeof(addr6)); + ASSERT_EQ(ret, -1); + ASSERT_EQ(errno, EADDRINUSE); + + close(fd[2]); + close(fd[1]); + close(fd[0]); +} + TEST_HARNESS_MAIN From 5aac571d919087d766d85729e0b53f41d275eb7b Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Thu, 12 Nov 2026 13:46:44 +0800 Subject: [PATCH 040/117] ipv6: ioam6: do not modify shared tuninfo eh.nexthdr ioam6_do_inline() and ioam6_do_encap() stored the next header into the shared ilwt->tuninfo template and then memcpy()ed it into the skb. The lwtstate is used from multiple CPUs without locking, so another packet can overwrite eh.nexthdr between the store and the memcpy. The packet can then leave with an HBH nexthdr that does not match its payload (e.g. TCP labelled as UDP, or a local packet labelled IPPROTO_IPV6). Set nexthdr on the per-packet Hop-by-Hop copy after memcpy instead, leave the shared template read-only. Mark the tuninfo argument const now that the shared template is no longer modified, and drop the unnecessary (u8 *) cast in memcpy. Fixes: 3edede08ff37 ("ipv6: ioam: Support for IOAM injection with lwtunnels") Fixes: 8cb3bf8bff3c ("ipv6: ioam: Add support for the ip6ip6 encapsulation") Reported-by: Sashiko Closes: https://lore.kernel.org/netdev/179336082844.3134.1265197633714491521@kernel.org Reviewed-by: Justin Iurman Signed-off-by: Hangbin Liu Link: https://patch.msgid.link/20261112-ipv6_ioam_lock-v4-1-89e3381be525@kylinos.cn Signed-off-by: Jakub Kicinski --- net/ipv6/ioam6_iptunnel.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/net/ipv6/ioam6_iptunnel.c b/net/ipv6/ioam6_iptunnel.c index cfb2c41634a0..e8be0d922f74 100644 --- a/net/ipv6/ioam6_iptunnel.c +++ b/net/ipv6/ioam6_iptunnel.c @@ -254,10 +254,11 @@ static int ioam6_do_fill(struct net *net, struct sk_buff *skb) } static int ioam6_do_inline(struct net *net, struct sk_buff *skb, - struct ioam6_lwt_encap *tuninfo, + const struct ioam6_lwt_encap *tuninfo, struct dst_entry *cache_dst) { struct ipv6hdr *oldhdr, *hdr; + struct ipv6_opt_hdr *opt_hdr; int hdrlen, err; hdrlen = (tuninfo->eh.hdrlen + 1) << 3; @@ -276,12 +277,13 @@ static int ioam6_do_inline(struct net *net, struct sk_buff *skb, hdr = ipv6_hdr(skb); memmove(hdr, oldhdr, sizeof(*oldhdr)); - tuninfo->eh.nexthdr = hdr->nexthdr; skb_set_transport_header(skb, sizeof(*hdr)); skb_postpush_rcsum(skb, hdr, sizeof(*hdr) + hdrlen); - memcpy(skb_transport_header(skb), (u8 *)tuninfo, hdrlen); + opt_hdr = (struct ipv6_opt_hdr *)skb_transport_header(skb); + memcpy(opt_hdr, tuninfo, hdrlen); + opt_hdr->nexthdr = hdr->nexthdr; hdr->nexthdr = NEXTHDR_HOP; hdr->payload_len = cpu_to_be16(skb->len - sizeof(*hdr)); @@ -290,7 +292,7 @@ static int ioam6_do_inline(struct net *net, struct sk_buff *skb, } static int ioam6_do_encap(struct net *net, struct sk_buff *skb, - struct ioam6_lwt_encap *tuninfo, + const struct ioam6_lwt_encap *tuninfo, bool has_tunsrc, struct in6_addr *tunsrc, struct in6_addr *tundst, @@ -298,6 +300,7 @@ static int ioam6_do_encap(struct net *net, struct sk_buff *skb, { struct dst_entry *dst = skb_dst(skb); struct ipv6hdr *hdr, *inner_hdr; + struct ipv6_opt_hdr *opt_hdr; int hdrlen, len, err; hdrlen = (tuninfo->eh.hdrlen + 1) << 3; @@ -314,8 +317,9 @@ static int ioam6_do_encap(struct net *net, struct sk_buff *skb, skb_mac_header_rebuild(skb); skb_set_transport_header(skb, sizeof(*hdr)); - tuninfo->eh.nexthdr = NEXTHDR_IPV6; - memcpy(skb_transport_header(skb), (u8 *)tuninfo, hdrlen); + opt_hdr = (struct ipv6_opt_hdr *)skb_transport_header(skb); + memcpy(opt_hdr, tuninfo, hdrlen); + opt_hdr->nexthdr = NEXTHDR_IPV6; hdr = ipv6_hdr(skb); memcpy(hdr, inner_hdr, sizeof(*hdr)); From ea538b5790eed4f042ea787ea761cb1a695f8138 Mon Sep 17 00:00:00 2001 From: Henry Martin Date: Thu, 12 Nov 2026 12:24:15 +0800 Subject: [PATCH 041/117] ip6mr: prevent info-leak in ip6mr_cache_report() The non-WHOLEPKT branch copies the IPv6 header at offset 0 and then appends 40 bytes with skb_put(), but the mrt6msg is written at offset 0 after skb_reset_transport_header(), so the appended 40 bytes are never initialized. They hold stale heap contents. The report is queued to the mroute6 socket and copied into the IP6MRA_CREPORT_PKT netlink attribute, disclosing the stale bytes to user space. The stale bytes can contain kernel heap and image pointers, and the report is reachable from an unprivileged user namespace (MRT6_INIT in a new netns, plus the non-root RTNLGRP_IPV6_MROUTE_R group). Use skb_put_zero() instead, as the IPv4 code does since commit 4f34002e2e376 ("ipmr: prevent info-leak in pmr_cache_report()"). This issue was discovered by Tencent CodeBuddy Security. Fixes: 7bc570c8b4f75 ("[IPV6] MROUTE: Support multicast forwarding.") Cc: stable@vger.kernel.org Signed-off-by: Henry Martin Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261112042415.617221-1-bsdhenrymartin@gmail.com Signed-off-by: Jakub Kicinski --- net/ipv6/ip6mr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index dd0638d3c3f9..b7ae220d6b21 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -1154,7 +1154,7 @@ static int ip6mr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt, /* * Add our header */ - skb_put(skb, sizeof(*msg)); + skb_put_zero(skb, sizeof(*msg)); skb_reset_transport_header(skb); msg = (struct mrt6msg *)skb_transport_header(skb); From f2540da93a113d3f0a70fd0961e00eb849ce8342 Mon Sep 17 00:00:00 2001 From: Yves Bieri Date: Thu, 12 Nov 2026 18:21:49 +0100 Subject: [PATCH 042/117] sctp: do not free a new asoc peeled off while sendmsg slept When sctp_sendmsg() creates a new association and sending on it fails with anything but -ESRCH, it frees the association. The send can sleep in sctp_wait_for_sndbuf(), which releases the socket lock, and meanwhile another thread can peel the new association off to a new socket. The wait then returns -EPIPE, and sctp_sendmsg() frees an association that now belongs to the peeled-off socket, without holding that socket's lock. If the peeled-off socket frees the association first, e.g. on close(), sctp_sendmsg() frees it a second time. Otherwise a syscall running concurrently on the peeled-off socket can use it after sctp_sendmsg() freed it. Both are reachable by an unprivileged user. The double free on net with KASAN: BUG: KASAN: double-free in sctp_tsnmap_free+0x5c/0x80 sctp_association_free+0x1eb/0x750 sctp_sendmsg+0x15ff/0x2020 Freed by task 836: sctp_association_free+0x1eb/0x750 sctp_primitive_ABORT+0x85/0xe0 sctp_close+0x22a/0x8d0 Commit dfcb9f4f99f1 ("sctp: deny peeloff operation on asocs with threads sleeping on it") fixed this double free by denying the peeloff. Commit cea0cc80a677 ("sctp: use the right sk after waking up from wait_buf sleep") replaced that check, and commit a0ff660058b8 ("sctp: return error if the asoc has been peeled off in sctp_wait_for_sndbuf") reverted it to return -EPIPE, without restoring the check. Fix this by holding a reference on the new association while sending on it, and by freeing it on error only if this socket still owns it. asoc->base.sk only changes in sctp_sock_migrate(), which runs with this socket locked, so the ownership check is stable. The reference keeps the check safe if the new owner frees the association meanwhile. Userspace still gets -EPIPE, and the association stays with the socket it was peeled off to. This was found by Xint Code, an AI code review agent, and reproduced as an unprivileged user on net with KASAN (trace above), without modifying the kernel or using error injection. With this patch the sender gets -EPIPE and the association keeps working on the peeled-off socket. Without a peeloff, a failed send that created the association (EAGAIN, EINTR) still frees it, and a peer ABORT while the sender sleeps still frees it exactly once. The SCTP selftest sctp_vrf.sh passes. The reproducer is available on request. Fixes: a0ff660058b8 ("sctp: return error if the asoc has been peeled off in sctp_wait_for_sndbuf") Cc: stable@vger.kernel.org Signed-off-by: Yves Bieri Acked-by: Xin Long Link: https://patch.msgid.link/20261112172149.27355-1-yves.bieri@theori.io Signed-off-by: Jakub Kicinski --- net/sctp/socket.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 8e647737b256..bc68af88e271 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -2063,6 +2063,11 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len) asoc = transport->asoc; new = true; + /* sctp_sendmsg_to_asoc() may release the socket lock, + * and the new asoc can be peeled off meanwhile. Hold + * it, and free it on error only if sk still owns it. + */ + sctp_association_hold(asoc); } if (!sctp_style(sk, TCP) && !(sflags & SCTP_ADDR_OVER)) @@ -2084,8 +2089,11 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len) /* Send msg to the asoc */ err = sctp_sendmsg_to_asoc(asoc, msg, msg_len, transport, sinfo); - if (err < 0 && err != -ESRCH && new) - sctp_association_free(asoc); + if (new) { + if (err < 0 && err != -ESRCH && asoc->base.sk == sk) + sctp_association_free(asoc); + sctp_association_put(asoc); + } out_unlock: release_sock(sk); From 6836fa400109ac8495224a35f9b2c16dc9d0d129 Mon Sep 17 00:00:00 2001 From: Wenbo Sun Date: Thu, 12 Nov 2026 11:36:22 +0800 Subject: [PATCH 043/117] net: dcb: flush rewrite table on device unregister In dcbnl_flush_dev(), which is called upon NETDEV_UNREGISTER for net devices with dcbnl_ops, only entries in dcb_app_list matching dev->ifindex are freed. The entries in dcb_rewr_list added via dcb_setrewr() are not flushed. This causes a memory leak of struct dcb_app_type nodes in dcb_rewr_list when a DCB-capable net device is unregistered, and leaves stale entries in the global rewrite table that could inappropriately match if another net device later reuses the same ifindex. Iterate over dcb_rewr_list in dcbnl_flush_dev() and remove and free all entries matching dev->ifindex, mirroring the cleanup performed for dcb_app_list. This issue was found via LLM-assisted code review, confirmed by reproducing the leaked rewrite table entry upon netdevice unregistration in a User-Mode Linux (ARCH=um) environment, and verified in UML by confirming that all rewrite table entries for the unregistered netdevice are flushed. Fixes: 622f1b2fae2e ("net: dcb: add new rewrite table") Reviewed-by: Daniel Machon Tested-by: Daniel Machon Reviewed-by: Petr Machata Signed-off-by: Wenbo Sun Link: https://patch.msgid.link/20261112033622.40333-1-sunwenbo@cmss.chinamobile.com Signed-off-by: Jakub Kicinski --- net/dcb/dcbnl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c index ad0aebe0ad3d..95250658ecc1 100644 --- a/net/dcb/dcbnl.c +++ b/net/dcb/dcbnl.c @@ -2393,6 +2393,13 @@ static void dcbnl_flush_dev(struct net_device *dev) } } + list_for_each_entry_safe(itr, tmp, &dcb_rewr_list, list) { + if (itr->ifindex == dev->ifindex) { + list_del(&itr->list); + kfree(itr); + } + } + spin_unlock_bh(&dcb_lock); } From 2718849027426f09c649a59b8f93fa7a00ced3ed Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 13 Nov 2026 11:11:00 +0100 Subject: [PATCH 044/117] net: kunit: move struct net_devmem_dmabuf_binding off stack The net_devmem_dmabuf_binding structure is really way too big to live on the stack, and causes warnings on my randconfig build machine with a reasonable per-function limit: net/core/net_test.c: In function 'netmem_ref_test_tcp_devmem_recv': net/core/net_test.c:1720:1: error: the frame size of 1744 bytes is larger than 1536 bytes [-Werror=frame-larger-than=] 1720 | } | ^ net/core/net_test.c: In function 'netmem_ref_test_skb_segment': net/core/net_test.c:1477:1: error: the frame size of 1584 bytes is larger than 1536 bytes [-Werror=frame-larger-than=] Since the binding object is never used concurrently in multiple tests, avoid this by just having a global copy of it and reinitializing it for every user. Fixes: 2285346afc99 ("net: kunit: test netmem, page_pool, and skb frag refcounting") Signed-off-by: Arnd Bergmann Reviewed-by: Mina Almasry Link: https://patch.msgid.link/20261113101109.3227815-1-arnd@kernel.org Signed-off-by: Jakub Kicinski --- net/core/net_test.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/net/core/net_test.c b/net/core/net_test.c index 2b5080c22663..c36333b36211 100644 --- a/net/core/net_test.c +++ b/net/core/net_test.c @@ -834,13 +834,14 @@ static void netmem_ref_test_pp_page(struct kunit *test) #endif #if defined(CONFIG_PAGE_POOL) && defined(CONFIG_NET_DEVMEM) +static struct net_devmem_dmabuf_binding binding; + static void dummy_percpu_ref_release(struct percpu_ref *ref) { } static void netmem_ref_test_net_iov(struct kunit *test) { - struct net_devmem_dmabuf_binding binding = {}; struct page_pool_params pp_params = { .order = 0, .pool_size = 4, @@ -853,6 +854,7 @@ static void netmem_ref_test_net_iov(struct kunit *test) long base_ref; int err; + memset(&binding, 0, sizeof(binding)); err = percpu_ref_init(&binding.ref, dummy_percpu_ref_release, PERCPU_REF_INIT_ATOMIC, GFP_KERNEL); KUNIT_ASSERT_EQ(test, err, 0); @@ -995,7 +997,6 @@ static void netmem_ref_test_release_data(struct kunit *test) .nid = NUMA_NO_NODE, }; struct sk_buff *skb, *clone1, *clone2, *ext; - struct net_devmem_dmabuf_binding binding = {}; struct net_iov niov = {}; struct page_pool *pool; struct page *page; @@ -1004,6 +1005,7 @@ static void netmem_ref_test_release_data(struct kunit *test) int base_ref; int i; + memset(&binding, 0, sizeof(binding)); pool = page_pool_create(&pp_params); KUNIT_ASSERT_FALSE(test, IS_ERR(pool)); page = page_pool_dev_alloc_pages(pool); @@ -1185,7 +1187,6 @@ static void netmem_ref_test_skb_segment(struct kunit *test) .flags = SKBFL_ZEROCOPY_ENABLE, }; struct sk_buff *head, *list, *segs, *seg; - struct net_devmem_dmabuf_binding binding = {}; struct net_iov niov = {}; struct page *pp_page, *reg_page; netmem_ref pp_nm, niov_nm; @@ -1193,6 +1194,7 @@ static void netmem_ref_test_skb_segment(struct kunit *test) long base_pp_ref, base_iov_ref; int base_pp_page_ref, base_reg_ref; + memset(&binding, 0, sizeof(binding)); pool = page_pool_create(&pp_params); KUNIT_ASSERT_FALSE(test, IS_ERR(pool)); pp_page = page_pool_dev_alloc_pages(pool); @@ -1484,7 +1486,6 @@ static void netmem_ref_test_try_coalesce(struct kunit *test) .nid = NUMA_NO_NODE, }; struct sk_buff *to, *from, *clone; - struct net_devmem_dmabuf_binding binding = {}; struct net_iov niov = {}; struct page *pp_page, *reg_page; netmem_ref pp_nm, niov_nm; @@ -1494,6 +1495,7 @@ static void netmem_ref_test_try_coalesce(struct kunit *test) bool fragstolen; int delta; + memset(&binding, 0, sizeof(binding)); pool = page_pool_create(&pp_params); KUNIT_ASSERT_FALSE(test, IS_ERR(pool)); pp_page = page_pool_dev_alloc_pages(pool); @@ -1616,7 +1618,6 @@ static void netmem_ref_test_tcp_devmem_recv(struct kunit *test) .pool_size = 4, .nid = NUMA_NO_NODE, }; - struct net_devmem_dmabuf_binding binding = {}; struct msghdr msg = {}; struct dmabuf_token token; struct dmabuf_cmsg *cmsg; @@ -1630,6 +1631,7 @@ static void netmem_ref_test_tcp_devmem_recv(struct kunit *test) long base_iov_ref; int ret; + memset(&binding, 0, sizeof(binding)); KUNIT_ASSERT_EQ(test, sock_create_kern(&init_net, AF_INET, SOCK_STREAM, IPPROTO_TCP, &sock), From de9886cb02f3efeba86a9c6f5f9f6a31d8b006fe Mon Sep 17 00:00:00 2001 From: Wenbo Sun Date: Fri, 13 Nov 2026 17:01:08 +0800 Subject: [PATCH 045/117] team: validate the length of U32 and S32 option data In team_nl_options_set_doit(), the policy for TEAM_ATTR_OPTION_DATA in team_attr_option_nl_policy is NLA_BINARY because the payload layout varies with the option type. For TEAM_OPTION_TYPE_U32 and TEAM_OPTION_TYPE_S32, the payload is read directly with nla_get_u32(attr_data) and nla_get_s32(attr_data) without checking its attribute length. When userspace supplies a truncated attribute (0 to 3 bytes), nla_get_u32() or nla_get_s32() performs an out-of-bounds read past the attribute buffer. Conversely, oversized payloads (> 4 bytes) would also have trailing bytes silently ignored instead of being rejected as invalid input. Validate that nla_len(attr_data) equals sizeof(u32) or sizeof(s32) for TEAM_OPTION_TYPE_U32 and TEAM_OPTION_TYPE_S32 respectively, and return -EINVAL otherwise, consistent with how NLA_U32/NLA_S32 attributes are validated and similar to commit 5bef3ac184b5 ("team: better TEAM_OPTION_TYPE_STRING validation"). This issue was identified with the assistance of an LLM-based code review of Netlink option handlers in the team driver, confirmed by sending malformed U32 (notify_peers_count) and S32 (priority) option attributes on a UML kernel, and verified after the patch that invalid lengths (0..3, 5, and 8 bytes) are rejected with -EINVAL while valid 4-byte options still work as expected. Built with W=1 on UML, x86_64 allmodconfig, and x86_64 allyesconfig with zero new warnings or errors. Fixes: 3d249d4ca7d0 ("net: introduce ethernet teaming device") Fixes: 69821638b274 ("team: add signed 32-bit team option type") Signed-off-by: Wenbo Sun Reviewed-by: Jiri Pirko Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20261113090108.175889-1-sunwenbo@cmss.chinamobile.com Signed-off-by: Jakub Kicinski --- drivers/net/team/team_core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/team/team_core.c b/drivers/net/team/team_core.c index cfb833c307c1..65ac25e97ae3 100644 --- a/drivers/net/team/team_core.c +++ b/drivers/net/team/team_core.c @@ -2834,6 +2834,10 @@ int team_nl_options_set_doit(struct sk_buff *skb, struct genl_info *info) ctx.info = opt_inst_info; switch (opt_type) { case TEAM_OPTION_TYPE_U32: + if (nla_len(attr_data) != sizeof(u32)) { + err = -EINVAL; + goto team_put; + } ctx.data.u32_val = nla_get_u32(attr_data); break; case TEAM_OPTION_TYPE_STRING: @@ -2853,6 +2857,10 @@ int team_nl_options_set_doit(struct sk_buff *skb, struct genl_info *info) ctx.data.bool_val = attr_data ? true : false; break; case TEAM_OPTION_TYPE_S32: + if (nla_len(attr_data) != sizeof(s32)) { + err = -EINVAL; + goto team_put; + } ctx.data.s32_val = nla_get_s32(attr_data); break; default: From 92c569c28b63067da0276f67f711a3ac20a62aca Mon Sep 17 00:00:00 2001 From: Amaan Cheval Date: Thu, 12 Nov 2026 14:44:50 +0530 Subject: [PATCH 046/117] gve: refuse XDP on queue formats without XDP support Commit d8a8ca14c937 ("gve: add XDP_TX and XDP_REDIRECT support for DQ RDA") enabled XDP on DQO-RDA by dropping the queue_format check from verify_xdp_configuration(), which until then refused every format but GQI-QPL. Nothing replaced it: gve_set_netdev_xdp_features() advertises no XDP features for DQO-QPL and GQI-RDA and gve_xdp_xmit() rejects both, but the core only checks that ndo_bpf exists, so a native XDP program, and an AF_XDP socket on top of it, can still be attached on a queue format the driver does not support. The DQO-QPL RX path was never written for that. Its page accounting assumes the driver keeps a reference of its own across every handoff: gve_xdp_done_dqo() passes the buffer to xdp_do_redirect() and then recycles it with gve_reuse_buffer(), so a redirect target that releases the buffer synchronously, such as an AF_XDP socket in copy mode, can drop the page's last reference when pagecnt_bias runs out. The page is then freed while it is still DMA-mapped and registered in the QPL, and the driver posts it back to the device. GQI-RDA is no better off: an XDP_TX there goes through gve_tx_fill_xdp(), which copies the frame into tx->tx_fifo, but a raw-addressing TX ring never allocates that FIFO, so the first XDP_TX writes through a NULL tx_fifo.base. Refuse XDP setup in gve_verify_xdp_configuration() whenever the driver advertises no XDP features for the current queue format, which today means DQO-QPL and GQI-RDA. A zero-copy XSK pool bind is already refused by the core for the same reason, and a copy-mode bind never reaches the driver and is harmless without a program. Fixes: d8a8ca14c937 ("gve: add XDP_TX and XDP_REDIRECT support for DQ RDA") Cc: stable@vger.kernel.org Reviewed-by: Joshua Washington Signed-off-by: Amaan Cheval Tested-by on v2: Link: https://patch.msgid.link/20261112091451.22969-2-amaan.cheval@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/google/gve/gve_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 0ee69bc11d83..35cf0f06a0f2 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -1798,6 +1798,12 @@ static int gve_verify_xdp_configuration(struct net_device *dev, struct gve_priv *priv = netdev_priv(dev); u16 max_xdp_mtu; + if (!(dev->xdp_features & NETDEV_XDP_ACT_BASIC)) { + NL_SET_ERR_MSG_MOD(extack, + "XDP is not supported on this queue format."); + return -EOPNOTSUPP; + } + if (dev->features & NETIF_F_GRO_HW) { NL_SET_ERR_MSG_MOD(extack, "XDP is not supported when HW-GRO is on."); From 3946899dbeac2397fdd1727d74a3547d2b13caf3 Mon Sep 17 00:00:00 2001 From: Amaan Cheval Date: Thu, 12 Nov 2026 14:44:51 +0530 Subject: [PATCH 047/117] gve: fix RX page refcount overflow from INT_MAX pagecnt_bias gve's GQI and DQO-QPL RX paths set every RX page's refcount to INT_MAX and hand references to the stack by decrementing page_info->pagecnt_bias, to avoid an atomic op per packet. This leaves no room for anyone else: while a fresh page's buffer sits in an skb its refcount is already INT_MAX, so a single get_page() from the stack overflows it to negative. splice() of received TCP data into a pipe takes such a reference, and the onward splice into a socket then fails: skb_splice_from_iter() sees page_count() < 1, sendpage_ok() fails and the send returns -EIO (since commit 2e910b95329c ("net: Add a function to splice pages into an skbuff for MSG_SPLICE_PAGES")). tee() of the pipe fails with -EFAULT via try_get_page(). On GQI the reuse check gve_rx_can_recycle_buffer() also sees page_count() < pagecnt_bias, WARNs and calls gve_schedule_reset(), so a task that merely pins a fresh RX page (e.g. holds spliced data in an undrained tee() pipe) can reset the NIC. Use USHRT_MAX in a u16, as igb, igc, ixgbe, i40e and hns3 do: the bias only has to make the per-packet atomic rare, so a small value keeps page_count() far below INT_MAX however many references the stack takes. Refill by adding a fixed batch and setting the bias to it, which keeps the rule `references = page_count() - bias` intact. Refilling at 0 hands the driver's last reference to the consumer once every USHRT_MAX handoffs rather than once every INT_MAX, which is only safe because every consumer on these paths holds its reference until the driver has recycled the buffer. The previous patch keeps it that way by blocking XDP on DQO-QPL, so this one depends on it. Trees before 6.17, without commit d8a8ca14c937 ("gve: add XDP_TX and XDP_REDIRECT support for DQ RDA"), still refuse XDP on every format but GQI-QPL in verify_xdp_configuration(), so there this patch stands alone. Reproduced on gVNIC in GQI-QPL mode (GCE n2-standard-8, 6.12) and in DQO-RDA mode (GCE c3-standard-8, 6.12, where DQO-RDA still uses the bias) with the help of relay.py -- a small splice(2) TCP proxy -- relaying a download while the RX ring is refilled with fresh pages: ethtool -G eth0 rx 512 && ethtool -G eth0 rx 1024 # fresh RX pages ./relay.py $HOST 8080 & # splice()s both ways for i in $(seq 200); do curl -so /dev/null \ --connect-to $HOST:80:127.0.0.1:8080 http://$HOST/file; done Most downloads failed with EIO before the fix (tee() with EFAULT) and all completed after it. relay.py is at the Link below. This bug was found and fixed with the help of an AI coding assistant (Claude Code) over an interactive session; it read the driver and splice/pipe code and ran the tests above. Link: https://github.com/amaanc/kernel-bias Fixes: 9b8dd5e5ea48 ("gve: DQO: Add RX path") Fixes: 58401b2a46e7 ("gve: Add rx buffer pagecnt bias") Fixes: 82fd151d38d9 ("gve: Reduce alloc and copy costs in the GQ rx path") Cc: stable@vger.kernel.org Reviewed-by: Harshitha Ramamurthy Tested-by: Harshitha Ramamurthy Reviewed-by: Maciej Fijalkowski Signed-off-by: Amaan Cheval Tested-by on v2: Link: https://patch.msgid.link/20261112091451.22969-3-amaan.cheval@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/google/gve/gve.h | 2 +- .../net/ethernet/google/gve/gve_buffer_mgmt_dqo.c | 4 ++-- drivers/net/ethernet/google/gve/gve_rx.c | 8 ++++---- drivers/net/ethernet/google/gve/gve_utils.c | 12 ++++-------- drivers/net/ethernet/google/gve/gve_utils.h | 2 +- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h index e509488a3d3e..143d8cd595aa 100644 --- a/drivers/net/ethernet/google/gve/gve.h +++ b/drivers/net/ethernet/google/gve/gve.h @@ -119,7 +119,7 @@ struct gve_rx_slot_page_info { void *page_address; u32 page_offset; /* offset to write to in page */ unsigned int buf_size; - int pagecnt_bias; /* expected pagecnt if only the driver has a ref */ + u16 pagecnt_bias; /* expected pagecnt if only the driver has a ref */ u16 pad; /* adjustment for rx padding */ u8 can_flip; /* tracks if the networking stack is using the page */ }; diff --git a/drivers/net/ethernet/google/gve/gve_buffer_mgmt_dqo.c b/drivers/net/ethernet/google/gve/gve_buffer_mgmt_dqo.c index 6880d1531ba5..52223baf0303 100644 --- a/drivers/net/ethernet/google/gve/gve_buffer_mgmt_dqo.c +++ b/drivers/net/ethernet/google/gve/gve_buffer_mgmt_dqo.c @@ -149,8 +149,8 @@ int gve_alloc_qpl_page_dqo(struct gve_rx_ring *rx, buf_state->last_single_ref_offset = 0; /* The page already has 1 ref. */ - page_ref_add(buf_state->page_info.page, INT_MAX - 1); - buf_state->page_info.pagecnt_bias = INT_MAX; + page_ref_add(buf_state->page_info.page, USHRT_MAX - 1); + buf_state->page_info.pagecnt_bias = USHRT_MAX; return 0; } diff --git a/drivers/net/ethernet/google/gve/gve_rx.c b/drivers/net/ethernet/google/gve/gve_rx.c index 81ea800e66e9..3bed19866376 100644 --- a/drivers/net/ethernet/google/gve/gve_rx.c +++ b/drivers/net/ethernet/google/gve/gve_rx.c @@ -152,8 +152,8 @@ static void gve_setup_rx_buffer(struct gve_rx_ring *rx, page_info->buf_size = rx->packet_buffer_size; *slot_addr = cpu_to_be64(addr); /* The page already has 1 ref */ - page_ref_add(page, INT_MAX - 1); - page_info->pagecnt_bias = INT_MAX; + page_ref_add(page, USHRT_MAX - 1); + page_info->pagecnt_bias = USHRT_MAX; } static int gve_rx_alloc_buffer(struct gve_priv *priv, struct device *dev, @@ -230,8 +230,8 @@ static int gve_rx_prefill_pages(struct gve_rx_ring *rx, rx->qpl_copy_pool[j].buf_size = rx->packet_buffer_size; /* The page already has 1 ref. */ - page_ref_add(page, INT_MAX - 1); - rx->qpl_copy_pool[j].pagecnt_bias = INT_MAX; + page_ref_add(page, USHRT_MAX - 1); + rx->qpl_copy_pool[j].pagecnt_bias = USHRT_MAX; } } diff --git a/drivers/net/ethernet/google/gve/gve_utils.c b/drivers/net/ethernet/google/gve/gve_utils.c index caed38cd5f2b..930555ac8fe9 100644 --- a/drivers/net/ethernet/google/gve/gve_utils.c +++ b/drivers/net/ethernet/google/gve/gve_utils.c @@ -93,15 +93,11 @@ void gve_dec_pagecnt_bias(struct gve_rx_slot_page_info *page_info) { page_info->pagecnt_bias--; if (page_info->pagecnt_bias == 0) { - int pagecount = page_count(page_info->page); - - /* If we have run out of bias - set it back up to INT_MAX - * minus the existing refs. + /* Out of bias: take another batch. USHRT_MAX keeps this rare + * while leaving page_count() far below INT_MAX. */ - page_info->pagecnt_bias = INT_MAX - pagecount; - - /* Set pagecount back up to max. */ - page_ref_add(page_info->page, INT_MAX - pagecount); + page_info->pagecnt_bias = USHRT_MAX; + page_ref_add(page_info->page, USHRT_MAX); } } diff --git a/drivers/net/ethernet/google/gve/gve_utils.h b/drivers/net/ethernet/google/gve/gve_utils.h index bf2e9a0adb36..c686142d37ea 100644 --- a/drivers/net/ethernet/google/gve/gve_utils.h +++ b/drivers/net/ethernet/google/gve/gve_utils.h @@ -25,7 +25,7 @@ struct sk_buff *gve_rx_copy_data(struct net_device *dev, struct napi_struct *nap struct sk_buff *gve_rx_copy(struct net_device *dev, struct napi_struct *napi, struct gve_rx_slot_page_info *page_info, u16 len); -/* Decrement pagecnt_bias. Set it back to INT_MAX if it reached zero. */ +/* Decrement pagecnt_bias. Top it up by USHRT_MAX if it reached zero. */ void gve_dec_pagecnt_bias(struct gve_rx_slot_page_info *page_info); void gve_add_napi(struct gve_priv *priv, int ntfy_idx, From 1932779607d2fc895464c676a2a420aa07403976 Mon Sep 17 00:00:00 2001 From: Haishuang Yan Date: Wed, 11 Nov 2026 00:30:01 +0900 Subject: [PATCH 048/117] virtio_net: Disable AF_XDP pools on queues above curr_queue_pairs With an XDP program attached, virtnet_xdp_set() adds nr_cpu_ids queue pairs for XDP_TX and raises curr_queue_pairs and real_num_rx_queues to match. virtnet_xsk_pool_enable() accepts any queue below curr_queue_pairs, so an AF_XDP zero-copy socket can be bound to one of them. When the program is removed, the queue count goes down again while the pool stays bound to the driver. When the socket is closed afterwards, virtnet_xsk_pool_disable() rejects the queue with -EINVAL, and the core frees the pool anyway: WARNING: net/xdp/xsk_buff_pool.c:160 at xp_disable_drv_zc+0x1ee/0x260 BUG: KASAN: slab-use-after-free in xp_alloc_batch+0x930/0xb40 Read of size 8 at addr ffff8880028eb400 by task ksoftirqd/0/14 xp_alloc_batch+0x930/0xb40 try_fill_recv+0xb27/0x26e0 as rq->xsk_pool still points to it and the queue is refilled from it. The device going away with XDP attached, e.g. on hot-unplug or driver unbind, ends the same way without an explicit removal: unregister_netdevice_many_notify() removes XDP before the xsk notifier unbinds the socket, so the pool is disabled on a queue above curr_queue_pairs there as well. Removing XDP must not fail, so let virtnet_xsk_pool_disable() accept any queue the driver has, below max_queue_pairs. The receive and send queues above curr_queue_pairs still exist, so they are unbound as usual. This was pointed out by the Sashiko review of v1 of this series, and reproduced in QEMU by binding a socket to an XDP queue and then either removing XDP and closing the socket, or unbinding the device from virtio_net. Fixes: 09d2b3182c8e ("virtio_net: xsk: bind/unbind xsk for rx") Signed-off-by: Haishuang Yan Link: https://patch.msgid.link/20261110153003.23731-3-yanhaishuang@cmss.chinamobile.com Signed-off-by: Jakub Kicinski --- drivers/net/virtio_net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 28b84de86153..1cd64f9e12e7 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -6040,7 +6040,8 @@ static int virtnet_xsk_pool_disable(struct net_device *dev, u16 qid) struct send_queue *sq; int err; - if (qid >= vi->curr_queue_pairs) + /* Removing XDP can leave the pool on a queue above curr_queue_pairs */ + if (qid >= vi->max_queue_pairs) return -EINVAL; sq = &vi->sq[qid]; From 533ec433efdc11196f438da90d683053a57257ff Mon Sep 17 00:00:00 2001 From: Xin Long Date: Thu, 12 Nov 2026 10:01:42 -0500 Subject: [PATCH 049/117] sctp: validate SACK pull length against chunk length, not skb length sctp_sm_pull_sack() derives its pull length from the num_gap_ack_blocks and num_dup_tsns fields in the SACK body, but validates it against chunk->skb->len (the remaining packet data) rather than the SACK chunk's declared length. A malformed SACK with an inflated num_dup_tsns can pass this check when subsequent chunks pad the skb, advancing skb->data past the SACK boundary into later chunks. This misaligns the skb cursor for subsequent chunk processing. When an AUTH chunk follows, sctp_sf_authenticate() reads and compares the HMAC digest from the wrong skb offset while sctp_auth_calculate_hmac() writes the computed HMAC through the correct chunk_hdr pointer, bypassing the authentication check. Fix by validating the computed pull length against the chunk's declared body length instead of the total remaining skb data. Fixes: 730fc3d05cd4 ("[SCTP]: Implete SCTP-AUTH parameter processing") Reported-by: on Sim Signed-off-by: Xin Long Link: https://patch.msgid.link/3fbf59d17a91c46098e3d4115e06987918b68c45.1794495702.git.lucien.xin@gmail.com Signed-off-by: Jakub Kicinski --- net/sctp/sm_statefuns.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c index 64519fd8f943..6a4205de0aa6 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -6372,7 +6372,8 @@ static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk) num_dup_tsns = ntohs(sack->num_dup_tsns); len = sizeof(struct sctp_sackhdr); len += (num_blocks + num_dup_tsns) * sizeof(__u32); - if (len > chunk->skb->len) + if (len > ntohs(chunk->chunk_hdr->length) - + sizeof(struct sctp_chunkhdr)) return NULL; skb_pull(chunk->skb, len); From a2239d5dbbda3a61b6323df8836f605921a29f7f Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Thu, 12 Nov 2026 20:29:40 +0200 Subject: [PATCH 050/117] net/mlx5: IFC, enlarge active_port field to support 8 port LAG active_port is a bitmask with a bit per LAG port. The cited commit enabled 8 port LAG, but active_port remained 4 bits wide. Enlarge active_port to 8 bits, as defined in the PRM. Fixes: e0e6adfe8c20 ("net/mlx5: Enable 8 ports LAG") Signed-off-by: Shay Drory Reviewed-by: Mark Bloch Reviewed-by: Akiva Goldberger Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20261112182940.3655773-1-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- include/linux/mlx5/mlx5_ifc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h index 697fc9387b73..37b6e47c9091 100644 --- a/include/linux/mlx5/mlx5_ifc.h +++ b/include/linux/mlx5/mlx5_ifc.h @@ -12453,8 +12453,8 @@ struct mlx5_ifc_lagc_bits { u8 reserved_at_18[0x5]; u8 lag_state[0x3]; - u8 reserved_at_20[0xc]; - u8 active_port[0x4]; + u8 reserved_at_20[0x8]; + u8 active_port[0x8]; u8 reserved_at_30[0x4]; u8 tx_remap_affinity_2[0x4]; u8 reserved_at_38[0x4]; From 297ae15901733df7562a6781613fb49f3d270401 Mon Sep 17 00:00:00 2001 From: Kalpesh Solanki Date: Thu, 12 Nov 2026 18:38:33 +0530 Subject: [PATCH 051/117] bonding: reject IEEE 802.15.4 and 6LoWPAN devices in bond_enslave When the first non-Ethernet slave is enslaved to a bond, bond_setup_by_slave() copies slave_dev->type to the bond device. However, the bonding driver does not set up subsystem-specific mid-layer contexts or private structures: 1. IEEE 802.15.4 routines (such as ieee802154_llsec_dump_table(), nl-phy.c, and socket callbacks) identify WPAN devices by dev->type alone and unconditionally dereference dev->ieee802154_ptr and dev->ml_priv (ieee802154_mlme_ops). Because bonding never allocates these, this results in a NULL pointer dereference. 2. The 6LoWPAN netdevice notifier (lowpan_event()) identifies devices by dev->type == ARPHRD_6LOWPAN and treats netdev_priv(dev) as struct lowpan_dev. On a bond master, netdev_priv() is struct bonding, so writes to lowpan_dev(dev)->ctx.table flags on events like NETDEV_DOWN corrupt the bonding driver's private state. The team driver closed an identical gap in commit 9043be310c6a ("team: reject CAN, IEEE 802.15.4 and 6LoWPAN devices in team_port_add"). Bonding previously only blocked CAN devices in commit 8ba68464e478 ("bonding: refuse to enslave CAN devices"). Reject ARPHRD_IEEE802154, ARPHRD_IEEE802154_MONITOR, and ARPHRD_6LOWPAN devices in bond_enslave(). Fixes: 872254dd6b1f ("net/bonding: Enable bonding to enslave non ARPHRD_ETHER") Signed-off-by: Kalpesh Solanki Reviewed-by: Oliver Hartkopp Reviewed-by: Hangbin Liu Link: https://patch.msgid.link/20261112130833.233208-1-skalpesh942@gmail.com Signed-off-by: Paolo Abeni --- drivers/net/bonding/bond_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index e9f5e753f677..042d7c75548f 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -1894,9 +1894,12 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, struct sockaddr_storage ss; int res = 0, i; - if (slave_dev->type == ARPHRD_CAN) { + if (slave_dev->type == ARPHRD_CAN || + slave_dev->type == ARPHRD_IEEE802154 || + slave_dev->type == ARPHRD_IEEE802154_MONITOR || + slave_dev->type == ARPHRD_6LOWPAN) { BOND_NL_ERR(bond_dev, extack, - "CAN devices cannot be enslaved"); + "CAN, IEEE 802.15.4 and 6LoWPAN devices cannot be enslaved"); return -EPERM; } From 8868b79a430e626ad72b11d355514bed34cbb8b9 Mon Sep 17 00:00:00 2001 From: Cunhao Lu <1579567540@qq.com> Date: Fri, 13 Nov 2026 10:33:06 +0800 Subject: [PATCH 052/117] MAINTAINERS: exclude CAN documentation from general networking The SocketCAN, ISO-TP and J1939 documents and the CAN driver documentation directory match the broad Documentation/networking/ pattern in NETWORKING [GENERAL]. This makes get_maintainer.pl select netdev and the general networking maintainers for these CAN-specific documentation changes. Exclude these paths from NETWORKING [GENERAL], as is already done for net/can/ and the CAN selftests. Add the driver documentation directory to CAN NETWORK DRIVERS to cover files without a dedicated CAN entry. Suggested-by: Jakub Kicinski Link: https://lore.kernel.org/all/20261111161459.4879a82d@kernel.org/ Signed-off-by: Cunhao Lu <1579567540@qq.com> Link: https://patch.msgid.link/20261113-exclude-can-docs-from-netdev-v2-1-8ae9dc553024@qq.com Signed-off-by: Paolo Abeni --- MAINTAINERS | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 056408bc086e..a809df29a6c5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5992,6 +5992,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git T: git git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git F: Documentation/devicetree/bindings/net/can/ F: Documentation/devicetree/bindings/phy/ti,tcan104x-can.yaml +F: Documentation/networking/device_drivers/can/ F: drivers/net/can/ F: drivers/phy/phy-can-transceiver.c F: include/linux/can/bittiming.h @@ -19601,6 +19602,10 @@ F: samples/pktgen/ F: tools/net/ F: tools/testing/selftests/net/ X: Documentation/networking/batman-adv.rst +X: Documentation/networking/can.rst +X: Documentation/networking/device_drivers/can/ +X: Documentation/networking/iso15765-2.rst +X: Documentation/networking/j1939.rst X: Documentation/networking/mac80211-injection.rst X: Documentation/networking/mac80211_hwsim/ X: Documentation/networking/regulatory.rst From 81c8333141b9aa465d98bb4c035284556e699701 Mon Sep 17 00:00:00 2001 From: Jaeyeong Lee Date: Thu, 12 Nov 2026 04:32:17 +0000 Subject: [PATCH 053/117] net/tls: serialize context removal in tls_device_down() tls_device_down() moves each context to tls_device_down_list while holding tls_device_lock. It then drops its reference and removes the context after releasing the lock. tls_device_queue_ctx_destruction() removes contexts from the same list under tls_device_lock. If it removes an adjacent context while tls_device_down() is deleting its node, the two list updates can interleave. One update can then target a context freed by the other path, causing a use-after-free write. Drop the reference and remove the context in the existing tls_device_lock critical section. Keep tls_device_free_ctx() after releasing the lock. This issue was found with a static analysis tool. Fixes: f6336724a4d4 ("net/tls: Remove the context from the list in tls_device_down") Cc: stable@vger.kernel.org Signed-off-by: Jaeyeong Lee Link: https://patch.msgid.link/20261112043209.102404-1-lee@jaeyeong.cc Signed-off-by: Paolo Abeni --- net/tls/tls_device.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index 4cdfbb57ecff..fa7170cd4fd1 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -1350,6 +1350,8 @@ static int tls_device_down(struct net_device *netdev) spin_unlock_irqrestore(&tls_device_lock, flags); list_for_each_entry_safe(ctx, tmp, &list, list) { + bool free_ctx; + /* Stop offloaded TX and switch to the fallback. * tls_is_skb_tx_device_offloaded will return false. */ @@ -1387,17 +1389,19 @@ static int tls_device_down(struct net_device *netdev) */ spin_lock_irqsave(&tls_device_lock, flags); list_move_tail(&ctx->list, &tls_device_down_list); + /* Serialize the final removal with sk_destruct. */ + free_ctx = refcount_dec_and_test(&ctx->refcount); + if (free_ctx) + list_del(&ctx->list); spin_unlock_irqrestore(&tls_device_lock, flags); /* Device contexts for RX and TX will be freed in on sk_destruct * by tls_device_free_ctx. rx_conf and tx_conf stay in TLS_HW. - * Now release the ref taken above. */ - if (refcount_dec_and_test(&ctx->refcount)) { + if (free_ctx) { /* sk_destruct ran after tls_device_down took a ref, and * it returned early. Complete the destruction here. */ - list_del(&ctx->list); tls_device_free_ctx(ctx); } } From 09599d876dd1c4ee6641aac7b467208b9a210158 Mon Sep 17 00:00:00 2001 From: Suraj Gupta Date: Thu, 12 Nov 2026 23:19:26 +0530 Subject: [PATCH 054/117] MAINTAINERS: Add Suraj Gupta as AXI Ethernet co-maintainer Add myself as co-maintainer of the Xilinx AXI Ethernet driver. I have been contributing patches to and reviewing patches for this driver, and will continue to help with review and maintenance. Signed-off-by: Suraj Gupta Acked-by: Radhey Shyam Pandey Link: https://patch.msgid.link/20261112174926.2102832-1-suraj.gupta2@amd.com Signed-off-by: Paolo Abeni --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index a809df29a6c5..66e609de66fa 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -30686,6 +30686,7 @@ F: drivers/iio/adc/xilinx-ams.c XILINX AXI ETHERNET DRIVER M: Radhey Shyam Pandey +M: Suraj Gupta S: Maintained F: Documentation/devicetree/bindings/net/xlnx,axi-ethernet.yaml F: drivers/net/ethernet/xilinx/xilinx_axienet* From 5e9b2ad9b8384cd3c417cd5e2c3bc7eee4a72791 Mon Sep 17 00:00:00 2001 From: Shay Drory Date: Thu, 12 Nov 2026 20:24:03 +0200 Subject: [PATCH 055/117] net/mlx5e: rep, Fix races between devcom PAIR event and uplink close mlx5e_sqs2vport_stop() frees each rep_sq and its per-peer send-to-vport rules (rep_sq->sq_peer) while holding only the uplink's priv->state_lock (it runs from the ndo_stop -> mlx5e_deactivate_priv_channels -> mlx5e_rep_deactivate_channels path). The same rep_sq->sq_peer entries are inserted and erased by the devcom ESW_OFFLOADS PAIR/UNPAIR handler (mlx5e_vport_rep_event_pair/unpair), which runs under the devcom component write semaphore and takes no state_lock. The two lock sets are disjoint, so closing the uplink of one eswitch can run concurrently with a pairing/unpairing event driven by the peer eswitch, both mutating the same rep's vport_sqs_list / sq_peer. This is a use-after-free: one side frees rep_sq / sq_peer while the other walks the list or inserts/erases the xarray. The add side (mlx5e_sqs2vport_start) is not safe either. It takes the devcom read semaphore only via mlx5_devcom_for_each_peer_begin(), which is gated on comp->ready. The PAIR handler does all of its rep work before setting ready, so a first-time PAIR runs with ready == false and start can list_add() into vport_sqs_list while the handler walks it. Add mlx5_devcom_comp_read_lock/unlock(), which take the component semaphore for read regardless of ready, and hold it across both mlx5e_sqs2vport_start() and mlx5e_sqs2vport_stop(). Start still adds peer rules only when the component is ready, now checked under the lock. Lock ordering is preserved: start already took state_lock -> comp->sem (read); stop now does the same. The event handler takes comp->sem and never state_lock, so there is no inversion. Fixes: 898b07861565 ("net/mlx5: Add send to vport rules on paired device") Signed-off-by: Shay Drory Reviewed-by: Moshe Shemesh Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20261112182403.3646298-1-tariqt@nvidia.com Signed-off-by: Paolo Abeni --- .../net/ethernet/mellanox/mlx5/core/en_rep.c | 21 ++++++++++--------- .../ethernet/mellanox/mlx5/core/lib/devcom.c | 14 +++++++++++++ .../ethernet/mellanox/mlx5/core/lib/devcom.h | 2 ++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c index c7b4a8a82773..ca5da48626f6 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c @@ -506,10 +506,11 @@ static int mlx5e_sqs2vport_start(struct mlx5_eswitch *esw, struct mlx5_eswitch_rep *rep, u32 *sqns_array, int sqns_num) { + struct mlx5_devcom_comp_dev *devcom = esw->devcom; struct mlx5_flow_handle *flow_rule; struct mlx5e_rep_priv *rpriv; struct mlx5e_rep_sq *rep_sq; - bool devcom_locked = false; + bool peers_ready; int err; int i; @@ -518,9 +519,8 @@ static int mlx5e_sqs2vport_start(struct mlx5_eswitch *esw, rpriv = mlx5e_rep_to_rep_priv(rep); - if (mlx5_devcom_comp_is_ready(esw->devcom) && - mlx5_devcom_for_each_peer_begin(esw->devcom)) - devcom_locked = true; + mlx5_devcom_comp_read_lock(devcom); + peers_ready = mlx5_devcom_comp_is_ready(devcom); for (i = 0; i < sqns_num; i++) { rep_sq = kzalloc_obj(*rep_sq); @@ -541,7 +541,7 @@ static int mlx5e_sqs2vport_start(struct mlx5_eswitch *esw, rep_sq->sqn = sqns_array[i]; xa_init(&rep_sq->sq_peer); - if (devcom_locked) { + if (peers_ready) { err = mlx5e_sqs2vport_add_peers_rules(esw, rep, rep_sq, i); if (err) { mlx5_eswitch_del_send_to_vport_rule(rep_sq->send_to_vport_rule); @@ -554,16 +554,13 @@ static int mlx5e_sqs2vport_start(struct mlx5_eswitch *esw, list_add(&rep_sq->list, &rpriv->vport_sqs_list); } - if (devcom_locked) - mlx5_devcom_for_each_peer_end(esw->devcom); + mlx5_devcom_comp_read_unlock(devcom); return 0; out_err: mlx5e_sqs2vport_stop(esw, rep); - - if (devcom_locked) - mlx5_devcom_for_each_peer_end(esw->devcom); + mlx5_devcom_comp_read_unlock(devcom); return err; } @@ -630,8 +627,12 @@ mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv) struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; struct mlx5e_rep_priv *rpriv = priv->ppriv; struct mlx5_eswitch_rep *rep = rpriv->rep; + struct mlx5_devcom_comp_dev *devcom; + devcom = esw->devcom; + mlx5_devcom_comp_read_lock(devcom); mlx5e_sqs2vport_stop(esw, rep); + mlx5_devcom_comp_read_unlock(devcom); } static int diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c index 75855481522b..aed9e2a74162 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c @@ -456,6 +456,20 @@ void mlx5_devcom_comp_unlock(struct mlx5_devcom_comp_dev *devcom) up_write(&devcom->comp->sem); } +void mlx5_devcom_comp_read_lock(struct mlx5_devcom_comp_dev *devcom) +{ + if (!devcom) + return; + down_read(&devcom->comp->sem); +} + +void mlx5_devcom_comp_read_unlock(struct mlx5_devcom_comp_dev *devcom) +{ + if (!devcom) + return; + up_read(&devcom->comp->sem); +} + int mlx5_devcom_comp_trylock(struct mlx5_devcom_comp_dev *devcom) { if (!devcom) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.h b/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.h index 7a704fafdbd3..94b0fe20cc26 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.h @@ -79,6 +79,8 @@ void *mlx5_devcom_get_next_peer_data_rcu(struct mlx5_devcom_comp_dev *devcom, void mlx5_devcom_comp_lock(struct mlx5_devcom_comp_dev *devcom); void mlx5_devcom_comp_unlock(struct mlx5_devcom_comp_dev *devcom); +void mlx5_devcom_comp_read_lock(struct mlx5_devcom_comp_dev *devcom); +void mlx5_devcom_comp_read_unlock(struct mlx5_devcom_comp_dev *devcom); int mlx5_devcom_comp_trylock(struct mlx5_devcom_comp_dev *devcom); void mlx5_devcom_comp_assert_locked(struct mlx5_devcom_comp_dev *devcom); From b05fb50e255a3214683ee3f6a9433ea442c0ce04 Mon Sep 17 00:00:00 2001 From: Hex Lindqvist Date: Fri, 13 Nov 2026 14:20:24 -0800 Subject: [PATCH 056/117] Bluetooth: btintel: Don't log unsupported debug features as an error Since commit af395330abed ("Bluetooth: btintel: Add Intel devcoredump support"), setup sends Read Supported Features (0xfca6) to decide whether to register devcoredump. Older controllers such as the 8260 and 8265 reject it with Command Disallowed, so every probe logs: Bluetooth: hci0: Reading supported features failed (-16) Bluetooth: hci0: Error reading debug features This is harmless: it happens after the firmware is loaded and only means devcoredump is not registered. Log the failure at debug level there, and keep the error in btintel_set_quality_report(), where the user asked for the feature. Tested on an 8265 (8087:0a2b): the messages are gone and Bluetooth works as before. AI was used to help write and test this patch. Fixes: af395330abed ("Bluetooth: btintel: Add Intel devcoredump support") Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219387 Signed-off-by: Hex Lindqvist Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/btintel.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c index 929018428c19..4cc5273fb175 100644 --- a/drivers/bluetooth/btintel.c +++ b/drivers/bluetooth/btintel.c @@ -1511,11 +1511,8 @@ static int btintel_read_debug_features(struct hci_dev *hdev, */ skb = __hci_cmd_sync(hdev, 0xfca6, sizeof(page_no), &page_no, HCI_INIT_TIMEOUT); - if (IS_ERR(skb)) { - bt_dev_err(hdev, "Reading supported features failed (%ld)", - PTR_ERR(skb)); + if (IS_ERR(skb)) return PTR_ERR(skb); - } if (skb->len != (sizeof(features->page1) + 3)) { bt_dev_err(hdev, "Supported features event size mismatch"); @@ -1632,8 +1629,10 @@ int btintel_set_quality_report(struct hci_dev *hdev, bool enable) * supported, need to load the additional DDC config to enable. */ err = btintel_read_debug_features(hdev, &features); - if (err) + if (err) { + bt_dev_err(hdev, "Reading supported features failed (%d)", err); return err; + } /* Set or reset the debug features. */ if (enable) @@ -1684,7 +1683,7 @@ static int btintel_register_devcoredump_support(struct hci_dev *hdev) err = btintel_read_debug_features(hdev, &features); if (err) { - bt_dev_info(hdev, "Error reading debug features"); + bt_dev_dbg(hdev, "Reading supported features failed (%d)", err); return err; } From 1f150a0bb8a1a2302f6895ac410f0aaaaa63b756 Mon Sep 17 00:00:00 2001 From: Jeremy Dean Clifton Date: Tue, 17 Nov 2026 02:33:42 +0000 Subject: [PATCH 057/117] Bluetooth: hci_conn: Free the unset handle when adding a connection fails hci_conn_add_unset() reserves a handle from hdev->unset_handle_ida and passes it to __hci_conn_add(). When __hci_conn_add() returns an error, no hci_conn exists, so hci_conn_cleanup() never runs and the handle is never returned to the IDA. It stays reserved until the device is released. The Sashiko AI reviewer found this while reviewing a change that adds another error return to __hci_conn_add(). Free the handle in hci_conn_add_unset() when __hci_conn_add() fails. Fixes: 181a42edddf5 ("Bluetooth: Make handle of hci_conn be unique") Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Jeremy Dean Clifton Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_conn.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index c468a9332e05..e44d9b29ab78 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1186,6 +1186,7 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type, bdaddr_t *dst, u8 dst_type, u8 role) { + struct hci_conn *conn; int handle; bt_dev_dbg(hdev, "dst %pMR", dst); @@ -1194,7 +1195,11 @@ struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type, if (unlikely(handle < 0)) return ERR_PTR(-ECONNREFUSED); - return __hci_conn_add(hdev, type, dst, dst_type, role, handle); + conn = __hci_conn_add(hdev, type, dst, dst_type, role, handle); + if (IS_ERR(conn)) + ida_free(&hdev->unset_handle_ida, handle); + + return conn; } struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst, From 56abe5c17b4d7e3bdc83b9671549f407a7113ceb Mon Sep 17 00:00:00 2001 From: Jeremy Dean Clifton Date: Tue, 17 Nov 2026 02:33:43 +0000 Subject: [PATCH 058/117] Bluetooth: hci_conn: Refuse new connections once HCI_UP is cleared hci_dev_close_sync() clears HCI_UP and later calls hci_conn_hash_flush() to delete every connection. A connection created by __hci_conn_add() after the flush has run is never deleted. It keeps the hci_dev_hold() reference and the sysfs device taken in __hci_conn_add(), so the hci_dev is never freed, and its works can still be queued after the workqueue is drained. Check HCI_UP in __hci_conn_add(), which serves both hci_conn_add() and hci_conn_add_unset(). All callers hold hdev->lock: the HCI event handlers, create_pa_complete() in hci_sync.c, and the l2cap, sco, iso and mgmt paths that reach the hci_connect_*() and hci_bind_*() helpers. hci_conn_hash_flush() runs under hdev->lock too, so a connection is either added before the flush and deleted by it, or refused. Also include lockdep_assert_held() so the locking rule is checked. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Jeremy Dean Clifton Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_conn.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index e44d9b29ab78..2fb37e078d73 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -1019,6 +1019,15 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, struct hci_conn *conn; struct smp_irk *irk = NULL; + lockdep_assert_held(&hdev->lock); + + /* hci_dev_close_sync() clears HCI_UP before hci_conn_hash_flush(). + * A connection added after that would never be flushed, so refuse + * it. The caller holds hdev->lock, which the flush also takes. + */ + if (!test_bit(HCI_UP, &hdev->flags)) + return ERR_PTR(-ENETDOWN); + switch (type) { case ACL_LINK: if (!hdev->acl_mtu) From 1ea7a0946b9ea0a962640fc314bdef268e7c2791 Mon Sep 17 00:00:00 2001 From: Jeremy Dean Clifton Date: Tue, 17 Nov 2026 02:33:44 +0000 Subject: [PATCH 059/117] Bluetooth: hci_sync: Disable connection works before draining A connection delayed work whose timer was armed before hci_dev_close_sync() can expire while drain_workqueue() runs. delayed_work_timer_fn() then queues it on the draining workqueue and triggers the "cannot queue ... on wq" warning. hci_conn_drop() can also queue disc_work from another context during the drain. Disable the per-connection delayed works under hdev->lock before draining. A disabled work is cancelled and any later attempt to queue it fails, so neither the timers nor hci_conn_drop() can queue it. The connections are deleted by hci_conn_hash_flush() below, so nothing needs to re-enable the works. Fixes: 76727c02c1e1 ("Bluetooth: Call drain_workqueue() before resetting state") Reported-by: syzbot+5897b3c764f5989ea942@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=5897b3c764f5989ea942 Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Jeremy Dean Clifton Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_sync.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index e771f0f2f308..44ce776890d1 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5772,6 +5772,7 @@ static int hci_dev_shutdown(struct hci_dev *hdev) int hci_dev_close_sync(struct hci_dev *hdev) { + struct hci_conn *conn; bool auto_off; int err = 0; @@ -5839,6 +5840,22 @@ int hci_dev_close_sync(struct hci_dev *hdev) cancel_delayed_work_sync(&adv_instance->rpa_expired_cb); } + /* A delayed work whose timer was armed before close would queue + * itself while the workqueue is draining. Disable the connection + * works so that hci_conn_drop() and the timers can no longer queue + * them. The connections are deleted below, so nothing re-enables + * them. HCI_UP is clear, so no new connection can be added after + * this walk. + */ + hci_dev_lock(hdev); + list_for_each_entry(conn, &hdev->conn_hash.list, list) { + disable_delayed_work(&conn->disc_work); + disable_delayed_work(&conn->auto_accept_work); + disable_delayed_work(&conn->idle_work); + disable_delayed_work(&conn->le_conn_timeout); + } + hci_dev_unlock(hdev); + /* Avoid potential lockdep warnings from the *_flush() calls by * ensuring the workqueue is empty up front. */ From ee43bade37c4578b52a76cf0cdb199d3c0019506 Mon Sep 17 00:00:00 2001 From: Zhao Li Date: Mon, 16 Nov 2026 16:05:38 +0800 Subject: [PATCH 060/117] Bluetooth: hci_serdev: serialize flush with transmit work hci_uart_flush() runs on HCI close and reset and frees hu->tx_skb while write_work may still be sending the same partial frame. The worker can then resume with a freed skb, or both paths can free the frame. The tty flush has stopped write_work before freeing the partial frame since commit 1b0d946d6f08 ("Bluetooth: hci_uart: clear HCI_UART_SENDING when write_work is canceled"). Do the same in the serdev flush: disable and drain write_work before releasing the frame, and hold HCI_UART_SENDING meanwhile so that hci_uart_tx_wakeup() only records HCI_UART_TX_WAKEUP. Then re-enable the work, release SENDING and replay a wakeup that arrived in between. AI assistance was used. Fixes: 82f5169bf3d3 ("Bluetooth: hci_uart: add serdev driver support library") Cc: stable@vger.kernel.org # needs adjustments for <= 7.4 Signed-off-by: Zhao Li Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_serdev.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c index d2c48df34199..194f11251cc5 100644 --- a/drivers/bluetooth/hci_serdev.c +++ b/drivers/bluetooth/hci_serdev.c @@ -97,17 +97,26 @@ static int hci_uart_flush(struct hci_dev *hdev) BT_DBG("hdev %p serdev %p", hdev, hu->serdev); + /* Stop write_work and hold SENDING so wakeups only set TX_WAKEUP. */ + disable_work_sync(&hu->write_work); + set_bit(HCI_UART_SENDING, &hu->tx_state); + if (hu->tx_skb) { kfree_skb(hu->tx_skb); hu->tx_skb = NULL; } - if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) - return 0; + if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) { + /* Flush any pending characters in the driver and discipline. */ + serdev_device_write_flush(hu->serdev); - /* Flush any pending characters in the driver and discipline. */ - serdev_device_write_flush(hu->serdev); + hu->proto->flush(hu); + } - hu->proto->flush(hu); + /* Resume TX and replay a wakeup recorded while it was stopped. */ + enable_work(&hu->write_work); + clear_bit(HCI_UART_SENDING, &hu->tx_state); + if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state)) + hci_uart_tx_wakeup(hu); return 0; } From c9eb955c4fe2c2611a57625767c4cc57ab8c7558 Mon Sep 17 00:00:00 2001 From: Michael McAllister Date: Mon, 16 Nov 2026 16:35:14 +0000 Subject: [PATCH 061/117] Bluetooth: hci_mrvl: Leave the serdev port lifetime to hci_serdev hci_uart_register_device_priv() opens the port before calling mrvl_open(), so Marvell opens it twice. Likewise, mrvl_close() closes it before the transport closes it again during unregister or registration error cleanup. Remove the extra calls and let hci_serdev own the port lifetime. This also avoids failing probe when serdev rejects a second open with -EALREADY. Fixes: be70e5e774a6 ("Bluetooth: hci_mrvl: Add serdev support") Reported-by: Markus Probst Closes: https://lore.kernel.org/341e56b1ff7d8a5b109e26e30dfed61faa54d603.camel@posteo.de/ Signed-off-by: Michael McAllister Reviewed-by: Loic Poulain Signed-off-by: Luiz Augusto von Dentz --- drivers/bluetooth/hci_mrvl.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/drivers/bluetooth/hci_mrvl.c b/drivers/bluetooth/hci_mrvl.c index 5798a8db016e..def19907c172 100644 --- a/drivers/bluetooth/hci_mrvl.c +++ b/drivers/bluetooth/hci_mrvl.c @@ -57,7 +57,6 @@ struct hci_mrvl_pkt { static int mrvl_open(struct hci_uart *hu) { struct mrvl_data *mrvl; - int ret; BT_DBG("hu %p", hu); @@ -75,17 +74,7 @@ static int mrvl_open(struct hci_uart *hu) hu->priv = mrvl; - if (hu->serdev) { - ret = serdev_device_open(hu->serdev); - if (ret) - goto err; - } - return 0; -err: - kfree(mrvl); - - return ret; } static int mrvl_close(struct hci_uart *hu) @@ -94,9 +83,6 @@ static int mrvl_close(struct hci_uart *hu) BT_DBG("hu %p", hu); - if (hu->serdev) - serdev_device_close(hu->serdev); - skb_queue_purge(&mrvl->txq); skb_queue_purge(&mrvl->rawq); kfree_skb(mrvl->rx_skb); From 5beb86f98c3d45f6d64be5b6d6c77480487b41b4 Mon Sep 17 00:00:00 2001 From: Nguyen Ngoc Thang Date: Tue, 17 Nov 2026 21:49:37 +0700 Subject: [PATCH 062/117] Bluetooth: L2CAP: return LE credits from recvmsg under the conn lock l2cap_chan_le_send_credits() allocates an ident from conn->tx_ida, sends L2CAP_LE_CREDITS and frees the ident right away, since the command has no response. The RX path frees idents in l2cap_put_ident() under conn->lock. That only works if the credits path holds conn->lock too, so that no response can be processed between the allocation and the free. The RX path does, but l2cap_sock_recvmsg() calls l2cap_publish_rx_avail() -> l2cap_chan_rx_avail() -> l2cap_chan_le_send_credits() with only the socket lock held. If the remote answers the credits packet with L2CAP_COMMAND_REJ, l2cap_put_ident() can free the ident first, and the credits path then frees it again: ida_free called for id=3 which is not allocated. WARNING: lib/idr.c:594 at ida_free+0x24c/0x2d4 lib/idr.c:594 Call trace: ida_free+0x24c/0x2d4 lib/idr.c:594 l2cap_chan_le_send_credits+0x17c/0x29c net/bluetooth/l2cap_core.c:7113 l2cap_chan_rx_avail+0xb4/0x134 net/bluetooth/l2cap_core.c:7126 l2cap_publish_rx_avail+0x110/0x168 net/bluetooth/l2cap_sock.c l2cap_sock_recvmsg+0x280/0x7b8 net/bluetooth/l2cap_sock.c:1317 The same unlocked call also updates chan->rx_credits and reads chan->sdu concurrently with the RX path. Publish rx_avail from recvmsg under conn->lock and chan->lock, taken with l2cap_chan_lock_conn() as l2cap_sock_defer() already does, before taking the socket lock to keep the conn->lock -> chan->lock -> sk_lock order. Assert conn->lock in l2cap_chan_le_send_credits() so that an unlocked caller is caught by lockdep. Fixes: 6e1930ece855 ("Bluetooth: L2CAP: fix tx ident leak for commands without a response") Reported-by: syzbot+9dc8780713b11155dd74@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=9dc8780713b11155dd74 Signed-off-by: Nguyen Ngoc Thang Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/l2cap_core.c | 3 +++ net/bluetooth/l2cap_sock.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 4ee1e62ded7e..686e86c04d7e 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -7150,6 +7150,9 @@ static void l2cap_chan_le_send_credits(struct l2cap_chan *chan) pkt.cid = cpu_to_le16(chan->scid); pkt.credits = cpu_to_le16(return_credits); + /* Keeps l2cap_put_ident() from releasing ident before we do */ + lockdep_assert_held(&conn->lock); + ident = l2cap_get_ident(conn); l2cap_send_cmd(conn, ident, L2CAP_LE_CREDITS, sizeof(pkt), &pkt); diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 304ebafdfeaa..6b65710845dc 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1292,6 +1292,7 @@ static int l2cap_sock_recvmsg(struct socket *sock, struct msghdr *msg, { struct sock *sk = sock->sk; struct l2cap_pinfo *pi = l2cap_pi(sk); + bool have_conn; int err; if (unlikely(flags & MSG_ERRQUEUE)) @@ -1312,9 +1313,12 @@ static int l2cap_sock_recvmsg(struct socket *sock, struct msghdr *msg, pi->chan->mode != L2CAP_MODE_EXT_FLOWCTL) return err; - lock_sock(sk); - + /* Returning credits must be serialized with the RX path */ + have_conn = l2cap_chan_lock_conn(pi->chan); l2cap_publish_rx_avail(pi->chan); + l2cap_chan_unlock_conn(pi->chan, have_conn); + + lock_sock(sk); /* Attempt to put pending rx data in the socket buffer */ while (!list_empty(&pi->rx_busy)) { From a0abc1e4c9d5b8b846abe4293b7bca578736da8a Mon Sep 17 00:00:00 2001 From: Sung Byeongchan Date: Sat, 7 Nov 2026 18:36:01 +0900 Subject: [PATCH 063/117] ieee802154: require CAP_NET_ADMIN for SIOCSIFADDR PF_IEEE802154 DGRAM sockets are available to ordinary init-net processes. Their family-specific SIOCSIFADDR path calls the netdev ioctl directly and does not pass through the generic network-device setter capability check. An unprivileged process can therefore change the PAN ID and short address of a separately administrator-owned down WPAN interface. In a local fakelb fixture, uid 1000 changed both identifiers and the values remained active through a later administrator interface open in three of three fresh KASAN boots. Require CAP_NET_ADMIN in the socket network namespace before processing SIOCSIFADDR. Keep SIOCGIFADDR and all existing state and value checks unchanged. The fixed kernel rejected the same unprivileged request with -EPERM and preserved the administrator identity in three of three matched boots. Administrator SET, running-device, invalid-value, wrong-device, cleanup, later-open and recovery controls passed in all baseline and fixed runs. The demonstrated impact is local cross-principal WPAN identity and policy modification after privileged device setup. Memory corruption, disclosure, RCE and LPE were not demonstrated. Fixes: 9ec767160357 ("net: add IEEE 802.15.4 socket family implementation") Cc: stable@vger.kernel.org Signed-off-by: Sung Byeongchan Reviewed-by: Miquel Raynal Link: https://patch.msgid.link/20261107093601.619363-1-tjdqudcks0424@naver.com Signed-off-by: Jakub Kicinski --- net/ieee802154/socket.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/ieee802154/socket.c b/net/ieee802154/socket.c index be8ca1f053a2..362457de8424 100644 --- a/net/ieee802154/socket.c +++ b/net/ieee802154/socket.c @@ -128,6 +128,10 @@ static int ieee802154_dev_ioctl(struct sock *sk, struct ifreq __user *arg, int ret = -ENOIOCTLCMD; struct net_device *dev; + if (cmd == SIOCSIFADDR && + !ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) + return -EPERM; + if (get_user_ifreq(&ifr, NULL, arg)) return -EFAULT; From 3e8c853c959e9637ed66ae1e55e0d3bb97372cc5 Mon Sep 17 00:00:00 2001 From: Joas Antonio dos Santos Date: Tue, 10 Nov 2026 09:03:23 +0000 Subject: [PATCH 064/117] mac802154: llsec: reject secured frames with security level 0 mac802154_llsec_decrypt() handles every received frame that has the Security Enabled bit set. The security level is taken from the auxiliary security header of the frame and is not required to be non-zero. The only check that looks at level 0 rejects the frame only if level 0 is not allowed by the matching seclevel entry, the entry has device_override set and the device is not seclevel_exempt: if (!(seclevel.sec_levels & BIT(hdr.sec.level)) && (hdr.sec.level == 0 && seclevel.device_override && !dev->dev.seclevel_exempt)) { Otherwise the frame reaches llsec_do_decrypt(), which sends every level other than IEEE802154_SCF_SECLEVEL_ENC to llsec_do_decrypt_auth(). There ieee802154_sechdr_authtag_len() returns 0 for level 0 and req = aead_request_alloc(llsec_tfm_by_len(key, authlen), GFP_ATOMIC); looks for a transform with an authentication tag size of 0. The key only has transforms for tag sizes 4, 8 and 16, so llsec_tfm_by_len() runs into its BUG(). The frame is not authenticated at that point. A station in radio range can crash a node that has llsec enabled if it sends a frame that matches a configured key entry and a device table entry (source address, key id mode and key id are sent in the clear and can be observed), uses a frame type that has a seclevel entry and carries a frame counter that is not lower than the stored one. No key material is needed. The frame counter of that device is also updated before the BUG() is reached. A frame with the Security Enabled bit set and security level 0 carries no protection and cannot be processed by the incoming security procedure. Reject it before any key or device state is looked up. The transmit side already leaves such frames alone in mac802154_llsec_encrypt(). Found by LLM-assisted source review. Fixes: 4c14a2fb5d14 ("mac802154: add llsec decryption method") Cc: stable@vger.kernel.org Signed-off-by: Joas Antonio dos Santos Reviewed-by: Miquel Raynal Link: https://patch.msgid.link/20261110-llsec-seclevel-none-v1-1-06ef143e467f@gmail.com Signed-off-by: Jakub Kicinski --- net/mac802154/llsec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/mac802154/llsec.c b/net/mac802154/llsec.c index 85452ef9a58c..32565f18897e 100644 --- a/net/mac802154/llsec.c +++ b/net/mac802154/llsec.c @@ -1019,6 +1019,8 @@ int mac802154_llsec_decrypt(struct mac802154_llsec *sec, struct sk_buff *skb) return 0; if (hdr.fc.version == 0) return -EINVAL; + if (hdr.sec.level == IEEE802154_SCF_SECLEVEL_NONE) + return -EINVAL; read_lock_bh(&sec->lock); if (!sec->params.enabled) { From 035fe1092f38476f7ea14705cf735640fd217f0a Mon Sep 17 00:00:00 2001 From: Hengyu Liang Date: Fri, 13 Nov 2026 14:33:55 -0500 Subject: [PATCH 065/117] neighbour: do not update an existing proxy entry on SIOCSARP Commit dc2a27e524ac ("neighbour: Update pneigh_entry in pneigh_create().") moved the update of flags, protocol and permanent from neigh_add() into pneigh_create(). However, arp_req_set_public() also calls pneigh_create(), with all three set to zero. As of now, SIOCSARP on an address that already has a proxy entry clears the flags of the entry and makes it non-permanent. The entry is then removed when the carrier goes down, and the host no longer answers ARP requests for the address. A similar issue happened before with the protocol. It was fixed by commit cbada1048847 ("neighbour: restore protocol != 0 check in pneigh update"). Perhaps flags and permanent need a fix as well. The issue can be reproduced with: ip link add d0 type veth peer name d1 ip link set d0 up ip link set d1 up ip neigh add proxy 10.9.9.9 dev d0 arp -i d0 -Ds 10.9.9.9 d0 pub ip link set d1 down sleep 1 ip neigh show proxy Before commit dc2a27e524ac ("neighbour: Update pneigh_entry in pneigh_create()."), the result is: 10.9.9.9 dev d0 proxy After that commit, the result is empty. This patch will add an update argument to pneigh_create(). Only neigh_add() sets it, so SIOCSARP leaves an existing entry alone again. Fixes: dc2a27e524ac ("neighbour: Update pneigh_entry in pneigh_create().") Signed-off-by: Hengyu Liang Reviewed-by: Kuniyuki Iwashima Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261113193355.3820232-1-hengyul@cs.unc.edu Signed-off-by: Jakub Kicinski --- include/net/neighbour.h | 2 +- net/core/neighbour.c | 9 ++++++--- net/ipv4/arp.c | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 79a5a548a129..d6d691fec124 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -394,7 +394,7 @@ struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, const void *key, struct net_device *dev); int pneigh_create(struct neigh_table *tbl, const void *key, struct net_device *dev, u32 flags, u8 protocol, - bool permanent); + bool permanent, bool update); int pneigh_delete(struct neigh_table *tbl, const void *key, struct net_device *dev); diff --git a/net/core/neighbour.c b/net/core/neighbour.c index d6e9c7c59a89..ae2db3912454 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -783,7 +783,7 @@ struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, int pneigh_create(struct neigh_table *tbl, const void *pkey, struct net_device *dev, - u32 flags, u8 protocol, bool permanent) + u32 flags, u8 protocol, bool permanent, bool update) { struct pneigh_entry *n; unsigned int key_len; @@ -793,8 +793,11 @@ int pneigh_create(struct neigh_table *tbl, mutex_lock(&tbl->phash_lock); n = pneigh_lookup(tbl, pkey, dev); - if (n) + if (n) { + if (!update) + goto out; goto update; + } key_len = tbl->key_len; n = kzalloc(sizeof(*n) + key_len, GFP_KERNEL); @@ -2155,7 +2158,7 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh, } err = pneigh_create(tbl, dst, dev, ndm_flags, protocol, - !!(ndm->ndm_state & NUD_PERMANENT)); + !!(ndm->ndm_state & NUD_PERMANENT), true); goto out; } diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index 1ca4ced280ae..3bc8db6ccd68 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c @@ -1099,7 +1099,7 @@ static int arp_req_set_public(struct net *net, struct arpreq *r, if (mask) { __be32 ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr; - return pneigh_create(tbl, &ip, dev, 0, 0, false); + return pneigh_create(tbl, &ip, dev, 0, 0, false, false); } return arp_req_set_proxy(net, dev, 1); From 686b5f47f8cc6ec8ad092dd10d944a75d731ea5b Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Fri, 13 Nov 2026 11:32:35 +0100 Subject: [PATCH 066/117] net: stmmac: Clear DMA errors for multi-channel interrupts The Multi-MSI interrupt handler doesn't clear the DMA error interrupts, and this leads to interrupt storms when one of these interrupts starts firing : - The RBU (rx buff unav) which triggers under high traffic load This triggers easily with iperf3 and small udp packets, and shows when running the netpoll kselftest - The RPS (rx process stop) which triggers when we stop the DMA RX. This one shows when restarting the RX logic without doing a down/up cycle, like when attaching an XDP program. The XSK kselftests triggers it. Let's make sure we clear these interrupts for multi-MSI cases, and call stmmac_global_err() upon fatal bus errors. For that introduce an "ERR" DMA dir, as we don't want to touch the RI/TI bits when handling these interrupts. Both of the above storms have been found on dwmac-motorcomm (YT6801), and are triggered by the xdp.py, xsk_reconfig.py, xdp_features.py, ring_reconfig.py and netpoll_basic kernel selftests. This seems to only affect dwmac4, there's no multi-msi mode on dwmac1000 (except on loongson which I couldn't test), and on dwxgmac these interrupts are masked as of today. Fixes: 6ccf12ae111e ("net: stmmac: use interrupt mode INTM=1 for multi-MSI") Fixes: 1b9707e6f1a9 ("net: stmmac: enable RPS and RBU interrupts") Reviewed-by: Nicolai Buchwitz Reviewed-by: Lorenzo Bianconi Tested-by: Magnus Leatti Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20261113103236.2184751-1-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/common.h | 1 + .../net/ethernet/stmicro/stmmac/dwmac4_dma.h | 5 +++++ .../net/ethernet/stmicro/stmmac/dwmac4_lib.c | 2 ++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 19 +++++++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h index c74bc7c9750e..a972bee66504 100644 --- a/drivers/net/ethernet/stmicro/stmmac/common.h +++ b/drivers/net/ethernet/stmicro/stmmac/common.h @@ -382,6 +382,7 @@ enum dma_irq_dir { DMA_DIR_RX = 0x1, DMA_DIR_TX = 0x2, DMA_DIR_RXTX = 0x3, + DMA_DIR_ERR = 0x4, }; enum request_irq_err { diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.h index 43b036d4e95b..a7caac3c98e6 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.h @@ -173,6 +173,11 @@ static inline u32 dma_chanx_base_addr(const struct dwmac4_addrs *addrs, DMA_CHAN_STATUS_TI | \ DMA_CHAN_STATUS_MSK_COMMON) +#define DMA_CHAN_STATUS_MSK_ERR (DMA_CHAN_STATUS_AIS | \ + DMA_CHAN_STATUS_FBE | \ + DMA_CHAN_STATUS_RPS | \ + DMA_CHAN_STATUS_RBU) + int dwmac4_dma_reset(void __iomem *ioaddr); void dwmac4_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan, bool rx, bool tx); diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c index a0249715fafa..02aa1a3dd1e2 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c @@ -150,6 +150,8 @@ int dwmac4_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, intr_status &= DMA_CHAN_STATUS_MSK_RX; else if (dir == DMA_DIR_TX) intr_status &= DMA_CHAN_STATUS_MSK_TX; + else if (dir == DMA_DIR_ERR) + intr_status &= DMA_CHAN_STATUS_MSK_ERR; /* ABNORMAL interrupts */ if (unlikely(intr_status & DMA_CHAN_STATUS_AIS)) { diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 25894771e9e9..0bcbf837d9cc 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3145,6 +3145,22 @@ static int stmmac_napi_check(struct stmmac_priv *priv, u32 chan, u32 dir) return status; } +static void stmmac_dma_err_interrupt(struct stmmac_priv *priv) +{ + u8 channels_to_check = max(priv->plat->rx_queues_to_use, + priv->plat->tx_queues_to_use); + int status; + u8 chan; + + for (chan = 0; chan < channels_to_check; chan++) { + status = stmmac_dma_interrupt_status(priv, priv->ioaddr, + &priv->xstats, chan, + DMA_DIR_ERR); + if (unlikely(status & tx_hard_error)) + stmmac_global_err(priv); + } +} + /** * stmmac_dma_interrupt - DMA ISR * @priv: driver private structure @@ -6498,6 +6514,9 @@ static irqreturn_t stmmac_mac_interrupt(int irq, void *dev_id) /* To handle Common interrupts */ stmmac_common_interrupt(priv); + if (priv->plat->core_type == DWMAC_CORE_GMAC4) + stmmac_dma_err_interrupt(priv); + return IRQ_HANDLED; } From c35761f43c582460b45429f51be5c2a0f07ed9af Mon Sep 17 00:00:00 2001 From: Anthony Pighin Date: Thu, 12 Nov 2026 09:31:40 -0500 Subject: [PATCH 067/117] net: gianfar: clear the pending Rx skb when freeing the Rx ring gfar_clean_rx_ring() keeps a frame that spans several Rx buffers in rx_queue->skb between NAPI polls. When the interface is stopped (close, MTU change, reset), free_skb_rx_queue() frees that skb but leaves the pointer set, and nothing clears it when the rings are set up again. After the restart, gfar_clean_rx_ring() picks up the stale pointer. The first buffer it sees has RXBD_FIRST set, so the overrun handling frees the skb a second time. By then the skb has usually been reallocated, so the second free releases another owner's skb and data while they are still in use. Clear rx_queue->skb after freeing it. Hit during development, as intermittent kernel panics in our automated regression on an NXP LS1021A board (eTSEC), in an L2 Ethernet traffic test that shuts and re-enables ports. It was seen on 6.6, 6.12 and 6.18 based kernels, crashing in unrelated places such as kmem_cache_alloc() called from build_skb() in gfar_poll_rx_sq(). With the fix, the same test ran 90 bounces with no warnings or crashes. Fixes: 75354148ce69 ("gianfar: Add paged allocation and Rx S/G") Cc: stable@vger.kernel.org Signed-off-by: Anthony Pighin Reviewed-by: Daniel Machon Link: https://patch.msgid.link/20261112143140.1395197-1-anthony.pighin@nokia.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/freescale/gianfar.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c index cf636fc5aafa..19010e08fc55 100644 --- a/drivers/net/ethernet/freescale/gianfar.c +++ b/drivers/net/ethernet/freescale/gianfar.c @@ -1092,6 +1092,7 @@ static void free_skb_rx_queue(struct gfar_priv_rx_q *rx_queue) struct rxbd8 *rxbdp = rx_queue->rx_bd_base; dev_kfree_skb(rx_queue->skb); + rx_queue->skb = NULL; for (i = 0; i < rx_queue->rx_ring_size; i++) { struct gfar_rx_buff *rxb = &rx_queue->rx_buff[i]; From 6e9764591bcc34705d1c7bb13b31b7e161db4110 Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Sun, 15 Nov 2026 13:42:34 +0200 Subject: [PATCH 068/117] net: ena: avoid double-counting TX DMA mappings on failure ena_tx_map_skb() increments tx_info->num_of_bufs after each successful DMA mapping. If a later fragment mapping fails, the error path adds the fragment index to this count before calling ena_unmap_tx_buff(). This can cause DMA unmapping of buffers that were never mapped and out-of-bounds access to the buffer array. Remove the extra increment so that cleanup uses only the number of successfully mapped buffers. Discovered by comparing the in-tree ENA driver with Amazon's standalone ENA driver. Fixes: 38005ca816a7 ("net: ena: add functions for handling Low Latency Queues in ena_netdev") Co-developed-by: Evgeny Ostrovsky Signed-off-by: Evgeny Ostrovsky Signed-off-by: Avi Weiss Reviewed-by: Daniel Machon Link: https://patch.msgid.link/20261115114233.2307630-2-thnkslprpt@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/amazon/ena/ena_netdev.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index ecc6f1d827f9..560b20a5861c 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -2609,7 +2609,6 @@ error_report_dma_error: tx_info->skb = NULL; - tx_info->num_of_bufs += i; ena_unmap_tx_buff(tx_ring, tx_info); return -EINVAL; From c5e5ac57b559962498886435394b9cbcef20d553 Mon Sep 17 00:00:00 2001 From: Wajeeh Atrash Date: Sun, 15 Nov 2026 13:42:40 +0200 Subject: [PATCH 069/117] net: ena: set admin device pointer before queue allocations On the first probe, ena_com_admin_init() allocates the completion contexts and admin SQ/CQ buffers before setting admin_queue->ena_dev. Their allocation failure paths log through this pointer, which is still NULL. A failed allocation therefore dereferences NULL instead of returning -ENOMEM. Set admin_queue->ena_dev before the first allocation so the helpers can log errors and return -ENOMEM normally. This issue has already been fixed in Amazon's standalone ENA driver (commit 7d1dc4341d4f). Fixes: da580ca8de2c ("net: ena: add device distinct log prefix to files") Signed-off-by: Wajeeh Atrash Signed-off-by: Avi Weiss Link: https://patch.msgid.link/20261115114239.2308017-2-thnkslprpt@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/amazon/ena/ena_com.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c b/drivers/net/ethernet/amazon/ena/ena_com.c index 297fb36ab8c1..9b14cddf4432 100644 --- a/drivers/net/ethernet/amazon/ena/ena_com.c +++ b/drivers/net/ethernet/amazon/ena/ena_com.c @@ -1992,6 +1992,7 @@ int ena_com_admin_init(struct ena_com_dev *ena_dev, admin_queue->q_depth = ENA_ADMIN_QUEUE_DEPTH; + admin_queue->ena_dev = ena_dev; admin_queue->q_dmadev = ena_dev->dmadev; admin_queue->polling = false; admin_queue->curr_cmd_id = 0; @@ -2045,7 +2046,6 @@ int ena_com_admin_init(struct ena_com_dev *ena_dev, if (ret) goto error; - admin_queue->ena_dev = ena_dev; admin_queue->running_state = true; return 0; From 728a2abd15a767f662a44030931ea7b2959b4e88 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sat, 14 Nov 2026 21:30:07 -0700 Subject: [PATCH 070/117] mptcp: Avoid unsequenced accesses to jiffies in mptcp_reset_tout_timer() After a recent improvement in clang to warn on unsequenced accesses to volatile variables [1], an instance appears in mptcp_reset_tout_timer(), which can break the build with CONFIG_WERROR=y / W=e: net/mptcp/protocol.c:3044:20: error: unsequenced accesses to volatile qualified 'jiffies' [-Werror,-Wunsequenced] 3044 | tcp_jiffies32 + jiffies + mptcp_close_timeout(sk); | ~~~~~~~~~~~~~ ^ Per C11 5.1.2.3.2, accessing a volatile object is a side effect. Per C11 6.5.2, unsequenced side effects on the same scalar object are undefined behavior. Per C11 6.5.3, unless otherwise specified, side effects and value computations of subexpressions are unsequenced within expressions. Add an explicit sequence point by splitting the addition expression in half, eliminating the undefined behavior and clearing up the warning. Cc: stable@vger.kernel.org Fixes: 76a13b315709 ("mptcp: invoke MP_FAIL response when needed") Closes: https://github.com/ClangBuiltLinux/linux/issues/2193 Link: https://github.com/llvm/llvm-project/commit/955715460eaf9188c241c74750637fc82dfcc423 [1] Signed-off-by: Nathan Chancellor Reviewed-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20261114-mptcp-wunsequenced-v1-1-707a73a6c172@kernel.org Signed-off-by: Jakub Kicinski --- net/mptcp/protocol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 8968db58083e..8a9efebf3497 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3041,7 +3041,8 @@ void mptcp_reset_tout_timer(struct mptcp_sock *msk, unsigned long fail_tout) return; close_timeout = (unsigned long)inet_csk(sk)->icsk_mtup.probe_timestamp - - tcp_jiffies32 + jiffies + mptcp_close_timeout(sk); + tcp_jiffies32; + close_timeout += jiffies + mptcp_close_timeout(sk); /* the close timeout takes precedence on the fail one, and here at least one of * them is active From cf704cc62ffaf9206f1cbc12c2a3baec316b0ac1 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolenko Date: Thu, 12 Nov 2026 16:58:20 -0800 Subject: [PATCH 071/117] net: e1000: fix warning in iounmap on probe failure In e1000_probe(), the error unwinding path at err_sw_init unconditionally calls iounmap(hw->ce4100_gbe_mdio_base_virt). On non-CE4100 hardware, hw->ce4100_gbe_mdio_base_virt remains NULL. Passing NULL to iounmap() triggers a WARN_ON_ONCE on x86 architectures. Furthermore, on CE4100 hardware, if probe fails before or during MDIO mapping, ce4100_gbe_mdio_base_virt is also NULL. Fix this by adding a NULL pointer check before calling iounmap() on hw->ce4100_gbe_mdio_base_virt. iounmap(hw->hw_addr) remains unconditional because every code path reaching err_sw_init occurs after hw->hw_addr has been successfully mapped. Reported-by: syzbot+ca1ef9e2e234b8d3599b@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=ca1ef9e2e234b8d3599b Fixes: 13acde8fffc0 ("e1000: cleanup CE4100 MDIO registers access") Cc: stable@vger.kernel.org Signed-off-by: Svyatoslav Nikolenko Reviewed-by: Aleksandr Loktionov Signed-off-by: Tony Nguyen Link: https://patch.msgid.link/20261113005823.130021-4-anthony.l.nguyen@intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/e1000/e1000_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c index d7f5c6f16142..d7e279b739b8 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_main.c +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c @@ -1227,7 +1227,8 @@ err_mdio_ioremap: kfree(adapter->rx_ring); err_dma: err_sw_init: - iounmap(hw->ce4100_gbe_mdio_base_virt); + if (hw->ce4100_gbe_mdio_base_virt) + iounmap(hw->ce4100_gbe_mdio_base_virt); iounmap(hw->hw_addr); err_ioremap: disable_dev = !test_and_set_bit(__E1000_DISABLED, &adapter->flags); From 9c9863f9b9f120b771a908849157791a32eadb02 Mon Sep 17 00:00:00 2001 From: Zxyan Zhu Date: Sat, 14 Nov 2026 09:55:54 +0800 Subject: [PATCH 072/117] net: stmmac: re-enable on-chip parity checkers for XGMAC ASP 0x2 Commit 669a55560e4b ("net: stmmac: Check more MAC HW features for XGMAC Core 3.20") made dwxgmac3_safety_feat_config() bail out early for asp == 0x2, assuming that configuration has no parity protection. Per the DWC_xgmac databook, the ASP field of MAC_HW_Feature3 selects: 0x1 (AS_EPPE): all automotive safety features, with ECC and parity ports on the external application interface 0x2 (AS_NEPPE): all automotive safety features, without ECC or parity ports on the external application interface 0x3 (AS_PPE): all automotive safety features, with parity ports on the external application interface The reset value of the field is defined as: (DWCXG_ASP_ALL && DWCXG_ASP_PPE == 1) ? "3" : (DWCXG_ASP_ALL && DWCXG_ASP_PPE == 0) ? "2" : (DWCXG_ASP_ALL && DWCXG_ASP_PPE == 2) ? "1" : "0" so ASP 0x2 implies DWCXG_ASP_ALL = 1, where the internal FSM state parity and timeout (MAC_FSM_Control) and the on-chip data-path parity (MTL_DPP_CONTROL) features exist; only the ports on the external application interface are absent. The early return therefore skips enabling safety checkers that are present in the hardware. Drop 0x2 from the condition so the FSM and data-path parity checkers are enabled again. Also update the safety feature descriptions printed by stmmac_dma_cap_show() to spell out that ASP 0x1/0x2/0x3 differ only in the ECC or parity ports on the external application interface; the previous wording, "All Safety Features without ECC or Parity", suggests the on-chip checkers are absent from an ASP 0x2 device. Keep the early return for ASP 0x4 (EASP), which selects only ECC protection for external memory and has no on-chip parity features. Tested on XGMAC 3.10 and 3.40 cores. Fixes: 669a55560e4b ("net: stmmac: Check more MAC HW features for XGMAC Core 3.20") Cc: stable@vger.kernel.org Signed-off-by: Zxyan Zhu Reviewed-by: Maxime Chevallier Reviewed-by: Nicolai Buchwitz Link: https://patch.msgid.link/20261114015554.2187341-1-zxyan0222@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 6 +++--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c index 1a88cbaed70c..6b2bfc241109 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c @@ -859,10 +859,10 @@ dwxgmac3_safety_feat_config(void __iomem *ioaddr, unsigned int asp, value |= XGMAC_TCEIE; /* TSO Memory Correctable Error */ writel(value, ioaddr + XGMAC_DMA_ECC_INT_ENABLE); - /* 0x2: Without ECC or Parity Ports on External Application Interface - * 0x4: Only ECC Protection for External Memory feature is selected + /* 0x4: Only ECC Protection for External Memory feature is + * selected, without any on-chip parity protection */ - if (asp == 0x2 || asp == 0x4) + if (asp == 0x4) return 0; /* 4. Enable Parity and Timeout for FSM */ diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 0bcbf837d9cc..ee63f5ecf570 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -6760,9 +6760,9 @@ static int stmmac_dma_cap_show(struct seq_file *seq, void *v) }; static const char * const dwxgmac_safety_feature_desc[] = { "No", - "All Safety Features with ECC and Parity", - "All Safety Features without ECC or Parity", - "All Safety Features with Parity Only", + "All Safety Features with ECC and Parity Ports on External Application Interface", + "All Safety Features without ECC or Parity Ports on External Application Interface", + "All Safety Features with Parity Ports on External Application Interface", "ECC Only", "UNDEFINED", "UNDEFINED", From 0dcf21648f258d2be36def2aacc8c7ee5e15e2ee Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Fri, 13 Nov 2026 18:24:34 +0500 Subject: [PATCH 073/117] net: spacemit: Fix TX timeout work deadlocking on itself emac_tx_timeout_task() takes RTNL and calls dev_close(), which ends up waiting for the work itself. The function call hierarchy is as follows emac_tx_timeout_task() dev_close() emac_stop() emac_down() cancel_work_sync(&priv->tx_timeout_task) The work never finishes and keeps RTNL held, so after a TX timeout everything that needs RTNL hangs. Remove cancel_work_sync() from emac_down(). Disable the work in emac_suspend() instead, and enable it again in emac_resume(). emac_remove() runs before the devm-managed unregister_netdev(), so use disable_work_sync() there to stop the work from being queued again. Found by code inspection. Not reproduced on hardware. Tested on Orange Pi RV2 (SpacemiT K1) with suspend/resume cycles and kselftest, with lockdep enabled. Fixes: bfec6d7f2001 ("net: spacemit: Add K1 Ethernet MAC") Reported-by: Troy Mitchell Closes: https://lore.kernel.org/all/DMO74K2MG3D7.15UUOU1O66K6N@linux.spacemit.com/ Suggested-by: Vivian Wang Signed-off-by: Ali Tariq Reviewed-by: Vivian Wang Reviewed-by: Muhammad Bilal Link: https://patch.msgid.link/20261113132435.434615-2-alitariq45892@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/spacemit/k1_emac.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/spacemit/k1_emac.c b/drivers/net/ethernet/spacemit/k1_emac.c index 71a80838bffd..51edc95f54c8 100644 --- a/drivers/net/ethernet/spacemit/k1_emac.c +++ b/drivers/net/ethernet/spacemit/k1_emac.c @@ -1732,7 +1732,6 @@ static int emac_down(struct emac_priv *priv) napi_disable(&priv->napi); timer_delete_sync(&priv->txtimer); - cancel_work_sync(&priv->tx_timeout_task); timer_delete_sync(&priv->stats_timer); @@ -2010,8 +2009,9 @@ static void emac_remove(struct platform_device *pdev) { struct emac_priv *priv = platform_get_drvdata(pdev); + disable_work_sync(&priv->tx_timeout_task); + timer_shutdown_sync(&priv->txtimer); - cancel_work_sync(&priv->tx_timeout_task); timer_shutdown_sync(&priv->stats_timer); @@ -2024,6 +2024,8 @@ static int emac_resume(struct device *dev) struct net_device *ndev = priv->ndev; int ret; + enable_work(&priv->tx_timeout_task); + ret = clk_prepare_enable(priv->bus_clk); if (ret < 0) { dev_err(dev, "Failed to enable bus clock: %d\n", ret); @@ -2051,6 +2053,8 @@ static int emac_suspend(struct device *dev) struct emac_priv *priv = dev_get_drvdata(dev); struct net_device *ndev = priv->ndev; + disable_work_sync(&priv->tx_timeout_task); + if (!ndev || !netif_running(ndev)) { clk_disable_unprepare(priv->bus_clk); return 0; From f60eae61466cca9b50690bd3f2b5b4b2397d9376 Mon Sep 17 00:00:00 2001 From: Ali Tariq Date: Fri, 13 Nov 2026 18:24:35 +0500 Subject: [PATCH 074/117] net: spacemit: Hold RTNL lock in emac_resume() and emac_suspend() The emac_resume() calls the emac_open() and emac_suspend() calls emac_stop() functions directly without holding the lock through rtnl_lock(). These functions rely on phy_disconnect() which reads pointer with rtnl_dereference(). But since no lock is being held, rtnl_dereference throws a suspicious RCU usage on Orange Pi RV2 (SpacemiT K1) warning when lockdep is enabled. WARNING: suspicious RCU usage drivers/net/phy/phy_device.c:1831 suspicious rcu_dereference_protected() usage! Call Trace: phy_detach_internal+0x490/0x5f2 phy_disconnect+0x90/0xc0 emac_stop+0x114/0x626 emac_suspend+0xac/0x126 platform_pm_suspend+0x72/0xe4 Take RTNL in emac_suspend() and emac_resume() before the netif_running() checks, so the interface can't be opened or closed between the check and emac_stop() or emac_open(). Found by CI suspend tests on Orange Pi RV2 (SpacemiT K1). Tested on the same board with lockdep enabled: 12 suspend/resume cycles without the warning, and kselftest with no new failures. Fixes: bfec6d7f2001 ("net: spacemit: Add K1 Ethernet MAC") Signed-off-by: Ali Tariq Reviewed-by: Vivian Wang Reviewed-by: Muhammad Bilal Link: https://patch.msgid.link/20261113132435.434615-3-alitariq45892@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/spacemit/k1_emac.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/spacemit/k1_emac.c b/drivers/net/ethernet/spacemit/k1_emac.c index 51edc95f54c8..d07d8a1aa5ee 100644 --- a/drivers/net/ethernet/spacemit/k1_emac.c +++ b/drivers/net/ethernet/spacemit/k1_emac.c @@ -2031,11 +2031,16 @@ static int emac_resume(struct device *dev) dev_err(dev, "Failed to enable bus clock: %d\n", ret); return ret; } + rtnl_lock(); - if (!netif_running(ndev)) + if (!netif_running(ndev)) { + rtnl_unlock(); return 0; + } ret = emac_open(ndev); + rtnl_unlock(); + if (ret) { clk_disable_unprepare(priv->bus_clk); return ret; @@ -2055,12 +2060,16 @@ static int emac_suspend(struct device *dev) disable_work_sync(&priv->tx_timeout_task); + rtnl_lock(); + if (!ndev || !netif_running(ndev)) { + rtnl_unlock(); clk_disable_unprepare(priv->bus_clk); return 0; } emac_stop(ndev); + rtnl_unlock(); clk_disable_unprepare(priv->bus_clk); netif_device_detach(ndev); From 0a3778b93be43f80ac529a1305a521ac55207a95 Mon Sep 17 00:00:00 2001 From: Kalpesh Solanki Date: Thu, 12 Nov 2026 18:40:55 +0530 Subject: [PATCH 075/117] tun: disallow setting ARPHRD_MCTP link type via TUNSETLINK When an IFF_TUN device is registered as ARPHRD_NONE, mctp_register() attaches an mctp_dev context to it. For ARPHRD_NONE and ARPHRD_LOOPBACK devices, incoming packets in mctp_pkttype_receive() invoke __mctp_cb(skb), which initializes cb->magic = 0x4d435450 and zeros cb->halen. If a userspace process sets the link type of the TUN device to ARPHRD_MCTP via ioctl(fd, TUNSETLINK, ARPHRD_MCTP) and transmits a frame carrying protocol ETH_P_MCTP, mctp_pkttype_receive() evaluates dev->type == ARPHRD_MCTP and calls mctp_cb(skb). Because frames allocated in tun_get_user() have a cleared skb->cb and were not constructed by an MCTP hardware driver, mctp_cb() trips: WARN_ON(cb->magic != 0x4d435450); On systems configured with panic_on_warn=1, an unprivileged user in a user+net namespace can trigger a denial-of-service kernel panic. MCTP communication over TUN interfaces is designed to use ARPHRD_NONE. Setting ARPHRD_MCTP on TUN is invalid and has never functioned. Disallow ARPHRD_MCTP in TUNSETLINK by returning -EINVAL. Fixes: ff4cc3ac93e1 ("[TUNTAP]: Allow setting the linktype of the tap device from userspace") Signed-off-by: Kalpesh Solanki Link: https://patch.msgid.link/20261112131056.234801-1-skalpesh942@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/tun.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 86fd44e10755..d4870bdc156f 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -3375,7 +3375,8 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, ret = -EBUSY; } else if ((unsigned short)arg == ARPHRD_IEEE802154 || (unsigned short)arg == ARPHRD_IEEE802154_MONITOR || - (unsigned short)arg == ARPHRD_6LOWPAN) { + (unsigned short)arg == ARPHRD_6LOWPAN || + (unsigned short)arg == ARPHRD_MCTP) { ret = -EINVAL; } else { ret = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE, From ff1ee9cc8993b1e5cf6459108dba1576fee221d0 Mon Sep 17 00:00:00 2001 From: Gal Pressman Date: Sun, 15 Nov 2026 09:29:34 +0200 Subject: [PATCH 076/117] net/mlx5e: Fix XSK pool corruption when switching channels When the device supports tis_tir_td_order, mlx5e_safe_switch_params() closes the old channels only after the new ones are activated. With an AF_XDP socket bound, the old and the new channel hold an XSK RQ on the same pool. The old RQ returns its buffers to the pool while the new RQ is already allocating from it. Since the pool is lockless and expects a single user at a time, it gets out of sync. Close the old XSK queues before activating the new channels, the rest of the old channels can still be closed later. The crash was hit by our regression tests, with a random sequence of binding xdpsock to every queue and later changing the ring size. This resolves the following call trace: BUG: kernel NULL pointer dereference, address: 0000000000000068 RIP: 0010:mlx5e_free_rx_mpwqe+0x113/0x250 [mlx5_core] Call Trace: mlx5e_dealloc_rx_mpwqe+0x38/0xb0 [mlx5_core] mlx5e_free_rx_descs+0x126/0x170 [mlx5_core] mlx5e_close_rq+0x81/0xb0 [mlx5_core] mlx5e_close_channels+0x4b/0xa0 [mlx5_core] mlx5e_safe_switch_params+0x34d/0x3e0 [mlx5_core] mlx5e_xdp_set+0x287/0x3a0 [mlx5_core] dev_xdp_install+0x269/0x400 Fixes: 3b88a535a8e1 ("net/mlx5e: Defer channels closure to reduce interface down time") Signed-off-by: Gal Pressman Reviewed-by: Nimrod Oren Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20261115072934.353341-1-tariqt@nvidia.com Signed-off-by: Jakub Kicinski --- .../net/ethernet/mellanox/mlx5/core/en_main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index d8563f863844..227695dfa51d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -3421,6 +3421,23 @@ static int mlx5e_switch_priv_params(struct mlx5e_priv *priv, return 0; } +/* The old and the new channel of the same index are bound to the same + * XSK pool, which is lockless and expects a single user at a time. + * Close the old XSK queues before the new ones are activated, even + * when the closure of the rest of the old channels is deferred. + */ +static void mlx5e_close_channels_xsk(struct mlx5e_channels *chs) +{ + int i; + + for (i = 0; i < chs->num; i++) { + struct mlx5e_channel *c = chs->c[i]; + + if (test_bit(MLX5E_CHANNEL_STATE_XSK, c->state)) + mlx5e_close_xsk(c); + } +} + static int mlx5e_switch_priv_channels(struct mlx5e_priv *priv, struct mlx5e_channels *old_chs, struct mlx5e_channels *new_chs, @@ -3452,6 +3469,8 @@ static int mlx5e_switch_priv_channels(struct mlx5e_priv *priv, mlx5e_set_xdp_feature(priv); if (!MLX5_CAP_GEN(priv->mdev, tis_tir_td_order)) mlx5e_close_channels(old_chs); + else + mlx5e_close_channels_xsk(old_chs); priv->profile->update_rx(priv); mlx5e_selq_apply(&priv->selq); From 5ec918f8d66a0311c52cc767ade67e7019beb176 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sat, 14 Nov 2026 21:38:26 -0700 Subject: [PATCH 077/117] net: microchip: encx24j600: Avoid unsequenced accesses to jiffies in encx24j600_tx() After a recent improvement in clang to warn on unsequenced accesses to volatile variables [1], an instance appears in encx24j600_tx(), which can break the build with CONFIG_WERROR=y / W=e: drivers/net/ethernet/microchip/encx24j600.c:898:14: error: unsequenced accesses to volatile qualified 'jiffies' [-Werror,-Wunsequenced] 898 | jiffies, jiffies - dev_trans_start(dev)); | ~~~~~~~ ^ Per C11 5.1.2.3.2, accessing a volatile object is a side effect. Per C11 6.5.2, unsequenced side effects on the same scalar object are undefined behavior. Per C11 6.5.2.2.10/12, the evaluation of arguments in a function call is indeterminately sequenced, meaning any side effects in the arguments are unsequenced. Add a local variable to hold the value of jiffies before the function call so that there are no unsequenced side effects, clearing up the warning. Cc: stable@vger.kernel.org Fixes: 04fbfce7a222 ("net: Microchip encx24j600 driver") Closes: https://github.com/ClangBuiltLinux/linux/issues/2196 Link: https://github.com/llvm/llvm-project/commit/955715460eaf9188c241c74750637fc82dfcc423 [1] Signed-off-by: Nathan Chancellor Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261114-encx24j600-wunsequenced-v1-1-c978fc36cacd@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/microchip/encx24j600.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/microchip/encx24j600.c b/drivers/net/ethernet/microchip/encx24j600.c index b011bf5c2305..ebc067cb2c9d 100644 --- a/drivers/net/ethernet/microchip/encx24j600.c +++ b/drivers/net/ethernet/microchip/encx24j600.c @@ -893,9 +893,10 @@ static netdev_tx_t encx24j600_tx(struct sk_buff *skb, struct net_device *dev) static void encx24j600_tx_timeout(struct net_device *dev, unsigned int txqueue) { struct encx24j600_priv *priv = netdev_priv(dev); + unsigned long j = jiffies; netif_err(priv, tx_err, dev, "TX timeout at %ld, latency %ld\n", - jiffies, jiffies - dev_trans_start(dev)); + j, j - dev_trans_start(dev)); dev->stats.tx_errors++; netif_wake_queue(dev); From 695d0824cb6b27ff1a1cdeabb2d5138f00b15251 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 15 Nov 2026 21:45:22 -0700 Subject: [PATCH 078/117] qca_spi: Avoid unsequenced accesses to jiffies in qcaspi_netdev_tx_timeout() After a recent improvement in clang to warn on unsequenced accesses to volatile variables [1], an instance appears in qcaspi_netdev_tx_timeout(), which can break the build with CONFIG_WERROR=y / W=e: drivers/net/ethernet/qualcomm/qca_spi.c:805:16: error: unsequenced accesses to volatile qualified 'jiffies' [-Werror,-Wunsequenced] 805 | jiffies, jiffies - dev_trans_start(dev)); | ~~~~~~~ ^ Per C11 5.1.2.3.2, accessing a volatile object is a side effect. Per C11 6.5.2, unsequenced side effects on the same scalar object are undefined behavior. Per C11 6.5.2.2.10/12, the evaluation of arguments in a function call is indeterminately sequenced, meaning any side effects in the arguments are unsequenced. Printing jiffies on its own is not that useful for debugging transmit timeouts, so get rid of it to clear up the warning. Cc: stable@vger.kernel.org Fixes: 291ab06ecf67 ("net: qualcomm: new Ethernet over SPI driver for QCA7000") Closes: https://github.com/ClangBuiltLinux/linux/issues/2197 Link: https://github.com/llvm/llvm-project/commit/955715460eaf9188c241c74750637fc82dfcc423 [1] Signed-off-by: Nathan Chancellor Acked-by: Stefan Wahren Reviewed-by: Nick Desaulniers Link: https://patch.msgid.link/20261115-qca_spi-wunsequenced-v2-1-8cf32f12d546@kernel.org Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/qualcomm/qca_spi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c b/drivers/net/ethernet/qualcomm/qca_spi.c index 38a779f4b866..249b4b549a12 100644 --- a/drivers/net/ethernet/qualcomm/qca_spi.c +++ b/drivers/net/ethernet/qualcomm/qca_spi.c @@ -801,8 +801,8 @@ qcaspi_netdev_tx_timeout(struct net_device *dev, unsigned int txqueue) { struct qcaspi *qca = netdev_priv(dev); - netdev_info(qca->net_dev, "Transmit timeout at %ld, latency %ld\n", - jiffies, jiffies - dev_trans_start(dev)); + netdev_info(qca->net_dev, "Transmit timeout, latency %ld\n", + jiffies - dev_trans_start(dev)); qca->net_dev->stats.tx_errors++; /* Trigger tx queue flush and QCA7000 reset */ set_bit(SPI_RESET, &qca->flags); From 98382d41f92f048cf3cbb7af415f48a722b19ebc Mon Sep 17 00:00:00 2001 From: Daniel Wade Date: Sun, 15 Nov 2026 23:32:11 +1030 Subject: [PATCH 079/117] net: bridge: fix skb leak of reinjected link-local frames br_handle_frame() passes the link-local frames it neither forwards nor delivers (01:80:c2:00:00:02 to 0d and 0f, unless set in the group forward mask) through NF_HOOK() at NF_BR_LOCAL_IN. Since commit 3b2e2904deb3 ("net: bridge: fix per-port af_packet sockets") the okfn only learns the source and returns 1, which becomes RX_HANDLER_PASS. That commit sent the nf_queue case to RX_HANDLER_CONSUMED, which is right for the synchronous return, but the frame comes back: on reinjection nf_reinject() calls the okfn and ignores its return value, because every other okfn consumes the skb. This one no longer does, so nothing frees the frame. NFQA_CFG_F_FAIL_OPEN leaks it the same way with no verdict at all, when the queue or the listener's socket is full. Each frame leaks an skb, and one sent from a local socket keeps that socket charged, so neither it nor the network namespace holding it is freed. Bridge, rule and queue need only CAP_NET_ADMIN in a netns, so with user namespaces an unprivileged user can exhaust kernel memory. nf_reinject() cannot free the skb on a 1 from the okfn, because other okfns return NET_RX_DROP, which is 1, after freeing it. Call nf_hook() instead of NF_HOOK() and do the learning and the RX_HANDLER_PASS return in br_handle_frame() on 1, as the 0x00 and 0x0e cases already do and as vrf_rcv_nfhook() does. The okfn then runs only for a reinjected frame, which br_handle_frame() has already reported consumed and cannot pass on the port, so it learns from the frame and frees it. These frames were not delivered before this change either. Also set *pskb before the new RX_HANDLER_PASS, as the other such returns do; skb_share_check() may have replaced the skb, and the commit above added that return without the assignment. Discovered by an AI code review agent and reproduced on unmodified mainline under KASAN: an unprivileged user in a new user and network namespace bridged a veth, queued link-local frames to an NFQUEUE listener that accepted every one, and leaked an skb per frame. With this patch the reinjected frames are freed and nothing leaks. Fixes: 3b2e2904deb3 ("net: bridge: fix per-port af_packet sockets") Cc: stable@vger.kernel.org Signed-off-by: Daniel Wade Reviewed-by: Xia Yan Acked-by: Nikolay Aleksandrov Link: https://patch.msgid.link/20261115130211.7724-1-danjwade95@gmail.com Signed-off-by: Jakub Kicinski --- net/bridge/br_input.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c index fc2e381c4fe0..b5bd9d6808fd 100644 --- a/net/bridge/br_input.c +++ b/net/bridge/br_input.c @@ -257,13 +257,18 @@ static void __br_handle_local_finish(struct sk_buff *skb) br_fdb_update(p->br, p, vlan, eth_hdr(skb)->h_source, 0); } -/* note: already called with rcu_read_lock */ +/* okfn of the link-local NF_BR_LOCAL_IN hook in br_handle_frame(). It is + * only called when a queued frame is reinjected, after br_handle_frame() + * returned RX_HANDLER_CONSUMED for it, so the frame can no longer be + * passed up on the port and has to be freed here. + * note: already called with rcu_read_lock + */ static int br_handle_local_finish(struct net *net, struct sock *sk, struct sk_buff *skb) { __br_handle_local_finish(skb); + kfree_skb(skb); - /* return 1 to signal the okfn() was called so it's ok to use the skb */ - return 1; + return 0; } static int nf_hook_bridge_pre(struct sk_buff *skb, struct sk_buff **pskb) @@ -424,11 +429,14 @@ static rx_handler_result_t br_handle_frame(struct sk_buff **pskb) /* The else clause should be hit when nf_hook(): * - returns < 0 (drop/error) * - returns = 0 (stolen/nf_queue) - * Thus return 1 from the okfn() to signal the skb is ok to pass + * On 1 the frame is passed on here. The okfn() only runs if a + * queued frame is reinjected later, and must consume it then. */ - if (NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, + if (nf_hook(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, dev_net(skb->dev), NULL, skb, skb->dev, NULL, br_handle_local_finish) == 1) { + *pskb = skb; + __br_handle_local_finish(skb); return RX_HANDLER_PASS; } else { return RX_HANDLER_CONSUMED; From 81d2cf1c6d567260e3195d2ef049f44446a462a7 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 16 Nov 2026 10:56:04 +0100 Subject: [PATCH 080/117] net: sparx5: fix RX ring stall on frames from inactive ports If the source port of a received frame does not map to a port with a netdev, sparx5_fdma_rx_get_frame() returns false without consuming the DB. The DB keeps its DONE bit, so every following poll picks the same DB and grows its skb with skb_put() again. This ends in skb_over_panic(), or in an RX stall if no more frames arrive. Drop the frame and return true, so that the DB is consumed like any other. Remove the extraction queue flush, as the FDMA has already extracted the frame, and ratelimit the error, as the source port comes from the hardware. Confirmed on Sparx5 (PCB135) with a kernel modified to give received frames an out-of-range source port, which made the board reset. The fix was tested the same way: only the bad frames are dropped. Fixes: 10615907e9b5 ("net: sparx5: switchdev: adding frame DMA functionality") Reported-by: Zhang Hewei Closes: https://lore.kernel.org/netdev/tencent_ACC296C1F221C304053BD0F1F4B0D2C2BA06@qq.com/ Signed-off-by: Daniel Machon Link: https://patch.msgid.link/20261116-sparx5-rx-inactive-port-v1-1-343d8bab58bb@microchip.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c b/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c index 15ec9b053824..8675702bf150 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c @@ -157,9 +157,15 @@ static bool sparx5_fdma_rx_get_frame(struct sparx5 *sparx5, struct sparx5_rx *rx sparx5->ports[fi.src_port] : NULL; if (!port || !port->ndev) { - dev_err(sparx5->dev, "Data on inactive port %d\n", fi.src_port); - sparx5_xtr_flush(sparx5, XTR_QUEUE); - return false; + dev_err_ratelimited(sparx5->dev, "Data on inactive port %d\n", + fi.src_port); + + /* Drop the frame, but report the DB as consumed so the + * caller advances past it and recycles the DCB. + */ + kfree_skb(skb); + + return true; } skb->dev = port->ndev; skb_pull(skb, IFH_LEN * sizeof(u32)); From 1a47bc214d00fbfaeb9a963a8aac2e4e58d36e71 Mon Sep 17 00:00:00 2001 From: Daniel Machon Date: Mon, 16 Nov 2026 10:56:05 +0100 Subject: [PATCH 081/117] net: lan969x: fix RX ring stall on frames from inactive ports If the source port of a received frame does not map to an active port, or build_skb() fails, lan969x_fdma_rx_get_frame() returns the page to the page_pool and returns NULL, and the NAPI poll loop breaks without advancing past the DB. The DB keeps its DONE bit, so every following poll returns the same page to the page_pool again, and RX stops on all ports. Drop the frame and advance past the DB like for any other frame, and replace the WARN_ON() with a ratelimited error, as the source port comes from the hardware. Confirmed on lan969x (EV23X71A) with a kernel modified to give received frames an out-of-range source port, which stopped RX on all ports. The fix was tested the same way: only the bad frames are dropped. Fixes: d84ad2c0d80c ("net: lan969x: add FDMA implementation") Reported-by: Zhang Hewei Closes: https://lore.kernel.org/netdev/tencent_ACC296C1F221C304053BD0F1F4B0D2C2BA06@qq.com/ Signed-off-by: Daniel Machon Link: https://patch.msgid.link/20261116-sparx5-rx-inactive-port-v1-2-343d8bab58bb@microchip.com Signed-off-by: Jakub Kicinski --- .../ethernet/microchip/sparx5/lan969x/lan969x_fdma.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c b/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c index 053d125eda65..fd532c89f911 100644 --- a/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c +++ b/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c @@ -113,8 +113,11 @@ static struct sk_buff *lan969x_fdma_rx_get_frame(struct sparx5 *sparx5, sparx5_ifh_parse(sparx5, page_address(page), &fi); port = fi.src_port < consts->n_ports ? sparx5->ports[fi.src_port] : NULL; - if (WARN_ON(!port)) + if (!port) { + dev_err_ratelimited(sparx5->dev, "Data on inactive port %d\n", + fi.src_port); goto free_page; + } skb = build_skb(page_address(page), fdma->db_size); if (unlikely(!skb)) @@ -258,10 +261,8 @@ int lan969x_fdma_napi_poll(struct napi_struct *napi, int weight) break; skb = lan969x_fdma_rx_get_frame(sparx5, rx); - if (!skb) - break; - - napi_gro_receive(&rx->napi, skb); + if (skb) + napi_gro_receive(&rx->napi, skb); fdma_db_advance(fdma); counter++; From 2c0d5e36aaf3cee1bc53c761704202b845be54d6 Mon Sep 17 00:00:00 2001 From: Siddharth Chintamaneni Date: Sat, 14 Nov 2026 16:26:31 +0000 Subject: [PATCH 082/117] af_unix: Fix scm_stat.nr_fds leak in unix_dgram_disconnected(). When a connected SOCK_DGRAM socket disconnects (e.g. via connect() with AF_UNSPEC), reconnects to a different peer, or observes a dead peer in unix_dgram_sendmsg(), unix_dgram_disconnected() purges all unread datagrams from sk->sk_receive_queue via skb_queue_purge_reason(). Because skb_queue_purge_reason() frees each skb without calling scm_stat_del(sk, skb), any SCM_RIGHTS file descriptors attached to the purged skbs remain permanently accounted in u->scm_stat.nr_fds (reported as scm_fds in /proc//fdinfo/) for the remaining lifetime of the socket. Move scm_stat_add() and scm_stat_del() above unix_dgram_disconnected(), splice sk->sk_receive_queue onto a local list under the queue lock, and call scm_stat_del() before kfree_skb_reason() on each purged skb. Fixes: 3c32da19a858 ("unix: Show number of pending scm files of receive queue in fdinfo") Signed-off-by: Siddharth Chintamaneni Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261114162632.16346-2-sidchintamaneni@gmail.com Signed-off-by: Jakub Kicinski --- net/unix/af_unix.c | 59 +++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index f847cf1fbeaf..91c1d6cad497 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -609,6 +609,28 @@ static void unix_write_space(struct sock *sk) rcu_read_unlock(); } +static void scm_stat_add(struct sock *sk, struct sk_buff *skb) +{ + struct scm_fp_list *fp = UNIXCB(skb).fp; + struct unix_sock *u = unix_sk(sk); + + if (unlikely(fp && fp->count)) { + atomic_add(fp->count, &u->scm_stat.nr_fds); + unix_add_edges(fp, u); + } +} + +static void scm_stat_del(struct sock *sk, struct sk_buff *skb) +{ + struct scm_fp_list *fp = UNIXCB(skb).fp; + struct unix_sock *u = unix_sk(sk); + + if (unlikely(fp && fp->count)) { + atomic_sub(fp->count, &u->scm_stat.nr_fds); + unix_del_edges(fp); + } +} + /* When dgram socket disconnects (or changes its peer), we clear its receive * queue of packets arrived from previous peer. First, it allows to do * flow control based only on wmem_alloc; second, sk connected to peer @@ -616,8 +638,19 @@ static void unix_write_space(struct sock *sk) static void unix_dgram_disconnected(struct sock *sk, struct sock *other) { if (!skb_queue_empty(&sk->sk_receive_queue)) { - skb_queue_purge_reason(&sk->sk_receive_queue, - SKB_DROP_REASON_UNIX_DISCONNECT); + struct sk_buff_head tmp; + struct sk_buff *skb; + + __skb_queue_head_init(&tmp); + + spin_lock(&sk->sk_receive_queue.lock); + skb_queue_splice_init(&sk->sk_receive_queue, &tmp); + spin_unlock(&sk->sk_receive_queue.lock); + + while ((skb = __skb_dequeue(&tmp)) != NULL) { + scm_stat_del(sk, skb); + kfree_skb_reason(skb, SKB_DROP_REASON_UNIX_DISCONNECT); + } wake_up_interruptible_all(&unix_sk(sk)->peer_wait); @@ -2059,28 +2092,6 @@ static bool unix_skb_scm_eq(const struct sock *sk, struct sk_buff *skb, unix_secdata_eq(scm, skb); } -static void scm_stat_add(struct sock *sk, struct sk_buff *skb) -{ - struct scm_fp_list *fp = UNIXCB(skb).fp; - struct unix_sock *u = unix_sk(sk); - - if (unlikely(fp && fp->count)) { - atomic_add(fp->count, &u->scm_stat.nr_fds); - unix_add_edges(fp, u); - } -} - -static void scm_stat_del(struct sock *sk, struct sk_buff *skb) -{ - struct scm_fp_list *fp = UNIXCB(skb).fp; - struct unix_sock *u = unix_sk(sk); - - if (unlikely(fp && fp->count)) { - atomic_sub(fp->count, &u->scm_stat.nr_fds); - unix_del_edges(fp); - } -} - static void unix_orphan_scm(struct sock *sk, struct sk_buff *skb) { scm_stat_del(sk, skb); From c550cea62c1e176629b1d814365b22aecfe6f4d5 Mon Sep 17 00:00:00 2001 From: Siddharth Chintamaneni Date: Sat, 14 Nov 2026 16:26:32 +0000 Subject: [PATCH 083/117] selftest: af_unix: Test scm_fds on dgram disconnect. Add dgram_disconnect_fdinfo in scm_rights.c verifying that scm_fds in /proc/self/fdinfo/ returns to 0 when a connected SOCK_DGRAM socket with queued SCM_RIGHTS datagrams disconnects via connect(AF_UNSPEC) or observes a dead peer in send(). Signed-off-by: Siddharth Chintamaneni Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261114162632.16346-3-sidchintamaneni@gmail.com Signed-off-by: Jakub Kicinski --- .../selftests/net/af_unix/scm_rights.c | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/tools/testing/selftests/net/af_unix/scm_rights.c b/tools/testing/selftests/net/af_unix/scm_rights.c index c165f250220a..19aa26c60f3b 100644 --- a/tools/testing/selftests/net/af_unix/scm_rights.c +++ b/tools/testing/selftests/net/af_unix/scm_rights.c @@ -395,4 +395,79 @@ TEST_F(scm_rights, mixed_lowpoint) close_sockets(6); } +static int count_scm_fds(struct __test_metadata *_metadata, int fd) +{ + char path[64], *line = NULL; + int scm_fds = -1, ret; + size_t unused = 0; + FILE *f; + + snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd); + + f = fopen(path, "r"); + ASSERT_NE(NULL, f); + + while (getline(&line, &unused, f) != -1) { + if (strncmp(line, "scm_fds:", 8)) + continue; + + ret = sscanf(line + 8, "%d", &scm_fds); + ASSERT_EQ(1, ret); + + break; + } + + free(line); + + ret = fclose(f); + ASSERT_EQ(0, ret); + + return scm_fds; +} + +TEST(dgram_disconnect_fdinfo) +{ + const FIXTURE_VARIANT(scm_rights) variant = { + .name = "UNIX ", + .type = SOCK_DGRAM, + }; + FIXTURE_DATA(scm_rights) self = {}; + struct sockaddr addr = { + .sa_family = AF_UNSPEC, + }; + int ret; + + ret = unshare(CLONE_NEWNET); + ASSERT_EQ(0, ret); + + create_socketpairs(_metadata, &self, &variant, 2); + + /* 1. Disconnect via connect(AF_UNSPEC) */ + __send_fd(_metadata, &self, &variant, 0, 0); + ASSERT_EQ(2, count_scm_fds(_metadata, self.fd[0])); + + ret = connect(self.fd[0], &addr, sizeof(addr.sa_family)); + ASSERT_EQ(0, ret); + ASSERT_EQ(0, count_scm_fds(_metadata, self.fd[0])); + + /* 2. Dead-peer disconnect via send() */ + __send_fd(_metadata, &self, &variant, 1, 1); + ASSERT_EQ(2, count_scm_fds(_metadata, self.fd[2])); + + ret = close(self.fd[3]); + ASSERT_EQ(0, ret); + + ret = send(self.fd[2], "x", 1, 0); + ASSERT_EQ(-1, ret); + ASSERT_EQ(ECONNREFUSED, errno); + ASSERT_EQ(0, count_scm_fds(_metadata, self.fd[2])); + + ret = close(self.fd[0]); + ASSERT_EQ(0, ret); + ret = close(self.fd[1]); + ASSERT_EQ(0, ret); + ret = close(self.fd[2]); + ASSERT_EQ(0, ret); +} + TEST_HARNESS_MAIN From d61480a622be17e5aa981f7ef4e6a0230b1d9049 Mon Sep 17 00:00:00 2001 From: Changyul Lee Date: Thu, 12 Nov 2026 23:03:23 -0500 Subject: [PATCH 084/117] net/mlx5e: Hold sync_lock while resetting VXLAN ports mlx5_vxlan_reset_to_default() walks vxlan->htable without sync_lock and calls mlx5_vxlan_del_port() for each user port. mlx5e_nic_disable() and mlx5e_uplink_rep_disable() call it after rtnl_unlock(), so the udp_tunnel_nic work can run mlx5e_vxlan_unset_port() at the same time. If that removes and frees the entry saved as the next one in hash_for_each_safe(), the walk then reads freed memory. Hold sync_lock over the whole walk, and add __mlx5_vxlan_del_port() for callers that already hold it. Fixes: c5eb51adf06b ("net/mlx5e: Fix VXLAN synchronization after function reload") Signed-off-by: Changyul Lee Reviewed-by: Tariq Toukan Link: https://patch.msgid.link/20261113040323.2090829-1-lcy8047@gmail.com Signed-off-by: Jakub Kicinski --- .../ethernet/mellanox/mlx5/core/lib/vxlan.c | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c index c2292cab4592..b953bbc4925c 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c @@ -121,25 +121,29 @@ int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port) return 0; } -int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port) +static int __mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port) { struct mlx5_vxlan_port *vxlanp; - int ret = 0; - mutex_lock(&vxlan->sync_lock); + lockdep_assert_held(&vxlan->sync_lock); vxlanp = vxlan_lookup_port(vxlan, port); - if (WARN_ON(!vxlanp)) { - ret = -ENOENT; - goto out_unlock; - } + if (WARN_ON(!vxlanp)) + return -ENOENT; hash_del_rcu(&vxlanp->hlist); synchronize_rcu(); mlx5_vxlan_core_del_port_cmd(vxlan->mdev, port); kfree(vxlanp); + return 0; +} -out_unlock: +int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port) +{ + int ret; + + mutex_lock(&vxlan->sync_lock); + ret = __mlx5_vxlan_del_port(vxlan, port); mutex_unlock(&vxlan->sync_lock); return ret; } @@ -185,12 +189,14 @@ void mlx5_vxlan_reset_to_default(struct mlx5_vxlan *vxlan) if (!mlx5_vxlan_allowed(vxlan)) return; + mutex_lock(&vxlan->sync_lock); hash_for_each_safe(vxlan->htable, bkt, tmp, vxlanp, hlist) { /* Don't delete default UDP port added by the HW. * Remove only user configured ports */ if (vxlanp->udp_port == IANA_VXLAN_UDP_PORT) continue; - mlx5_vxlan_del_port(vxlan, vxlanp->udp_port); + __mlx5_vxlan_del_port(vxlan, vxlanp->udp_port); } + mutex_unlock(&vxlan->sync_lock); } From ece404eac250fc4be7aa4cec82e8c248cca83c28 Mon Sep 17 00:00:00 2001 From: Arun Iyengar Date: Fri, 13 Nov 2026 17:13:40 +0000 Subject: [PATCH 085/117] net: stmmac: drop the rest of the frame when napi_build_skb() fails If napi_build_skb() fails on the first buffer of a frame that spans several descriptors, stmmac_rx() drops that buffer but goes on with the next descriptor of the same frame as if a new frame started there. The rest of the frame is then passed up the stack as a frame of its own. A frame spans several descriptors when it does not fit in the RX buffers of one descriptor. Mark the frame as errored instead, so that its remaining descriptors are discarded like those of a frame with a receive error. The frame is counted once in rx_dropped and once against the NAPI budget. Found while working on the sun8i EMAC jumbo frame series, where frames over 2032 bytes span several descriptors. Tested on an Orange Pi Zero2 (dwmac-sun8i, MTU 4070), w/ jumbo series and error injection. Fixes: ec222003bd94 ("net: stmmac: Prepare to add Split Header support") Cc: stable@vger.kernel.org Signed-off-by: Arun Iyengar Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20261113-stmmac-rx-skb-fail-v1-1-fcaae89f2d2c@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index ee63f5ecf570..9a9c44aab2e4 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -6045,7 +6045,7 @@ read_again: buf->page); buf->page = NULL; rx_dropped++; - count++; + error = 1; goto drain_data; } @@ -6081,7 +6081,7 @@ drain_data: if (likely(status & rx_not_ls)) goto read_again; if (!skb) - continue; + goto next; /* Got entire packet into SKB. Finish it. */ From 3d10dc3ae1f7c85375fb25f5e32bde0adb75089e Mon Sep 17 00:00:00 2001 From: Alexey Charkov Date: Fri, 13 Nov 2026 17:01:05 +0400 Subject: [PATCH 086/117] net: via-rhine: Stop the NIC on platform device shutdown Close a running interface on platform device shutdown, so that the chip stops its receive DMA before kexec hands its memory to the next kernel. Do it in the driver, as the platform (OF) variant lacks a .shutdown callback and nothing else stops it, unlike for PCI, where the core clears bus mastering ahead of kexec. Keep incoming frames from landing in receive buffers the old kernel had allocated: on a WonderMedia WM8950 board, broadcast traffic alone corrupts the next kernel at random points as it decompresses and boots, hanging about a third of kexec attempts early on, e.g. with "unrecognized/unsupported processor variant". Fixes: 2d283862dc62 ("net: via-rhine: add OF bus binding") Signed-off-by: Alexey Charkov Link: https://patch.msgid.link/20261113-vt8500-rhine-shutdown-v1-1-9448ea9548ec@gmail.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/via/via-rhine.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c index e56ebbdd428d..dbbbaf7f20ac 100644 --- a/drivers/net/ethernet/via/via-rhine.c +++ b/drivers/net/ethernet/via/via-rhine.c @@ -2461,6 +2461,17 @@ static void rhine_remove_one_platform(struct platform_device *pdev) free_netdev(dev); } +static void rhine_shutdown_platform(struct platform_device *pdev) +{ + struct net_device *dev = platform_get_drvdata(pdev); + + rtnl_lock(); + netif_device_detach(dev); + if (netif_running(dev)) + dev_close(dev); + rtnl_unlock(); +} + static void rhine_shutdown_pci(struct pci_dev *pdev) { struct net_device *dev = pci_get_drvdata(pdev); @@ -2580,6 +2591,7 @@ static struct pci_driver rhine_driver_pci = { static struct platform_driver rhine_driver_platform = { .probe = rhine_init_one_platform, .remove = rhine_remove_one_platform, + .shutdown = rhine_shutdown_platform, .driver = { .name = DRV_NAME, .of_match_table = rhine_of_tbl, From bcb42672751a8786dce871a35bde363b041cb2f7 Mon Sep 17 00:00:00 2001 From: Theodor Arsenij Larionov Trichkine Date: Mon, 16 Nov 2026 14:38:45 +0300 Subject: [PATCH 087/117] fou: reserve headroom before pushing the encap header ip_tunnel_xmit() and ip_md_tunnel_xmit() push the encap header before reserving headroom. A packet redirected into the tunnel (tc mirred, nft fwd/dup) keeps the headroom of its original device, so fou_build_udp() panics: kernel BUG at net/core/skbuff.c:214! Call Trace: skb_push+0xcc/0xf0 fou_build_udp+0x2f/0x380 gue_build_header+0xfa/0x150 ip_tunnel_xmit+0x87f/0x21c0 With a mirred mirror, the push overwrites the original packet instead. Reachable with CAP_NET_ADMIN in a user namespace. Reserve the headroom in fou_build_header() and gue_build_header(); GUE sizes and builds the header from one copy of the encap fields. The skb head may move, so reload inner_iph after ip_tunnel_encap() and read tnl_params, which points into the head for GRE with header_ops, before the call. sit's ipip6_tunnel_xmit() holds no head pointer across it. Fixes: 56328486539d ("net: Changes to ip_tunnel to support foo-over-udp encapsulation") Fixes: ac931d4cdec3 ("ipip,ip_tunnel,sit: Add FOU support for externally controlled ipip devices") Reported-by: Chengfeng Ye Closes: https://lore.kernel.org/netdev/20260801060115.3538849-1-nicoyip.dev@gmail.com/ Cc: stable@vger.kernel.org Signed-off-by: Theodor Arsenij Larionov Trichkine Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261116113845.166280-1-theodorlarionov@gmail.com Signed-off-by: Jakub Kicinski --- net/ipv4/fou_core.c | 19 +++++++++++++++---- net/ipv4/ip_tunnel.c | 6 ++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/net/ipv4/fou_core.c b/net/ipv4/fou_core.c index 5c3c8f55d057..bff4dc488def 100644 --- a/net/ipv4/fou_core.c +++ b/net/ipv4/fou_core.c @@ -1071,6 +1071,9 @@ static int fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, __be16 sport; int err; + if (skb_cow_head(skb, fou_encap_hlen(e))) + return -ENOMEM; + err = __fou_build_header(skb, e, protocol, &sport, type); if (err) return err; @@ -1083,16 +1086,24 @@ static int fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, static int gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, u8 *protocol, struct flowi4 *fl4) { - int type = e->flags & TUNNEL_ENCAP_FLAG_CSUM ? SKB_GSO_UDP_TUNNEL_CSUM : - SKB_GSO_UDP_TUNNEL; + struct ip_tunnel_encap encap = { + .flags = READ_ONCE(e->flags), + .sport = READ_ONCE(e->sport), + .dport = READ_ONCE(e->dport), + }; + int type = encap.flags & TUNNEL_ENCAP_FLAG_CSUM ? + SKB_GSO_UDP_TUNNEL_CSUM : SKB_GSO_UDP_TUNNEL; __be16 sport; int err; - err = __gue_build_header(skb, e, protocol, &sport, type); + if (skb_cow_head(skb, gue_encap_hlen(&encap))) + return -ENOMEM; + + err = __gue_build_header(skb, &encap, protocol, &sport, type); if (err) return err; - fou_build_udp(skb, e, fl4, protocol, sport); + fou_build_udp(skb, &encap, fl4, protocol, sport); return 0; } diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index 0875474a578a..1052af6245df 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -610,6 +610,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, if (ip_tunnel_encap(skb, &tun_info->encap, &proto, &fl4) < 0) goto tx_error; + inner_iph = (const struct iphdr *)skb_inner_network_header(skb); use_cache = ip_tunnel_dst_cache_usable(skb, tun_info); if (use_cache) @@ -753,6 +754,8 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, } tos = tnl_params->tos; + df = tnl_params->frag_off; + ttl = tnl_params->ttl; if (tos & 0x1) { tos &= ~0x1; if (payload_protocol == htons(ETH_P_IP)) { @@ -771,6 +774,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4) < 0) goto tx_error; + inner_iph = (const struct iphdr *)skb_inner_network_header(skb); if (connected && md) { use_cache = ip_tunnel_dst_cache_usable(skb, tun_info); @@ -803,7 +807,6 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, goto tx_error; } - df = tnl_params->frag_off; if (payload_protocol == htons(ETH_P_IP) && !tunnel->ignore_df) df |= (inner_iph->frag_off & htons(IP_DF)); @@ -825,7 +828,6 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, } tos = ip_tunnel_ecn_encap(tos, inner_iph, skb); - ttl = tnl_params->ttl; if (ttl == 0) { if (payload_protocol == htons(ETH_P_IP)) ttl = inner_iph->ttl; From f16d85cd3de9d0c761b74155b4cbe2f20d3dcf80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= Date: Sun, 15 Nov 2026 22:40:45 +0100 Subject: [PATCH 088/117] net: phy: realtek: fix listing of sysfs directory tree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On git master, listing the contents of sysfs produces an error: root@mateusz-debian:/sys# LANG=C find -iname foobar find: './module/realtek/drivers': Input/output error root@mateusz-debian:/sys# LANG=C ls -1 ./module/realtek/drivers ls: reading directory './module/realtek/drivers': Input/output error 'mdio_bus:Generic FE-GE Realtek PHY' 'mdio_bus:RTL8201CP Ethernet' 'mdio_bus:RTL8201F Fast Ethernet' 'mdio_bus:RTL8208 Fast Ethernet' 'mdio_bus:RTL8211B Gigabit Ethernet' [...] Investigation shows that the forward slash in the driver name is the culprit. Fix it. Cc: stable@vger.kernel.org Fixes: f0667918d5fc ("net: phy: realtek: add support for RTL8261D") Signed-off-by: Mateusz Jończyk Reviewed-by: Andrew Lunn Link: https://patch.msgid.link/20261115214045.3704-1-mat.jonczyk@o2.pl Signed-off-by: Jakub Kicinski --- drivers/net/phy/realtek/realtek_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index ca2d515b77b3..a39ad18382f2 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -3483,7 +3483,7 @@ static struct phy_driver realtek_drvs[] = { .write_mmd = genphy_write_mmd_unsupported, }, { PHY_ID_MATCH_EXACT(RTL_8261C_CG), - .name = "Realtek RTL8261C/D 10Gbps PHY", + .name = "Realtek RTL8261C_RTL8261D 10Gbps PHY", .probe = rtl8261x_probe, .config_init = rtl8261x_config_init, .get_features = rtl8261x_get_features, From 342e62fd34c2674e82bffc89cb5c7091924986d9 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Sat, 14 Nov 2026 12:12:47 +0100 Subject: [PATCH 089/117] tcp: purge Fast Open RST queue when listen() fails inet_csk_listen_start() moves the socket to TCP_LISTEN before calling ->get_port() and ->hash(). If one of them fails, the socket goes back to TCP_CLOSE without going through inet_csk_listen_stop(). If the socket was a Fast Open listener in a previous life, and was stopped with shutdown(SHUT_RD) or connect(AF_UNSPEC) while an accepted Fast Open child was still in TCP_SYN_RECV state, the request_sock of this child still points to the listener. A valid RST received for this child while the listener is transiently in TCP_LISTEN state makes reqsk_fastopen_remove() queue the request_sock in rskq_rst_head. When listen() fails, for instance with -EADDRINUSE because another SO_REUSEADDR socket started listening on the same port, nothing reclaims it: - __tcp_close(), tcp_disconnect() and tcp_abort() only call inet_csk_listen_stop() for sockets in TCP_LISTEN state. - A later successful listen() overwrites rskq_rst_head in reqsk_queue_alloc(). The request_sock is leaked, together with the reference it holds on the listener. Move the rskq_rst_head purge to a helper, and call it from the inet_csk_listen_start() error path as well, after the socket state has been set back to TCP_CLOSE: reqsk_fastopen_remove() checks sk_state under fastopenq.lock, so it either queued the request before the purge acquires the lock, or does not queue it at all. Reported-by: Sashiko AI review Closes: https://lore.kernel.org/netdev/179450310167.2199510.18107423940014989443@kernel.org/ Fixes: 0536fcc039a8 ("tcp: prepare fastopen code for upcoming listener changes") Signed-off-by: Eric Dumazet Reviewed-by: Hyunwoo Kim Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261114111247.21995-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski --- net/ipv4/inet_connection_sock.c | 35 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index d1c864b4252f..9a3b05edb62b 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1340,6 +1340,22 @@ static int inet_ulp_can_listen(const struct sock *sk) return 0; } +/* Free all the reqs queued in rskq_rst_head. */ +static void reqsk_fastopen_purge_rst(struct request_sock_queue *queue) +{ + struct request_sock *next, *req; + + spin_lock_bh(&queue->fastopenq.lock); + req = queue->fastopenq.rskq_rst_head; + queue->fastopenq.rskq_rst_head = NULL; + spin_unlock_bh(&queue->fastopenq.lock); + while (req != NULL) { + next = req->dl_next; + reqsk_put(req); + req = next; + } +} + static void reqsk_queue_alloc(struct request_sock_queue *queue) { queue->fastopenq.rskq_rst_head = NULL; @@ -1382,6 +1398,12 @@ int inet_csk_listen_start(struct sock *sk) } inet_sk_set_state(sk, TCP_CLOSE); + + /* A Fast Open child accepted before a previous shutdown() of this + * listener might have queued its request in rskq_rst_head while + * we were transiently in TCP_LISTEN state. + */ + reqsk_fastopen_purge_rst(&icsk->icsk_accept_queue); return err; } @@ -1486,7 +1508,7 @@ void inet_csk_listen_stop(struct sock *sk) { struct inet_connection_sock *icsk = inet_csk(sk); struct request_sock_queue *queue = &icsk->icsk_accept_queue; - struct request_sock *next, *req; + struct request_sock *req; /* Following specs, it would be better either to send FIN * (and enter FIN-WAIT-1, it is normal close) @@ -1542,16 +1564,7 @@ skip_child_forget: if (!has_current_bpf_ctx()) cond_resched(); } - /* Free all the reqs queued in rskq_rst_head. */ - spin_lock_bh(&queue->fastopenq.lock); - req = queue->fastopenq.rskq_rst_head; - queue->fastopenq.rskq_rst_head = NULL; - spin_unlock_bh(&queue->fastopenq.lock); - while (req != NULL) { - next = req->dl_next; - reqsk_put(req); - req = next; - } + reqsk_fastopen_purge_rst(queue); WARN_ON_ONCE(sk->sk_ack_backlog); } From cd057fd9c742cd37a210452c8ffff1777a3fd205 Mon Sep 17 00:00:00 2001 From: Omar Ramadan Date: Tue, 10 Nov 2026 21:05:32 +0000 Subject: [PATCH 090/117] amt: stop receiving before amt_dev_stop() tears down its state amt_dev_stop() clears amt->sk and waits in synchronize_net(), but the socket's sk_user_data still points at the device until udp_tunnel_sock_release() clears it afterwards, and nothing waits for readers then. An amt_rcv() that loads the pointer after the grace period can still be running once amt_dev_stop() has cancelled event_wq and torn down the relay's tunnels. A gateway can then queue a received Advertisement or Membership Query on event_wq again, and a relay can link a new tunnel from a Request and arm its gc_wq. Either work can then run after the device has been freed. Clear sk_user_data before the grace period, so synchronize_net() also waits for every amt_rcv() that can still see the device. Once it is NULL, amt_rcv() drops the packet and amt_err_lookup() ignores the ICMP error. The race is as old as amt_rcv(). From commit 3cf7203ca620 ("net/tunnel: wait until all sk_user_data reader finish before releasing the sock") until commit 72d3b9a4c2b1 ("udp_tunnel: Remove synchronize_rcu() in udp_tunnel_sock_release()."), udp_tunnel_sock_release() waited for those readers after clearing sk_user_data, which hid it. The wait was removed because each tunnel driver frees its fast-path state only after a grace period, but amt_rcv() does more than read that state: it queues work and links tunnels that amt_dev_stop() must already have stopped. Found by code inspection; not triggered. Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface") Fixes: 72d3b9a4c2b1 ("udp_tunnel: Remove synchronize_rcu() in udp_tunnel_sock_release().") Signed-off-by: Omar Ramadan Link: https://patch.msgid.link/20261110210538.217936-2-omar@blockcast.net Signed-off-by: Jakub Kicinski --- drivers/net/amt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 8b9fc3d11ece..989cabee0dfa 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -3072,9 +3072,14 @@ static int amt_dev_stop(struct net_device *dev) disable_delayed_work_sync(&amt->discovery_wq); cancel_delayed_work_sync(&amt->secret_wq); - /* shutdown */ + /* shutdown. Detach the receive path as well, so that once the + * grace period ends no amt_rcv() can still see the device and queue + * work after the teardown below. + */ sk = rtnl_dereference(amt->sk); RCU_INIT_POINTER(amt->sk, NULL); + if (sk) + rcu_assign_sk_user_data(sk, NULL); synchronize_net(); if (sk) udp_tunnel_sock_release(sk); From 5931fd2440de6ade0b0017d718635c6dceb0d95a Mon Sep 17 00:00:00 2001 From: Omar Ramadan Date: Tue, 10 Nov 2026 21:05:33 +0000 Subject: [PATCH 091/117] amt: fix use-after-free when a Membership Update re-arms a freed tunnel amt_update_handler() refreshes a relay tunnel's garbage-collection timer with mod_delayed_work() on a tunnel found by an RCU walk. A concurrent amt_tunnel_expire() can unlink and free that tunnel while the Update path still has the cached pointer, leaving gc_wq armed in freed memory. A tunnel can also be freed twice. amt_dev_stop() unlinks and frees tunnels without amt->lock, while amt_tunnel_expire() unlinks and frees them under it, so an ifdown that races a tunnel timeout can run list_del_rcu() and kfree_rcu() on the same tunnel twice. Group and source nodes have lifetime bugs of their own: - __amt_source_gc_work() frees a source, and amt_del_group() a group, after only cancel_delayed_work(), which does not wait for a timer work that is already running. amt_source_work() or amt_group_work() can then run on the freed node. - amt_source_work() reads snode->gnode and gnode->tunnel_list, and amt_group_work() gnode->tunnel_list, before taking tunnel->lock or the RCU read lock, so either can follow a pointer to a group or tunnel that has already been freed. - A timer work that waits for tunnel->lock while its node is deleted can then act on the deleted node: amt_source_work() destroys the source again, or amt_group_work() deletes the group again. Either decrements nr_sources or nr_groups a second time and unlinks, queues or frees the node a second time. Make amt_tunnel_expire() the only timeout-path freer. The Update path records last_seen under tunnel->lock, and expire reads it under tunnel->lock and, in the same section, either re-arms gc_wq from it or marks the tunnel dead for freeing, so an Update either keeps the tunnel alive or finds it dead. Protect the dead state with tunnel->lock so report handling cannot add multicast state after teardown begins. Device stop marks tunnels dead under amt->lock, unlinks them one at a time under it, synchronously cancels their work, and frees them after lockless readers have passed. Apply the same lifetime rules to group and source timer work: mark nodes dead under tunnel->lock, keep RCU held while workers resolve their parents, clear the parent pointers before a node is queued for freeing, defer node freeing, and synchronously cancel each node's timer before freeing that node. Park sources and groups through a gc_node of their own. A destroyed source used to reuse snode->node, its link into the group's hash; no lockless reader is known to follow it onto the GC list, so this is hardening. Run the deferred GC directly before freeing a tunnel so nodes are reclaimed promptly. Do not flush the GC work instead: flush_delayed_work() queues the work and waits for it to run, which needs a free amt_wq active slot, so amt_tunnel_expire() and the group GC, both amt_wq work, can deadlock once every slot is held by such a waiter. The cancel_delayed_work_sync() calls the GC makes need no slot: each takes a pending timer work off its timer or queue, or waits for a running one on a barrier that max_active does not count. Lifetime does not rest on that GC run, which misses nodes a concurrent run has already spliced off: it rests on kfree_rcu() and on the parent pointers being cleared, and the dead checks made, under tunnel->lock. Release the group timer's device reference on every exit. A node on a GC list is no longer charged to max_groups or max_sources, and unless a tunnel expires or the device stops, only the periodic GC drains the lists, every 30 seconds. Sources were already parked that way; groups, which went to kfree_rcu() before, now are too, so Report/Leave churn from one gateway could pin memory without bound in between. Count the nodes parked on both lists, under the one lock that now protects both, and when the count reaches AMT_GC_KICK (2048) queue the drain of both lists at once. A parked group still holds its AMT_HSIZE (256) source hash heads, so it is a kmalloc-4k object, and 2048 of them is about 8 MiB; the kick keeps the backlog near that instead of letting it grow for up to 30 seconds. A periodic drain that ends with that many parked again runs again at once rather than after the interval. This also bounds what amt_dev_stop() has to free in its drain under RTNL, and both drains now call cond_resched() after each node. A Request-only tunnel retains the original GMI timeout. Its last_seen stays 0, a value an Update never stores, and only a valid, authenticated Membership Update refreshes last_seen and gives the tunnel the longer lifetime: an Update whose encapsulated message fails ip_mc_check_igmp() or ipv6_mc_check_mld() no longer extends the tunnel. amt_tunnel_expire() reads jiffies once, so the re-arm delay comes from the value it compared. The Sashiko AI review of an earlier posting of this series pointed out the gc_wq re-arm, and reading amt_update_handler() against amt_tunnel_expire() and amt_dev_stop() confirms it. It is theoretical: it needs a Membership Update that has already found the tunnel under RCU to arrive while amt_tunnel_expire() is freeing that tunnel. Review of later postings raised the races in the group and source timer work, the amt_dev_stop() double free and the unbounded GC lists. I have not triggered any of them, so there is no trace to include. Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface") Fixes: bc54e49c140b ("amt: add multicast(IGMP) report message handler") Signed-off-by: Omar Ramadan Link: https://patch.msgid.link/20261110210538.217936-3-omar@blockcast.net Signed-off-by: Jakub Kicinski --- drivers/net/amt.c | 239 +++++++++++++++++++++++++++++++++++++++++----- include/net/amt.h | 18 ++++ 2 files changed, 232 insertions(+), 25 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 989cabee0dfa..70eabc523b2f 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -35,9 +35,19 @@ static struct workqueue_struct *amt_wq; static HLIST_HEAD(source_gc_list); -/* Lock for source_gc_list */ +/* Lock for source_gc_list, group_gc_list and the counts below */ static spinlock_t source_gc_lock; static struct delayed_work source_gc_wq; +static HLIST_HEAD(group_gc_list); +static struct delayed_work group_gc_wq; +/* Nodes parked on source_gc_list and group_gc_list, and the sources among + * them, so that a drain of either list can take its nodes off the count. + * Parked nodes are not charged to max_groups or max_sources, so + * Report/Leave churn could park them faster than the AMT_GC_INTERVAL tick + * frees them: once AMT_GC_KICK are parked, the drain runs at once. + */ +static unsigned int amt_gc_queued; +static unsigned int amt_gc_sources; static char *status_str[] = { "AMT_STATUS_INIT", "AMT_STATUS_SENT_DISCOVERY", @@ -88,11 +98,15 @@ static void __amt_source_gc_work(void) spin_lock_bh(&source_gc_lock); hlist_move_list(&source_gc_list, &gc_list); + amt_gc_queued -= amt_gc_sources; + amt_gc_sources = 0; spin_unlock_bh(&source_gc_lock); - hlist_for_each_entry_safe(snode, t, &gc_list, node) { - hlist_del_rcu(&snode->node); + hlist_for_each_entry_safe(snode, t, &gc_list, gc_node) { + cancel_delayed_work_sync(&snode->source_timer); + hlist_del_init(&snode->gc_node); kfree_rcu(snode, rcu); + cond_resched(); } } @@ -106,6 +120,62 @@ static void amt_source_gc_work(struct work_struct *work) spin_unlock_bh(&source_gc_lock); } +static void __amt_group_gc_work(void) +{ + struct amt_group_node *gnode; + struct hlist_head gc_list; + struct hlist_node *t; + + spin_lock_bh(&source_gc_lock); + hlist_move_list(&group_gc_list, &gc_list); + amt_gc_queued = amt_gc_sources; + spin_unlock_bh(&source_gc_lock); + + /* Group deletion queues all of its sources first. Reclaim them now + * rather than at the next periodic run; a source callback cannot + * reach a freed group because it resolves snode->gnode under RCU and + * the pointer is cleared before the source is queued. Call the GC + * here rather than flush source_gc_wq: a flush queues the work and + * waits for it to run, which needs a free amt_wq active slot, and + * when this runs on amt_wq every slot can be held by such waiters. + * The cancel_delayed_work_sync() calls in the GC need no slot: each + * takes a pending timer work off its timer or queue, or waits for a + * running one on a barrier that max_active does not count. + */ + __amt_source_gc_work(); + + hlist_for_each_entry_safe(gnode, t, &gc_list, gc_node) { + cancel_delayed_work_sync(&gnode->group_timer); + hlist_del_init(&gnode->gc_node); + kfree_rcu(gnode, rcu); + cond_resched(); + } +} + +static void amt_group_gc_work(struct work_struct *work) +{ + __amt_group_gc_work(); + + /* Run again at once if AMT_GC_KICK nodes were parked meanwhile: a + * kick that landed during the drain must not be pushed back to the + * interval. + */ + spin_lock_bh(&source_gc_lock); + mod_delayed_work(amt_wq, &group_gc_wq, + amt_gc_queued >= AMT_GC_KICK ? 0 : + msecs_to_jiffies(AMT_GC_INTERVAL)); + spin_unlock_bh(&source_gc_lock); +} + +/* Caller holds source_gc_lock and has just parked one node. This runs + * under tunnel->lock, often in softirq; mod_delayed_work() does not sleep. + */ +static void amt_gc_parked(void) +{ + if (++amt_gc_queued == AMT_GC_KICK) + mod_delayed_work(amt_wq, &group_gc_wq, 0); +} + static bool amt_addr_equal(union amt_addr *a, union amt_addr *b) { return !memcmp(a, b, sizeof(union amt_addr)); @@ -215,8 +285,13 @@ static struct amt_group_node *amt_lookup_group(struct amt_tunnel_list *tunnel, static void amt_destroy_source(struct amt_source_node *snode) { - struct amt_group_node *gnode = snode->gnode; struct amt_tunnel_list *tunnel; + struct amt_group_node *gnode; + + if (snode->dead) + return; + snode->dead = true; + gnode = snode->gnode; tunnel = gnode->tunnel_list; @@ -238,8 +313,11 @@ static void amt_destroy_source(struct amt_source_node *snode) hlist_del_init_rcu(&snode->node); tunnel->nr_sources--; gnode->nr_sources--; + WRITE_ONCE(snode->gnode, NULL); spin_lock_bh(&source_gc_lock); - hlist_add_head_rcu(&snode->node, &source_gc_list); + hlist_add_head(&snode->gc_node, &source_gc_list); + amt_gc_sources++; + amt_gc_parked(); spin_unlock_bh(&source_gc_lock); } @@ -249,6 +327,9 @@ static void amt_del_group(struct amt_dev *amt, struct amt_group_node *gnode) struct hlist_node *t; int i; + if (gnode->dead) + return; + gnode->dead = true; if (cancel_delayed_work(&gnode->group_timer)) dev_put(amt->dev); hlist_del_rcu(&gnode->node); @@ -266,10 +347,11 @@ static void amt_del_group(struct amt_dev *amt, struct amt_group_node *gnode) hlist_for_each_entry_safe(snode, t, &gnode->sources[i], node) amt_destroy_source(snode); - /* tunnel->lock was acquired outside of amt_del_group() - * But rcu_read_lock() was acquired too so It's safe. - */ - kfree_rcu(gnode, rcu); + WRITE_ONCE(gnode->tunnel_list, NULL); + spin_lock_bh(&source_gc_lock); + hlist_add_head(&gnode->gc_node, &group_gc_list); + amt_gc_parked(); + spin_unlock_bh(&source_gc_lock); } /* If a source timer expires with a router filter-mode for the group of @@ -282,13 +364,28 @@ static void amt_source_work(struct work_struct *work) struct amt_source_node *snode = container_of(to_delayed_work(work), struct amt_source_node, source_timer); - struct amt_group_node *gnode = snode->gnode; - struct amt_dev *amt = gnode->amt; struct amt_tunnel_list *tunnel; + struct amt_group_node *gnode; + struct amt_dev *amt; - tunnel = gnode->tunnel_list; - spin_lock_bh(&tunnel->lock); rcu_read_lock(); + gnode = READ_ONCE(snode->gnode); + if (!gnode) { + rcu_read_unlock(); + return; + } + amt = gnode->amt; + tunnel = READ_ONCE(gnode->tunnel_list); + if (!tunnel) { + rcu_read_unlock(); + return; + } + spin_lock_bh(&tunnel->lock); + if (snode->dead || gnode->dead) { + spin_unlock_bh(&tunnel->lock); + rcu_read_unlock(); + return; + } if (gnode->filter_mode == MCAST_INCLUDE) { amt_destroy_source(snode); if (!gnode->nr_sources) @@ -299,8 +396,8 @@ static void amt_source_work(struct work_struct *work) */ snode->status = AMT_SOURCE_STATUS_D_FWD; } - rcu_read_unlock(); spin_unlock_bh(&tunnel->lock); + rcu_read_unlock(); } static void amt_act_src(struct amt_tunnel_list *tunnel, @@ -368,6 +465,7 @@ static struct amt_source_node *amt_alloc_snode(struct amt_group_node *gnode, snode->status = AMT_SOURCE_STATUS_NONE; snode->flags = AMT_SOURCE_NEW; INIT_HLIST_NODE(&snode->node); + INIT_HLIST_NODE(&snode->gc_node); INIT_DELAYED_WORK(&snode->source_timer, amt_source_work); return snode; @@ -403,23 +501,31 @@ static void amt_group_work(struct work_struct *work) struct amt_group_node *gnode = container_of(to_delayed_work(work), struct amt_group_node, group_timer); - struct amt_tunnel_list *tunnel = gnode->tunnel_list; - struct amt_dev *amt = gnode->amt; + struct amt_tunnel_list *tunnel; struct amt_source_node *snode; bool delete_group = true; struct hlist_node *t; + struct amt_dev *amt; int i, buckets; + rcu_read_lock(); + tunnel = READ_ONCE(gnode->tunnel_list); + amt = gnode->amt; + if (!tunnel) + goto out; buckets = amt->hash_buckets; spin_lock_bh(&tunnel->lock); + if (gnode->dead) { + spin_unlock_bh(&tunnel->lock); + goto out; + } if (gnode->filter_mode == MCAST_INCLUDE) { /* Not Used */ spin_unlock_bh(&tunnel->lock); goto out; } - rcu_read_lock(); for (i = 0; i < buckets; i++) { hlist_for_each_entry_safe(snode, t, &gnode->sources[i], node) { @@ -436,9 +542,9 @@ static void amt_group_work(struct work_struct *work) amt_del_group(amt, gnode); else gnode->filter_mode = MCAST_INCLUDE; - rcu_read_unlock(); spin_unlock_bh(&tunnel->lock); out: + rcu_read_unlock(); dev_put(amt->dev); } @@ -479,6 +585,7 @@ static struct amt_group_node *amt_add_group(struct amt_dev *amt, gnode->tunnel_list = tunnel; gnode->filter_mode = MCAST_INCLUDE; INIT_HLIST_NODE(&gnode->node); + INIT_HLIST_NODE(&gnode->gc_node); INIT_DELAYED_WORK(&gnode->group_timer, amt_group_work); for (i = 0; i < amt->hash_buckets; i++) INIT_HLIST_HEAD(&gnode->sources[i]); @@ -1342,14 +1449,51 @@ static void amt_tunnel_expire(struct work_struct *work) struct amt_tunnel_list, gc_wq); struct amt_dev *amt = tunnel->amt; + unsigned long deadline, now; spin_lock_bh(&amt->lock); + spin_lock_bh(&tunnel->lock); + /* amt_dev_stop() has taken ownership of the teardown. */ + if (READ_ONCE(tunnel->dead)) { + spin_unlock_bh(&tunnel->lock); + spin_unlock_bh(&amt->lock); + return; + } + /* A Membership Update may have refreshed the tunnel after this work + * was queued. Re-arm from last_seen rather than letting + * amt_update_handler() re-arm gc_wq: this handler is then the only + * context that frees the tunnel on the timeout path; amt_dev_stop() + * still owns teardown during device shutdown. last_seen is read and + * dead is set under tunnel->lock, which the Update path holds while + * it refreshes last_seen, so an Update either keeps the tunnel alive + * or finds it dead. + */ + now = jiffies; + deadline = tunnel->last_seen; + /* No Update yet: the Request armed gc_wq for one GMI. */ + if (!deadline) + deadline = now; + else + deadline += msecs_to_jiffies(amt_gmi(amt)) * 3; + if (time_before(now, deadline)) { + mod_delayed_work(amt_wq, &tunnel->gc_wq, deadline - now); + spin_unlock_bh(&tunnel->lock); + spin_unlock_bh(&amt->lock); + return; + } + WRITE_ONCE(tunnel->dead, true); + spin_unlock_bh(&tunnel->lock); rcu_read_lock(); list_del_rcu(&tunnel->list); amt->nr_tunnels--; amt_clear_groups(tunnel); rcu_read_unlock(); spin_unlock_bh(&amt->lock); + /* Free now, rather than at the next periodic run, the nodes that + * amt_clear_groups() queued. Call the GC rather than flush + * group_gc_wq, as explained in __amt_group_gc_work(). + */ + __amt_group_gc_work(); kfree_rcu(tunnel, rcu); } @@ -2507,9 +2651,6 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb) if (tunnel->ip4 == saddr) { if ((nonce == tunnel->nonce && response_mac == tunnel->mac)) { - mod_delayed_work(amt_wq, &tunnel->gc_wq, - msecs_to_jiffies(amt_gmi(amt)) - * 3); goto report; } else { netdev_dbg(amt->dev, "Invalid MAC\n"); @@ -2535,6 +2676,18 @@ report: } spin_lock_bh(&tunnel->lock); + if (READ_ONCE(tunnel->dead)) { + spin_unlock_bh(&tunnel->lock); + return true; + } + /* Refresh liveness under tunnel->lock, where + * amt_tunnel_expire() reads it; 0 is kept for a tunnel no + * Update has refreshed. gc_wq is re-armed by + * amt_tunnel_expire() itself from last_seen, never from + * here, so this cannot re-queue the work of a tunnel that is + * being freed. + */ + tunnel->last_seen = jiffies ?: 1; amt_igmp_report_handler(amt, skb, tunnel); spin_unlock_bh(&tunnel->lock); @@ -2555,6 +2708,11 @@ report: } spin_lock_bh(&tunnel->lock); + if (READ_ONCE(tunnel->dead)) { + spin_unlock_bh(&tunnel->lock); + return true; + } + tunnel->last_seen = jiffies ?: 1; amt_mld_report_handler(amt, skb, tunnel); spin_unlock_bh(&tunnel->lock); @@ -3063,7 +3221,7 @@ static int amt_dev_open(struct net_device *dev) static int amt_dev_stop(struct net_device *dev) { struct amt_dev *amt = netdev_priv(dev); - struct amt_tunnel_list *tunnel, *tmp; + struct amt_tunnel_list *tunnel; struct sk_buff *skb; struct sock *sk; int i; @@ -3097,11 +3255,37 @@ static int amt_dev_stop(struct net_device *dev) amt->req_cnt = 0; WRITE_ONCE(amt->remote_ip, 0); - list_for_each_entry_safe(tunnel, tmp, &amt->tunnel_list, list) { - list_del_rcu(&tunnel->list); - amt->nr_tunnels--; + /* Mark every tunnel dead first, so a concurrent amt_tunnel_expire() + * sees ->dead and bails instead of freeing a tunnel in parallel; this + * path is then the sole freer. + */ + spin_lock_bh(&amt->lock); + list_for_each_entry(tunnel, &amt->tunnel_list, list) { + spin_lock_bh(&tunnel->lock); + WRITE_ONCE(tunnel->dead, true); + spin_unlock_bh(&tunnel->lock); + } + spin_unlock_bh(&amt->lock); + + /* Unlink one tunnel at a time with list_del_rcu() rather than splicing + * the list onto a local head: a lockless reader walking tunnel_list + * must always terminate at &amt->tunnel_list, never at a stack head. + */ + for (;;) { + spin_lock_bh(&amt->lock); + tunnel = list_first_entry_or_null(&amt->tunnel_list, + struct amt_tunnel_list, list); + if (tunnel) { + list_del_rcu(&tunnel->list); + amt->nr_tunnels--; + } + spin_unlock_bh(&amt->lock); + if (!tunnel) + break; + cancel_delayed_work_sync(&tunnel->gc_wq); amt_clear_groups(tunnel); + __amt_group_gc_work(); kfree_rcu(tunnel, rcu); } @@ -3475,6 +3659,9 @@ static int __init amt_init(void) INIT_DELAYED_WORK(&source_gc_wq, amt_source_gc_work); mod_delayed_work(amt_wq, &source_gc_wq, msecs_to_jiffies(AMT_GC_INTERVAL)); + INIT_DELAYED_WORK(&group_gc_wq, amt_group_gc_work); + mod_delayed_work(amt_wq, &group_gc_wq, + msecs_to_jiffies(AMT_GC_INTERVAL)); spin_unlock_bh(&source_gc_lock); return 0; @@ -3495,6 +3682,8 @@ static void __exit amt_fini(void) unregister_netdevice_notifier(&amt_notifier_block); cancel_delayed_work_sync(&source_gc_wq); __amt_source_gc_work(); + cancel_delayed_work_sync(&group_gc_wq); + __amt_group_gc_work(); destroy_workqueue(amt_wq); } module_exit(amt_fini); diff --git a/include/net/amt.h b/include/net/amt.h index 2846dde0cadc..dedf328d8415 100644 --- a/include/net/amt.h +++ b/include/net/amt.h @@ -240,6 +240,17 @@ struct amt_tunnel_list { u32 nr_sources; enum amt_status status; struct delayed_work gc_wq; + /* Last time a Membership Update refreshed this tunnel, under ->lock. + * gc_wq re-arms itself from this rather than being re-armed by the + * Update path, so the Update path cannot re-queue the work of a + * tunnel that amt_tunnel_expire() is freeing. + */ + unsigned long last_seen; + /* Set under amt->lock and tunnel->lock by whichever freer reaches the + * tunnel first; the other then leaves it alone, so the tunnel is freed + * exactly once. + */ + bool dead; __be16 source_port; __be32 ip4; __be32 nonce; @@ -275,6 +286,7 @@ enum amt_source_status { /* protected by gnode->lock */ struct amt_source_node { struct hlist_node node; + struct hlist_node gc_node; struct amt_group_node *gnode; struct delayed_work source_timer; union amt_addr source_addr; @@ -282,6 +294,8 @@ struct amt_source_node { #define AMT_SOURCE_OLD 0 #define AMT_SOURCE_NEW 1 u8 flags; + /* Protected by gnode->tunnel_list->lock. */ + bool dead; struct rcu_head rcu; }; @@ -295,7 +309,10 @@ struct amt_group_node { u32 nr_sources; struct amt_tunnel_list *tunnel_list; struct hlist_node node; + struct hlist_node gc_node; struct delayed_work group_timer; + /* Protected by tunnel_list->lock. */ + bool dead; struct rcu_head rcu; struct hlist_head sources[]; }; @@ -370,6 +387,7 @@ struct amt_dev { #define AMT_IPHDR_OPTS 4 #define AMT_IP6HDR_OPTS 8 #define AMT_GC_INTERVAL (30 * 1000) +#define AMT_GC_KICK 2048 #define AMT_MAX_GROUP 32 #define AMT_MAX_SOURCE 128 #define AMT_HSIZE_SHIFT 8 From b4fa7f8daed658c122bf0407dca9d5a26863f37c Mon Sep 17 00:00:00 2001 From: Omar Ramadan Date: Tue, 10 Nov 2026 21:05:34 +0000 Subject: [PATCH 092/117] amt: reject a gateway Query or Data from 0.0.0.0 before a relay is learned A gateway's amt_rcv() admits a Membership Query or Multicast Data message when "saddr != remote_ip" is false. remote_ip is 0 before discovery has learned a relay (and is reset to 0 by amt_dev_open(), by amt_dev_stop(), and when the gateway gives up after its Requests go unanswered), so a packet whose source is 0.0.0.0 would otherwise pass the equality check and could spoof a Query or inject multicast data. IPv4 input accepts a 0.0.0.0 source only on a limited broadcast or a link-local (224.0.0.0/24) multicast destination, so the sender has to be on the gateway's link. A forged Query must also carry the gateway's nonce. That is 0 until the next discovery tick re-randomizes it, because amt_dev_open() and the give-up path in amt_event_send_request() zero amt->nonce along with remote_ip. The Query handler then sets ready4 or ready6, mac and qi, and moves the gateway to AMT_STATUS_RECEIVED_QUERY. From there amt_event_send_discovery() returns early and amt_advertisement_handler() rejects every Advertisement, so discovery stays blocked until the Request retries run out and the device is back in AMT_STATUS_INIT with nonce 0. The Data check is defense in depth: amt_multicast_data_handler() already requires AMT_STATUS_SENT_UPDATE, which a gateway with no relay reaches only after such a forged Query, or in the short window in which the give-up path has cleared remote_ip but not yet reset the status. Reject both when no relay is learned: a 0 remote_ip must match nothing, so guard the check with !remote_ip. A Query is queued before its event worker processes it, so the relay address can also change in that window. Recheck the packet source against the current remote_ip in the handler and discard stale Queries. Discovery is unaffected because Relay Advertisements are validated against discovery_ip, not remote_ip. Found by code inspection while writing the IPv6 receive path for the AMT IPv6 outer transport; not triggered at runtime. The Sashiko AI review of an earlier posting pointed out the nonce condition, the blocked discovery and that the Data check is defense in depth. Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface") Fixes: 30e22a6ebca0 ("amt: use workqueue for gateway side message handling") Signed-off-by: Omar Ramadan Link: https://patch.msgid.link/20261110210538.217936-4-omar@blockcast.net Signed-off-by: Jakub Kicinski --- drivers/net/amt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 70eabc523b2f..13f689af6b51 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -2526,6 +2526,10 @@ static bool amt_membership_query_handler(struct amt_dev *amt, if (amtmq->reserved || amtmq->version) return true; + /* A deferred query may outlive a relay address change. */ + if (ip_hdr(skb)->saddr != READ_ONCE(amt->remote_ip)) + return true; + if (amtmq->nonce != amt->nonce) return true; @@ -3004,7 +3008,7 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb) } goto out; case AMT_MSG_MULTICAST_DATA: - if (saddr != remote_ip) { + if (!remote_ip || saddr != remote_ip) { netdev_dbg(amt->dev, "Invalid Relay IP\n"); err = true; goto drop; @@ -3015,7 +3019,7 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb) else goto out; case AMT_MSG_MEMBERSHIP_QUERY: - if (saddr != remote_ip) { + if (!remote_ip || saddr != remote_ip) { netdev_dbg(amt->dev, "Invalid Relay IP\n"); err = true; goto drop; From 144183ab4b053460ccbe7ca462e1b0527a617cb7 Mon Sep 17 00:00:00 2001 From: Omar Ramadan Date: Tue, 10 Nov 2026 21:05:35 +0000 Subject: [PATCH 093/117] amt: require an exact IPv4-sized IFLA_AMT_{LOCAL,DISCOVERY}_IP The netlink policy for IFLA_AMT_LOCAL_IP and IFLA_AMT_DISCOVERY_IP is an untyped entry with .len set to the size of an IPv4 address, which netlink validation treats as a minimum length only. Any longer payload passes, and nla_get_in_addr() then reads just its first four bytes: an iproute2 that puts a 16-byte IPv6 literal in one of these IPv4 attributes turns "2001:db8::" into 32.1.13.184, and the device is created with an address the user never asked for. Use NLA_POLICY_EXACT_LEN(sizeof(__be32)) for both, so every payload that is not exactly four bytes long is refused with a standard extack instead of being truncated. The range check this expands to fails the attribute even under the liberal parsing rtnetlink applies to IFLA_INFO_DATA. amt_get_size() and amt_fill_info() already emit exactly four bytes for these attributes. IFLA_AMT_REMOTE_IP is only ever reported, never read from a request, so it is left unchanged. Triggered while writing a selftest for the AMT IPv6 outer transport: an iproute2 without the IPv6 attributes put all 16 bytes of "discovery 2001:db8:a::2" into IFLA_AMT_DISCOVERY_IP. On a stock kernel the command exited 0 with no error or warning, and the device came up as an IPv4 gateway with discovery address 32.1.13.184, the first four bytes. There is no oops or trace; the symptom is the silently wrong address, which fooled the selftest's capability probe. Fixes: b9022b53adad ("amt: add control plane of amt interface") Signed-off-by: Omar Ramadan Link: https://patch.msgid.link/20261110210538.217936-5-omar@blockcast.net Signed-off-by: Jakub Kicinski --- drivers/net/amt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 13f689af6b51..716451a4f250 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -3358,9 +3358,9 @@ static const struct nla_policy amt_policy[IFLA_AMT_MAX + 1] = { [IFLA_AMT_RELAY_PORT] = { .type = NLA_U16 }, [IFLA_AMT_GATEWAY_PORT] = { .type = NLA_U16 }, [IFLA_AMT_LINK] = { .type = NLA_U32 }, - [IFLA_AMT_LOCAL_IP] = { .len = sizeof_field(struct iphdr, daddr) }, + [IFLA_AMT_LOCAL_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)), [IFLA_AMT_REMOTE_IP] = { .len = sizeof_field(struct iphdr, daddr) }, - [IFLA_AMT_DISCOVERY_IP] = { .len = sizeof_field(struct iphdr, daddr) }, + [IFLA_AMT_DISCOVERY_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)), [IFLA_AMT_MAX_TUNNELS] = { .type = NLA_U32 }, }; From ee58008edb995de5f19222e4aa9a2acf74e80185 Mon Sep 17 00:00:00 2001 From: Omar Ramadan Date: Tue, 10 Nov 2026 21:05:36 +0000 Subject: [PATCH 094/117] amt: make pre-query report drops visible A gateway cannot forward an IGMP or MLD report until it has received the relay's Membership Query for that family. The Query supplies the response MAC the Update echoes, so dropping an early report is required, but doing so silently leaves operators with a dark multicast path and no indication why the join never happened. Emit a family-specific debug message before taking the drop path. tx_dropped could not show these drops either: amt_dev_xmit() reaches the same tx_dropped increment after amt_send_membership_update() has handed the report to the tunnel, so in gateway mode every forwarded report was also counted as a drop. Return NETDEV_TX_OK directly once the report has been sent, so a report the tunnel accepted is no longer counted in tx_dropped. The device is LLTX, so amt_dev_xmit() can run on several CPUs at once; use DEV_STATS_INC() for tx_dropped and tx_errors, there and in the control-message senders that update the same counters, so concurrent increments are not lost. Found by code inspection while debugging an IPv6-in-IPv6 forwarding failure in a selftest for the AMT IPv6 outer transport. This drop can leave one address family dark, so it was a suspect, but that was not confirmed: the failure was later traced to the selftest, which sent a single datagram without waiting for the relay's multicast routes to converge. The drop has not been observed in production, and there is no oops or trace. The Sashiko AI review of an earlier posting found the tx_dropped miscount and the non-atomic counter updates. Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface") Signed-off-by: Omar Ramadan Link: https://patch.msgid.link/20261110210538.217936-6-omar@blockcast.net Signed-off-by: Jakub Kicinski --- drivers/net/amt.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 716451a4f250..b7be685d8401 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -735,7 +735,7 @@ static void amt_send_discovery(struct amt_dev *amt) IPPROTO_UDP, 0, amt->stream_dev->ifindex); if (IS_ERR(rt)) { - amt->dev->stats.tx_errors++; + DEV_STATS_INC(amt->dev, tx_errors); goto out; } @@ -745,7 +745,7 @@ static void amt_send_discovery(struct amt_dev *amt) skb = netdev_alloc_skb_ip_align(amt->dev, len); if (!skb) { ip_rt_put(rt); - amt->dev->stats.tx_errors++; + DEV_STATS_INC(amt->dev, tx_errors); goto out; } @@ -790,7 +790,7 @@ static void amt_send_discovery(struct amt_dev *amt) ip_send_check(iph); err = ip_local_out(amt->net, sk, skb); if (unlikely(net_xmit_eval(err))) - amt->dev->stats.tx_errors++; + DEV_STATS_INC(amt->dev, tx_errors); amt_update_gw_status(amt, AMT_STATUS_SENT_DISCOVERY, true); out: @@ -826,7 +826,7 @@ static void amt_send_request(struct amt_dev *amt, bool v6) IPPROTO_UDP, 0, amt->stream_dev->ifindex); if (IS_ERR(rt)) { - amt->dev->stats.tx_errors++; + DEV_STATS_INC(amt->dev, tx_errors); goto out; } @@ -836,7 +836,7 @@ static void amt_send_request(struct amt_dev *amt, bool v6) skb = netdev_alloc_skb_ip_align(amt->dev, len); if (!skb) { ip_rt_put(rt); - amt->dev->stats.tx_errors++; + DEV_STATS_INC(amt->dev, tx_errors); goto out; } @@ -883,7 +883,7 @@ static void amt_send_request(struct amt_dev *amt, bool v6) ip_send_check(iph); err = ip_local_out(amt->net, sk, skb); if (unlikely(net_xmit_eval(err))) - amt->dev->stats.tx_errors++; + DEV_STATS_INC(amt->dev, tx_errors); out: rcu_read_unlock(); @@ -905,7 +905,7 @@ static void amt_send_igmp_gq(struct amt_dev *amt, skb_pull(skb, sizeof(struct ethhdr)); if (amt_send_membership_query(amt, skb, tunnel, false)) { - amt->dev->stats.tx_dropped++; + DEV_STATS_INC(amt->dev, tx_dropped); kfree_skb(skb); } } @@ -949,7 +949,7 @@ static struct sk_buff *amt_build_mld_gq(struct amt_dev *amt) if (ipv6_dev_get_saddr(amt->net, amt->dev, &ip6h->daddr, 0, &ip6h->saddr)) { - amt->dev->stats.tx_errors++; + DEV_STATS_INC(amt->dev, tx_errors); kfree_skb(skb); return NULL; } @@ -993,7 +993,7 @@ static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel) skb_pull(skb, sizeof(struct ethhdr)); if (amt_send_membership_query(amt, skb, tunnel, true)) { - amt->dev->stats.tx_dropped++; + DEV_STATS_INC(amt->dev, tx_dropped); kfree_skb(skb); } } @@ -1353,7 +1353,7 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) group.ip6 = ipv6_hdr(skb)->daddr; #endif } else { - dev->stats.tx_errors++; + DEV_STATS_INC(dev, tx_errors); goto free; } @@ -1366,12 +1366,21 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) /* Gateway only passes IGMP/MLD packets */ if (!report) goto free; + /* A validated report can only be forwarded after the relay's + * family-specific Membership Query supplies the state echoed + * by the Membership Update. Log this readiness failure before + * the shared drop path accounts it. + */ if ((!v6 && !READ_ONCE(amt->ready4)) || - (v6 && !READ_ONCE(amt->ready6))) + (v6 && !READ_ONCE(amt->ready6))) { + netdev_dbg(dev, "drop %s report: waiting for Membership Query\n", + v6 ? "MLD" : "IGMP"); goto free; + } if (amt_send_membership_update(amt, skb, v6)) goto free; - goto unlock; + /* Sent: the tunnel consumed the skb. Not a drop. */ + return NETDEV_TX_OK; } else if (amt->mode == AMT_MODE_RELAY) { if (!data) goto free; @@ -1400,8 +1409,7 @@ found: return NETDEV_TX_OK; free: dev_kfree_skb(skb); -unlock: - dev->stats.tx_dropped++; + DEV_STATS_INC(dev, tx_dropped); return NETDEV_TX_OK; } @@ -2776,7 +2784,7 @@ static void amt_send_advertisement(struct amt_dev *amt, __be32 nonce, IPPROTO_UDP, 0, amt->stream_dev->ifindex); if (IS_ERR(rt)) { - amt->dev->stats.tx_errors++; + DEV_STATS_INC(amt->dev, tx_errors); goto out; } @@ -2786,7 +2794,7 @@ static void amt_send_advertisement(struct amt_dev *amt, __be32 nonce, skb = netdev_alloc_skb_ip_align(amt->dev, len); if (!skb) { ip_rt_put(rt); - amt->dev->stats.tx_errors++; + DEV_STATS_INC(amt->dev, tx_errors); goto out; } @@ -2832,7 +2840,7 @@ static void amt_send_advertisement(struct amt_dev *amt, __be32 nonce, ip_send_check(iph); err = ip_local_out(amt->net, sk, skb); if (unlikely(net_xmit_eval(err))) - amt->dev->stats.tx_errors++; + DEV_STATS_INC(amt->dev, tx_errors); out: rcu_read_unlock(); From 8ddd3a1c207f2f777f01d02110e556a187da73c6 Mon Sep 17 00:00:00 2001 From: Omar Ramadan Date: Tue, 10 Nov 2026 21:05:37 +0000 Subject: [PATCH 095/117] amt: create relay tunnels only from authenticated Updates An AMT Request has an unauthenticated, spoofable source address. Allocating tunnel state from that path allowed spoofed Requests to consume tunnel slots or overwrite the nonce and MAC of an established gateway. Keep Requests stateless by deriving the Query MAC from the source address, source port, nonce, and current secret, and retain four secret generations so a gateway can renew its MAC across rotations. Authenticate the Membership Update before decapsulation, and create or refresh tunnel state only once ip_mc_check_igmp() or ipv6_mc_check_mld() has accepted the encapsulated message. Key verified state by the address/port endpoint, enforce global and per-source limits, and silently reject an endpoint that cannot be admitted: withhold the Query rather than send ICMP Host Unreachable to a source address nothing has authenticated yet. A MAC is now accepted only for a bounded time after the Query that carried it. Before, a tunnel copied the secret when a Request created it and never saw it rotate, so its MAC never expired. Now the secret rotates every 60 seconds and four generations are kept, so a MAC is accepted for 180 to 240 seconds. RFC 7450 section 5.2.3.5.4 has a gateway start a query timer when it accepts a Query, with a duration it SHOULD compute from the Query's QQIC (125 seconds here), and section 5.2.3.5.5 has it send a new Request when that timer expires, so a gateway that times its next Request from QQIC renews its MAC inside the window. The in-tree gateway re-Requests every two seconds while its Requests are answered. A gateway that never sends another Request kept working before; now its Updates are dropped as Invalid MAC once the window has passed. So is the first Update after a new join from a gateway that, as section 5.2.3.5.4 also allows, uses a longer timer while it has no group subscriptions to report: it is dropped until that gateway's next Request. Which MACs are accepted changes too. Before, an Update had to carry the nonce and MAC of the latest Request from its address; now any pair minted for its address and port within the window is accepted. The MAC never covered the encapsulated report, so this changes only how long a pair seen by an on-path observer stays usable: off-path senders still cannot produce a valid pair. The secret is now seeded before amt_socket_create() enables the receive path. It was seeded after the socket was created since commit b9022b53adad ("amt: add control plane of amt interface"), when there was no receive path yet, and commit cbc21dc1cfe9 ("amt: add data plane of amt interface") added amt_rcv() and the per-tunnel copy of the key without moving it. Since then a Request that arrived during amt_dev_open() could get a tunnel whose MAC used an all-zero key (on the first open) or the previous key for the tunnel's whole life. amt_update_tunnel() retries once when it finds its tunnel dead, and the lookup skips dead tunnels, so an Update that races amt_tunnel_expire() creates the replacement instead of being dropped. The Request path's per-source count and the re-check under amt->lock in amt_tunnel_get_or_create() skip them too. Every tunnel is now created by an Update, which stamps last_seen, so amt_tunnel_expire() no longer treats a last_seen of 0 as never refreshed. amt_tunnel_get_or_create() also rechecks netif_running() under amt->lock before it links a tunnel. dev_close() clears the running state before it calls amt_dev_stop(), which drains the list under amt->lock, so an Update still being received while the device goes down cannot link a tunnel after the drain. Every Membership Update, forged ones included, reads the secret generations to check its MAC. Their writers hold amt->lock and update them inside a seqcount, amt->key_seq. The Update path copies them in a key_seq read loop, so reading them takes amt->lock only on PREEMPT_RT, to wait for a writer. Keying by address and port lets one address hold several tunnels; before this patch the Request path looked tunnels up by address alone, so an address normally held only one. amt_max_tunnels_per_src() bounds that at an eighth of max_tunnels, at least one tunnel and at most AMT_MAX_TUNNELS_PER_SRC (16): 16 at the default 128 slots, 2 at 16. One address then holds at most an eighth of a table of eight or more slots, while gateways behind NAT still get several tunnels once the table has 16 or more slots. A configurable limit needs new uAPI, so it is left for net-next. Found by code inspection against RFC 7450; not triggered at runtime. The Sashiko AI review of an earlier posting pointed out the undocumented behaviour changes and that a fixed per-source cap let one address fill a small table. Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface") Signed-off-by: Omar Ramadan Link: https://patch.msgid.link/20261110210538.217936-7-omar@blockcast.net Signed-off-by: Jakub Kicinski --- drivers/net/amt.c | 413 ++++++++++++++++++++++++++++++++-------------- include/net/amt.h | 14 +- 2 files changed, 298 insertions(+), 129 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index b7be685d8401..b145ed3ca6ed 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -700,14 +700,6 @@ static void __amt_update_relay_status(struct amt_tunnel_list *tunnel, tunnel->status = status; } -static void amt_update_relay_status(struct amt_tunnel_list *tunnel, - enum amt_status status, bool validate) -{ - spin_lock_bh(&tunnel->lock); - __amt_update_relay_status(tunnel, status, validate); - spin_unlock_bh(&tunnel->lock); -} - static void amt_send_discovery(struct amt_dev *amt) { struct amt_header_discovery *amtd; @@ -891,11 +883,16 @@ out: static bool amt_send_membership_query(struct amt_dev *amt, struct sk_buff *skb, - struct amt_tunnel_list *tunnel, + __be32 daddr, __be16 dport, + __be32 nonce, u64 mac, bool v6); -static void amt_send_igmp_gq(struct amt_dev *amt, - struct amt_tunnel_list *tunnel) +/* The destination is passed by value rather than as a tunnel: a Request is + * unauthenticated, so no tunnel state is created or changed for it - see + * amt_request_handler(). + */ +static void amt_send_igmp_gq(struct amt_dev *amt, __be32 daddr, __be16 dport, + __be32 nonce, u64 mac) { struct sk_buff *skb; @@ -904,7 +901,8 @@ static void amt_send_igmp_gq(struct amt_dev *amt, return; skb_pull(skb, sizeof(struct ethhdr)); - if (amt_send_membership_query(amt, skb, tunnel, false)) { + if (amt_send_membership_query(amt, skb, daddr, dport, nonce, mac, + false)) { DEV_STATS_INC(amt->dev, tx_dropped); kfree_skb(skb); } @@ -983,7 +981,8 @@ static struct sk_buff *amt_build_mld_gq(struct amt_dev *amt) return skb; } -static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel) +static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport, + __be32 nonce, u64 mac) { struct sk_buff *skb; @@ -992,13 +991,15 @@ static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel) return; skb_pull(skb, sizeof(struct ethhdr)); - if (amt_send_membership_query(amt, skb, tunnel, true)) { + if (amt_send_membership_query(amt, skb, daddr, dport, nonce, mac, + true)) { DEV_STATS_INC(amt->dev, tx_dropped); kfree_skb(skb); } } #else -static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel) +static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport, + __be32 nonce, u64 mac) { } #endif @@ -1032,7 +1033,16 @@ static void amt_secret_work(struct work_struct *work) secret_wq); spin_lock_bh(&amt->lock); - get_random_bytes(&amt->key, sizeof(siphash_key_t)); + write_seqcount_begin(&amt->key_seq); + /* Keep three previous generations for a 180-240s MAC lifetime. + * Its 180s floor exceeds the advertised QQIC (amt->qi, 125s), + * allowing the gateway to renew its MAC with a periodic Request. + */ + amt->key[3] = amt->key[2]; + amt->key[2] = amt->key[1]; + amt->key[1] = amt->key[0]; + get_random_bytes(&amt->key[0], sizeof(siphash_key_t)); + write_seqcount_end(&amt->key_seq); spin_unlock_bh(&amt->lock); mod_delayed_work(amt_wq, &amt->secret_wq, msecs_to_jiffies(AMT_SECRET_TIMEOUT)); @@ -1232,9 +1242,16 @@ static void amt_send_multicast_data(struct amt_dev *amt, 0); } +/* Send a Membership Query in reply to an unauthenticated Request. + * + * No per-source state is read or created: the gateway echoes the nonce and + * the keyed MAC in its Membership Update, where the MAC is recomputed, so + * everything this needs is passed by value. + */ static bool amt_send_membership_query(struct amt_dev *amt, struct sk_buff *skb, - struct amt_tunnel_list *tunnel, + __be32 daddr, __be16 dport, + __be32 nonce, u64 mac, bool v6) { struct amt_header_membership_query *amtmq; @@ -1255,13 +1272,13 @@ static bool amt_send_membership_query(struct amt_dev *amt, skb_reset_inner_headers(skb); memset(&fl4, 0, sizeof(struct flowi4)); fl4.flowi4_oif = amt->stream_dev->ifindex; - fl4.daddr = tunnel->ip4; + fl4.daddr = daddr; fl4.saddr = amt->local_ip; fl4.flowi4_dscp = inet_dsfield_to_dscp(AMT_TOS); fl4.flowi4_proto = IPPROTO_UDP; rt = ip_route_output_key(amt->net, &fl4); if (IS_ERR(rt)) { - netdev_dbg(amt->dev, "no route to %pI4\n", &tunnel->ip4); + netdev_dbg(amt->dev, "no route to %pI4\n", &daddr); return true; } @@ -1271,8 +1288,8 @@ static bool amt_send_membership_query(struct amt_dev *amt, amtmq->reserved = 0; amtmq->l = 0; amtmq->g = 0; - amtmq->nonce = tunnel->nonce; - amtmq->response_mac = tunnel->mac; + amtmq->nonce = nonce; + amtmq->response_mac = mac; if (!v6) skb_set_inner_protocol(skb, htons(ETH_P_IP)); @@ -1285,11 +1302,10 @@ static bool amt_send_membership_query(struct amt_dev *amt, ip4_dst_hoplimit(&rt->dst), 0, amt->relay_port, - tunnel->source_port, + dport, false, false, 0); - amt_update_relay_status(tunnel, AMT_STATUS_SENT_QUERY, true); return false; } @@ -1477,12 +1493,7 @@ static void amt_tunnel_expire(struct work_struct *work) * or finds it dead. */ now = jiffies; - deadline = tunnel->last_seen; - /* No Update yet: the Request armed gc_wq for one GMI. */ - if (!deadline) - deadline = now; - else - deadline += msecs_to_jiffies(amt_gmi(amt)) * 3; + deadline = tunnel->last_seen + msecs_to_jiffies(amt_gmi(amt)) * 3; if (time_before(now, deadline)) { mod_delayed_work(amt_wq, &tunnel->gc_wq, deadline - now); spin_unlock_bh(&tunnel->lock); @@ -2630,16 +2641,165 @@ static bool amt_membership_query_handler(struct amt_dev *amt, return false; } +/* The live tunnel of the gateway endpoint @saddr:@sport, or NULL. Dead + * tunnels are skipped, so the retry in amt_update_tunnel() after losing a + * race with amt_tunnel_expire() creates the replacement. + */ +static struct amt_tunnel_list *amt_tunnel_lookup(struct amt_dev *amt, + __be32 saddr, __be16 sport) +{ + struct amt_tunnel_list *tunnel; + + list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list) { + if (tunnel->ip4 == saddr && tunnel->source_port == sport && + !READ_ONCE(tunnel->dead)) + return tunnel; + } + return NULL; +} + +/* Most tunnels one source address may hold: an eighth of the table, at + * least one and at most AMT_MAX_TUNNELS_PER_SRC. + */ +static u32 amt_max_tunnels_per_src(const struct amt_dev *amt) +{ + return clamp_t(u32, amt->max_tunnels / 8, 1, + AMT_MAX_TUNNELS_PER_SRC); +} + +/* Look up the tunnel for a source whose Membership Update has already been + * authenticated, creating it on first contact. + * + * This is the only place tunnel state is allocated, so amt->max_tunnels + * bounds the number of *verified* gateways rather than the number of + * unverified Requests anyone can send. A per-source cap derived from the + * table, amt_max_tunnels_per_src(), additionally limits the tunnels one + * verified source address may hold. + */ +static struct amt_tunnel_list *amt_tunnel_get_or_create(struct amt_dev *amt, + __be32 saddr, + __be16 sport) +{ + struct amt_tunnel_list *tunnel; + u32 per_src = 0; + int i; + + tunnel = amt_tunnel_lookup(amt, saddr, sport); + if (tunnel) + return tunnel; + + spin_lock_bh(&amt->lock); + + /* Re-check under the lock in case a concurrent Update won the race, and + * count how many tunnels this source already holds on the same walk. + * Skip dead tunnels, as amt_tunnel_lookup() and the Request path do, so + * a tunnel being freed neither stands in for its endpoint nor counts + * against its address. + */ + list_for_each_entry(tunnel, &amt->tunnel_list, list) { + if (tunnel->ip4 != saddr || READ_ONCE(tunnel->dead)) + continue; + if (tunnel->source_port == sport) { + spin_unlock_bh(&amt->lock); + return tunnel; + } + per_src++; + } + + if (amt->nr_tunnels >= amt->max_tunnels || + per_src >= amt_max_tunnels_per_src(amt)) { + spin_unlock_bh(&amt->lock); + return NULL; + } + + if (!netif_running(amt->dev)) { + spin_unlock_bh(&amt->lock); + return NULL; + } + + tunnel = kzalloc(sizeof(*tunnel) + + (sizeof(struct hlist_head) * amt->hash_buckets), + GFP_ATOMIC); + if (!tunnel) { + spin_unlock_bh(&amt->lock); + return NULL; + } + + tunnel->source_port = sport; + tunnel->ip4 = saddr; + tunnel->amt = amt; + spin_lock_init(&tunnel->lock); + for (i = 0; i < amt->hash_buckets; i++) + INIT_HLIST_HEAD(&tunnel->groups[i]); + + tunnel->last_seen = jiffies; + INIT_DELAYED_WORK(&tunnel->gc_wq, amt_tunnel_expire); + __amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_UPDATE, false); + + /* Publish only once the entry is fully initialised. */ + list_add_tail_rcu(&tunnel->list, &amt->tunnel_list); + amt->nr_tunnels++; + mod_delayed_work(amt_wq, &tunnel->gc_wq, + msecs_to_jiffies(amt_gmi(amt)) * 3); + spin_unlock_bh(&amt->lock); + + return tunnel; +} + +/* Apply a valid, authenticated Membership Update to the tunnel of its + * endpoint, creating the tunnel on first contact. Returns false if the + * Update is dropped. + * + * amt_tunnel_expire() reads last_seen and sets dead under tunnel->lock, so + * the refresh below either keeps the tunnel alive or finds it dead. A + * tunnel that expired between the lookup and the lock is skipped by the + * second amt_tunnel_get_or_create() call, which creates its replacement. + */ +static bool amt_update_tunnel(struct amt_dev *amt, struct sk_buff *skb, + __be32 saddr, __be16 sport, bool v6) +{ + struct amt_tunnel_list *tunnel; + int i; + + for (i = 0; i < 2; i++) { + tunnel = amt_tunnel_get_or_create(amt, saddr, sport); + if (!tunnel) + return false; + + spin_lock_bh(&tunnel->lock); + if (!READ_ONCE(tunnel->dead)) { + /* gc_wq is re-armed by amt_tunnel_expire() itself + * from last_seen, never from here, so this cannot + * re-queue the work of a tunnel that is being freed. + */ + tunnel->last_seen = jiffies; +#if IS_ENABLED(CONFIG_IPV6) + if (v6) + amt_mld_report_handler(amt, skb, tunnel); + else +#endif + amt_igmp_report_handler(amt, skb, tunnel); + spin_unlock_bh(&tunnel->lock); + return true; + } + spin_unlock_bh(&tunnel->lock); + } + return false; +} + static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb) { struct amt_header_membership_update *amtmu; - struct amt_tunnel_list *tunnel; + bool verified = false; + siphash_key_t key[4]; + int len, hdr_size, i; struct ethhdr *eth; struct iphdr *iph; - int len, hdr_size; + unsigned int seq; u64 response_mac; __be32 saddr; __be32 nonce; + __be16 sport; saddr = ip_hdr(skb)->saddr; @@ -2653,27 +2813,45 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb) nonce = amtmu->nonce; response_mac = amtmu->response_mac; + /* Snapshot the tunnel endpoint port before the encap is stripped. */ + sport = udp_hdr(skb)->source; + /* Recompute the MAC handed out in the Membership Query. Four live + * secrets cover 180-240s, exceeding the advertised QQIC (amt->qi, + * 125s), so a periodic Request can renew the MAC before it expires. + * Authenticate before decapsulation or allocating tunnel state. + */ + do { + seq = read_seqcount_begin(&amt->key_seq); + for (i = 0; i < ARRAY_SIZE(key); i++) + key[i] = amt->key[i]; + } while (read_seqcount_retry(&amt->key_seq, seq)); + + for (i = 0; i < ARRAY_SIZE(key); i++) { + u64 mac = siphash_3u32((__force u32)saddr, + (__force u32)sport, + (__force u32)nonce, + &key[i]) >> 16; + + if (response_mac == mac) { + verified = true; + break; + } + } + + if (!verified) { + netdev_dbg(amt->dev, "Invalid MAC\n"); + return true; + } + + /* Create or refresh a tunnel only once the encapsulated message has + * passed ip_mc_check_igmp() or ipv6_mc_check_mld(). + */ if (iptunnel_pull_header(skb, hdr_size, skb->protocol, false)) return true; skb_reset_network_header(skb); - list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list) { - if (tunnel->ip4 == saddr) { - if ((nonce == tunnel->nonce && - response_mac == tunnel->mac)) { - goto report; - } else { - netdev_dbg(amt->dev, "Invalid MAC\n"); - return true; - } - } - } - - return true; - -report: if (!pskb_may_pull(skb, sizeof(*iph))) return true; @@ -2687,21 +2865,8 @@ report: return true; } - spin_lock_bh(&tunnel->lock); - if (READ_ONCE(tunnel->dead)) { - spin_unlock_bh(&tunnel->lock); + if (!amt_update_tunnel(amt, skb, saddr, sport, false)) return true; - } - /* Refresh liveness under tunnel->lock, where - * amt_tunnel_expire() reads it; 0 is kept for a tunnel no - * Update has refreshed. gc_wq is re-armed by - * amt_tunnel_expire() itself from last_seen, never from - * here, so this cannot re-queue the work of a tunnel that is - * being freed. - */ - tunnel->last_seen = jiffies ?: 1; - amt_igmp_report_handler(amt, skb, tunnel); - spin_unlock_bh(&tunnel->lock); skb_push(skb, sizeof(struct ethhdr)); skb_reset_mac_header(skb); @@ -2719,14 +2884,8 @@ report: return true; } - spin_lock_bh(&tunnel->lock); - if (READ_ONCE(tunnel->dead)) { - spin_unlock_bh(&tunnel->lock); + if (!amt_update_tunnel(amt, skb, saddr, sport, true)) return true; - } - tunnel->last_seen = jiffies ?: 1; - amt_mld_report_handler(amt, skb, tunnel); - spin_unlock_bh(&tunnel->lock); skb_push(skb, sizeof(struct ethhdr)); skb_reset_mac_header(skb); @@ -2745,13 +2904,10 @@ report: skb->pkt_type = PACKET_MULTICAST; skb->ip_summed = CHECKSUM_NONE; len = skb->len; - if (__netif_rx(skb) == NET_RX_SUCCESS) { - amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_UPDATE, - true); + if (__netif_rx(skb) == NET_RX_SUCCESS) dev_sw_netstats_rx_add(amt->dev, len); - } else { + else amt->dev->stats.rx_dropped++; - } return false; } @@ -2867,15 +3023,30 @@ static bool amt_discovery_handler(struct amt_dev *amt, struct sk_buff *skb) return false; } +/* Handle an AMT Request. + * + * The source of a Request is unauthenticated: it is a bare UDP datagram with a + * trivially spoofable source address. Allocating tunnel state here would let + * an attacker fill the table from spoofed addresses, or let one spoofed packet + * overwrite the nonce/MAC of an established tunnel and cut that gateway off. + * + * Nothing needs to be remembered at this point. Every input to the keyed MAC + * is carried in the packet or is device state, so the MAC is generated here, + * echoed back by the gateway in its Membership Update, and recomputed and + * verified there - see amt_update_handler(). Tunnel state is created only once + * that verification succeeds and the encapsulated message passes its IGMP or + * MLD check. + */ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb) { struct amt_header_request *amtrh; struct amt_tunnel_list *tunnel; - unsigned long long key; + bool full, have = false; struct udphdr *udph; struct iphdr *iph; + siphash_key_t key; + u32 per_src = 0; u64 mac; - int i; if (!pskb_may_pull(skb, sizeof(*udph) + sizeof(*amtrh))) return true; @@ -2887,59 +3058,45 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb) if (amtrh->reserved1 || amtrh->reserved2 || amtrh->version) return true; - list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list) - if (tunnel->ip4 == iph->saddr) - goto send; - - spin_lock_bh(&amt->lock); - if (amt->nr_tunnels >= amt->max_tunnels) { - spin_unlock_bh(&amt->lock); - icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0); - return true; - } - - tunnel = kzalloc(sizeof(*tunnel) + - (sizeof(struct hlist_head) * amt->hash_buckets), - GFP_ATOMIC); - if (!tunnel) { - spin_unlock_bh(&amt->lock); - return true; - } - - tunnel->source_port = udph->source; - tunnel->ip4 = iph->saddr; - - memcpy(&key, &tunnel->key, sizeof(unsigned long long)); - tunnel->amt = amt; - spin_lock_init(&tunnel->lock); - for (i = 0; i < amt->hash_buckets; i++) - INIT_HLIST_HEAD(&tunnel->groups[i]); - - INIT_DELAYED_WORK(&tunnel->gc_wq, amt_tunnel_expire); - - list_add_tail_rcu(&tunnel->list, &amt->tunnel_list); - tunnel->key = amt->key; - __amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_REQUEST, true); - amt->nr_tunnels++; - mod_delayed_work(amt_wq, &tunnel->gc_wq, - msecs_to_jiffies(amt_gmi(amt))); - spin_unlock_bh(&amt->lock); - -send: - tunnel->nonce = amtrh->nonce; - mac = siphash_3u32((__force u32)tunnel->ip4, - (__force u32)tunnel->source_port, - (__force u32)tunnel->nonce, - &tunnel->key); - tunnel->mac = mac >> 16; - if (!netif_running(amt->dev) || !netif_running(amt->stream_dev)) return true; + /* Snapshot the secret and the table-full state under the lock and walk + * the endpoints outside it, so a Request holds amt->lock only for this + * O(1) snapshot. + */ + spin_lock_bh(&amt->lock); + key = amt->key[0]; + full = amt->nr_tunnels >= amt->max_tunnels; + spin_unlock_bh(&amt->lock); + + /* Skip dead tunnels, as amt_tunnel_lookup() does: each is already + * being torn down, so it must not count against a new endpoint. + */ + rcu_read_lock(); + list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list) { + if (tunnel->ip4 != iph->saddr || READ_ONCE(tunnel->dead)) + continue; + per_src++; + if (tunnel->source_port == udph->source) + have = true; + } + rcu_read_unlock(); + + /* Withhold the Query when a new endpoint cannot get a tunnel. */ + if (!have && (full || per_src >= amt_max_tunnels_per_src(amt))) + return true; + + mac = siphash_3u32((__force u32)iph->saddr, + (__force u32)udph->source, + (__force u32)amtrh->nonce, + &key) >> 16; if (!amtrh->p) - amt_send_igmp_gq(amt, tunnel); + amt_send_igmp_gq(amt, iph->saddr, udph->source, amtrh->nonce, + mac); else - amt_send_mld_gq(amt, tunnel); + amt_send_mld_gq(amt, iph->saddr, udph->source, amtrh->nonce, + mac); return false; } @@ -3207,6 +3364,16 @@ static int amt_dev_open(struct net_device *dev) enable_delayed_work(&amt->discovery_wq); enable_delayed_work(&amt->req_wq); + /* Seed the keys before amt_socket_create() enables the encap receive + * path, so no Query MAC is generated, and no Update verified, with an + * all-zero (predictable) secret. + */ + spin_lock_bh(&amt->lock); + write_seqcount_begin(&amt->key_seq); + get_random_bytes(&amt->key, sizeof(amt->key)); + write_seqcount_end(&amt->key_seq); + spin_unlock_bh(&amt->lock); + err = amt_socket_create(amt); if (err) { disable_delayed_work(&amt->req_wq); @@ -3217,7 +3384,6 @@ static int amt_dev_open(struct net_device *dev) amt->req_cnt = 0; WRITE_ONCE(amt->remote_ip, 0); amt->nonce = 0; - get_random_bytes(&amt->key, sizeof(siphash_key_t)); amt->status = AMT_STATUS_INIT; if (amt->mode == AMT_MODE_GATEWAY) { @@ -3435,6 +3601,7 @@ static int amt_newlink(struct net_device *dev, amt->max_tunnels = AMT_MAX_TUNNELS; spin_lock_init(&amt->lock); + seqcount_spinlock_init(&amt->key_seq, &amt->lock); amt->max_groups = AMT_MAX_GROUP; amt->max_sources = AMT_MAX_SOURCE; amt->hash_buckets = AMT_HSIZE; diff --git a/include/net/amt.h b/include/net/amt.h index dedf328d8415..9ba09712731d 100644 --- a/include/net/amt.h +++ b/include/net/amt.h @@ -253,10 +253,6 @@ struct amt_tunnel_list { bool dead; __be16 source_port; __be32 ip4; - __be32 nonce; - siphash_key_t key; - u64 mac:48, - reserved:16; struct rcu_head rcu; struct hlist_head groups[]; }; @@ -342,8 +338,12 @@ struct amt_dev { struct work_struct event_wq; /* AMT status */ enum amt_status status; - /* Generated key */ - siphash_key_t key; + /* Current key and three previous generations keep MACs valid for + * 180-240s, beyond the advertised QQIC (see amt_secret_work()). + */ + siphash_key_t key[4]; + /* For lockless readers of key; writers hold lock */ + seqcount_spinlock_t key_seq; struct sock __rcu *sk; u32 max_groups; u32 max_sources; @@ -401,6 +401,8 @@ struct amt_dev { #define AMT_SECRET_TIMEOUT 60000 #define IANA_AMT_UDP_PORT 2268 #define AMT_MAX_TUNNELS 128 +/* Upper bound of amt_max_tunnels_per_src(), the per-address tunnel cap */ +#define AMT_MAX_TUNNELS_PER_SRC 16 #define AMT_MAX_REQS 128 #define AMT_GW_HLEN (sizeof(struct iphdr) + \ sizeof(struct udphdr) + \ From 4957f668681a2e1e2dab4731d75a2c53c6017319 Mon Sep 17 00:00:00 2001 From: Filip Balluch Date: Thu, 12 Nov 2026 16:45:56 -0800 Subject: [PATCH 096/117] i40e: fix freeing of TX rings on RX allocation failure When ethtool -G is used to change ring buffer sizes while the interface is up, i40e_set_ringparam() allocates temporary TX and RX rings. If the RX ring allocation fails, the error path at the free_tx label incorrectly calls i40e_free_tx_resources(vsi->tx_rings[i]), freeing the live TX rings instead of the temporary tx_rings[i]. Since the interface is still up, the next TX completion interrupt causes i40e_clean_tx_irq() to dereference the freed ring descriptors, resulting in a NULL pointer dereference in IRQ context and a kernel panic. This can be reproduced on systems with Intel X710 NICs under memory pressure, where the second port's DMA allocation fails after the first port succeeds. Fix by freeing the temporary tx_rings[i] in the error path instead of the live vsi->tx_rings[i]. Fixes: 74608d17fe29 ("i40e: add support for XDP_TX action") Signed-off-by: Filip Balluch Reviewed-by: Aleksandr Loktionov Tested-by: Alexander Nowlin Signed-off-by: Tony Nguyen Link: https://patch.msgid.link/20261113004602.129864-3-anthony.l.nguyen@intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c index 6a992df06fa1..ef756487d668 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c +++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c @@ -2249,7 +2249,7 @@ free_tx: if (tx_rings) { for (i = 0; i < tx_alloc_queue_pairs; i++) { if (i40e_active_tx_ring_index(vsi, i)) - i40e_free_tx_resources(vsi->tx_rings[i]); + i40e_free_tx_resources(&tx_rings[i]); } kfree(tx_rings); tx_rings = NULL; From e3916fa03f4d300be91468a7b7a608d38b6b3277 Mon Sep 17 00:00:00 2001 From: Aleksandr Loktionov Date: Thu, 12 Nov 2026 16:45:57 -0800 Subject: [PATCH 097/117] i40e: avoid resetting BQL state when freeing temporary Tx rings in set_ringparam Temporary Tx rings built by i40e_set_ringparam() while resizing descriptor counts are shallow struct copies of the live vsi->tx_rings[] entries, so they retain the same ring->netdev and ring->queue_index as the live ring they are staged to replace. If an error path frees one of these clones with i40e_free_tx_resources() before i40e_down() has run - either the i40e_setup_tx_descriptors() failure unwind loop, or the free_tx: error label - i40e_clean_tx_ring() will call netdev_tx_reset_queue() on txring_txq(tx_ring), which resolves to the *same* netdev_queue as the live ring because netdev/queue_index alias. That call resets the queue's BQL/dql state (dql_reset(): num_queued = num_completed = 0) while the live ring is still actively transmitting and completing Tx on that same queue. The next time the live ring reports completions for bytes that were queued before the reset, dql_completed() can underflow its own sanity check and hit: BUG_ON(count > num_queued - dql->num_completed); i.e. a guaranteed kernel panic, not just a warning, given a queue with outstanding (queued but not yet completed) Tx traffic at the moment the clone is freed. Reproduced on real hardware by forcing i40e_setup_tx_descriptors() to fail partway through building tx_rings[] while flooding real Tx traffic on the affected queues: kernel BUG at lib/dynamic_queue_limits.c:99! RIP: 0010:dql_completed+0x285/0x2a0 Call Trace: i40e_napi_poll+0x74b/0x1700 [i40e] __napi_poll+0x10a/0x200 net_rx_action+0x2f7/0x380 handle_softirqs+0xcc/0x270 Confirmed the same trigger no longer panics with this fix applied, including repeated resize/traffic cycles. Clear the clone ring netdev before freeing it in both error paths, so i40e_clean_tx_ring()'s existing `if (!tx_ring->netdev) return;` guard skips the netdev_tx_reset_queue() call for the clone. This mirrors the same idiom i40e already uses for XDP Tx rings, which also have no netdev_queue of their own (ring->netdev = NULL in i40e_vsi_setup_tx()). Only the temporary, about-to-be-freed clone is touched; the live ring in vsi->tx_rings[] keeps its netdev. Fixes: 9f65e15b4f98 ("i40e: Move rings from pointer to array to array of pointers") Cc: stable@vger.kernel.org Signed-off-by: Aleksandr Loktionov Tested-by: Alexander Nowlin Signed-off-by: Tony Nguyen Link: https://patch.msgid.link/20261113004602.129864-4-anthony.l.nguyen@intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c index ef756487d668..58d842d67642 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c +++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c @@ -2143,6 +2143,8 @@ static int i40e_set_ringparam(struct net_device *netdev, i--; if (!i40e_active_tx_ring_index(vsi, i)) continue; + /* not live yet, skip its BQL reset on free */ + tx_rings[i].netdev = NULL; i40e_free_tx_resources(&tx_rings[i]); } kfree(tx_rings); @@ -2248,8 +2250,11 @@ free_tx: /* error cleanup if the Rx allocations failed after getting Tx */ if (tx_rings) { for (i = 0; i < tx_alloc_queue_pairs; i++) { - if (i40e_active_tx_ring_index(vsi, i)) + if (i40e_active_tx_ring_index(vsi, i)) { + /* not live yet, skip its BQL reset on free */ + tx_rings[i].netdev = NULL; i40e_free_tx_resources(&tx_rings[i]); + } } kfree(tx_rings); tx_rings = NULL; From 65f6ffb9001bf539aebd478798460477980b60c4 Mon Sep 17 00:00:00 2001 From: Xuanqiang Luo Date: Thu, 12 Nov 2026 16:45:58 -0800 Subject: [PATCH 098/117] iavf: fix QoS capabilities memory leak Commit 4c1a457cb8b0 ("iavf: add support to exchange qos capabilities") allocates adapter->qos_caps during probe, but iavf_remove() does not free it. This leaks the allocation whenever an iavf device is removed. Free adapter->qos_caps in iavf_remove(). Fixes: 4c1a457cb8b0 ("iavf: add support to exchange qos capabilities") Cc: stable@vger.kernel.org Reviewed-by: Jedrzej Jagielski Signed-off-by: Xuanqiang Luo Reviewed-by: Aleksandr Loktionov Signed-off-by: Tony Nguyen Link: https://patch.msgid.link/20261113004602.129864-5-anthony.l.nguyen@intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/iavf/iavf_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c index 2f8a80a11336..4de3ea8525b3 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_main.c +++ b/drivers/net/ethernet/intel/iavf/iavf_main.c @@ -5638,6 +5638,7 @@ static void iavf_remove(struct pci_dev *pdev) iounmap(hw->hw_addr); pci_release_regions(pdev); kfree(adapter->vf_res); + kfree(adapter->qos_caps); spin_lock_bh(&adapter->mac_vlan_list_lock); /* If we got removed before an up/down sequence, we've got a filter * hanging out there that we need to get rid of. From 2a1f106379a90ce7ac63f96a57c241a4cf20a983 Mon Sep 17 00:00:00 2001 From: Xuanqiang Luo Date: Thu, 12 Nov 2026 16:45:59 -0800 Subject: [PATCH 099/117] iavf: fix ASQ command buffer leak on init failure iavf_alloc_adminq_asq_ring() allocates cmd_buf before the remaining ASQ resources. If iavf_alloc_asq_bufs() or iavf_config_asq_regs() fails, the unwind path elides cmd_buf while freeing the other allocations. The ASQ count is not set until initialization succeeds, so the shutdown path cannot reclaim the buffer. Free cmd_buf in the common unwind path. Fixes: d358aa9a7a2d ("i40evf: init code and hardware support") Cc: stable@vger.kernel.org Signed-off-by: Xuanqiang Luo Reviewed-by: Jedrzej Jagielski Reviewed-by: Aleksandr Loktionov Signed-off-by: Tony Nguyen Link: https://patch.msgid.link/20261113004602.129864-6-anthony.l.nguyen@intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/iavf/iavf_adminq.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/intel/iavf/iavf_adminq.c b/drivers/net/ethernet/intel/iavf/iavf_adminq.c index 6937b7dd44cb..40f76f9507f4 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_adminq.c +++ b/drivers/net/ethernet/intel/iavf/iavf_adminq.c @@ -60,6 +60,7 @@ static enum iavf_status iavf_alloc_adminq_arq_ring(struct iavf_hw *hw) **/ static void iavf_free_adminq_asq(struct iavf_hw *hw) { + iavf_free_virt_mem(hw, &hw->aq.asq.cmd_buf); iavf_free_dma_mem(hw, &hw->aq.asq.desc_buf); } From adbc4d0fff640541d7071421ac59dbd70da33b18 Mon Sep 17 00:00:00 2001 From: Xuanqiang Luo Date: Thu, 12 Nov 2026 16:46:00 -0800 Subject: [PATCH 100/117] iavf: add missing PTP adjustment callbacks The PTP hardware clock documentation requires drivers to implement all callbacks and return -EOPNOTSUPP for unsupported features. The iavf driver registers a PHC without adjtime or adjfine callbacks. A userspace clock_adjtime(2) request reaches ptp_clock_adjtime(), where ADJ_SETOFFSET calls adjtime and ADJ_FREQUENCY calls adjfine. The missing callbacks can therefore cause a NULL dereference. Provide both callbacks and return -EOPNOTSUPP for the unsupported operations. Fixes: d734223b2f0d ("iavf: add initial framework for registering PTP clock") Link: https://docs.kernel.org/driver-api/ptp.html#writing-clock-drivers Link: https://lore.kernel.org/all/20260826101004.100979-1-xuanqiang.luo@linux.dev/ Cc: stable@vger.kernel.org Signed-off-by: Xuanqiang Luo Reviewed-by: Vadim Fedorenko Acked-by: Jacob Keller Tested-by: Rafal Romanowski Signed-off-by: Tony Nguyen Link: https://patch.msgid.link/20261113004602.129864-7-anthony.l.nguyen@intel.com Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/intel/iavf/iavf_ptp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/ethernet/intel/iavf/iavf_ptp.c b/drivers/net/ethernet/intel/iavf/iavf_ptp.c index 87b97e09df14..fcb273828bc1 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_ptp.c +++ b/drivers/net/ethernet/intel/iavf/iavf_ptp.c @@ -252,6 +252,16 @@ static int iavf_ptp_gettimex64(struct ptp_clock_info *info, return iavf_read_phc_indirect(adapter, ts, sts); } +static int iavf_ptp_adjfine(struct ptp_clock_info *info, long scaled_ppm) +{ + return -EOPNOTSUPP; +} + +static int iavf_ptp_adjtime(struct ptp_clock_info *info, s64 delta) +{ + return -EOPNOTSUPP; +} + static int iavf_ptp_settime64(struct ptp_clock_info *info, const struct timespec64 *ts) { @@ -326,6 +336,8 @@ static int iavf_ptp_register_clock(struct iavf_adapter *adapter) KBUILD_MODNAME, dev_name(dev)); ptp_info->owner = THIS_MODULE; ptp_info->gettimex64 = iavf_ptp_gettimex64; + ptp_info->adjfine = iavf_ptp_adjfine; + ptp_info->adjtime = iavf_ptp_adjtime; ptp_info->settime64 = iavf_ptp_settime64; ptp_info->do_aux_work = iavf_ptp_do_aux_work; From 8a0b03058ff700deb74f4b38f5a254238bdf4e07 Mon Sep 17 00:00:00 2001 From: Simon Schippers Date: Fri, 13 Nov 2026 11:46:47 +0100 Subject: [PATCH 101/117] veth: wake a stopped peer txq beyond real_num_tx_queues Since commit dc82a33297fc ("veth: apply qdisc backpressure on full ptr_ring to reduce TX drops"), only the peer's veth_poll() wakes a txq that veth_xmit() stopped on a full ptr_ring. veth_poll() skips txqs at or above the peer's real_num_tx_queues. If the peer shrinks its TX channels while such a txq is stopped, nothing wakes it. netif_set_real_num_tx_queues() keeps its state, so once the channels are grown back, its first skb is requeued forever. With a single root qdisc this blocks all transmission of the device. Look the txq up below num_tx_queues instead. Waking a txq that is not in use is harmless. Reproduced in virtme-ng with a UDP flood from veth0 into veth1, which has GRO, while switching veth0 between one and two TX channels: without this patch veth0 stopped transmitting within 11 cycles in 3 of 3 runs, with it veth0 kept transmitting through 30 cycles in 3 of 3 runs. Fixes: 08f566e8f83b ("veth: fix OOB txq access in veth_poll() with asymmetric queue counts") Signed-off-by: Simon Schippers Reviewed-by: Tianyi Gao Tested-by: Tianyi Gao Link: https://patch.msgid.link/20261113104648.225983-2-simon.schippers@tu-dortmund.de Signed-off-by: Paolo Abeni --- drivers/net/veth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index a61842b2585b..62a60a033675 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -984,7 +984,7 @@ static int veth_poll(struct napi_struct *napi, int budget) /* NAPI functions as RCU section */ peer_dev = rcu_dereference_check(priv->peer, rcu_read_lock_bh_held()); - peer_txq = (peer_dev && queue_idx < peer_dev->real_num_tx_queues) ? + peer_txq = (peer_dev && queue_idx < peer_dev->num_tx_queues) ? netdev_get_tx_queue(peer_dev, queue_idx) : NULL; xdp_set_return_frame_no_direct(); From b2f4c44d7d83770ee1f235a732d8e1fd831c4926 Mon Sep 17 00:00:00 2001 From: Simon Schippers Date: Fri, 13 Nov 2026 11:46:48 +0100 Subject: [PATCH 102/117] veth: wake the peer txq when deleting NAPI Since commit dc82a33297fc ("veth: apply qdisc backpressure on full ptr_ring to reduce TX drops"), only the peer's veth_poll() wakes a txq that veth_xmit() stopped on a full ptr_ring. If veth_xmit() stops the txq after the last poll before napi_disable(), its __veth_xdp_flush() can no longer schedule NAPI. Nothing wakes the txq, also not after NAPI is added back, so the device stops transmitting for good. This can happen whenever the peer deletes its NAPI: when it goes down, turns GRO off, detaches XDP or reduces its RX channels. Wake the peer txq in veth_napi_del_range() once NAPI is deleted, also when the peer is down, as opening it does not restart its queues. Reproduced in virtme-ng with a pktgen flood while toggling GRO on the peer, with a udelay() before netif_tx_stop_queue() to widen the race: the txq got stuck within four toggles without this patch, and not in 300 with it. Without the udelay() it was not hit in 1200 toggles. Fixes: dc82a33297fc ("veth: apply qdisc backpressure on full ptr_ring to reduce TX drops") Signed-off-by: Simon Schippers Reviewed-by: Tianyi Gao Tested-by: Tianyi Gao Link: https://patch.msgid.link/20261113104648.225983-3-simon.schippers@tu-dortmund.de Signed-off-by: Paolo Abeni --- drivers/net/veth.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 62a60a033675..faa837acea7b 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1087,6 +1087,7 @@ static int __veth_napi_enable(struct net_device *dev) static void veth_napi_del_range(struct net_device *dev, int start, int end) { struct veth_priv *priv = netdev_priv(dev); + struct net_device *peer; int i; for (i = start; i < end; i++) { @@ -1099,11 +1100,17 @@ static void veth_napi_del_range(struct net_device *dev, int start, int end) } synchronize_net(); + peer = rtnl_dereference(priv->peer); + for (i = start; i < end; i++) { struct veth_rq *rq = &priv->rq[i]; rq->rx_notify_masked = false; ptr_ring_cleanup(&rq->xdp_ring, veth_ptr_free); + + /* veth_poll() can no longer wake a txq stopped on a full ring */ + if (peer && i < peer->num_tx_queues) + netif_wake_subqueue(peer, i); } for (i = start; i < end; i++) { From fcfc52fcf89a3076c3a9afbbc70c0fecd2b5fc8d Mon Sep 17 00:00:00 2001 From: Christian Schmidbauer Date: Sat, 14 Nov 2026 14:36:37 +0100 Subject: [PATCH 103/117] net: stmmac: honour Rx checksum errors in the AF_XDP zero-copy path Commit ee0aace5f844 ("net: stmmac: Correctly handle Rx checksum offload errors") taught stmmac_rx() to honour the csum_none status, but stmmac_dispatch_skb_zc() still ignores it and sets CHECKSUM_UNNECESSARY for every IP frame whenever the checksum offload engine (CoE) is enabled. Since commit fe4042797651 ("net: stmmac: dwmac4: stop hardware from dropping checksum-error packets") dwmac4 delivers such frames instead of dropping them, so this path receives them. Mark the skb CHECKSUM_NONE when csum_none is set, as stmmac_rx() does. Fixes: bba2556efad6 ("net: stmmac: Enable RX via AF_XDP zero-copy") Cc: Signed-off-by: Christian Schmidbauer Reviewed-by: Maxime Chevallier Link: https://patch.msgid.link/20261114133640.3285413-2-opensource@grische.xyz Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 9a9c44aab2e4..a685ce4638f6 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5563,7 +5563,7 @@ static struct sk_buff *stmmac_construct_skb_zc(struct stmmac_channel *ch, static void stmmac_dispatch_skb_zc(struct stmmac_priv *priv, u32 queue, struct dma_desc *p, struct dma_desc *np, - struct xdp_buff *xdp) + struct xdp_buff *xdp, int status) { struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[queue]; struct stmmac_channel *ch = &priv->channel[queue]; @@ -5591,7 +5591,8 @@ static void stmmac_dispatch_skb_zc(struct stmmac_priv *priv, u32 queue, skb->protocol = eth_type_trans(skb, priv->dev); - if (unlikely(!coe) || !stmmac_has_ip_ethertype(skb)) + if (unlikely(!coe) || !stmmac_has_ip_ethertype(skb) || + (status & csum_none)) skb_checksum_none_assert(skb); else skb->ip_summed = CHECKSUM_UNNECESSARY; @@ -5805,7 +5806,8 @@ read_again: switch (res) { case STMMAC_XDP_PASS: - stmmac_dispatch_skb_zc(priv, queue, p, np, buf->xdp); + stmmac_dispatch_skb_zc(priv, queue, p, np, buf->xdp, + status); xsk_buff_free(buf->xdp); break; case STMMAC_XDP_CONSUMED: From 596c9408682feba536d7f39de97959807eb3ba1c Mon Sep 17 00:00:00 2001 From: Christian Schmidbauer Date: Sat, 14 Nov 2026 14:36:38 +0100 Subject: [PATCH 104/117] net: stmmac: dwmac1000: don't discard frames with only a checksum error On dwmac1000 with enhanced descriptors, the hardware sets the Error Summary (ES) bit of the Rx descriptor not only for L2 errors but also for an L3/L4 checksum error. enh_desc_get_rx_status() returns discard_frame whenever ES is set, and since commit 1b746ce8b397 ("net: stmmac: don't overwrite discard_frame status") the checksum status is only evaluated for good frames. Return discard_frame only when ES comes with one of the L2 error bits. A frame with only a checksum error is then reported as csum_none and reaches the stack as CHECKSUM_NONE, so the stack verifies the checksum itself. This matches dwmac4, whose Error Summary bit does not cover checksum errors. RDES0 bit 7 is not in the mask, because depending on the core and on Rx checksum offload it reports a timestamp, an IP header checksum error or a giant frame, and enh_desc_get_rx_status() cannot tell which. In threshold Rx mode, a giant frame that fits one buffer therefore reaches the stack with a verified FCS. Also remove the pr_err that enh_desc_get_rx_status() prints when bit 7 is set. Once the MAC stops dropping checksum-error frames, any host on the link can flood the kernel log by sending frames with a bad IPv4 header checksum. This prepares for setting DMA_CONTROL_DT, which makes the MAC deliver checksum-error frames instead of dropping them in its Rx FIFO. Fixes: 1b746ce8b397 ("net: stmmac: don't overwrite discard_frame status") Cc: # 6.6.x: ee0aace5f844: net: stmmac: Correctly handle Rx checksum offload errors Cc: # 6.6.x Signed-off-by: Christian Schmidbauer Reviewed-by: Maxime Chevallier Tested-by: Maxime Chevallier Link: https://patch.msgid.link/20261114133640.3285413-3-opensource@grische.xyz Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/enh_desc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c index 7ece8d4157a8..d0622f2605aa 100644 --- a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c +++ b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c @@ -216,9 +216,6 @@ static int enh_desc_get_rx_status(struct stmmac_extra_stats *x, if (unlikely(rdes0 & RDES0_OVERFLOW_ERROR)) x->rx_gmac_overflow++; - if (unlikely(rdes0 & RDES0_IPC_CSUM_ERROR)) - pr_err("\tIPC Csum Error/Giant frame\n"); - if (unlikely(rdes0 & RDES0_COLLISION)) x->rx_collision++; if (unlikely(rdes0 & RDES0_RECEIVE_WATCHDOG)) @@ -230,7 +227,10 @@ static int enh_desc_get_rx_status(struct stmmac_extra_stats *x, if (unlikely(rdes0 & RDES0_CRC_ERROR)) { x->rx_crc_errors++; } - ret = discard_frame; + if (rdes0 & (RDES0_DESCRIPTOR_ERROR | RDES0_OVERFLOW_ERROR | + RDES0_COLLISION | RDES0_RECEIVE_WATCHDOG | + RDES0_MII_ERROR | RDES0_CRC_ERROR)) + ret = discard_frame; } /* After a payload csum error, the ES bit is set. From 2dd48c4615a67ebb1762c2b0d79801be1949fcfb Mon Sep 17 00:00:00 2001 From: Christian Schmidbauer Date: Sat, 14 Nov 2026 14:36:39 +0100 Subject: [PATCH 105/117] net: stmmac: dwmac1000: stop hardware from dropping checksum-error packets When the checksum offload engine (CoE) is enabled, the dwmac1000 MAC silently drops any frame for which the engine detects a checksum error, before the driver sees it. This breaks VXLAN over IPv6 with zero UDP checksums, which RFC 6935 and RFC 6936 allow for tunnels. Set DMA_CONTROL_DT so that such frames are delivered instead of dropped, as commit fe4042797651 ("net: stmmac: dwmac4: stop hardware from dropping checksum-error packets") did for dwmac4. CoE remains enabled, so the driver still sees the error status and marks the skb CHECKSUM_NONE for the stack to verify. Set the bit only with enhanced descriptors. The normal descriptor parser does not report a checksum-only error to the stack, so cores that use it keep dropping such frames in hardware anyway. Tested on an Aruba AP-325 (ipq806x-gmac-dwmac) with Rx checksum offload on. Link: https://lore.kernel.org/all/20250625132117.1b3264e8@kernel.org/ Link: https://github.com/freifunk-gluon/gluon/issues/3783 Fixes: 47dd7a540b8a ("net: add support for STMicroelectronics Ethernet controllers.") Cc: # 6.6.x: ee0aace5f844: net: stmmac: Correctly handle Rx checksum offload errors Cc: # 6.6.x Signed-off-by: Christian Schmidbauer Reviewed-by: Maxime Chevallier Tested-by: Maxime Chevallier Link: https://patch.msgid.link/20261114133640.3285413-4-opensource@grische.xyz Signed-off-by: Paolo Abeni --- drivers/net/ethernet/stmicro/stmmac/dwmac1000.h | 2 +- drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h index 1de1f929d61c..55d9c39287f1 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h @@ -162,7 +162,7 @@ enum rx_tx_priority_ratio { /* DMA CRS Control and Status Register Mapping */ /* DMA operation mode defines (start/stop tx/rx are placed in common header)*/ -/* Disable Drop TCP/IP csum error */ +#define DMA_CONTROL_DT 0x04000000 /* Disable Drop of TCP/IP csum errors */ #define DMA_CONTROL_RSF 0x02000000 /* Receive Store and Forward */ #define DMA_CONTROL_DFF 0x01000000 /* Disaable flushing */ /* Threshold for Activating the FC */ diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c index 3ac7a7949529..31d5f79ef560 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c @@ -15,6 +15,7 @@ #include #include "dwmac1000.h" #include "dwmac_dma.h" +#include "stmmac.h" static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) { @@ -129,6 +130,13 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv, { u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel)); + /* Deliver checksum-error frames only with enhanced + * descriptors, because the normal descriptor parser does not + * report a checksum-only error. + */ + if (priv->plat->enh_desc) + csr6 |= DMA_CONTROL_DT; + if (mode == SF_DMA_MODE) { pr_debug("GMAC: enable RX store and forward mode\n"); csr6 |= DMA_CONTROL_RSF | DMA_CONTROL_DFF; From 050f2adb60434a2b4dee2cf3350269379a32cf72 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Fri, 13 Nov 2026 13:46:21 +0100 Subject: [PATCH 106/117] ipv6: gro: limit the number of extension headers Hyunwoo Kim reported that a long chain of IPv6 extension headers can push the transport header offset of a GRO packet beyond what the 16-bit skb->transport_header can store. The truncated offset is later used by gro_receive_network_flush() to locate the network header of a packet held in the GRO list, leading to an out-of-bounds read. Since commit 3744b0964d52 ("ipv6: Implement limits on extension header parsing"), ip6_protocol_deliver_rcu() drops packets carrying more than IP6_MAX_EXT_HDRS_CNT extension headers, but ipv6_gro_pull_exthdrs() was left unbounded. There is no point trying to aggregate packets that the stack is going to drop anyway if they are locally delivered. Apply the same limit in ipv6_gro_pull_exthdrs(). When the limit is hit, @proto still designates an extension header. Extension header offloads have no gro_receive() callback, so ipv6_gro_receive() takes its existing "goto out" path with flush set, and the packet is given to the normal receive path. Local delivery drops it with SKB_DROP_REASON_IPV6_TOO_MANY_EXTHDRS, while forwarded packets are simply not aggregated. An extension header being at most 2048 bytes, this bounds a chain to 24576 bytes. Note that offsets can still accumulate over nested encapsulations, so the places storing them should be hardened separately. Fixes: 4b0ebbca3e16 ("net: gro: move L3 flush checks to tcp_gro_receive and udp_gro_receive_segment") Cc: stable@vger.kernel.org Reported-by: Hyunwoo Kim Link: https://lore.kernel.org/netdev/avTTQNyvwPP6LtGx@v4bel/ Signed-off-by: Eric Dumazet Cc: Daniel Borkmann Cc: David Ahern Cc: Ido Schimmel Tested-by: Hyunwoo Kim Reviewed-by: Ido Schimmel Reviewed-by: Aaron Conole Link: https://patch.msgid.link/20261113124625.4010206-2-edumazet@kernel.org Reviewed-by: Justin Iurman Signed-off-by: Paolo Abeni --- net/ipv6/ip6_offload.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c index 700f1861d8eb..01642900c0fa 100644 --- a/net/ipv6/ip6_offload.c +++ b/net/ipv6/ip6_offload.c @@ -26,6 +26,7 @@ static int ipv6_gro_pull_exthdrs(struct sk_buff *skb, int off, int proto) { const struct net_offload *ops = NULL; struct ipv6_opt_hdr *opth; + int exthdr_cnt = 0; for (;;) { int len; @@ -38,6 +39,13 @@ static int ipv6_gro_pull_exthdrs(struct sk_buff *skb, int off, int proto) if (!(ops->flags & INET6_PROTO_GSO_EXTHDR)) break; + /* Same limit as ip6_protocol_deliver_rcu(). + * @proto is left pointing to an extension header, + * so that the caller does not aggregate this packet. + */ + if (unlikely(exthdr_cnt++ >= IP6_MAX_EXT_HDRS_CNT)) + break; + opth = skb_gro_header(skb, off + sizeof(*opth), off); if (unlikely(!opth)) break; From 425b1fe50b71628299d33faff28057e7fa4c60c7 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Fri, 13 Nov 2026 13:46:22 +0100 Subject: [PATCH 107/117] ipv6: mcast: use skb_set_transport_header_careful() in ipv6_mc_check_exthdrs() skb->transport_header is a 16-bit offset from skb->head, and U16_MAX is reserved as the "not set" value. skb_set_transport_header() silently truncates an offset that does not fit. ipv6_mc_check_exthdrs() stores the offset returned by ipv6_skip_exthdr(), which depends on the extension headers found in the packet. Should the value be truncated, ipv6_mc_check_icmpv6() and ipv6_mc_check_mld_msg() would then validate and parse the MLD message at the wrong place. Since commit 3744b0964d52 ("ipv6: Implement limits on extension header parsing") a single chain is bounded to IP6_MAX_EXT_HDRS_CNT headers (24576 bytes), so this needs a large skb->data - skb->head on top of it, for instance after several nested decapsulations, each of them possibly pulling its own extension header chain. No reproducer was written, this is hardening. Use skb_set_transport_header_careful() and treat such a packet as broken (-EINVAL). Fixes: 9afd85c9e455 ("net: Export IGMP/MLD message validation code") Cc: stable@vger.kernel.org Signed-off-by: Eric Dumazet Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261113124625.4010206-3-edumazet@kernel.org Reviewed-by: Justin Iurman Signed-off-by: Paolo Abeni --- net/ipv6/mcast_snoop.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ipv6/mcast_snoop.c b/net/ipv6/mcast_snoop.c index 04d5fcdfa6e0..7abf79815aa2 100644 --- a/net/ipv6/mcast_snoop.c +++ b/net/ipv6/mcast_snoop.c @@ -56,7 +56,8 @@ static int ipv6_mc_check_exthdrs(struct sk_buff *skb) if (nexthdr != IPPROTO_ICMPV6) return -ENOMSG; - skb_set_transport_header(skb, offset); + if (!skb_set_transport_header_careful(skb, offset)) + return -EINVAL; return 0; } From b9b77e2430032c21cc82b7da3a0bc0d8e74e6c26 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Fri, 13 Nov 2026 13:46:23 +0100 Subject: [PATCH 108/117] net: openvswitch: use skb_set_transport_header_careful() in parse_ipv6hdr() skb->transport_header is a 16-bit offset from skb->head, and U16_MAX is reserved as the "not set" value. skb_set_transport_header() silently truncates an offset that does not fit. parse_ipv6hdr() stores the payload offset found by ipv6_find_hdr(), which depends on the extension headers found in the packet. Should the value be truncated, key_extract_l3l4() would parse the L4 header at the wrong place. Since commit 3744b0964d52 ("ipv6: Implement limits on extension header parsing") a single chain is bounded to IP6_MAX_EXT_HDRS_CNT headers (24576 bytes), so this needs a large skb->data - skb->head on top of it, for instance after several nested decapsulations, each of them possibly pulling its own extension header chain. No reproducer was written, this is hardening. Use skb_set_transport_header_careful() and return -EPROTO if the offset can not be stored. As for other ipv6_find_hdr() failures, the caller then sets the transport header to the network header and does not parse L4. While at it, use payload_ofs directly, since nh_ofs + nh_len == payload_ofs. Fixes: 1a37e412a022 ("net: Use 16bits for *_headers fields of struct skbuff") Cc: stable@vger.kernel.org Signed-off-by: Eric Dumazet Reviewed-by: Ilya Maximets Reviewed-by: Aaron Conole Link: https://patch.msgid.link/20261113124625.4010206-4-edumazet@kernel.org Reviewed-by: Justin Iurman Signed-off-by: Paolo Abeni --- net/openvswitch/flow.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c index 3734416b518d..5fbeb0cca9dc 100644 --- a/net/openvswitch/flow.c +++ b/net/openvswitch/flow.c @@ -438,7 +438,8 @@ static int parse_ipv6hdr(struct sk_buff *skb, struct sw_flow_key *key) return -EPROTO; nh_len = payload_ofs - nh_ofs; - skb_set_transport_header(skb, nh_ofs + nh_len); + if (unlikely(!skb_set_transport_header_careful(skb, payload_ofs))) + return -EPROTO; key->ip.proto = nexthdr; return nh_len; } From 13391f1a8c584e7c1addaea3fd47105d92cc724c Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Fri, 13 Nov 2026 13:46:24 +0100 Subject: [PATCH 109/117] sctp: use skb_set_transport_header_careful() in sctp_v6_err() skb->transport_header is a 16-bit offset from skb->head, and U16_MAX is reserved as the "not set" value. skb_set_transport_header() silently truncates an offset that does not fit. sctp_v6_err() stores @offset, computed by icmpv6_notify() from the extension headers of the packet embedded in an ICMPv6 error. Should the value be truncated, sctp_err_lookup() would read the SCTP header at the wrong place. Since commit 3744b0964d52 ("ipv6: Implement limits on extension header parsing") a single chain is bounded to IP6_MAX_EXT_HDRS_CNT headers (24576 bytes), so this needs a large skb->data - skb->head on top of it, for instance after several nested decapsulations, each of them possibly pulling its own extension header chain, since @offset is relative to the IPv6 header embedded in the ICMPv6 error. No reproducer was written, this is hardening. Use skb_set_transport_header_careful() and ignore the ICMPv6 error if the offset can not be stored. Do this before changing the network header, so that nothing has to be restored on failure. Fixes: 1a37e412a022 ("net: Use 16bits for *_headers fields of struct skbuff") Cc: stable@vger.kernel.org Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20261113124625.4010206-5-edumazet@kernel.org Reviewed-by: Justin Iurman Signed-off-by: Paolo Abeni --- net/sctp/ipv6.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c index 97390569c4bd..ad5c951efdf0 100644 --- a/net/sctp/ipv6.c +++ b/net/sctp/ipv6.c @@ -170,8 +170,11 @@ static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, /* Fix up skb to look at the embedded net header. */ saveip = skb->network_header; savesctp = skb->transport_header; + if (unlikely(!skb_set_transport_header_careful(skb, offset))) { + __ICMP6_INC_STATS(net, __in6_dev_get(skb->dev), ICMP6_MIB_INERRORS); + return -EINVAL; + } skb_reset_network_header(skb); - skb_set_transport_header(skb, offset); sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &transport); /* Put back, the original pointers. */ skb->network_header = saveip; From 02f578b736f1524ed73ef879fb1cf1ba4a875aa4 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Fri, 13 Nov 2026 13:46:25 +0100 Subject: [PATCH 110/117] udp: use skb_set_transport_header_careful() in __udp6_lib_err_encap() skb->transport_header is a 16-bit offset from skb->head, and U16_MAX is reserved as the "not set" value. skb_set_transport_header() silently truncates an offset that does not fit. __udp6_lib_err_encap() stores @offset, computed by icmpv6_notify() from the extension headers of the packet embedded in an ICMPv6 error. Should the value be truncated, the tunnel encap_err_lookup() and err_handler() callbacks would read the UDP header at the wrong place. Since commit 3744b0964d52 ("ipv6: Implement limits on extension header parsing") a single chain is bounded to IP6_MAX_EXT_HDRS_CNT headers (24576 bytes), so this needs a large skb->data - skb->head on top of it, for instance after several nested decapsulations, each of them possibly pulling its own extension header chain, since @offset is relative to the IPv6 header embedded in the ICMPv6 error. No reproducer was written, this is hardening. Use skb_set_transport_header_careful() and return an error if the offset can not be stored, in which case udpv6_err() ignores the ICMPv6 error. Do this before changing the network header, so that nothing has to be restored on failure. Fixes: a36e185e8c85 ("udp: Handle ICMP errors for tunnels with same destination port on both endpoints") Cc: stable@vger.kernel.org Signed-off-by: Eric Dumazet Reviewed-by: Stefano Brivio Link: https://patch.msgid.link/20261113124625.4010206-6-edumazet@kernel.org Reviewed-by: Justin Iurman Signed-off-by: Paolo Abeni --- net/ipv6/udp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 9dcefa162522..a6886a0432f9 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -651,12 +651,13 @@ static struct sock *__udp6_lib_err_encap(struct net *net, network_offset = skb_network_offset(skb); transport_offset = skb_transport_offset(skb); + /* Transport header needs to point to the UDP header */ + if (unlikely(!skb_set_transport_header_careful(skb, offset))) + return ERR_PTR(-EINVAL); + /* Network header needs to point to the outer IPv6 header inside ICMP */ skb_reset_network_header(skb); - /* Transport header needs to point to the UDP header */ - skb_set_transport_header(skb, offset); - if (sk) { up = udp_sk(sk); From abccf171fa8e97954e74934bde811d76a5410cbd Mon Sep 17 00:00:00 2001 From: Julius Bairaktaris Date: Sat, 14 Nov 2026 19:26:57 +0100 Subject: [PATCH 111/117] net: make room for the tunnel header in skb_segment_list() skb_segment_list() pushes each frag_list member back to the outer MAC header and copies the tunnel headers in front of it, but never checks that the member has the headroom. A fraglist GRO packet forwarded into a tunnel and segmented in software then hits skb_under_panic() on IPIP, and on VXLAN the copy writes before the member's head (KASAN: slab-out-of-bounds write in skb_segment_list()). Call skb_cow_head() on each member before pushing it. Fixes: 3a1296a38d0c ("net: Support GRO/GSO fraglist chaining.") Tested-by: Henry Martin Reviewed-by: Simon Horman Reviewed-by: Eric Dumazet Signed-off-by: Julius Bairaktaris Link: https://patch.msgid.link/c976a72586cda383b3e42486ee3d0176033b973c.1794151759.git.julius@bairaktaris.de Signed-off-by: Paolo Abeni --- net/core/skbuff.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 1ac1e327ac4c..74e9a96bc5df 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -4789,6 +4789,10 @@ struct sk_buff *skb_segment_list(struct sk_buff *skb, } } + if (!err) + err = skb_cow_head(nskb, offset + tnl_hlen - + skb_network_offset(nskb)); + if (!tail) skb->next = nskb; else From 5d2a5ad0367725f2833bbfcec25aae1e69d71ba1 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Wed, 18 Nov 2026 10:51:45 -0500 Subject: [PATCH 112/117] tcp: don't let __tcp_set_rto() return 0 tcp_retransmit_timer() backs off by doubling icsk_rto, so the backoff only works if icsk_rto is nonzero. __tcp_set_rto() adds srtt_us >> 3 and rttvar_us with no lower bound, and relies on tcp_rtt_estimator() to keep rttvar_us at tcp_rto_min() or above. But tcp_rto_min() returns 0 for a route with a locked RTAX_RTO_MIN of 0. A first RTT sample of 0 usec, which usec TS allows, then gives: srtt_us = max(1U, 0 << 3) = 1 rttvar_us = max(mdev_us, tcp_rto_min_us(sk)) = 0 __tcp_set_rto() = usecs_to_jiffies((1 >> 3) + 0) = 0 Keep the result from 0, so that the backoff recovers from any state of the RTT estimator. Do it in __tcp_set_rto() and not in tcp_set_rto(), since tcp_ld_RTO_revert() uses the same sum. The third caller, the linear timeouts of thin streams in tcp_retransmit_timer(), already clamps the result to tcp_rto_min(). Found by code inspection (Eric Dumazet), not reproduced. Fixed by LLM, and tested with existing kernel selftests. Fixes: 05bb1fad1cde ("[TCP]: Allow minimum RTO to be configurable via routing metrics.") Suggested-by: Eric Dumazet Signed-off-by: Chris Mason Link: https://patch.msgid.link/20261118155144.18393-2-mason@kernel.org Signed-off-by: Paolo Abeni --- include/net/tcp.h | 4 +++- net/ipv4/tcp_input.c | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 5c9203aae834..6a714189bcc7 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -910,7 +910,9 @@ static inline void tcp_bound_rto(struct sock *sk) static inline u32 __tcp_set_rto(const struct tcp_sock *tp) { - return usecs_to_jiffies((tp->srtt_us >> 3) + tp->rttvar_us); + u32 rto = usecs_to_jiffies((tp->srtt_us >> 3) + tp->rttvar_us); + + return max(rto, 1U); } static inline unsigned long tcp_reqsk_timeout(struct request_sock *req) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index a2074a1af422..f65697bc96c9 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -1221,8 +1221,9 @@ void tcp_set_rto(struct sock *sk) * with correct one. It is exactly, which we pretend to do. */ - /* NOTE: clamping at TCP_RTO_MIN is not required, current algo - * guarantees that rto is higher. + /* NOTE: clamping at tcp_rto_min() is not required, tcp_rtt_estimator() + * applies it to rttvar_us. But rto must never be 0, which exponential + * backoff could not leave: __tcp_set_rto() takes care of that. */ tcp_bound_rto(sk); } From fa472d53d9b7aaff384d25f4ca86540d63815113 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Wed, 18 Nov 2026 10:51:46 -0500 Subject: [PATCH 113/117] tcp: clamp RTT samples in tcp_rtt_estimator() tcp_rtt_estimator() keeps its state in u32 fields, in microseconds. srtt_us holds 8 times the smoothed RTT, so it wraps at an RTT of 536.9 s. Samples can be larger than that: - For an ACK of retransmitted data, the sample is the timestamp clock minus TSecr, and tcp_rtt_tsopt_us() accepts a sample of up to 2,147 s. - For a SACK of a segment that was never retransmitted, the sample is the age of that segment. Samples from TSecr could wrap these fields when they still held jiffies. The age of a segment can wrap them since commit 740b0f1841f6 ("tcp: switch rtt estimations to usec resolution"), which took the wrap of the smoothed RTT from 2^29 jiffies to 2^29 us. The fix used here is to clamp each sample to 120 s, the largest possible RTO, in tcp_rtt_estimator(), where the samples of all sources meet. The smoothed RTT now saturates at 120 s. A path with a larger real RTT sees that in TCP_INFO, in the pacing rate and in the metrics cache. BPF programs on the RTT callback get the clamped sample too. Found by code inspection (Eric Dumazet), and confirmed with LLM generated reproducers on an unmodified kernel. Fixed by LLM, and tested with the reproducers and existing kernel selftests. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Fixes: 740b0f1841f6 ("tcp: switch rtt estimations to usec resolution") Signed-off-by: Chris Mason Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20261118155144.18393-3-mason@kernel.org Signed-off-by: Paolo Abeni --- include/net/tcp.h | 7 +++++++ net/ipv4/tcp_input.c | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 6a714189bcc7..a617a72ee2c6 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -164,6 +164,13 @@ static_assert((1 << ATO_BITS) > TCP_DELACK_MAX); #define TCP_TIMEOUT_MIN_US (2*USEC_PER_MSEC) /* Min TCP timeout in microsecs */ +/* Max RTT sample for tcp_rtt_estimator(). srtt_us holds 8 times the RTT, and + * mdev_us and rttvar_us up to 4 times its deviation, all in u32, like the sum + * in __tcp_set_rto(). A larger sample could not raise the RTO, which + * TCP_RTO_MAX bounds. + */ +#define TCP_RTT_MAX_US (TCP_RTO_MAX_SEC * USEC_PER_SEC) + #define TCP_TIMEOUT_INIT ((unsigned)(1*HZ)) /* RFC6298 2.1 initial RTO value */ #define TCP_TIMEOUT_FALLBACK ((unsigned)(3*HZ)) /* RFC 1122 initial RTO value, now * used as a fallback RTO for the diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index f65697bc96c9..e796497b84be 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -1098,8 +1098,11 @@ static void tcp_event_data_recv(struct sock *sk, struct sk_buff *skb) static void tcp_rtt_estimator(struct sock *sk, long mrtt_us) { struct tcp_sock *tp = tcp_sk(sk); - long m = mrtt_us; /* RTT */ u32 srtt = tp->srtt_us; + long m; /* RTT */ + + mrtt_us = min(mrtt_us, TCP_RTT_MAX_US); + m = mrtt_us; /* The following amusing code comes from Jacobson's * article in SIGCOMM '88. Note that rtt and mdev From 1b91d9c09aa703d19995412ad41f23b8886bc608 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Wed, 18 Nov 2026 10:51:47 -0500 Subject: [PATCH 114/117] tcp: reject RTT samples from TSecr above 120 s tcp_rtt_tsopt_us() returns the timestamp clock minus TSecr as an RTT sample, and accepts up to 2,147 s. If TSecr echoes an old timestamp, the sample is the age of that timestamp, not an RTT. tcp_ack_update_rtt() takes this sample for an ACK of retransmitted data. tcp_rtt_estimator() clamps it to 120 s. The congestion control gets the sample unclamped, in rs->rtt_us. tcp_rcv_rtt_measure_ts() takes the same sample for the RTT estimate of the receive side. The fix used here is to reject a sample from TSecr above 120 s, for both callers of tcp_rtt_tsopt_us(). An ACK of retransmitted data whose TSecr is more than 120 s old now gives no RTT sample. So it no longer resets the backoff, as on a connection without timestamps. Found by LLM code inspection, and confirmed with LLM generated reproducers on an unmodified kernel. Fixed by LLM, and tested with the reproducers and existing kernel selftests. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Chris Mason Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20261118155144.18393-4-mason@kernel.org Signed-off-by: Paolo Abeni --- net/ipv4/tcp_input.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index e796497b84be..69e038b9389a 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -901,15 +901,16 @@ new_measure: tp->rcv_rtt_est.time = tp->tcp_mstamp; } +/* A sample from TSecr above TCP_RTT_MAX_US is bogus, not large. */ static s32 tcp_rtt_tsopt_us(const struct tcp_sock *tp, u32 min_delta) { u32 delta, delta_us; delta = tcp_time_stamp_ts(tp) - tp->rx_opt.rcv_tsecr; if (tp->tcp_usec_ts) - return delta; + return delta <= TCP_RTT_MAX_US ? delta : -1; - if (likely(delta < INT_MAX / (USEC_PER_SEC / TCP_TS_HZ))) { + if (likely(delta <= TCP_RTT_MAX_US / (USEC_PER_SEC / TCP_TS_HZ))) { if (!delta) delta = min_delta; delta_us = delta * (USEC_PER_SEC / TCP_TS_HZ); From f22d5042faa6b03df9586074e0322db60973933b Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Wed, 18 Nov 2026 10:51:48 -0500 Subject: [PATCH 115/117] tcp: clamp the samples in tcp_rcv_rtt_update() tcp_rcv_rtt_update() starts with sample << 3 in u32 arithmetic, so a sample of 536.9 s or more wraps. tcp_rcv_rtt_measure() can hand it one. Its sample is the time the sender took to fill one receive window, and a low rate flow can take longer than that. This caller only looks for a minimum, so the wrapped value is kept whenever it is below the current estimate. A 540 s sample ends up as an estimate of about 3.1 s. Clamp the sample to TCP_RTT_MAX_US in tcp_rcv_rtt_update(), like tcp_rtt_estimator() does on the send side. That covers both callers, and the smoothed estimate now tops out at 8 * 120 s, which fits in a u32. Found by code inspection (Eric Dumazet), who also suggested the fix. Confirmed with an LLM generated reproducer on an unmodified kernel, and tested with the reproducer and existing kernel selftests. Fixes: 645f4c6f2ebd ("tcp: switch rcv_rtt_est and rcvq_space to high resolution timestamps") Suggested-by: Eric Dumazet Signed-off-by: Chris Mason Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20261118155144.18393-5-mason@kernel.org Signed-off-by: Paolo Abeni --- net/ipv4/tcp_input.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 69e038b9389a..d9a66a1342ef 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -857,7 +857,11 @@ void tcp_initialize_rcv_mss(struct sock *sk) static void tcp_rcv_rtt_update(struct tcp_sock *tp, u32 sample, int win_dep) { u32 new_sample, old_sample = tp->rcv_rtt_est.rtt_us; - long m = sample << 3; + long m; + + /* Keep sample << 3 and the smoothed estimate within u32. */ + sample = min(sample, TCP_RTT_MAX_US); + m = sample << 3; if (old_sample == 0 || m < old_sample) { new_sample = m; From 314b35c8173cb5726ae4c3dd401d982e16de9482 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Wed, 18 Nov 2026 10:51:49 -0500 Subject: [PATCH 116/117] tcp: bound the rto_min of a route in tcp_rto_min() For a route with a locked RTAX_RTO_MIN, tcp_rto_min() returns the metric as it is, and that can be any 32-bit number of milliseconds. All other ways to set the minimum RTO have a nonzero floor: the tcp_rto_min_us sysctl, TCP_RTO_MIN_US and TCP_BPF_RTO_MIN. Both ends of that range give us trouble. With an rto_min of 0, tcp_init_metrics() can start a connection with an RTO of 0, if the cached RTT is below one jiffy: icsk_rto = crtt + max(2 * crtt, tcp_rto_min(sk)) = 0 It sets icsk_rto itself, so the lower bound in __tcp_set_rto() does not help here. At the other end, tcp_rto_min_us() and the sum in __tcp_set_rto() are u32 values in usec, so an rto_min of more than about 71 minutes does not fit. Clamp a locked rto_min to the range from one jiffy to TCP_RTO_MAX in tcp_rto_min(). ip_metrics_convert() could reject these values instead, as it does for a locked cwnd of 0. But a route with "rto_min lock 0" is accepted today and mostly works, so that would break existing setups. A route still shows the rto_min that it was given, while TCP uses one jiffy or 120 s. Found by LLM code inspection, and confirmed with LLM generated reproducers on an unmodified kernel. Fixed by LLM, and tested with the reproducers and existing kernel selftests. Fixes: 05bb1fad1cde ("[TCP]: Allow minimum RTO to be configurable via routing metrics.") Signed-off-by: Chris Mason Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20261118155144.18393-6-mason@kernel.org Signed-off-by: Paolo Abeni --- include/net/tcp.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index a617a72ee2c6..27de546dc802 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -939,7 +939,8 @@ static inline u32 tcp_rto_min(const struct sock *sk) u32 rto_min = READ_ONCE(inet_csk(sk)->icsk_rto_min); if (dst && dst_metric_locked(dst, RTAX_RTO_MIN)) - rto_min = dst_metric_rtt(dst, RTAX_RTO_MIN); + rto_min = clamp(dst_metric_rtt(dst, RTAX_RTO_MIN), + 1, TCP_RTO_MAX); return rto_min; } From b10c986f1769287270de248548476f6dc2275d59 Mon Sep 17 00:00:00 2001 From: Chris J Arges Date: Wed, 18 Nov 2026 08:32:27 -0600 Subject: [PATCH 117/117] net: prevent receive header offset overflow during decapsulation Repeated decapsulation can leave skb->data far from skb->head while the remaining packet data is still valid. Since the skb header positions are 16-bit offsets, a later header update can truncate and make header access use unrelated bytes and eventually crash. Limit receive headroom to 32 KiB. This is well beyond the headroom of normal packets while allowing the networking stack to pull enough headers in a single pass without overflowing 16-bit header offsets. Tunnel decapsulation re-enters __netif_receive_skb_core(), so its check protects nested IPIP and GRE. FOU and GUE bypass receive core, so check their IPv4 and IPv6 resubmission paths too. Together, these checks prevent 16-bit header-offset truncation in cases of repeated decapsulation. Report these rejections with the SKB_RX_HEADROOM drop reason. Fixes: 1a37e412a022 ("net: Use 16bits for *_headers fields of struct skbuff") Cc: stable@kernel.org Suggested-by: Eric Dumazet Signed-off-by: Chris J Arges Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261118-prevent_rx_header_offset_overflow-v1-1-92a5be55f994@cloudflare.com Signed-off-by: Paolo Abeni --- include/linux/skbuff.h | 1 + include/net/dropreason-core.h | 6 ++++++ net/core/dev.c | 4 ++++ net/ipv4/ip_input.c | 6 ++++++ net/ipv6/ip6_input.c | 4 ++++ 5 files changed, 21 insertions(+) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 6787fcf6ac3e..adc61f5e3e85 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -268,6 +268,7 @@ SKB_WITH_OVERHEAD((PAGE_SIZE << (ORDER)) - (X)) #define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0)) #define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 2)) +#define SKB_MAX_RX_HEADROOM (U16_MAX / 2) /* return minimum truesize of one skb containing X bytes of data */ #define SKB_TRUESIZE(X) ((X) + \ diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h index fa2fe8990557..903d6a3a0ff1 100644 --- a/include/net/dropreason-core.h +++ b/include/net/dropreason-core.h @@ -128,6 +128,7 @@ FN(PSP_INPUT) \ FN(PSP_OUTPUT) \ FN(RECURSION_LIMIT) \ + FN(SKB_RX_HEADROOM) \ FNe(MAX) /** @@ -612,6 +613,11 @@ enum skb_drop_reason { * itself. */ SKB_DROP_REASON_RECURSION_LIMIT, + /** + * @SKB_DROP_REASON_SKB_RX_HEADROOM: accumulated receive headroom + * exceeds the header-offset budget. + */ + SKB_DROP_REASON_SKB_RX_HEADROOM, /** * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which * shouldn't be used as a real 'reason' - only for tracing code gen diff --git a/net/core/dev.c b/net/core/dev.c index 3c58db732761..6140fd9d11cd 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6223,6 +6223,10 @@ static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc, trace_netif_receive_skb(skb); orig_dev = skb->dev; + if (unlikely(skb_headroom(skb) > SKB_MAX_RX_HEADROOM)) { + drop_reason = SKB_DROP_REASON_SKB_RX_HEADROOM; + goto drop; + } skb_reset_network_header(skb); #if !defined(CONFIG_DEBUG_NET) diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index 9860178752b8..c74886b1f445 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -207,6 +207,12 @@ resubmit: ret = INDIRECT_CALL_2(ipprot->handler, tcp_v4_rcv, udp_rcv, skb); if (ret < 0) { + if (unlikely(skb_headroom(skb) > SKB_MAX_RX_HEADROOM)) { + __IP_INC_STATS(net, IPSTATS_MIB_INDISCARDS); + kfree_skb_reason(skb, + SKB_DROP_REASON_SKB_RX_HEADROOM); + return; + } protocol = -ret; goto resubmit; } diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c index d332ec60f915..6dc1211eade6 100644 --- a/net/ipv6/ip6_input.c +++ b/net/ipv6/ip6_input.c @@ -479,6 +479,10 @@ resubmit_final: ret = INDIRECT_CALL_2(ipprot->handler, tcp_v6_rcv, udpv6_rcv, skb); if (ret > 0) { + if (unlikely(skb_headroom(skb) > SKB_MAX_RX_HEADROOM)) { + SKB_DR_SET(reason, SKB_RX_HEADROOM); + goto discard; + } if (ipprot->flags & INET6_PROTO_FINAL) { /* Not an extension header, most likely UDP * encapsulation. Use return value as nexthdr