Skip to contentSkip to conversation

FAILED: patch "[PATCH] gve: Fix race between stats query and queue reconfig" failed to apply to 6.18-stable tree

PATCH New [email protected] 2 participants 2 messages Nov 25

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 7de69da15088ac2add08eb2b5f5c0a79fd461c1e
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026112501-underpay-modified-f1d3@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 7de69da15088ac2add08eb2b5f5c0a79fd461c1e Mon Sep 17 00:00:00 2001
From: Pin-yen Lin <[email protected]>
Date: Mon, 9 Nov 2026 18:20:33 +0000
Subject: [PATCH] gve: Fix race between stats query and queue reconfig

Fix a concurrency bug where network statistics queries race with queue reconfiguration or interface teardown, causing a Use-After-Free (UAF) or NULL pointer dereference.

Currently, statistics queries access priv->tx and priv->rx without locking. When an interface is brought down or reconfigured, gve_queues_mem_remove() frees these arrays. A concurrent stats query can dereference freed queue structures and crash the kernel.

This issue was discovered and actually triggered by the drivers/net/stats.py selftest. When an interface was brought down, querying per-queue statistics via Netlink caused a kernel NULL pointer dereference in gve_get_rx_queue_stats():

  BUG: kernel NULL pointer dereference, address: 00000000000000a0
  RIP: 0010:gve_get_rx_queue_stats+0x17/0x50 [gve]
  Call Trace:
   <TASK>
   netdev_stat_queue_sum+0x11c/0x250
   netdev_nl_stats_by_netdev+0x21b/0x2d0
   netdev_nl_qstats_get_dumpit+0xd2/0x220
   genl_dumpit+0x32/0x90
   netlink_dump+0x1d2/0x450
   __netlink_dump_start+0x1db/0x2a0
   genl_family_rcv_msg_dumpit+0x9b/0x100
   ...

The per-queue stats callbacks run under the netdev instance lock, so this NULL dereference is not a race; it happens on any query while the interface is down.

Additionally, concurrent stats queries during queue reconfiguration can race with gve_queues_mem_remove(), causing a Use-After-Free. This affects gve_get_stats(), which does not hold the instance lock. gve_handle_report_stats() also runs without it; it is stopped before queue teardown, but can still read priv->rx[idx] while the single-queue restart path rewrites it.

Fix this by introducing stats_lock to serialize stats queries against queue teardown. In gve_queues_mem_remove(), queue pointers are set to NULL under stats_lock before freeing. Stats readers acquire the lock and verify pointers are non-NULL before reading counters. The per-queue stats callbacks already run under the instance lock, but take stats_lock as well for consistency.
The single-queue restart path also rewrites priv->rx[idx] in place, so gve_rx_queue_stop() and gve_rx_queue_start() do those writes under stats_lock as well.

This change was tested using the DQO RDA queue format.

Fixes f5cedc84a30d ("gve: Add transmit and receive support")
Fixes 2e5e0932dff5 ("gve: add support for basic queue stats")
drivers/net/ethernet/google/gve/gve.h +5 -0
index b7ce6e8632db..1911d05eb697 100644
@@ -957,6 +957,11 @@ struct gve_priv {
 	struct workqueue_struct *gve_wq;
 	struct work_struct service_task;
 	struct work_struct stats_report_task;
+	/* Protects the priv->tx/priv->rx arrays, the in-place rewrite of
+	 * priv->rx[idx] and the queue counts against stats readers that do
+	 * not hold the netdev instance lock.
+	 */
+	spinlock_t stats_lock;
 	unsigned long service_task_flags;
 	unsigned long state_flags;
 
drivers/net/ethernet/google/gve/gve_main.c +39 -4

145 lines not on this page · raw message

maintainer
#1 lore raw

PATCH 1/1 gve: Fix race between stats query and queue reconfig

From: Pin-yen Lin <[email protected]>

[ Upstream commit 7de69da15088ac2add08eb2b5f5c0a79fd461c1e ]

Fix a concurrency bug where network statistics queries race with queue reconfiguration or interface teardown, causing a Use-After-Free (UAF) or NULL pointer dereference.

Currently, statistics queries access priv->tx and priv->rx without locking. When an interface is brought down or reconfigured, gve_queues_mem_remove() frees these arrays. A concurrent stats query can dereference freed queue structures and crash the kernel.

This issue was discovered and actually triggered by the drivers/net/stats.py selftest. When an interface was brought down, querying per-queue statistics via Netlink caused a kernel NULL pointer dereference in gve_get_rx_queue_stats():

  BUG: kernel NULL pointer dereference, address: 00000000000000a0
  RIP: 0010:gve_get_rx_queue_stats+0x17/0x50 [gve]
  Call Trace:
   <TASK>
   netdev_stat_queue_sum+0x11c/0x250
   netdev_nl_stats_by_netdev+0x21b/0x2d0
   netdev_nl_qstats_get_dumpit+0xd2/0x220
   genl_dumpit+0x32/0x90
   netlink_dump+0x1d2/0x450
   __netlink_dump_start+0x1db/0x2a0
   genl_family_rcv_msg_dumpit+0x9b/0x100
   ...

The per-queue stats callbacks run under the netdev instance lock, so this NULL dereference is not a race; it happens on any query while the interface is down.

Additionally, concurrent stats queries during queue reconfiguration can race with gve_queues_mem_remove(), causing a Use-After-Free. This affects gve_get_stats(), which does not hold the instance lock. gve_handle_report_stats() also runs without it; it is stopped before queue teardown, but can still read priv->rx[idx] while the single-queue restart path rewrites it.

Fix this by introducing stats_lock to serialize stats queries against queue teardown. In gve_queues_mem_remove(), queue pointers are set to NULL under stats_lock before freeing. Stats readers acquire the lock and verify pointers are non-NULL before reading counters. The per-queue stats callbacks already run under the instance lock, but take stats_lock as well for consistency.
The single-queue restart path also rewrites priv->rx[idx] in place, so gve_rx_queue_stop() and gve_rx_queue_start() do those writes under stats_lock as well.

This change was tested using the DQO RDA queue format.

Fixes f5cedc84a30d ("gve: Add transmit and receive support")
Fixes 2e5e0932dff5 ("gve: add support for basic queue stats")
[ sashal: Adjusted context in gve_queues_start() and gve_queues_mem_remove() because this tree lacks the qpl, header-split and packet-buffer-size lines, so the unlock follows rx_desc_cnt. ]
---
 drivers/net/ethernet/google/gve/gve.h      |  5 +++
 drivers/net/ethernet/google/gve/gve_main.c | 43 ++++++++++++++++++++--
 2 files changed, 44 insertions(+), 4 deletions(-)
drivers/net/ethernet/google/gve/gve.h +5 -0
index f0bc910dd6d44..2aecaf892d659 100644
@@ -877,6 +877,11 @@ struct gve_priv {
 	struct workqueue_struct *gve_wq;
 	struct work_struct service_task;
 	struct work_struct stats_report_task;
+	/* Protects the priv->tx/priv->rx arrays, the in-place rewrite of
+	 * priv->rx[idx] and the queue counts against stats readers that do
+	 * not hold the netdev instance lock.
+	 */
+	spinlock_t stats_lock;
 	unsigned long service_task_flags;
 	unsigned long state_flags;
 
drivers/net/ethernet/google/gve/gve_main.c +39 -4

145 lines not on this page · raw message

Signature · 1 line
2.53.0