Skip to content

Commit 73a98cf

Browse files
jwrdegoedegregkh
authored andcommitted
platform/x86: x86-android-tablets: Fix use after free on platform_device_register() errors
commit 2fae312 upstream. x86_android_tablet_remove() frees the pdevs[] array, so it should not be used after calling x86_android_tablet_remove(). When platform_device_register() fails, store the pdevs[x] PTR_ERR() value into the local ret variable before calling x86_android_tablet_remove() to avoid using pdevs[] after it has been freed. Fixes: 5eba014 ("platform/x86: x86-android-tablets: Add support for instantiating platform-devs") Fixes: e2200d3 ("platform/x86: x86-android-tablets: Add gpio_keys support to x86_android_tablet_init()") Cc: stable@vger.kernel.org Reported-by: Aleksandr Burakov <a.burakov@rosalinux.ru> Closes: https://lore.kernel.org/platform-driver-x86/20240917120458.7300-1-a.burakov@rosalinux.ru/ Signed-off-by: Hans de Goede <hdegoede@redhat.com> Link: https://lore.kernel.org/r/20241005130545.64136-1-hdegoede@redhat.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 82f1799 commit 73a98cf

File tree

1 file changed

+4
-2
lines changed
  • drivers/platform/x86/x86-android-tablets

1 file changed

+4
-2
lines changed

drivers/platform/x86/x86-android-tablets/core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,9 @@ static __init int x86_android_tablet_probe(struct platform_device *pdev)
390390
for (i = 0; i < pdev_count; i++) {
391391
pdevs[i] = platform_device_register_full(&dev_info->pdev_info[i]);
392392
if (IS_ERR(pdevs[i])) {
393+
ret = PTR_ERR(pdevs[i]);
393394
x86_android_tablet_remove(pdev);
394-
return PTR_ERR(pdevs[i]);
395+
return ret;
395396
}
396397
}
397398

@@ -443,8 +444,9 @@ static __init int x86_android_tablet_probe(struct platform_device *pdev)
443444
PLATFORM_DEVID_AUTO,
444445
&pdata, sizeof(pdata));
445446
if (IS_ERR(pdevs[pdev_count])) {
447+
ret = PTR_ERR(pdevs[pdev_count]);
446448
x86_android_tablet_remove(pdev);
447-
return PTR_ERR(pdevs[pdev_count]);
449+
return ret;
448450
}
449451
pdev_count++;
450452
}

0 commit comments

Comments
 (0)