mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-09-22 09:34:56 +02:00
staging: media: ipu7: fix double-free and use-after-free in error paths
commitd3a9a8cf2dupstream. In both ipu7_isys_init() and ipu7_psys_init(), pdata is allocated and then passed to ipu7_bus_initialize_device(), which stores it in adev->pdata. The ipu7_bus_release() function frees adev->pdata when the device's reference count drops to zero. Two error paths incorrectly call kfree(pdata) after the device teardown has already freed it: 1. When ipu7_mmu_init() fails: put_device() is called, which drops the reference count to zero and triggers ipu7_bus_release() -> kfree(pdata). The subsequent kfree(pdata) is a double-free. 2. When ipu7_bus_add_device() fails: it calls auxiliary_device_uninit() internally, which calls put_device() -> ipu7_bus_release() -> kfree(pdata). The subsequent kfree(pdata) is again a double-free. Note that the kfree(pdata) when ipu7_bus_initialize_device() itself fails is correct, because in that case auxiliary_device_init() failed and the release function was never set up, so pdata must be freed manually. Additionally, the error code was not saved before calling put_device(), causing ERR_CAST() to dereference the already-freed adev pointer when constructing the return value. Fix this by saving the error from dev_err_probe() before put_device() and returning ERR_PTR() instead. Remove the redundant kfree(pdata) calls and fix the use-after-free in the return values of the two affected error paths. Fixes:b7fe4c0019("media: staging/ipu7: add Intel IPU7 PCI device driver") Cc: stable@vger.kernel.org Reviewed-by: Dan Carpenter <error27@gmail.com> Signed-off-by: Alexandru Hossu <hossu.alexandru@gmail.com> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
1ca4f310c6
commit
b5ddc7257b
@@ -2169,21 +2169,18 @@ ipu7_isys_init(struct pci_dev *pdev, struct device *parent,
|
||||
isys_adev->mmu = ipu7_mmu_init(dev, base, ISYS_MMID,
|
||||
&ipdata->hw_variant);
|
||||
if (IS_ERR(isys_adev->mmu)) {
|
||||
dev_err_probe(dev, PTR_ERR(isys_adev->mmu),
|
||||
"ipu7_mmu_init(isys_adev->mmu) failed\n");
|
||||
ret = dev_err_probe(dev, PTR_ERR(isys_adev->mmu),
|
||||
"ipu7_mmu_init(isys_adev->mmu) failed\n");
|
||||
put_device(&isys_adev->auxdev.dev);
|
||||
kfree(pdata);
|
||||
return ERR_CAST(isys_adev->mmu);
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
|
||||
isys_adev->mmu->dev = &isys_adev->auxdev.dev;
|
||||
isys_adev->subsys = IPU_IS;
|
||||
|
||||
ret = ipu7_bus_add_device(isys_adev);
|
||||
if (ret) {
|
||||
kfree(pdata);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
|
||||
return isys_adev;
|
||||
}
|
||||
@@ -2216,21 +2213,18 @@ ipu7_psys_init(struct pci_dev *pdev, struct device *parent,
|
||||
psys_adev->mmu = ipu7_mmu_init(&pdev->dev, base, PSYS_MMID,
|
||||
&ipdata->hw_variant);
|
||||
if (IS_ERR(psys_adev->mmu)) {
|
||||
dev_err_probe(&pdev->dev, PTR_ERR(psys_adev->mmu),
|
||||
"ipu7_mmu_init(psys_adev->mmu) failed\n");
|
||||
ret = dev_err_probe(&pdev->dev, PTR_ERR(psys_adev->mmu),
|
||||
"ipu7_mmu_init(psys_adev->mmu) failed\n");
|
||||
put_device(&psys_adev->auxdev.dev);
|
||||
kfree(pdata);
|
||||
return ERR_CAST(psys_adev->mmu);
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
|
||||
psys_adev->mmu->dev = &psys_adev->auxdev.dev;
|
||||
psys_adev->subsys = IPU_PS;
|
||||
|
||||
ret = ipu7_bus_add_device(psys_adev);
|
||||
if (ret) {
|
||||
kfree(pdata);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
|
||||
return psys_adev;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user