public inbox for virtualization@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: Paul Moses <p@1g4.org>
To: "Michael S . Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
	"Eugenio Pérez" <eperezma@redhat.com>,
	"Eli Cohen" <elic@nvidia.com>, "Parav Pandit" <parav@nvidia.com>
Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org,
	Paul Moses <p@1g4.org>,
	stable@vger.kernel.org
Subject: [PATCH] vdpa: don't free reply skb after genlmsg_reply()
Date: Thu, 12 Mar 2026 11:04:30 +0000	[thread overview]
Message-ID: <20260312110421.2880401-1-p@1g4.org> (raw)

genlmsg_reply() hands the reply skb to netlink, and
netlink_unicast() consumes it on all return paths, whether the
skb is queued successfully or freed on an error path.

vdpa_nl_cmd_dev_config_get_doit() currently jumps to nlmsg_free(msg)
after genlmsg_reply() fails, which can hit the same skb twice.

Return the genlmsg_reply() error directly and keep nlmsg_free()
only for pre-reply failures.

Fixes: ad69dd0bf26b ("vdpa: Introduce query of device config layout")
Cc: stable@vger.kernel.org
Signed-off-by: Paul Moses <p@1g4.org>
---
 drivers/vdpa/vdpa.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
index 34874beb0152e..702d3a7772219 100644
--- a/drivers/vdpa/vdpa.c
+++ b/drivers/vdpa/vdpa.c
@@ -1352,15 +1352,19 @@ 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)
-		err = genlmsg_reply(msg, info);
+	if (err)
+		goto mdev_err;
+
+	put_device(dev);
+	up_read(&vdpa_dev_lock);
+
+	return genlmsg_reply(msg, info);
 
 mdev_err:
 	put_device(dev);
 dev_err:
 	up_read(&vdpa_dev_lock);
-	if (err)
-		nlmsg_free(msg);
+	nlmsg_free(msg);
 	return err;
 }
 
-- 
2.53.GIT



             reply	other threads:[~2026-03-12 11:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 11:04 Paul Moses [this message]
2026-03-17  1:22 ` [PATCH] vdpa: don't free reply skb after genlmsg_reply() Paul Moses
2026-03-20 21:11   ` Paul Moses
2026-03-20 22:37     ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260312110421.2880401-1-p@1g4.org \
    --to=p@1g4.org \
    --cc=elic@nvidia.com \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=parav@nvidia.com \
    --cc=stable@vger.kernel.org \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox