Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp839793pxb; Tue, 9 Nov 2021 00:42:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBc0EMv7lcvIhvrBqqs8HcNiktlQNbtEFOiykZ9Nm9VOo13LI6gIHF2FGUXrxs/3CJlnyV X-Received: by 2002:a17:906:6a08:: with SMTP id qw8mr7133869ejc.200.1636447328637; Tue, 09 Nov 2021 00:42:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636447328; cv=none; d=google.com; s=arc-20160816; b=o/qOaumkpB+F5G5UN1qN15IB0y8sQ3iNZSvNgfFubKjQt3EnW+5Gwwn4FcNSKEY/zj b1jhQNt8fVfZhU4PLVUKkay23KhRMvm5DZId22rlFnPMJv5wQszsABsNpmjDvIFMuBRn 6ThbN/Em//NffgBpgcquLE6JmnVYGZnYB9BDdHl1EH6xJpzLYpthP/P48g0hheBKCWMt whVWn7xfwGoIIKy0tdid+L32/NcdnMP0mx0OR8IEktSj6G2lz1Vblt82sqTsqpFwONTP PbhIZEuh8ryHuLYeh47wlfGrVdliqBoXjVJjq+QkwpA3Zp3J/FKgy/PUa5R6HTOqJ7Ip 3MeQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Y9ttoC5OVc00xFcjW5BoOOp30sk8JcMPt1G0k0GPVmk=; b=Tp2I3sg6PksBUpwTk0djFX8r+96IO3FabaZ15IKcL9vg68aQYkO378PVlMEAQho4my kfrhd+/fi0j5E9FD2bnwOBhSxTJ+H9rB7I+AfojLueyQZdPKelZaASHaXpieNgqF0ozk i0l//BT+zr/NaL+Qq4RebBcSCiaLpDicQFYnaZGPm8oZL0I3weK7hxQX6VNBCsEZtPL8 Z4rQjSToPHNL0bnvC1P/CrLK6sxsvnUyefmBzvKtlH+T//yTFHEar0BYzw3AxkY0nlUP nnx9Kle9YoCE4oPJFUu7iKfj0AqBLwSJNuT1fFcacvtSaBzSKzBLA1LO+EabilP34Rcw tZtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Oai3aJfk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nd33si41218324ejc.633.2021.11.09.00.41.43; Tue, 09 Nov 2021 00:42:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Oai3aJfk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237427AbhKIBE6 (ORCPT + 99 others); Mon, 8 Nov 2021 20:04:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:60822 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241683AbhKIBD6 (ORCPT ); Mon, 8 Nov 2021 20:03:58 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BD3B4613A6; Tue, 9 Nov 2021 01:01:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636419672; bh=S4LCCpzYJLPe4LBP4YPSi1HqUeJ5icw6ybAi5xgnjM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oai3aJfk7LOr1FnDvBNre/W7eD2+ZwxmzgYKRq8/av6f1E7Sx6GrR10BSL4qDOEFH d1BQe+S+3+VceNS04K4YhROsP+1fM5JYDz+o1aI295sLfFsQFejx/jXiZMnsc+6Y40 50LRK4oiYnbWaKTZZeA4p2AWLmHMJnPm6DB/Mwl78BJSWXwj0kyi6mwn1CH+hzWePi xGADI7EHWFpHqdPmY6Z6olY75uFWD3Hj8QOeuJyAhD+VGrtfuEgegOPZAkXFAWfG4G CUPV3gu1ST7WCbe4PFfiizedAvoFwhWFR/RDWKVsVNwNqhIte2wdCgAq5tv9n/UC43 3UR4etyQywc/Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dmitriy Ulitin , Alexey Khoroshilov , Sakari Ailus , Mauro Carvalho Chehab , Sasha Levin , hugues.fruchet@foss.st.com, mchehab@kernel.org, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux-media@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 5.15 041/146] media: stm32: Potential NULL pointer dereference in dcmi_irq_thread() Date: Mon, 8 Nov 2021 12:43:08 -0500 Message-Id: <20211108174453.1187052-41-sashal@kernel.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211108174453.1187052-1-sashal@kernel.org> References: <20211108174453.1187052-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dmitriy Ulitin [ Upstream commit 548fa43a58696450c15b8f5564e99589c5144664 ] At the moment of enabling irq handling: 1922 ret = devm_request_threaded_irq(&pdev->dev, irq, dcmi_irq_callback, 1923 dcmi_irq_thread, IRQF_ONESHOT, 1924 dev_name(&pdev->dev), dcmi); there is still uninitialized field sd_format of struct stm32_dcmi *dcmi. If an interrupt occurs in the interval between the installation of the interrupt handler and the initialization of this field, NULL pointer dereference happens. This field is dereferenced in the handler function without any check: 457 if (dcmi->sd_format->fourcc == V4L2_PIX_FMT_JPEG && 458 dcmi->misr & IT_FRAME) { The patch moves interrupt handler installation after initialization of the sd_format field that happens in dcmi_graph_notify_complete() via dcmi_set_default_fmt(). Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Dmitriy Ulitin Signed-off-by: Alexey Khoroshilov Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/platform/stm32/stm32-dcmi.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c index d914ccef98317..6110718645a4f 100644 --- a/drivers/media/platform/stm32/stm32-dcmi.c +++ b/drivers/media/platform/stm32/stm32-dcmi.c @@ -128,6 +128,7 @@ struct stm32_dcmi { int sequence; struct list_head buffers; struct dcmi_buf *active; + int irq; struct v4l2_device v4l2_dev; struct video_device *vdev; @@ -1759,6 +1760,14 @@ static int dcmi_graph_notify_complete(struct v4l2_async_notifier *notifier) return ret; } + ret = devm_request_threaded_irq(dcmi->dev, dcmi->irq, dcmi_irq_callback, + dcmi_irq_thread, IRQF_ONESHOT, + dev_name(dcmi->dev), dcmi); + if (ret) { + dev_err(dcmi->dev, "Unable to request irq %d\n", dcmi->irq); + return ret; + } + return 0; } @@ -1914,6 +1923,8 @@ static int dcmi_probe(struct platform_device *pdev) if (irq <= 0) return irq ? irq : -ENXIO; + dcmi->irq = irq; + dcmi->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!dcmi->res) { dev_err(&pdev->dev, "Could not get resource\n"); @@ -1926,14 +1937,6 @@ static int dcmi_probe(struct platform_device *pdev) return PTR_ERR(dcmi->regs); } - ret = devm_request_threaded_irq(&pdev->dev, irq, dcmi_irq_callback, - dcmi_irq_thread, IRQF_ONESHOT, - dev_name(&pdev->dev), dcmi); - if (ret) { - dev_err(&pdev->dev, "Unable to request irq %d\n", irq); - return ret; - } - mclk = devm_clk_get(&pdev->dev, "mclk"); if (IS_ERR(mclk)) { if (PTR_ERR(mclk) != -EPROBE_DEFER) -- 2.33.0