ACPI: SBS: Fix NULL pointer dereference on allocation failure
Subsystems (2)
PATCH 1/1 ACPI: SBS: Fix NULL pointer dereference on allocation failure
acpi_sbs_probe() jumps to the common error path when kzalloc_obj() fails, but platform_set_drvdata() is only called after the allocation succeeds.
The error path calls acpi_sbs_remove(), which retrieves the unset driver data and dereferences the resulting NULL pointer when locking sbs->lock, causing a NULL pointer dereference.
Return -ENOMEM directly when the allocation fails, since no resources have been initialized at that point and there is nothing to clean up.
This issue was found by manual code inspection.
--- drivers/acpi/sbs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/acpi/sbs.c +2 -4
@@ -639,10 +639,8 @@ static int acpi_sbs_probe(struct platform_device *pdev)return -ENODEV ; sbs = kzalloc_obj(struct acpi_sbs); -if (!sbs) { - result = -ENOMEM ; - goto end; - } +if (!sbs) +return -ENOMEM ;mutex_init (&sbs->lock);
Signature · 1 line
2.43.0
Quoted 29 lines · Guangshuo Li
acpi_sbs_probe()jumps to the common error path whenkzalloc_obj()fails, butplatform_set_drvdata()is only called after the allocation succeeds.The error path calls
acpi_sbs_remove(), which retrieves the unset driver data and dereferences the resulting NULL pointer when lockingsbs->lock, causing a NULL pointer dereference.Return
-ENOMEMdirectly when the allocation fails, since no resources have been initialized at that point and there is nothing to clean up.This issue was found by manual code inspection.
Fixes 9460eaae2ee42 ("ACPI: SBS: Convert the driver to a platform one")Signed-off-by Guangshuo Li <[email protected]>--- drivers/acpi/sbs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/acpi/sbs.c +0
-0@@ -639,10 +639,8 @@ static int acpi_sbs_probe(struct platform_device *pdev)return -ENODEV ; sbs = kzalloc_obj(struct acpi_sbs);
drivers/acpi/sbs.c static int acpi_sbs_probe(struct platform_device *pdev)
Quoted 10 lines
drivers/acpi/sbs.c +2
-5-if (!sbs) { - result = -ENOMEM ; - goto end; - } +if (!sbs) +return -ENOMEM ;mutex_init (&sbs->lock); --
Applied as 7.4 material, thanks!