Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp31665390rwd; Fri, 7 Jul 2023 02:39:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlF6kS4bI4zxG/s/h37+x+9E9F7m3Ch/NXrgLCB8gNIbFcUWxeIfGYMKVOjJncNth3hVeCou X-Received: by 2002:a05:6a20:7348:b0:12e:de44:59d4 with SMTP id v8-20020a056a20734800b0012ede4459d4mr4878148pzc.12.1688722794004; Fri, 07 Jul 2023 02:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688722793; cv=none; d=google.com; s=arc-20160816; b=E4HaDMvLdUBZy2Bw31RYFw6svwqwIwkCkPHskEmpwYEGKzgjfNd8ArhxwJnukbpI7o uGT4glEcf3jlnFQC90S5jj7h450wLSxNuMt84m0MsxD9s1kGU4cPdomFLfi98oyD0zy/ IGtkYCCCMSrB8IxhNcIj79IcTAJJsKdh22wZO3onakQ9gmtNrqNulx/I5vwEl8Bcjx/W LIclqKHFmxF7UlrCQV+CvPjuaLSektSRR8Zh+IiMKyCQzsDjrGWnbfKM7D4jiS/ZoVES vQKqIJETUHHI/d9Ay7oXyQLTXvJxiRDc5LS23SHcXXt2pWBPjVBf6thfew+B2sKvlCHn pGiQ== 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=1ZSFgIwAdkqH7N1HARcWbHynu04UbnWZF0dHrxv5TFE=; fh=7gu6p2XRaqkhFzUd6HR0R1PxsmyRTmmPMM4CRT2kcc4=; b=H4jQzZvzAc55UJjTiv7KteQEV2tr674Lci3HRpCEichFz1gk4KFp2Uy2bz5XCA6o3v GFJRtdqZPv6SmXM4OpdoixT+6nKPg0DwJ5c8gV1HT7q6Ds9kVBjJe2fNf4ZmOkcfOoic +UPocrqI5OKWVQIXkaP9v4qXffXqnaLV8CHDxbjnmDAJbKMrX5/rm/WhAeQ/0jovztkn nMeNHA4dVUBMv9nerXDmhYSRaxyHZQc3C+WtdpuV0I9fQcA3woOfUeo2XqIrwJ2o+5co pc7MrEbVyfA1g6RuJ3jiyNmMSANliaDijTEgDEdMHLE9VDAcYQkUqU9xlHvRB0zybXlp ROsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=V6IkZMTI; 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 w20-20020a627b14000000b0063b8a054e06si3286306pfc.259.2023.07.07.02.39.40; Fri, 07 Jul 2023 02:39:53 -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=V6IkZMTI; 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 S232360AbjGGJZ4 (ORCPT + 99 others); Fri, 7 Jul 2023 05:25:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbjGGJZz (ORCPT ); Fri, 7 Jul 2023 05:25:55 -0400 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.216]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 919B5172B; Fri, 7 Jul 2023 02:25:52 -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=1ZSFg IwAdkqH7N1HARcWbHynu04UbnWZF0dHrxv5TFE=; b=V6IkZMTIcRqKgYiXxGieM DqGVE9KJlUxFfbDN59IkXE8ducvoNEY/dunfwg9ZIh5yTVFF2XoL1xKcjWECIrnm NduxOiQ6Oxy2z0wcnXqsCjhSbI/DJPekxiNu4PFgqkUvt5ZVHhG7vouT1bra7Bvt RVHaIrxMOJg7XvFqcZsT2I= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g5-4 (Coremail) with SMTP id _____wBXXT3A2adkGf2qBw--.56525S2; Fri, 07 Jul 2023 17:24:16 +0800 (CST) From: Zheng Wang To: Kyrie.Wu@mediatek.com Cc: bin.liu@mediatek.com, mchehab@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Irui.Wang@mediatek.com, security@kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, Zheng Wang Subject: [RESEND PATCH v2] media: mtk-jpeg: Fix use after free bug due to uncanceled work Date: Fri, 7 Jul 2023 17:24:14 +0800 Message-Id: <20230707092414.866760-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wBXXT3A2adkGf2qBw--.56525S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7uF17uw15Jr4xtw4xCFy7trb_yoW8Wr43pr W3K3yUCrWUGFs0qr1UJ3W7ZFyrCwnxKa1xWr17uw4Iv393Jrs7JryFya48tFWIyF92kayf Jr18X34xGr4qvFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziaZXrUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiXAWlU1Xl7LcvLgAAsF 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_DNSWL_NONE,RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_L4,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 mtk_jpeg_probe, &jpeg->job_timeout_work is bound with mtk_jpeg_job_timeout_work. Then mtk_jpeg_dec_device_run and mtk_jpeg_enc_device_run may be called to start the work. If we remove the module which will call mtk_jpeg_remove to make cleanup, there may be a unfinished work. The possible sequence is as follows, which will cause a typical UAF bug. Fix it by canceling the work before cleanup in the mtk_jpeg_remove CPU0 CPU1 |mtk_jpeg_job_timeout_work mtk_jpeg_remove | v4l2_m2m_release | kfree(m2m_dev); | | | v4l2_m2m_get_curr_priv | m2m_dev->curr_ctx //use Fixes: b2f0d2724ba4 ("[media] vcodec: mediatek: Add Mediatek JPEG Decoder Driver") Signed-off-by: Zheng Wang --- - v2: use cancel_delayed_work_sync instead of cancel_delayed_work suggested by Kyrie. --- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c index 0051f372a66c..6069ecf420b0 100644 --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c @@ -1816,6 +1816,7 @@ static void mtk_jpeg_remove(struct platform_device *pdev) { struct mtk_jpeg_dev *jpeg = platform_get_drvdata(pdev); + cancel_delayed_work_sync(&jpeg->job_timeout_work); pm_runtime_disable(&pdev->dev); video_unregister_device(jpeg->vdev); v4l2_m2m_release(jpeg->m2m_dev); -- 2.25.1