From patchwork Thu Apr 13 08:06:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Wang X-Patchwork-Id: 674377 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 67F79C77B6C for ; Thu, 13 Apr 2023 08:07:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230243AbjDMIHS (ORCPT ); Thu, 13 Apr 2023 04:07:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230019AbjDMIHO (ORCPT ); Thu, 13 Apr 2023 04:07:14 -0400 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 76BB62717; Thu, 13 Apr 2023 01:07:12 -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=ifcRl RY2wnxK/bxPgDJsLpW6jFf3XS+a+YJY9e/sNe8=; b=WuZiL3Si151uyxP4TOAIm W9bG9f4sel4Yjn+AX0ox6gXADtVYNiC+YeS3FF9gkgS3kiSlSVt8MzGQoSQwXBnA L97xGfRD1vGkqdEDj0BBG1xLnokabHs2TL6M9wlnQoUnMP3m2hkQZgL5lfaNuS+V pDnMy6LdYX2uHXgPcHbLTI= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g2-0 (Coremail) with SMTP id _____wBn9i4euDdkptklBQ--.44659S2; Thu, 13 Apr 2023 16:06:54 +0800 (CST) From: Zheng Wang To: stanimir.k.varbanov@gmail.com Cc: quic_vgarodia@quicinc.com, agross@kernel.org, andersson@kernel.org, konrad.dybcio@linaro.org, mchehab@kernel.org, linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, Zheng Wang Subject: [PATCH v2] media: venus: fix use after free bug in venus_remove due to race condition Date: Thu, 13 Apr 2023 16:06:53 +0800 Message-Id: <20230413080653.254346-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: _____wBn9i4euDdkptklBQ--.44659S2 X-Coremail-Antispam: 1Uf129KBjvJXoWrury5ZFWkXrWxWw43WFy5XFb_yoW8JF1Dpr ZrJ39FkrW8GF4UKw4DXa17WFW3CayrtFyjganru3s7Aan8Awn8tF10kF1ru34UJFWDJ3W5 JrySqrn8Aa90vF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zMMKtUUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/xtbBzgFQU2I0YqCOCQAAsf Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org in venus_probe, core->work is bound with venus_sys_error_handler, which is used to handle error. The code use core->sys_err_done to make sync work. The core->work is started in venus_event_notify. If we call venus_remove, there might be an unfished work. The possible sequence is as follows: CPU0 CPU1 |venus_sys_error_handler venus_remove | hfi_destroy | venus_hfi_destroy | kfree(hdev); | |hfi_reinit |venus_hfi_queues_reinit |//use hdev Fix it by canceling the work in venus_remove. Fixes: af2c3834c8ca ("[media] media: venus: adding core part and helper functions") Signed-off-by: Zheng Wang --- v2: - add more details to clarify the bug --- drivers/media/platform/qcom/venus/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c index 990a1519f968..54ace8bf45e7 100644 --- a/drivers/media/platform/qcom/venus/core.c +++ b/drivers/media/platform/qcom/venus/core.c @@ -423,6 +423,7 @@ static int venus_remove(struct platform_device *pdev) struct device *dev = core->dev; int ret; + cancel_delayed_work(&core->work); ret = pm_runtime_get_sync(dev); WARN_ON(ret < 0);