All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vdpa: fix double free of the reply skb in vdpa_nl_cmd_dev_config_get_doit()
@ 2026-09-12 21:54 Xiang Mei
  2026-09-12 22:01 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Xiang Mei @ 2026-09-12 21:54 UTC (permalink / raw)
  To: mst, jasowangio, eperezma, xuanzhuo
  Cc: virtualization, linux-kernel, co+6dcbccedc9ec6452, Xiang Mei

genlmsg_reply() consumes the reply skb on every outcome: netlink_unicast()
frees it whether it queues it, drops it, or bails out early.
vdpa_nl_cmd_dev_config_get_doit() lets its return value fall through to the
shared error label, which calls nlmsg_free(msg) again and double-frees the
sk_buff on any reply failure. The failure is reachable unprivileged:
VDPA_CMD_DEV_CONFIG_GET carries no GENL_ADMIN_PERM, so batching several
requests into one sendto() on a socket with a shrunken SO_RCVBUF fills the
receive queue, and netlink_attachskb() then takes its MSG_DONTWAIT path,
freeing the skb and returning -EAGAIN.

Set msg to NULL once genlmsg_reply() has consumed it so the shared exit
path frees the skb only on the early error gotos that still own it;
nlmsg_free(NULL) is a no-op.

  BUG: KASAN: slab-use-after-free in sk_skb_reason_drop (net/core/skbuff.c:1220)
  Read of size 4 at addr ffff88800d99d49c by task exploit/147
  Call Trace:
   sk_skb_reason_drop (net/core/skbuff.c:1220)
   vdpa_nl_cmd_dev_config_get_doit (drivers/vdpa/vdpa.c:1324)
   genl_family_rcv_msg_doit (net/netlink/genetlink.c:1114)
   genl_rcv_msg (net/netlink/genetlink.c:1194)
   netlink_rcv_skb (net/netlink/af_netlink.c:2556)
   genl_rcv (net/netlink/genetlink.c:1218)
   netlink_unicast (net/netlink/af_netlink.c:1345)
   netlink_sendmsg (net/netlink/af_netlink.c:1900)
   __sys_sendto (net/socket.c:2281)
   __x64_sys_sendto (net/socket.c:2284)
   entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)

  The buggy address belongs to the object at ffff88800d99d3c0
   which belongs to the cache skbuff_head_cache of size 232
  The buggy address is located 220 bytes inside of
   freed 232-byte region [ffff88800d99d3c0, ffff88800d99d4a8)

Fixes: ad69dd0bf26b ("vdpa: Introduce query of device config layout")
Reported-by: co+6dcbccedc9ec6452@bugs.sh
Closes: https://lore.kernel.org/all/ILTHcT8oe1HP47sY25JVxssvKmkCTjYlX9Hs%40bugs.sh/
Assisted-by: Claude:claude-opus-5
Signed-off-by: Xiang Mei <xmei5@asu.edu>
---
 drivers/vdpa/vdpa.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
index 47c6c3d23f5c..6455f837dd26 100644
--- a/drivers/vdpa/vdpa.c
+++ b/drivers/vdpa/vdpa.c
@@ -1313,15 +1313,16 @@ static int vdpa_nl_cmd_dev_config_get_doit(struct sk_buff *skb, struct genl_info
 	}
 	err = vdpa_dev_config_fill(vdev, msg, info->snd_portid, info->snd_seq,
 				   0, info->extack);
-	if (!err)
+	if (!err) {
 		err = genlmsg_reply(msg, info);
+		msg = NULL;
+	}
 
 mdev_err:
 	put_device(dev);
 dev_err:
 	up_read(&vdpa_dev_lock);
-	if (err)
-		nlmsg_free(msg);
+	nlmsg_free(msg);
 	return err;
 }
 
-- 
2.43.0


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

* Re: [PATCH] vdpa: fix double free of the reply skb in vdpa_nl_cmd_dev_config_get_doit()
  2026-09-12 21:54 [PATCH] vdpa: fix double free of the reply skb in vdpa_nl_cmd_dev_config_get_doit() Xiang Mei
@ 2026-09-12 22:01 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-09-12 22:01 UTC (permalink / raw)
  To: Xiang Mei; +Cc: Eugenio Perez, Michael S. Tsirkin, virtualization

> genlmsg_reply() consumes the reply skb on every outcome: netlink_unicast()
> frees it whether it queues it, drops it, or bails out early.
> vdpa_nl_cmd_dev_config_get_doit() lets its return value fall through to the
> shared error label, which calls nlmsg_free(msg) again and double-frees the
> sk_buff on any reply failure. The failure is reachable unprivileged:
> VDPA_CMD_DEV_CONFIG_GET carries no GENL_ADMIN_PERM, so batching several
> requests into one sendto() on a socket with a shrunken SO_RCVBUF fills the
> receive queue, and netlink_attachskb() then takes its MSG_DONTWAIT path,
> freeing the skb and returning -EAGAIN.
> 
> Set msg to NULL once genlmsg_reply() has consumed it so the shared exit
> path frees the skb only on the early error gotos that still own it;
> nlmsg_free(NULL) is a no-op.
> 
>   BUG: KASAN: slab-use-after-free in sk_skb_reason_drop (net/core/skbuff.c:1220)
> [ ... ]
> Fixes: ad69dd0bf26b ("vdpa: Introduce query of device config layout")
> Reported-by: co+6dcbccedc9ec6452@bugs.sh
> Closes: https://lore.kernel.org/all/ILTHcT8oe1HP47sY25JVxssvKmkCTjYlX9Hs%40bugs.sh/
> Assisted-by: Claude:claude-opus-5
> Signed-off-by: Xiang Mei <xmei5@asu.edu>

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

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260912215401.126194-1-xmei5@asu.edu?part=1


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

end of thread, other threads:[~2026-09-12 22:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-12 21:54 [PATCH] vdpa: fix double free of the reply skb in vdpa_nl_cmd_dev_config_get_doit() Xiang Mei
2026-09-12 22:01 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.