qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: "Duan, Zhenzhong" <zhenzhong.duan@intel.com>
Cc: "Cédric Le Goater" <clg@redhat.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"minwoo.im@samsung.com" <minwoo.im@samsung.com>,
	"Peng, Chao P" <chao.p.peng@intel.com>
Subject: Re: [PATCH] vfio/pci: Fix a use-after-free issue
Date: Tue, 16 May 2023 12:59:45 -0600	[thread overview]
Message-ID: <20230516125945.266c35e4.alex.williamson@redhat.com> (raw)
In-Reply-To: <SJ0PR11MB6744418C6BCC9BF373898AEF92799@SJ0PR11MB6744.namprd11.prod.outlook.com>

On Tue, 16 May 2023 10:02:24 +0000
"Duan, Zhenzhong" <zhenzhong.duan@intel.com> wrote:

> >-----Original Message-----
> >From: Cédric Le Goater <clg@redhat.com>
> >Sent: Tuesday, May 16, 2023 4:58 PM
> >To: Duan, Zhenzhong <zhenzhong.duan@intel.com>; qemu-
> >devel@nongnu.org
> >Cc: minwoo.im@samsung.com; alex.williamson@redhat.com; Peng, Chao P
> ><chao.p.peng@intel.com>
> >Subject: Re: [PATCH] vfio/pci: Fix a use-after-free issue
> >
> >On 5/16/23 05:43, Zhenzhong Duan wrote:  
> >> We should free the duplicated variant of vbasedev->name plus uuid
> >> rather than vbasedev->name itself.
> >>
> >> Fixes: 2dca1b37a7 ("vfio/pci: add support for VF toke")  
> >
> >"toke" -> "token"  
> Will fix, thanks
> 
> >  
> >> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> >> ---
> >>   hw/vfio/pci.c | 4 +++-
> >>   1 file changed, 3 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index
> >> bf27a3990564..d2593681e000 100644
> >> --- a/hw/vfio/pci.c
> >> +++ b/hw/vfio/pci.c
> >> @@ -2998,7 +2998,9 @@ static void vfio_realize(PCIDevice *pdev, Error  
> >**errp)  
> >>       }
> >>
> >>       ret = vfio_get_device(group, name, vbasedev, errp);
> >> -    g_free(name);
> >> +    if (name != vbasedev->name) {  
> >
> >
> >yes. I wonder if we shouldn't use the same test with which 'name' was
> >allocated instead :
> >
> >     if (!qemu_uuid_is_null(&vdev->vf_token)) {  
> 
> I think they are same effect and " if (name != vbasedev->name) {" is a bit
> more optimal. If you prefer " if (!qemu_uuid_is_null(&vdev->vf_token)) {",
> let me know and I'll update in v2.

My preference would be that both paths allocate name so that we don't
need to conditionalize the free.  For example:

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index bf27a3990564..73874a94de12 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2994,7 +2994,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
         qemu_uuid_unparse(&vdev->vf_token, uuid);
         name = g_strdup_printf("%s vf_token=%s", vbasedev->name, uuid);
     } else {
-        name = vbasedev->name;
+        name = g_strdup(vbasedev->name);
     }
 
     ret = vfio_get_device(group, name, vbasedev, errp);

Thanks,
Alex



      reply	other threads:[~2023-05-16 19:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16  3:43 [PATCH] vfio/pci: Fix a use-after-free issue Zhenzhong Duan
2023-05-16  8:57 ` Cédric Le Goater
2023-05-16 10:02   ` Duan, Zhenzhong
2023-05-16 18:59     ` Alex Williamson [this message]

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=20230516125945.266c35e4.alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=chao.p.peng@intel.com \
    --cc=clg@redhat.com \
    --cc=minwoo.im@samsung.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhenzhong.duan@intel.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;
as well as URLs for NNTP newsgroup(s).