From patchwork Sun Mar 12 14:00:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Wang X-Patchwork-Id: 662581 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06093C6FD19 for ; Sun, 12 Mar 2023 14:00:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229846AbjCLOA3 (ORCPT ); Sun, 12 Mar 2023 10:00:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229509AbjCLOA3 (ORCPT ); Sun, 12 Mar 2023 10:00:29 -0400 Received: from m12.mail.163.com (m12.mail.163.com [123.126.96.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CDE6836442; Sun, 12 Mar 2023 07:00:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=GU4Bt iF/mURnT05J+b2ZAAYVXtRHoTughkALlexgzGg=; b=qJoU/4vI/YVTuX1+AsU3r GVVp1mtVWe6qKliIRQoSM0Por/g/ix+MJValgPRVgCa6Kh7lzJydz6Z5XnCdpZis FBwqKyYBOJcw0jW0RmaZhXfo73ZAhWX6XnbcYnxRv2ZI39rHur4wMQGTXA0u5+S/ W6pTwBBikv5NauKTmc5fyo= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by smtp16 (Coremail) with SMTP id MNxpCgBXMzIW2w1k8rBRHQ--.17887S2; Sun, 12 Mar 2023 22:00:54 +0800 (CST) From: Zheng Wang To: mchehab@kernel.org Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, Zheng Wang Subject: [PATCH] media: dm1105: Fix use after free bug in dm1105_remove due to race condition Date: Sun, 12 Mar 2023 22:00:12 +0800 Message-Id: <20230312140012.1816214-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: MNxpCgBXMzIW2w1k8rBRHQ--.17887S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7GrWDtr43Cw48Aw1kuryxAFb_yoW8Jry5pr ZxCFyYkFWfGry8Jr1DGw17XFy5JrZxJFy3WrW7Ww43Xr15ZFWDtayqv3WUAry3AFZ7ZrWa qa1rXr13W3yUAF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziJUU8UUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiXAgvU1Xl55FePwABsO Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org In dm1105_probe, it called dm1105_ir_init and bound &dm1105->ir.work with dm1105_emit_key. When it handles IRQ request with dm1105_irq, it may call schedule_work to start the work. When we call dm1105_remove to remove the driver, there may be a sequence as follows: Fix it by finishing the work before cleanup in dm1105_remove CPU0 CPU1 |dm1105_emit_key dm1105_remove | dm1105_ir_exit | rc_unregister_device | rc_free_device | rc_dev_release | kfree(dev); | | | rc_keydown | //use Fixes: 34d2f9bf189c ("V4L/DVB: dm1105: use dm1105_dev & dev instead of dm1105dvb") Signed-off-by: Zheng Wang --- drivers/media/pci/dm1105/dm1105.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/pci/dm1105/dm1105.c b/drivers/media/pci/dm1105/dm1105.c index 4ac645a56c14..9e9c7c071acc 100644 --- a/drivers/media/pci/dm1105/dm1105.c +++ b/drivers/media/pci/dm1105/dm1105.c @@ -1176,6 +1176,7 @@ static void dm1105_remove(struct pci_dev *pdev) struct dvb_demux *dvbdemux = &dev->demux; struct dmx_demux *dmx = &dvbdemux->dmx; + cancel_work_sync(&dev->ir.work); dm1105_ir_exit(dev); dmx->close(dmx); dvb_net_release(&dev->dvbnet);