mmc: core: fix possible use after free of host
authorPan Bian <bianpan2016@163.com>
Wed, 17 Apr 2019 08:28:37 +0000 (16:28 +0800)
committerUlf Hansson <ulf.hansson@linaro.org>
Mon, 6 May 2019 09:55:39 +0000 (11:55 +0200)
In the function mmc_alloc_host, the function put_device is called to
release allocated resources when mmc_gpio_alloc fails. Finally, the
function pointed by host->class_dev.class->dev_release (i.e.,
mmc_host_classdev_release) is used to release resources including the
host structure. However, after put_device, host is used and released
again. Resulting in a use-after-free bug.

Fixes: 1ed217194488 ("mmc: core: fix error path in mmc_host_alloc")
Signed-off-by: Pan Bian <bianpan2016@163.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/mmc/core/host.c

index b3fa9c9..6a51f7a 100644 (file)
@@ -429,8 +429,6 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
 
        if (mmc_gpio_alloc(host)) {
                put_device(&host->class_dev);
-               ida_simple_remove(&mmc_host_ida, host->index);
-               kfree(host);
                return NULL;
        }