platform/chrome: wilco_ec: fix use after free issue
authorWen Yang <wenyang@linux.alibaba.com>
Sat, 30 Nov 2019 13:08:42 +0000 (21:08 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 26 Jan 2020 09:01:08 +0000 (10:01 +0100)
[ Upstream commit 856a0a6e2d09d31fd8f00cc1fc6645196a509d56 ]

This is caused by dereferencing 'dev_data' after put_device() in
the telem_device_remove() function.
This patch just moves the put_device() down a bit to avoid this
issue.

Fixes: 1210d1e6bad1 ("platform/chrome: wilco_ec: Add telemetry char device interface")
Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
Cc: Benson Leung <bleung@chromium.org>
Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Nick Crews <ncrews@chromium.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/platform/chrome/wilco_ec/telemetry.c

index b9d03c3..1176d54 100644 (file)
@@ -406,8 +406,8 @@ static int telem_device_remove(struct platform_device *pdev)
        struct telem_device_data *dev_data = platform_get_drvdata(pdev);
 
        cdev_device_del(&dev_data->cdev, &dev_data->dev);
-       put_device(&dev_data->dev);
        ida_simple_remove(&telem_ida, MINOR(dev_data->dev.devt));
+       put_device(&dev_data->dev);
 
        return 0;
 }