All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zheng Wang <zyytlz.wz@163.com>
To: srinivas.pandruvada@linux.intel.com
Cc: jikos@kernel.org, benjamin.tissoires@redhat.com,
	rafael@kernel.org, hdegoede@redhat.com,
	gregkh@linuxfoundation.org, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org, hackerzheng666@gmail.com,
	1395428693sheep@gmail.com, alex000young@gmail.com,
	Zheng Wang <zyytlz.wz@163.com>
Subject: [PATCH] HID: intel-ish-hid: pci-ish:  Fix use after free bug in  ish_remove due to race condition
Date: Thu, 13 Apr 2023 01:14:41 +0800	[thread overview]
Message-ID: <20230412171441.18958-1-zyytlz.wz@163.com> (raw)

In ish_probe, it calls ish_dev_init to init the device. In this function,
ishtp_device_init is called and &dev->bh_hbm_work is bound with 
bh_hbm_work_fn. recv_hbm may be called to start the timer work.

If we remove the module which will call ish_remove to make cleanup,
there may be an unfinished work. The possible sequence is as follows:

Fix it by canceling the work before cleanup in ishtp_bus_remove_all_clients

CPU0                  CPUc1

                    |bh_hbm_work_fn
ish_remove      |
ishtp_bus_remove_all_clients  |
kfree(ishtp_dev->fw_clients); |
                    |
                    |&dev->fw_clients[...]
                    |   //use

Fixes: 3703f53b99e4 ("HID: intel_ish-hid: ISH Transport layer")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
 drivers/hid/intel-ish-hid/ishtp/bus.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c b/drivers/hid/intel-ish-hid/ishtp/bus.c
index 81385ab37fa9..ada7cd08dbeb 100644
--- a/drivers/hid/intel-ish-hid/ishtp/bus.c
+++ b/drivers/hid/intel-ish-hid/ishtp/bus.c
@@ -744,6 +744,7 @@ void ishtp_bus_remove_all_clients(struct ishtp_device *ishtp_dev,
 		 */
 	}
 	spin_unlock_irqrestore(&ishtp_dev->cl_list_lock, flags);
+	cancel_work_sync(&ishtp_dev->bh_hbm_work);
 
 	/* Release DMA buffers for client messages */
 	ishtp_cl_free_dma_buf(ishtp_dev);
-- 
2.25.1


             reply	other threads:[~2023-04-12 17:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-12 17:14 Zheng Wang [this message]
2023-04-12 17:18 ` [PATCH] HID: intel-ish-hid: pci-ish: Fix use after free bug in ish_remove due to race condition Zheng Hacker
2023-04-25 15:55 ` srinivas pandruvada
2023-04-25 17:18   ` Zheng Hacker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230412171441.18958-1-zyytlz.wz@163.com \
    --to=zyytlz.wz@163.com \
    --cc=1395428693sheep@gmail.com \
    --cc=alex000young@gmail.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hackerzheng666@gmail.com \
    --cc=hdegoede@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=srinivas.pandruvada@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.