From patchwork Sat Apr 15 08:05:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Duoming Zhou X-Patchwork-Id: 13212330 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 60198C77B71 for ; Sat, 15 Apr 2023 08:06:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229561AbjDOIGH (ORCPT ); Sat, 15 Apr 2023 04:06:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjDOIGG (ORCPT ); Sat, 15 Apr 2023 04:06:06 -0400 X-Greylist: delayed 342 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sat, 15 Apr 2023 01:06:02 PDT Received: from zg8tmja2lje4os4yms4ymjma.icoremail.net (zg8tmja2lje4os4yms4ymjma.icoremail.net [206.189.21.223]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B533F5FE1; Sat, 15 Apr 2023 01:06:02 -0700 (PDT) Received: from ubuntu.localdomain (unknown [106.117.97.24]) by mail-app4 (Coremail) with SMTP id cS_KCgCHHQveWjpkz2cQAA--.9344S2; Sat, 15 Apr 2023 16:05:57 +0800 (CST) From: Duoming Zhou To: linux-kernel@vger.kernel.org Cc: linux-media@vger.kernel.org, mchehab@kernel.org, aospan@netup.ru, serjk@netup.ru, Duoming Zhou Subject: [PATCH RESEND] media: netup_unidvb: fix use-after-free bug caused by del_timer() Date: Sat, 15 Apr 2023 16:05:48 +0800 Message-Id: <20230415080548.6230-1-duoming@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: cS_KCgCHHQveWjpkz2cQAA--.9344S2 X-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wIGAWQ5a9oSIAAss0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org When Universal DVB card is detaching, netup_unidvb_dma_fini() uses del_timer() to stop dma->timeout timer. But when timer handler netup_unidvb_dma_timeout() is running, del_timer() could not stop it. As a result, the use-after-free bug could happen. The process is shown below: (cleanup routine) | (timer routine) | mod_timer(&dev->tx_sim_timer, ..) netup_unidvb_finidev() | (wait a time) netup_unidvb_dma_fini() | netup_unidvb_dma_timeout() del_timer(&dma->timeout); | kfree(ndev); //FREE | | ndev->pci_dev->dev //USE Fix by changing del_timer() to del_timer_sync(). Fixes: 52b1eaf4c59a ("[media] netup_unidvb: NetUP Universal DVB-S/S2/T/T2/C PCI-E card driver") Signed-off-by: Duoming Zhou --- drivers/media/pci/netup_unidvb/netup_unidvb_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/pci/netup_unidvb/netup_unidvb_core.c b/drivers/media/pci/netup_unidvb/netup_unidvb_core.c index 8287851b5ff..aaa1d2dedeb 100644 --- a/drivers/media/pci/netup_unidvb/netup_unidvb_core.c +++ b/drivers/media/pci/netup_unidvb/netup_unidvb_core.c @@ -697,7 +697,7 @@ static void netup_unidvb_dma_fini(struct netup_unidvb_dev *ndev, int num) netup_unidvb_dma_enable(dma, 0); msleep(50); cancel_work_sync(&dma->work); - del_timer(&dma->timeout); + del_timer_sync(&dma->timeout); } static int netup_unidvb_dma_setup(struct netup_unidvb_dev *ndev)