Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH 0/2] virtio-net/dim: fix irq moderation init failure unwind
@ 2026-09-30  8:19 Jianlin Shi
  2026-09-30  8:19 ` [PATCH 1/2] dim: clear irq_moder on init failure Jianlin Shi
  2026-09-30  8:19 ` [PATCH 2/2] virtio-net: unwind VQs when irq moderation init fails Jianlin Shi
  0 siblings, 2 replies; 7+ messages in thread
From: Jianlin Shi @ 2026-09-30  8:19 UTC (permalink / raw)
  To: netdev, virtualization
  Cc: mst, jasowangio, eperezma, xuanzhuo, andrew+netdev, davem,
	edumazet, kuba, pabeni, talgi, hengqi, horms

net_dim_init_irq_moder() leaves dev->irq_moder dangling when profile
allocation fails.  virtio-net probe then skips virtqueue teardown if
that init fails after init_vqs().

Patch 1 makes the dim init failure path clear irq_moder, so
net_dim_free_irq_moder() is a no-op.

Patch 2 sends the virtio-net failure through the existing
free_irq_moder unwind (reset + del_vqs), matching the page-pool
failure path.

Patch 2 depends on patch 1.

Jianlin Shi (2):
  dim: clear irq_moder on init failure
  virtio-net: unwind VQs when irq moderation init fails

 drivers/net/virtio_net.c | 2 +-
 lib/dim/net_dim.c        | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] dim: clear irq_moder on init failure
  2026-09-30  8:19 [PATCH 0/2] virtio-net/dim: fix irq moderation init failure unwind Jianlin Shi
@ 2026-09-30  8:19 ` Jianlin Shi
  2026-09-30  8:33   ` sashiko-bot
  2026-10-06  1:53   ` Jakub Kicinski
  2026-09-30  8:19 ` [PATCH 2/2] virtio-net: unwind VQs when irq moderation init fails Jianlin Shi
  1 sibling, 2 replies; 7+ messages in thread
From: Jianlin Shi @ 2026-09-30  8:19 UTC (permalink / raw)
  To: netdev, virtualization
  Cc: mst, jasowangio, eperezma, xuanzhuo, andrew+netdev, davem,
	edumazet, kuba, pabeni, talgi, hengqi, horms

net_dim_init_irq_moder() publishes the allocated object in
dev->irq_moder before copying the moderation profiles.  If kmemdup()
fails, the object is freed but the pointer is left dangling.
net_dim_free_irq_moder() treats a non-NULL irq_moder as live, so a
caller unwinding the failure path would use-after-free.

NULL the pointer after freeing it.  On error the device is left as if
initialization never happened.

Fixes: f750dfe825b90 ("ethtool: provide customized dim profile management")
Signed-off-by: Jianlin Shi <shijianlin11@foxmail.com>
---
 lib/dim/net_dim.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/dim/net_dim.c b/lib/dim/net_dim.c
index d8d4f6553559..bf59deae6a29 100644
--- a/lib/dim/net_dim.c
+++ b/lib/dim/net_dim.c
@@ -141,6 +141,7 @@ int net_dim_init_irq_moder(struct net_device *dev, u8 profile_flags,
 	kfree(rxp);
 free_moder:
 	kfree(moder);
+	dev->irq_moder = NULL;
 	return -ENOMEM;
 }
 EXPORT_SYMBOL(net_dim_init_irq_moder);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] virtio-net: unwind VQs when irq moderation init fails
  2026-09-30  8:19 [PATCH 0/2] virtio-net/dim: fix irq moderation init failure unwind Jianlin Shi
  2026-09-30  8:19 ` [PATCH 1/2] dim: clear irq_moder on init failure Jianlin Shi
@ 2026-09-30  8:19 ` Jianlin Shi
  2026-09-30  8:33   ` sashiko-bot
  1 sibling, 1 reply; 7+ messages in thread
From: Jianlin Shi @ 2026-09-30  8:19 UTC (permalink / raw)
  To: netdev, virtualization
  Cc: mst, jasowangio, eperezma, xuanzhuo, andrew+netdev, davem,
	edumazet, kuba, pabeni, talgi, hengqi, horms

virtnet_probe() calls init_vqs() before virtnet_init_irq_moder().
The failure path used "goto free", which only calls free_netdev() and
skips virtio_reset_device() and virtnet_del_vqs().  The virtqueues and
their DMA mappings leak.

Use the existing free_irq_moder label, as virtnet_create_page_pools()
already does.  This is safe only after net_dim_init_irq_moder() clears
dev->irq_moder on failure; otherwise virtnet_free_irq_moder() would
free the dangling pointer.

Fixes: dcb67f6a9ead6 ("virtio-net: support dim profile fine-tuning")
Signed-off-by: Jianlin Shi <shijianlin11@foxmail.com>
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index e34c52d059d3..ef61097c4404 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -6996,7 +6996,7 @@ static int virtnet_probe(struct virtio_device *vdev)
 
 		err = virtnet_init_irq_moder(vi);
 		if (err)
-			goto free;
+			goto free_irq_moder;
 	}
 
 	/* Create page pools for receive queues.
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] dim: clear irq_moder on init failure
  2026-09-30  8:19 ` [PATCH 1/2] dim: clear irq_moder on init failure Jianlin Shi
@ 2026-09-30  8:33   ` sashiko-bot
  2026-10-06  1:53   ` Jakub Kicinski
  1 sibling, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-09-30  8:33 UTC (permalink / raw)
  To: Jianlin Shi; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez

> net_dim_init_irq_moder() publishes the allocated object in
> dev->irq_moder before copying the moderation profiles.  If kmemdup()
> fails, the object is freed but the pointer is left dangling.
> net_dim_free_irq_moder() treats a non-NULL irq_moder as live, so a
> caller unwinding the failure path would use-after-free.
> 
> NULL the pointer after freeing it.  On error the device is left as if
> initialization never happened.
> 
> Fixes: f750dfe825b90 ("ethtool: provide customized dim profile management")
> Signed-off-by: Jianlin Shi <shijianlin11@foxmail.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1790751008.git.shijianlin11@foxmail.com?part=1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] virtio-net: unwind VQs when irq moderation init fails
  2026-09-30  8:19 ` [PATCH 2/2] virtio-net: unwind VQs when irq moderation init fails Jianlin Shi
@ 2026-09-30  8:33   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-09-30  8:33 UTC (permalink / raw)
  To: Jianlin Shi; +Cc: virtualization, Eugenio Perez, Michael S. Tsirkin

> virtnet_probe() calls init_vqs() before virtnet_init_irq_moder().
> The failure path used "goto free", which only calls free_netdev() and
> skips virtio_reset_device() and virtnet_del_vqs().  The virtqueues and
> their DMA mappings leak.
> 
> Use the existing free_irq_moder label, as virtnet_create_page_pools()
> already does.  This is safe only after net_dim_init_irq_moder() clears
> dev->irq_moder on failure; otherwise virtnet_free_irq_moder() would
> free the dangling pointer.
> 
> Fixes: dcb67f6a9ead6 ("virtio-net: support dim profile fine-tuning")
> Signed-off-by: Jianlin Shi <shijianlin11@foxmail.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1790751008.git.shijianlin11@foxmail.com?part=2


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] dim: clear irq_moder on init failure
  2026-09-30  8:19 ` [PATCH 1/2] dim: clear irq_moder on init failure Jianlin Shi
  2026-09-30  8:33   ` sashiko-bot
@ 2026-10-06  1:53   ` Jakub Kicinski
  2026-10-08 15:42     ` Jianlin Shi
  1 sibling, 1 reply; 7+ messages in thread
From: Jakub Kicinski @ 2026-10-06  1:53 UTC (permalink / raw)
  To: Jianlin Shi
  Cc: netdev, virtualization, mst, jasowangio, eperezma, xuanzhuo,
	andrew+netdev, davem, edumazet, pabeni, talgi, hengqi, horms

On Wed, 30 Sep 2026 16:19:51 +0800 Jianlin Shi wrote:
> net_dim_init_irq_moder() publishes the allocated object in
> dev->irq_moder before copying the moderation profiles.  If kmemdup()
> fails, the object is freed but the pointer is left dangling.
> net_dim_free_irq_moder() treats a non-NULL irq_moder as live, so a
> caller unwinding the failure path would use-after-free.
> 
> NULL the pointer after freeing it.  On error the device is left as if
> initialization never happened.


Please add an example sequence of calls in the current source tree
where this is a problem. Dangling pointers are not an issue unless
something tries to deref them.
-- 
pw-bot: cr

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] dim: clear irq_moder on init failure
  2026-10-06  1:53   ` Jakub Kicinski
@ 2026-10-08 15:42     ` Jianlin Shi
  0 siblings, 0 replies; 7+ messages in thread
From: Jianlin Shi @ 2026-10-08 15:42 UTC (permalink / raw)
  To: kuba, netdev, virtualization
  Cc: mst, jasowangio, eperezma, xuanzhuo, andrew+netdev, davem,
	edumazet, pabeni, talgi, hengqi, horms

You're right - there is no such sequence on current mainline.

net_dim_init_irq_moder() has a single in-tree caller (virtio-net). If it
fails, virtnet_probe() still does "goto free", which only ends in
free_netdev(). Nothing calls net_dim_free_irq_moder() on that path, so
the stale dev->irq_moder value is never dereferenced; it disappears when
the net_device is freed.

The dereference becomes reachable with the unwind change in patch 2:

  virtnet_init_irq_moder()
    -> net_dim_init_irq_moder()  /* fails after kfree(moder); irq_moder stale */
  goto free_irq_moder;            /* patch 2 */
    virtnet_free_irq_moder()
      net_dim_free_irq_moder()
        /* non-NULL irq_moder => */
        rtnl_dereference(dev->irq_moder->rx_profile)  /* UAF */
        kfree(dev->irq_moder)                         /* freed again */

So patch 1 is not fixing a reachable bug on today's tree by itself; it is
a hard prerequisite for patch 2. Without patch 1, patch 2 would trade the
virtqueue leak for UAF (and a second kfree of moder) on this error path.

I can add this call chain to the patch 1 commit message in v2 if you prefer.

Jianlin

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-10-08 15:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-30  8:19 [PATCH 0/2] virtio-net/dim: fix irq moderation init failure unwind Jianlin Shi
2026-09-30  8:19 ` [PATCH 1/2] dim: clear irq_moder on init failure Jianlin Shi
2026-09-30  8:33   ` sashiko-bot
2026-10-06  1:53   ` Jakub Kicinski
2026-10-08 15:42     ` Jianlin Shi
2026-09-30  8:19 ` [PATCH 2/2] virtio-net: unwind VQs when irq moderation init fails Jianlin Shi
2026-09-30  8:33   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox