um: vector: fix NULL pointer derefs in queue-less transports
Subsystems (2)
PATCH 1/1 um: vector: fix NULL pointer derefs in queue-less transports
TAP transport sets neither VECTOR_RX nor VECTOR_TX, so vector_net_open() never allocates rx_queue or tx_queue. HYBRID sets VECTOR_RX but not VECTOR_TX, so tx_queue is NULL there too.
vector_reset_stats(), vector_poll(), vector_get_ethtool_stats(), and vector_get_ringparam() unconditionally deref these queue pointers, causing a NULL pointer crash on SMP or with any lock debugging option.
Guard all queue pointer accesses with NULL checks.
---
Found while enabling KCOV and lockdep on UML for a network-stack test lab. Tested boot with SMP=y + PROVE_LOCKING + DEBUG_SPINLOCK + DEBUG_LOCK_ALLOC + LOCKDEP + KCOV, all with vec0:transport=tap.
Without the fix, the same config panics at addr 0x18 (SMP, no debug), 0x1c (DEBUG_SPINLOCK), or 0x30 (lockdep) -- all offsets into a NULL vector_queue pointer.
arch/um/drivers/vector_kern.c | 48 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-)
arch/um/drivers/vector_kern.c +24 -24
@@ -105,25 +105,18 @@ static const struct {static void vector_reset_stats (struct vector_private *vp) { -/* We reuse the existing queue locks for stats */ - -/* RX stats are modified with RX head_lock held -* in vector_poll. -*/ - -spin_lock (&vp->rx_queue->head_lock); +if (vp->rx_queue) +spin_lock (&vp->rx_queue->head_lock); vp->estats.rx_queue_max =0 ; vp->estats.rx_queue_running_average =0 ; vp->estats.rx_encaps_errors =0 ; vp->estats.sg_ok =0 ; vp->estats.sg_linearized =0 ; -spin_unlock (&vp->rx_queue->head_lock); - -/* TX stats are modified with TX head_lock held -* in vector_send. -*/ +if (vp->rx_queue) +spin_unlock (&vp->rx_queue->head_lock); -spin_lock (&vp->tx_queue->head_lock); +if (vp->tx_queue) +spin_lock (&vp->tx_queue->head_lock); vp->estats.tx_timeout_count =0 ; vp->estats.tx_restart_queue =0 ; vp->estats.tx_kicks =0 ;
@@ -131,7 +124,8 @@ static void vector_reset_stats(struct vector_private *vp) vp->estats.tx_flow_control_xoff =0 ; vp->estats.tx_queue_max =0 ; vp->estats.tx_queue_running_average =0 ; -spin_unlock (&vp->tx_queue->head_lock); +if (vp->tx_queue) +spin_unlock (&vp->tx_queue->head_lock); }static int get_mtu (struct arglist *def)
@@ -1163,7 +1157,8 @@ static int vector_poll(struct napi_struct *napi, int budget)if ((vp->options &VECTOR_TX ) !=0 ) tx_enqueued = (vector_send (vp->tx_queue) >0 ); -spin_lock (&vp->rx_queue->head_lock); +if (vp->rx_queue) +spin_lock (&vp->rx_queue->head_lock);if ((vp->options &VECTOR_RX ) >0 ) err =vector_mmsg_rx (vp, budget);else {
@@ -1171,7 +1166,8 @@ static int vector_poll(struct napi_struct *napi, int budget)if (err >0 ) err =1 ; } -spin_unlock (&vp->rx_queue->head_lock); +if (vp->rx_queue) +spin_unlock (&vp->rx_queue->head_lock);if (err >0 ) work_done += err;
@@ -1421,10 +1417,10 @@ static void vector_get_ringparam(struct net_device *netdev, {struct vector_private *vp =netdev_priv (netdev); - ring->rx_max_pending = vp->rx_queue->max_depth; - ring->tx_max_pending = vp->tx_queue->max_depth; - ring->rx_pending = vp->rx_queue->max_depth; - ring->tx_pending = vp->tx_queue->max_depth; + ring->rx_max_pending = vp->rx_queue ? vp->rx_queue->max_depth :0 ; + ring->tx_max_pending = vp->tx_queue ? vp->tx_queue->max_depth :0 ; + ring->rx_pending = ring->rx_max_pending; + ring->tx_pending = ring->tx_max_pending; }static void vector_get_strings (struct net_device *dev,u32 stringset,u8 *buf)
@@ -1466,11 +1462,15 @@ static void vector_get_ethtool_stats(struct net_device *dev,* to date. */ -spin_lock (&vp->tx_queue->head_lock); -spin_lock (&vp->rx_queue->head_lock); +if (vp->tx_queue) +spin_lock (&vp->tx_queue->head_lock); +if (vp->rx_queue) +spin_lock (&vp->rx_queue->head_lock);memcpy (tmp_stats, &vp->estats,sizeof (struct vector_estats )); -spin_unlock (&vp->rx_queue->head_lock); -spin_unlock (&vp->tx_queue->head_lock); +if (vp->rx_queue) +spin_unlock (&vp->rx_queue->head_lock); +if (vp->tx_queue) +spin_unlock (&vp->tx_queue->head_lock); } static int vector_get_coalesce(struct net_device *netdev,
Signature · 1 line
2.53.0
Quoted 119 lines · Michael Bommarito
TAP transport sets neither
VECTOR_RXnorVECTOR_TX, sovector_net_open()never allocatesrx_queueortx_queue. HYBRID setsVECTOR_RXbut notVECTOR_TX, sotx_queueis NULL there too.
vector_reset_stats(),vector_poll(),vector_get_ethtool_stats(), andvector_get_ringparam()unconditionally deref these queue pointers, causing a NULL pointer crash on SMP or with any lock debugging option.Guard all queue pointer accesses with NULL checks.
Fixes 49da7e64f33e ("High Performance UML Vector Network Driver")Cc Anton Ivanov <[email protected]>Assisted-by Claude:claude-opus-4-6Assisted-by Codex:gpt-5-4Signed-off-by Michael Bommarito <[email protected]>---
Found while enabling KCOV and lockdep on UML for a network-stack test lab. Tested boot with SMP=y +PROVE_LOCKING+DEBUG_SPINLOCK+DEBUG_LOCK_ALLOC+ LOCKDEP + KCOV, all with vec0:transport=tap.Without the fix, the same config panics at addr
0x18(SMP, no debug),0x1c(DEBUG_SPINLOCK), or0x30(lockdep) -- all offsets into a NULLvector_queuepointer.arch/um/drivers/vector_kern.c | 48 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-)arch/um/drivers/vector_kern.c +20
-22@@ -105,25 +105,18 @@ static const struct {static void vector_reset_stats (struct vector_private *vp) { -/* We reuse the existing queue locks for stats */ - -/* RX stats are modified with RX head_lock held -* in vector_poll. -*/ - -spin_lock (&vp->rx_queue->head_lock); +if (vp->rx_queue) +spin_lock (&vp->rx_queue->head_lock); vp->estats.rx_queue_max =0 ; vp->estats.rx_queue_running_average =0 ; vp->estats.rx_encaps_errors =0 ; vp->estats.sg_ok =0 ; vp->estats.sg_linearized =0 ; -spin_unlock (&vp->rx_queue->head_lock); - -/* TX stats are modified with TX head_lock held -* in vector_send. -*/ +if (vp->rx_queue) +spin_unlock (&vp->rx_queue->head_lock); -spin_lock (&vp->tx_queue->head_lock); +if (vp->tx_queue) +spin_lock (&vp->tx_queue->head_lock); vp->estats.tx_timeout_count =0 ; vp->estats.tx_restart_queue =0 ; vp->estats.tx_kicks =0 ;@@ -131,7 +124,8 @@ static void vector_reset_stats(struct vector_private *vp) vp->estats.tx_flow_control_xoff =0 ; vp->estats.tx_queue_max =0 ; vp->estats.tx_queue_running_average =0 ; -spin_unlock (&vp->tx_queue->head_lock); +if (vp->tx_queue) +spin_unlock (&vp->tx_queue->head_lock); }static int get_mtu (struct arglist *def)@@ -1163,7 +1157,8 @@ static int vector_poll(struct napi_struct *napi, int budget)if ((vp->options &VECTOR_TX ) !=0 ) tx_enqueued = (vector_send (vp->tx_queue) >0 ); -spin_lock (&vp->rx_queue->head_lock); +if (vp->rx_queue) +spin_lock (&vp->rx_queue->head_lock);if ((vp->options &VECTOR_RX ) >0 ) err =vector_mmsg_rx (vp, budget);else {@@ -1171,7 +1166,8 @@ static int vector_poll(struct napi_struct *napi, int budget)if (err >0 ) err =1 ; } -spin_unlock (&vp->rx_queue->head_lock); +if (vp->rx_queue) +spin_unlock (&vp->rx_queue->head_lock);if (err >0 ) work_done += err;@@ -1421,10 +1417,10 @@ static void vector_get_ringparam(struct net_device *netdev, {struct vector_private *vp =netdev_priv (netdev); - ring->rx_max_pending = vp->rx_queue->max_depth; - ring->tx_max_pending = vp->tx_queue->max_depth; - ring->rx_pending = vp->rx_queue->max_depth; - ring->tx_pending = vp->tx_queue->max_depth; + ring->rx_max_pending = vp->rx_queue ? vp->rx_queue->max_depth :0 ; + ring->tx_max_pending = vp->tx_queue ? vp->tx_queue->max_depth :0 ; + ring->rx_pending = ring->rx_max_pending; + ring->tx_pending = ring->tx_max_pending; }static void vector_get_strings (struct net_device *dev,u32 stringset,u8 *buf)@@ -1466,11 +1462,15 @@ static void vector_get_ethtool_stats(struct net_device *dev,* to date. */ -spin_lock (&vp->tx_queue->head_lock); -spin_lock (&vp->rx_queue->head_lock); +if (vp->tx_queue) +spin_lock (&vp->tx_queue->head_lock); +if (vp->rx_queue) +spin_lock (&vp->rx_queue->head_lock);
arch/um/drivers/vector_kern.c static void vector_get_ethtool_stats(struct net_device *dev, · line 1476
Quoted 10 lines
arch/um/drivers/vector_kern.c +4
-2memcpy (tmp_stats, &vp->estats,sizeof (struct vector_estats )); -spin_unlock (&vp->rx_queue->head_lock); -spin_unlock (&vp->tx_queue->head_lock); +if (vp->rx_queue) +spin_unlock (&vp->rx_queue->head_lock); +if (vp->tx_queue) +spin_unlock (&vp->tx_queue->head_lock); } static int vector_get_coalesce(struct net_device *netdev,
Signature · 2 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661
Johannes Berg
maintainerSorry, I didn't pay much attention to this before...
Quoted 9 lines · Michael Bommarito
TAP transport sets neither
VECTOR_RXnorVECTOR_TX, sovector_net_open()never allocatesrx_queueortx_queue. HYBRID setsVECTOR_RXbut notVECTOR_TX, sotx_queueis NULL there too.
vector_reset_stats(),vector_poll(),vector_get_ethtool_stats(), andvector_get_ringparam()unconditionally deref these queue pointers, causing a NULL pointer crash on SMP or with any lock debugging option.Guard all queue pointer accesses with NULL checks.
I see how that fixes the crash, but maybe you could write a few words on why it's still correct?
arch/um/drivers/vector_kern.c static void vector_get_ethtool_stats(struct net_device *dev, · line 1469
Quoted 7 lines
arch/um/drivers/vector_kern.c +4
-2-spin_lock (&vp->tx_queue->head_lock); -spin_lock (&vp->rx_queue->head_lock); +if (vp->tx_queue) +spin_lock (&vp->tx_queue->head_lock); +if (vp->rx_queue) +spin_lock (&vp->rx_queue->head_lock);memcpy (tmp_stats, &vp->estats,sizeof (struct vector_estats ));
I could imagine for example this memcpy() observing a torn write or something like that and getting strange results out?
Or is that just not a thing because UML is (still) mostly non-SMP?
Also I think there are related issues that wouldn't show up for a broken configuration, such as if create_queue() fails to allocate memory and we get an inconsistency between tx_queue / rx_queue pointers and VECTOR_TX / VECTOR_RX flags? Though I'll admit that seems highly unlikely.
johannes