Commit 37df9f3f authored by Lv Yunlong's avatar Lv Yunlong Committed by Wei Liu

video: hyperv_fb: Fix a double free in hvfb_probe

Function hvfb_probe() calls hvfb_getmem(), expecting upon return that
info->apertures is either NULL or points to memory that should be freed
by framebuffer_release().  But hvfb_getmem() is freeing the memory and
leaving the pointer non-NULL, resulting in a double free if an error
occurs or later if hvfb_remove() is called.

Fix this by removing all kfree(info->apertures) calls in hvfb_getmem().
This will allow framebuffer_release() to free the memory, which follows
the pattern of other fbdev drivers.

Fixes: 3a6fb6c4 ("video: hyperv: hyperv_fb: Use physical memory for fb on HyperV Gen 1 VMs.")
Signed-off-by: default avatarLv Yunlong <lyl2019@mail.ustc.edu.cn>
Reviewed-by: default avatarMichael Kelley <mikelley@microsoft.com>
Link: https://lore.kernel.org/r/20210324103724.4189-1-lyl2019@mail.ustc.edu.cnSigned-off-by: default avatarWei Liu <wei.liu@kernel.org>
parent fe07bfda
...@@ -1031,7 +1031,6 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info) ...@@ -1031,7 +1031,6 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
PCI_DEVICE_ID_HYPERV_VIDEO, NULL); PCI_DEVICE_ID_HYPERV_VIDEO, NULL);
if (!pdev) { if (!pdev) {
pr_err("Unable to find PCI Hyper-V video\n"); pr_err("Unable to find PCI Hyper-V video\n");
kfree(info->apertures);
return -ENODEV; return -ENODEV;
} }
...@@ -1129,7 +1128,6 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info) ...@@ -1129,7 +1128,6 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
} else { } else {
pci_dev_put(pdev); pci_dev_put(pdev);
} }
kfree(info->apertures);
return 0; return 0;
...@@ -1141,7 +1139,6 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info) ...@@ -1141,7 +1139,6 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
err1: err1:
if (!gen2vm) if (!gen2vm)
pci_dev_put(pdev); pci_dev_put(pdev);
kfree(info->apertures);
return -ENOMEM; return -ENOMEM;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment