Commit 8ae2f2b0 authored by Reka Norman's avatar Reka Norman Committed by Jiri Kosina

HID: intel-ish-hid: ipc: Fix potential use-after-free in work function

When a reset notify IPC message is received, the ISR schedules a work
function and passes the ISHTP device to it via a global pointer
ishtp_dev. If ish_probe() fails, the devm-managed device resources
including ishtp_dev are freed, but the work is not cancelled, causing a
use-after-free when the work function tries to access ishtp_dev. Use
devm_work_autocancel() instead, so that the work is automatically
cancelled if probe fails.
Signed-off-by: default avatarReka Norman <rekanorman@chromium.org>
Acked-by: default avatarSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent db50f7a3
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Copyright (c) 2014-2016, Intel Corporation. * Copyright (c) 2014-2016, Intel Corporation.
*/ */
#include <linux/devm-helpers.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/delay.h> #include <linux/delay.h>
...@@ -621,7 +622,6 @@ static void recv_ipc(struct ishtp_device *dev, uint32_t doorbell_val) ...@@ -621,7 +622,6 @@ static void recv_ipc(struct ishtp_device *dev, uint32_t doorbell_val)
case MNG_RESET_NOTIFY: case MNG_RESET_NOTIFY:
if (!ishtp_dev) { if (!ishtp_dev) {
ishtp_dev = dev; ishtp_dev = dev;
INIT_WORK(&fw_reset_work, fw_reset_work_fn);
} }
schedule_work(&fw_reset_work); schedule_work(&fw_reset_work);
break; break;
...@@ -940,6 +940,7 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev) ...@@ -940,6 +940,7 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev)
{ {
struct ishtp_device *dev; struct ishtp_device *dev;
int i; int i;
int ret;
dev = devm_kzalloc(&pdev->dev, dev = devm_kzalloc(&pdev->dev,
sizeof(struct ishtp_device) + sizeof(struct ish_hw), sizeof(struct ishtp_device) + sizeof(struct ish_hw),
...@@ -975,6 +976,12 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev) ...@@ -975,6 +976,12 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev)
list_add_tail(&tx_buf->link, &dev->wr_free_list); list_add_tail(&tx_buf->link, &dev->wr_free_list);
} }
ret = devm_work_autocancel(&pdev->dev, &fw_reset_work, fw_reset_work_fn);
if (ret) {
dev_err(dev->devc, "Failed to initialise FW reset work\n");
return NULL;
}
dev->ops = &ish_hw_ops; dev->ops = &ish_hw_ops;
dev->devc = &pdev->dev; dev->devc = &pdev->dev;
dev->mtu = IPC_PAYLOAD_SIZE - sizeof(struct ishtp_msg_hdr); dev->mtu = IPC_PAYLOAD_SIZE - sizeof(struct ishtp_msg_hdr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment