Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp994170rdb; Tue, 19 Sep 2023 17:27:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEORTZLH1PC81w3ciRJrGlvaHAvn2iiAgObFEw+6c5WJI8sD9Q3RPTSvbvK82O4/awatX51 X-Received: by 2002:a05:6870:2104:b0:1d5:d899:a9c1 with SMTP id f4-20020a056870210400b001d5d899a9c1mr1064048oae.37.1695169660508; Tue, 19 Sep 2023 17:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695169660; cv=none; d=google.com; s=arc-20160816; b=OombiThp9gSm5WuJteXkvd5M06KEd4f6UEngcwCt9KJ9B1R3UFnpDs1I+lGO5X2l+w aLJHHaP/hQuIWmX9PkQvBCa0JBt0441cHfd39VJF5U1Z5izDkBBua7f7P7pUubMg6fNY 8HgHYFQHEHY0Q6QtuqzBq1C7zABwIVPoQBrVte5USna03ol4HnzPk18MD8EleGhFFwpB idWC0YvC3+z4KOcYnvGTiB9T1pabCJKBBzn1ucUuUkMGfvl0blcrOkDV4f8bUpVYAzuP EXYXP8/adidoP18KZ+gSayQG038S9eXczo8DoGvgjFwtaRKlfwyQcVGZqM9bw3LyFnLI umeA== 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:dkim-signature; bh=tWgubB6GrlRErRfwYdzSA/Vs0ln8g4uqwYzkBD6kKZA=; fh=gkRNgtuoopu2eotJj9juZDPmTt5fFAlUkH1jEDqo+hA=; b=DpLvw/jAbeCAdyrkd2Vj7Y1FXq9hlsyGpLnwX3uRIovl2I+nAbEW47lfxcLnnyMyzT JzQrqaeOkf462COWtn9/Ke0GppE7zeBK8qx4SPg0t+ieSzwBi/jcs7eNlQ08Tu5C/0G0 S4LMbRLXmkTCyDE8iBXtnqzb1VREwP41OP9e2JdyV3yxWVLQEwsQj3IhDhWvXtl2KdKF v/O9znPmSMAGmpVWL0g7ESN6GSnKbwyvZuNQCRk/cCNJ8o7jikpfugf+nDZGEnPtifv3 12HZNgtn/R7cmoStgSBu6jrIw4tMFLLPXHA5UbRELXy/a/Hvdt+U5EoiRw+cNCFpHfam F7Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=VJyfYdN9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id k62-20020a638441000000b00578a2da0e4bsi2822557pgd.302.2023.09.19.17.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 17:27:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=VJyfYdN9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id DAF4882685FE; Tue, 19 Sep 2023 11:24:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232285AbjISSYn (ORCPT + 99 others); Tue, 19 Sep 2023 14:24:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232353AbjISSYj (ORCPT ); Tue, 19 Sep 2023 14:24:39 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F41E2BC; Tue, 19 Sep 2023 11:24:30 -0700 (PDT) Received: from [192.168.2.59] (109-252-153-31.dynamic.spd-mgts.ru [109.252.153.31]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 76CD2660319E; Tue, 19 Sep 2023 19:24:28 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1695147869; bh=46IRBQcTc3xVzoCBaR42oqV61VUa5ntA61hgbQ977h8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=VJyfYdN93Ho9wgb/de6ZZaSLk0wJ8j//7QcsdRTdOeexr2iNMDD0/3AJ9G2gqLPLW i4KrGMsYzzdq43ICgcz83YRB6pcGkZY+EWO+PmNN7gtF75tdU7qMbLg6SoMvmShFRf b0E7EVPF5SQTYFHiix6S9Ax+/dGyo6yIGR1BsU+3p1GxWxVVSGK44hRUmJ6Re5c27i HsVlFRqUNo4frzDWAJNOUDRnHcjRI9ZQF7een+0TqI2M8y6YA3K5eEXyx+8v7eAwve wvgzvtfqfStwBsSLB0QGUWD7VLP3cAqy0xWOGECbu4KD1HsHfhtPKVfopjHEPbJVLA 76ZQ1NPw+dk/Q== Message-ID: <4d533beb-f416-1b22-6d9d-cee7f3cfdad1@collabora.com> Date: Tue, 19 Sep 2023 21:24:25 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [RESEND PATCH v2] media: mtk-jpeg: Fix use after free bug due to uncanceled work Content-Language: en-US To: Zheng Hacker , AngeloGioacchino Del Regno Cc: Zheng Wang , Kyrie.Wu@mediatek.com, 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, 1395428693sheep@gmail.com, alex000young@gmail.com, Collabora Kernel ML References: <20230707092414.866760-1-zyytlz.wz@163.com> <8c8bd3ec-a5a4-32e4-45b5-ee16eeeac246@collabora.com> <54b14ebe-b51b-2744-328d-2adcdaaf6d0e@collabora.com> From: Dmitry Osipenko In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 19 Sep 2023 11:24:52 -0700 (PDT) On 8/31/23 11:18, Zheng Hacker wrote: >> The v4l2_m2m_ctx_release() already should wait for the job_timeout_work >> completion or for the interrupt fire. Apparently it doesn't work in >> yours case. You'll need to debug why v4l job or job_timeout_work is >> running after v4l2_m2m_ctx_release(), it shouldn't happen. >> > Yes, v4l2_m2m_cancel_job waits for m2m_ctx->job_flags to be ~TRANS_RUNNING, > the mtk_jpeg_job_timeout_work will finally invoke v4l2_m2m_job_finish > to trigger that. > > However, this is not the only path to call v4l2_m2m_job_finish. Here > is a invoking chain: > v4l_streamon > ->v4l2_m2m_ioctl_streamon > ->v4l2_m2m_streamon > ->v4l2_m2m_try_schedule > ->v4l2_m2m_try_run > ->mtk_jpeg_dec_device_run > ->schedule_delayed_work(&jpeg->job_timeout_work... > ->error path goto dec_end > ->v4l2_m2m_job_finish > > In some specific situation, it starts the worker and also calls > v4l2_m2m_job_finish, which might > make v4l2_m2m_cancel_job continues. Then the error path should cancel the job_timeout_work, or better job needs to be run after the dec/enc has been started and not before. Looking further at the code, I'm confused by this hunk: mtk_jpeg_dec_start(comp_jpeg[hw_id]->reg_base); v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); The job should be marked as finished when h/w has finished processing the job and not right after the job has been started. So the job is always completed and mtk_jpeg_job_timeout_work() doesn't work as expected, am I missing something? -- Best regards, Dmitry