From patchwork Tue Apr 27 13:27:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lv Yunlong X-Patchwork-Id: 12226743 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 318DDC433ED for ; Tue, 27 Apr 2021 13:30:54 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 90EB5613C8 for ; Tue, 27 Apr 2021 13:30:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 90EB5613C8 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=mail.ustc.edu.cn Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=Qctcn0/a4YGvJvtO3jO3sF/x8NVmD2jAMe3GhTkBENM=; b=Kr6pn2+ANipZYAsteCgqP5OW0v QC9DEtghbLQJ9U4cusx1sIkEB39pesYIy/KwxIstC8U1XBbCSp1dEA5IzLJGXxXu3Q/vpf6C53VqV +vRFeKUDwqUY+w+WtLyMDaV/ORqiAXdOwq8wjMSeurl/AkpEwD3rG0OQ9EvM0LW4KdYOlLwm/fAAC VdIRoyzoxEMg/tDIihLJwXNBYwCibx+6HMPu16Fyv0FrGaYJR3WNbwLU6wO1CoOv66IcGgozBV/bD Ltk4ozOveaCqxbDb7Y7R9Y8rrj4BFfiy4LHeoe2qZZ5RDpRgsqJ/qh+M8oZfdktYMszPb5wboRWqy ViPx1Zog==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lbNl4-001gE7-QT; Tue, 27 Apr 2021 13:28:11 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lbNl1-001gDq-FS for linux-arm-kernel@desiato.infradead.org; Tue, 27 Apr 2021 13:28:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=LLXiqaWB2ihLi1eC6hvDshqkAOBZKDMRNCRMgQqT8rc=; b=K8exij5Byw5ZZoS1hwlUBoc30N YEIbH86qtYyRr7GFX1nJ8qNA91Mp4Y4SmDD7gjywhQTMb2wQCc1lldREeukuC2ly9+jcqaeGeaXTD g6Ga1fMmYRm8KpFSPJZNC4e3vIeZZuqoLFRapi5dGa3sYTr+XZ4iS4Tgqukmnc1a/lWJ7pVtybXsX U9/0WTZZPQr0XDe+9NqWfvxa6LJO3r9daqxA3GnAarJf3wktax1mG3MRBPw3rQP/AgMa0dvcYct1c M+oKQ3eL5mQ4cP/2hyVMYlOFt9b4xngMFcJApx0Cs9UGaP1Rwu8qrpK8SwwneblADAX2kc3bqXy2m /ZU9ckmw==; Received: from email6.ustc.edu.cn ([2001:da8:d800::8] helo=ustc.edu.cn) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lbNkt-00GlBF-5Y for linux-arm-kernel@lists.infradead.org; Tue, 27 Apr 2021 13:28:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ustc.edu.cn; s=dkim; h=Received:From:To:Cc:Subject:Date: Message-Id:MIME-Version:Content-Transfer-Encoding; bh=LLXiqaWB2i hLi1eC6hvDshqkAOBZKDMRNCRMgQqT8rc=; b=NTG7Clph5d68j85wWLxsNffHZ2 SQ3MwSfPwGBtXUAUNlzedKlLCs1MaubGcggLxUAQOb7UE1bNhBRZjVhf9RdpYu/7 lsHWR5rnF6wfinLLmer1tMAJqME59i0R6PyE+4K1xSV4WWgGfeGuQ6XDpqUljYYP P5qN4Bsm0uw+NkMJY= Received: from ubuntu.localdomain (unknown [202.38.69.14]) by newmailweb.ustc.edu.cn (Coremail) with SMTP id LkAmygBXXp5REYhg_VlTAA--.5809S4; Tue, 27 Apr 2021 21:27:45 +0800 (CST) From: Lv Yunlong To: s.nawrocki@samsung.com, mchehab@kernel.org, krzk@kernel.org Cc: linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Lv Yunlong Subject: [PATCH v3] media:exynos4-is: Fix a use after free in isp_video_release Date: Tue, 27 Apr 2021 06:27:34 -0700 Message-Id: <20210427132734.5212-1-lyl2019@mail.ustc.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: LkAmygBXXp5REYhg_VlTAA--.5809S4 X-Coremail-Antispam: 1UD129KBjvJX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yrz6zt1loo32lwfovvfxof0/ X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210427_062759_953533_A56EBB3A X-CRM114-Status: GOOD ( 11.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In isp_video_release, file->private_data is freed via _vb2_fop_release()->v4l2_fh_release(). But the freed file->private_data is still used in v4l2_fh_is_singular_file() ->v4l2_fh_is_singular(file->private_data), which is a use after free bug. My patch sets file->private_data to NULL after _vb2_fop_release() to avoid the use after free, and uses a variable 'is_singular_file' to keep the original function unchanged. Fixes: 34947b8aebe3f ("[media] exynos4-is: Add the FIMC-IS ISP capture DMA driver") Signed-off-by: Lv Yunlong Reviewed-by: Sylwester Nawrocki --- drivers/media/platform/exynos4-is/fimc-isp-video.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c index 612b9872afc8..c07dcb0bccc2 100644 --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c @@ -306,17 +306,21 @@ static int isp_video_release(struct file *file) struct fimc_is_video *ivc = &isp->video_capture; struct media_entity *entity = &ivc->ve.vdev.entity; struct media_device *mdev = entity->graph_obj.mdev; + bool is_singular_file; mutex_lock(&isp->video_lock); - if (v4l2_fh_is_singular_file(file) && ivc->streaming) { + is_singular_file = v4l2_fh_is_singular_file(file); + + if (is_singular_file && ivc->streaming) { media_pipeline_stop(entity); ivc->streaming = 0; } _vb2_fop_release(file, NULL); + file->private_data = NULL; - if (v4l2_fh_is_singular_file(file)) { + if (is_singular_file) { fimc_pipeline_call(&ivc->ve, close); mutex_lock(&mdev->graph_mutex);