* [PATCH] video/fbdev: Fix a double free in hvfb_probe
@ 2021-03-23 7:33 Lv Yunlong
2021-03-23 11:28 ` Wei Liu
2021-03-23 18:52 ` Michael Kelley
0 siblings, 2 replies; 4+ messages in thread
From: Lv Yunlong @ 2021-03-23 7:33 UTC (permalink / raw)
To: kys, haiyangz, sthemmin, wei.liu
Cc: linux-hyperv, Lv Yunlong, linux-fbdev, dri-devel, linux-kernel
In function hvfb_probe in hyperv_fb.c, it calls hvfb_getmem(hdev, info)
and return err when info->apertures is freed.
In the error1 label of hvfb_probe, info->apertures will be freed twice
by framebuffer_release(info).
My patch sets info->apertures to NULL after it was freed to avoid
double free.
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
drivers/video/fbdev/hyperv_fb.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
index c8b0ae676809..2fc9b507e73a 100644
--- a/drivers/video/fbdev/hyperv_fb.c
+++ b/drivers/video/fbdev/hyperv_fb.c
@@ -1032,6 +1032,7 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
if (!pdev) {
pr_err("Unable to find PCI Hyper-V video\n");
kfree(info->apertures);
+ info->apertures = NULL;
return -ENODEV;
}
@@ -1130,6 +1131,7 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
pci_dev_put(pdev);
}
kfree(info->apertures);
+ info->apertures = NULL;
return 0;
@@ -1142,6 +1144,7 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
if (!gen2vm)
pci_dev_put(pdev);
kfree(info->apertures);
+ info->apertures = NULL;
return -ENOMEM;
}
--
2.25.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] video/fbdev: Fix a double free in hvfb_probe
2021-03-23 7:33 [PATCH] video/fbdev: Fix a double free in hvfb_probe Lv Yunlong
@ 2021-03-23 11:28 ` Wei Liu
2021-03-23 18:52 ` Michael Kelley
1 sibling, 0 replies; 4+ messages in thread
From: Wei Liu @ 2021-03-23 11:28 UTC (permalink / raw)
To: Lv Yunlong
Cc: wei.liu, sthemmin, haiyangz, linux-hyperv, dri-devel,
linux-kernel, linux-fbdev, kys
Thanks for your patch.
I would like to change the prefix to "video: hyperv_fb:" to be more
specific.
On Tue, Mar 23, 2021 at 12:33:50AM -0700, Lv Yunlong wrote:
> In function hvfb_probe in hyperv_fb.c, it calls hvfb_getmem(hdev, info)
> and return err when info->apertures is freed.
>
> In the error1 label of hvfb_probe, info->apertures will be freed twice
> by framebuffer_release(info).
>
I would say "freed for the second time" here. What you wrote reads to me
fraembuffer_release frees the buffer twice all by itself.
> My patch sets info->apertures to NULL after it was freed to avoid
> double free.
>
I think this approach works. I would like to give other people a chance
to comment though.
Fixes: 3a6fb6c4255c ("video: hyperv: hyperv_fb: Use physical memory for fb on HyperV Gen 1 VMs.")
> Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
> ---
> drivers/video/fbdev/hyperv_fb.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
> index c8b0ae676809..2fc9b507e73a 100644
> --- a/drivers/video/fbdev/hyperv_fb.c
> +++ b/drivers/video/fbdev/hyperv_fb.c
> @@ -1032,6 +1032,7 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
> if (!pdev) {
> pr_err("Unable to find PCI Hyper-V video\n");
> kfree(info->apertures);
> + info->apertures = NULL;
> return -ENODEV;
> }
>
> @@ -1130,6 +1131,7 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
> pci_dev_put(pdev);
> }
> kfree(info->apertures);
> + info->apertures = NULL;
>
> return 0;
>
> @@ -1142,6 +1144,7 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
> if (!gen2vm)
> pci_dev_put(pdev);
> kfree(info->apertures);
> + info->apertures = NULL;
>
> return -ENOMEM;
> }
> --
> 2.25.1
>
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] video/fbdev: Fix a double free in hvfb_probe
2021-03-23 7:33 [PATCH] video/fbdev: Fix a double free in hvfb_probe Lv Yunlong
2021-03-23 11:28 ` Wei Liu
@ 2021-03-23 18:52 ` Michael Kelley
2021-03-24 10:24 ` lyl2019
1 sibling, 1 reply; 4+ messages in thread
From: Michael Kelley @ 2021-03-23 18:52 UTC (permalink / raw)
To: Lv Yunlong, KY Srinivasan, Haiyang Zhang, Stephen Hemminger, wei.liu
Cc: linux-hyperv, linux-fbdev, dri-devel, linux-kernel
From: Lv Yunlong <lyl2019@mail.ustc.edu.cn> Sent: Tuesday, March 23, 2021 12:34 AM
>
> In function hvfb_probe in hyperv_fb.c, it calls hvfb_getmem(hdev, info)
> and return err when info->apertures is freed.
>
> In the error1 label of hvfb_probe, info->apertures will be freed twice
> by framebuffer_release(info).
>
> My patch sets info->apertures to NULL after it was freed to avoid
> double free.
>
> Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
> ---
> drivers/video/fbdev/hyperv_fb.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
> index c8b0ae676809..2fc9b507e73a 100644
> --- a/drivers/video/fbdev/hyperv_fb.c
> +++ b/drivers/video/fbdev/hyperv_fb.c
> @@ -1032,6 +1032,7 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info
> *info)
> if (!pdev) {
> pr_err("Unable to find PCI Hyper-V video\n");
> kfree(info->apertures);
> + info->apertures = NULL;
> return -ENODEV;
> }
>
> @@ -1130,6 +1131,7 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info
> *info)
> pci_dev_put(pdev);
> }
> kfree(info->apertures);
> + info->apertures = NULL;
>
> return 0;
>
> @@ -1142,6 +1144,7 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info
> *info)
> if (!gen2vm)
> pci_dev_put(pdev);
> kfree(info->apertures);
> + info->apertures = NULL;
>
> return -ENOMEM;
> }
> --
> 2.25.1
>
While I think this works, a slightly better solution might be to remove
all calls to kfree(info->apertures) in hvfb_getmem(), and just let
framebuffer_release() handle freeing the memory. That's what is
done in other drivers that follow the fbdev pattern, and it's less
code overall.
Michael
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: RE: [PATCH] video/fbdev: Fix a double free in hvfb_probe
2021-03-23 18:52 ` Michael Kelley
@ 2021-03-24 10:24 ` lyl2019
0 siblings, 0 replies; 4+ messages in thread
From: lyl2019 @ 2021-03-24 10:24 UTC (permalink / raw)
To: Michael Kelley
Cc: wei.liu, Stephen Hemminger, Haiyang Zhang, linux-hyperv,
dri-devel, linux-kernel, linux-fbdev, KY Srinivasan
> -----原始邮件-----
> 发件人: "Michael Kelley" <mikelley@microsoft.com>
> 发送时间: 2021-03-24 02:52:07 (星期三)
> 收件人: "Lv Yunlong" <lyl2019@mail.ustc.edu.cn>, "KY Srinivasan" <kys@microsoft.com>, "Haiyang Zhang" <haiyangz@microsoft.com>, "Stephen Hemminger" <sthemmin@microsoft.com>, "wei.liu@kernel.org" <wei.liu@kernel.org>
> 抄送: "linux-hyperv@vger.kernel.org" <linux-hyperv@vger.kernel.org>, "dri-devel@lists.freedesktop.org" <dri-devel@lists.freedesktop.org>, "linux-fbdev@vger.kernel.org" <linux-fbdev@vger.kernel.org>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
> 主题: RE: [PATCH] video/fbdev: Fix a double free in hvfb_probe
>
> From: Lv Yunlong <lyl2019@mail.ustc.edu.cn> Sent: Tuesday, March 23, 2021 12:34 AM
> >
> > In function hvfb_probe in hyperv_fb.c, it calls hvfb_getmem(hdev, info)
> > and return err when info->apertures is freed.
> >
> > In the error1 label of hvfb_probe, info->apertures will be freed twice
> > by framebuffer_release(info).
> >
> > My patch sets info->apertures to NULL after it was freed to avoid
> > double free.
> >
> > Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
> > ---
> > drivers/video/fbdev/hyperv_fb.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
> > index c8b0ae676809..2fc9b507e73a 100644
> > --- a/drivers/video/fbdev/hyperv_fb.c
> > +++ b/drivers/video/fbdev/hyperv_fb.c
> > @@ -1032,6 +1032,7 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info
> > *info)
> > if (!pdev) {
> > pr_err("Unable to find PCI Hyper-V video\n");
> > kfree(info->apertures);
> > + info->apertures = NULL;
> > return -ENODEV;
> > }
> >
> > @@ -1130,6 +1131,7 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info
> > *info)
> > pci_dev_put(pdev);
> > }
> > kfree(info->apertures);
> > + info->apertures = NULL;
> >
> > return 0;
> >
> > @@ -1142,6 +1144,7 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info
> > *info)
> > if (!gen2vm)
> > pci_dev_put(pdev);
> > kfree(info->apertures);
> > + info->apertures = NULL;
> >
> > return -ENOMEM;
> > }
> > --
> > 2.25.1
> >
>
> While I think this works, a slightly better solution might be to remove
> all calls to kfree(info->apertures) in hvfb_getmem(), and just let
> framebuffer_release() handle freeing the memory. That's what is
> done in other drivers that follow the fbdev pattern, and it's less
> code overall.
>
> Michael
Ok, i agree with you. Remove all calls to kfree(info->apertures)
in hvfb_getmem() is a better solution.
I will subimt a PATCH v2 for you to review. Thanks.
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-03-24 10:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23 7:33 [PATCH] video/fbdev: Fix a double free in hvfb_probe Lv Yunlong
2021-03-23 11:28 ` Wei Liu
2021-03-23 18:52 ` Michael Kelley
2021-03-24 10:24 ` lyl2019
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).