Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2086408rwl; Thu, 13 Apr 2023 01:11:01 -0700 (PDT) X-Google-Smtp-Source: AKy350Yf78uc3fcgT7gsPzCGEgN7DGHoVdzyleO8iX3PxnQiI6G5Xd4LmGwPm8k/ieJy4At6fufI X-Received: by 2002:a05:6402:32b:b0:504:9b97:a578 with SMTP id q11-20020a056402032b00b005049b97a578mr1510678edw.22.1681373460977; Thu, 13 Apr 2023 01:11:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681373460; cv=none; d=google.com; s=arc-20160816; b=hbDn+vMltbbI8oLiCNx97zcNxRHSXF/KbI9BBNFVoK4nuIamDeqUZAmx/14aitw9Ed P9PwsnNxYvw9cwBeRP56VTiLevisO2cVDXaf2Y2ChVAJ2rqIWYzYsNGpFm9NZC3/asnu 64XqQInNTkLF+PUJ7Lo7RubBx6iGsUGBEUvRDa/tCajawG+ks3ZV3bJs1UM2VfEjvu+t 0BokdjR0Wgdss8oFO8w0IwnJd9chMA23j6s9PHzsdbUPULuM1K525I2QnnYFxBwIXtdG IFwmp3mBMoSK0Qw30cl47AhSM4pPJIyTOl/YPZRiLe6l0LS7GRUZs7BI5L29Wk5oaFCF OJcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ifcRlRY2wnxK/bxPgDJsLpW6jFf3XS+a+YJY9e/sNe8=; b=NqExbo76ygUZAzBVmHsFO9sNonuTJNF97BgY8LLSx/4OPBmYQxlSmB72tTPj6Vd45z Qx2IoXIEf36sQ5m1Sd+sTBdzT7KkoDPV4ygHlWnnYIanvlIR4Fo5Vtv1z3ysLDjoz492 66xeSMufEGjiMptW6YFkgKc1qBFH6VjpPbQaxLNsF+NeCyYwwHzcqPFAuVS+1durcAxL gGBuEZ5nsscCVUutfk3slawObIx2as0jDguRVBJqNASkqlvEDRkjuYVaZ9WHa9OAiGib aH0Dq8FrSEYgYzVM4IB73gPDwG1rx0g/9qCUSTnUBRIbU2y1b3+2kD6ChM9JTFfLoA0l Guaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=WuZiL3Si; 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=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i23-20020aa7c9d7000000b00504b0e54129si1312191edt.539.2023.04.13.01.10.35; Thu, 13 Apr 2023 01:11:00 -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; dkim=pass header.i=@163.com header.s=s110527 header.b=WuZiL3Si; 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=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230133AbjDMIHT (ORCPT + 99 others); Thu, 13 Apr 2023 04:07:19 -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 Content-Transfer-Encoding: 8bit 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2, 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 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); -- 2.25.1