Commit d4697885 authored by Joshua Washington's avatar Joshua Washington Committed by Wang Liang
Browse files

gve: guard XDP xmit NDO on existence of xdp queues

stable inclusion
from stable-v6.6.70
commit cbe9eb2c39d09f3c8574febcfa39d8c09d0c7cb5
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IBJ6O9
CVE: CVE-2024-57932

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=cbe9eb2c39d09f3c8574febcfa39d8c09d0c7cb5



--------------------------------

commit ff7c2dea9dd1a436fc79d6273adffdcc4a7ffea3 upstream.

In GVE, dedicated XDP queues only exist when an XDP program is installed
and the interface is up. As such, the NDO XDP XMIT callback should
return early if either of these conditions are false.

In the case of no loaded XDP program, priv->num_xdp_queues=0 which can
cause a divide-by-zero error, and in the case of interface down,
num_xdp_queues remains untouched to persist XDP queue count for the next
interface up, but the TX pointer itself would be NULL.

The XDP xmit callback also needs to synchronize with a device
transitioning from open to close. This synchronization will happen via
the GVE_PRIV_FLAGS_NAPI_ENABLED bit along with a synchronize_net() call,
which waits for any RCU critical sections at call-time to complete.

Fixes: 39a7f4aa ("gve: Add XDP REDIRECT support for GQI-QPL format")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarJoshua Washington <joshwash@google.com>
Signed-off-by: default avatarPraveen Kaligineedi <pkaligineedi@google.com>
Reviewed-by: default avatarPraveen Kaligineedi <pkaligineedi@google.com>
Reviewed-by: default avatarShailend Chand <shailend@google.com>
Reviewed-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarWang Liang <wangliang74@huawei.com>
parent f8c09dd6
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1757,6 +1757,9 @@ static void gve_turndown(struct gve_priv *priv)

	gve_clear_napi_enabled(priv);
	gve_clear_report_stats(priv);

	/* Make sure that all traffic is finished processing. */
	synchronize_net();
}

static void gve_turnup(struct gve_priv *priv)
+4 −1
Original line number Diff line number Diff line
@@ -777,9 +777,12 @@ int gve_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames,
	struct gve_tx_ring *tx;
	int i, err = 0, qid;

	if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
	if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK) || !priv->xdp_prog)
		return -EINVAL;

	if (!gve_get_napi_enabled(priv))
		return -ENETDOWN;

	qid = gve_xdp_tx_queue_id(priv,
				  smp_processor_id() % priv->num_xdp_queues);