Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2153481rwl; Thu, 13 Apr 2023 02:19:47 -0700 (PDT) X-Google-Smtp-Source: AKy350aYhJ4LUHZjmzBH5fKpbSqs76B1tZoeqggDlkjqnd+pVd+O2olpEyi9jTSpYDTznr1bshy3 X-Received: by 2002:a05:6402:8c2:b0:506:6c6a:f6d9 with SMTP id d2-20020a05640208c200b005066c6af6d9mr2002504edz.3.1681377587282; Thu, 13 Apr 2023 02:19:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681377587; cv=none; d=google.com; s=arc-20160816; b=p7lPvAXRxMPmT5vzErJvLiyxNNQPj29gQ1jmjNwaB0oWkZbmH9wBybyM8eshk7YxWW FV3qMFg4SekBBT1TFyXPNItX1pU70dCdKHqeH4di7czj6M3DOUnTKBgv7W2+fKtT1GYZ /+wtNLPhI+7kfeMbrwtIIEVRqpjm2q0E/RjpngMCJO6RsoNj6P1RxPabUymMklaHts9Z I5NCUQ4xNC5v2iWEI0ydm1TcSAjBLo7N0+R46rYnoboZVbjNRGVdGivQqa0dhPzsY5PG kFkMJrGizmVeuWic+gGNrKU/ymvLSMg5VNtlaI4ckszCzaFIupQJiVZRDYW1Qe2MsJro 3dqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=Lez9M9S3Anra/hEIibGZMNuhgQu4h5nt1WR9g65onQU=; b=elifi0IAsYRU74EjTIpQa/wfHBHO482C4axtPBu+wKtJlorP39zCsg6882Y637qVFQ a12hZjg+aXwQj5V2WaCbbgHWYgVH/Tya7DcsfSm8OH9oxMWph4xWzwxiha3994pKcsqv ajxj6KriGibXtg3ndfLXqoDaomhNt4Rb0a0JFfl6Ei3DY9wIFlBDkoJ2Ceuv4uDSPYyc I3Xd7i/nX77ks+HOb7v6bQXPAUknnQLwNcYit8DCSzQHufM88Kt2D6zuCPUl5snBBUDZ oM/1ueYZvzJwWUwSKLTCehr8NRusf+YRzUD6ChpwUw29VA9GQOuYPJtLNM2HtZCCO0nD LOeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b22-20020aa7df96000000b005066c3f3ff0si1297850edy.552.2023.04.13.02.19.22; Thu, 13 Apr 2023 02:19:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229663AbjDMJTG (ORCPT + 99 others); Thu, 13 Apr 2023 05:19:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbjDMJS5 (ORCPT ); Thu, 13 Apr 2023 05:18:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 008E59753; Thu, 13 Apr 2023 02:18:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5C43563C90; Thu, 13 Apr 2023 09:18:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3618C433D2; Thu, 13 Apr 2023 09:18:29 +0000 (UTC) Message-ID: <078e3a48-acdb-e6e4-8963-84ecf1c1429d@xs4all.nl> Date: Thu, 13 Apr 2023 11:18:28 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH v3] media: bttv: fix use after free error due to btv->timeout timer Content-Language: en-US To: Zheng Wang , Deborah Brouwer Cc: laurent.pinchart@ideasonboard.com, sakari.ailus@linux.intel.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, alex000young@gmail.com, hackerzheng666@gmail.com, security@kernel.org, hdanton@sina.com, mchehab@kernel.org References: <20230413034942.40831-1-zyytlz.wz@163.com> From: Hans Verkuil In-Reply-To: <20230413034942.40831-1-zyytlz.wz@163.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Zheng, Deb Brouwer is working on converting bttv to the vb2 framework, so I want to wait for that to finish before taking other bttv patches. I suspect this is still valid post-vb2 conversion, but I'm not certain. Regards, Hans On 13/04/2023 05:49, Zheng Wang wrote: > There may be some a race condition between timer function > bttv_irq_timeout and bttv_remove. The timer is setup in > probe and there is no timer_delete operation in remove > function. When it hit kfree btv, the function might still be > invoked, which will cause use after free bug. > > This bug is found by static analysis, it may be false positive. > > Fix it by adding del_timer_sync invoking to the remove function. > > cpu0 cpu1 > bttv_probe > ->timer_setup > ->bttv_set_dma > ->mod_timer; > bttv_remove > ->kfree(btv); > ->bttv_irq_timeout > ->USE btv > > Fixes: 162e6376ac58 ("media: pci: Convert timers to use timer_setup()") > Signed-off-by: Zheng Wang > --- > v3: > - Add Fix label > v2: > - stop replacing del_timer with del_timer_sync suggested by Hillf Danton > --- > drivers/media/pci/bt8xx/bttv-driver.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c > index d40b537f4e98..24ba5729969d 100644 > --- a/drivers/media/pci/bt8xx/bttv-driver.c > +++ b/drivers/media/pci/bt8xx/bttv-driver.c > @@ -4248,6 +4248,7 @@ static void bttv_remove(struct pci_dev *pci_dev) > > /* free resources */ > free_irq(btv->c.pci->irq,btv); > + del_timer_sync(&btv->timeout); > iounmap(btv->bt848_mmio); > release_mem_region(pci_resource_start(btv->c.pci,0), > pci_resource_len(btv->c.pci,0));