Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp852014pxk; Thu, 17 Sep 2020 19:05:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZgs7r8xng+8NJZ+bgmLQKE/tl4PJeWNaS8f+tS4FvY86rNm9NKWtDMr5vLiNEv6NgZ81V X-Received: by 2002:a17:906:c191:: with SMTP id g17mr26584685ejz.117.1600394714827; Thu, 17 Sep 2020 19:05:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600394714; cv=none; d=google.com; s=arc-20160816; b=0UQI9cNvFX9I7u3PYnVe7H1KEy9sRt2TK/U3yXmoVb/qA/+IdL6i0s1uQSs0Rf4eXf Y/te7eh0o+NEJH12wSRmsbKra7hVjaL4BtsvWOInkrQfVMkuLSpbqvG36FAALGzBZVTk y7lYFWAKeElDq5vXIPIAXO1QNE4EwCi4FZthaLsZnaInXHOfHtF2lYifgW10/L55LjM0 or5Bfqzpf/nKKlCwxPVzIbqXg4RC/W6z13MXwLGG97qPowcHT3AiYt6QNgQDgA0TrYQr dnTo5ePPqXY7b+ALMKtYDK38BIU0AyL2NpYGWF5ASdpmmWp7QM6MZmynjqhhUkPdMUp+ YB6g== 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=GPOFMO6z0CiNym3GKORCM9vyrUqy7pVuwWXLfRjowzo=; b=NQbWqyElh5ULyNKSzKtwh0ts3cRDs2kYlOQj84HMJ1ijAh7fLKeuehMcPJMb+8IrqD Q4rM5gJLMps0l7ydoQWMBYNLxJBqjYoFn/pb5TRFbHulesECyfoZ5kHTzlNwO3HBcCKH /zwuBrHxrk/O+5hIP4dBfIMQbvOd6kmGoBZbksL9n/+MU8Xn1+6CYclUe9+g599E0GtT T+iAdahUYSu46qe3hJl9o1SY4FGkU1f9MYQpG+aOFgyHu5iCoPRJcWx/TVgLPl2hYU5g fwz8xlPD2wL7V/CE6J02jiKtNCQ8XGGcKqzYV3Ju6Am2sJsh0A85CeSooqzq0CwETiqL CfMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KHghSHzD; 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 qx7si1281462ejb.438.2020.09.17.19.04.51; Thu, 17 Sep 2020 19:05:14 -0700 (PDT) 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=default header.b=KHghSHzD; 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 S1726948AbgIRCDD (ORCPT + 99 others); Thu, 17 Sep 2020 22:03:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:48612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726837AbgIRCCz (ORCPT ); Thu, 17 Sep 2020 22:02:55 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E50F421734; Fri, 18 Sep 2020 02:02:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394574; bh=1ASpYRPHJjODGalxRsGGYSOGbUDOxxZ+738NcHxfn1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KHghSHzD+NP7pOQSVgXfq+rS6iv30NGBHatoag3QtiBC0iQ5AYmv8zaeGIlCC8/+H U4lfwt7pDLASSSqjUEcRlsiF4GE45tXgNREDRW42+SsRvb9/Op5LiyAyaxv12/eVtc jnJC3K5j1pMihpN9/nMdY5NOYRRNL/wIdQm9Hg5Y= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Nikhil Devshatwar , Benoit Parrot , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 086/330] media: ti-vpe: cal: Restrict DMA to avoid memory corruption Date: Thu, 17 Sep 2020 21:57:06 -0400 Message-Id: <20200918020110.2063155-86-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-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: Nikhil Devshatwar [ Upstream commit 6e72eab2e7b7a157d554b8f9faed7676047be7c1 ] When setting DMA for video capture from CSI channel, if the DMA size is not given, it ends up writing as much data as sent by the camera. This may lead to overwriting the buffers causing memory corruption. Observed green lines on the default framebuffer. Restrict the DMA to maximum height as specified in the S_FMT ioctl. Signed-off-by: Nikhil Devshatwar Signed-off-by: Benoit Parrot Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/platform/ti-vpe/cal.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c index 955a49b8e9c08..f06408009a9c2 100644 --- a/drivers/media/platform/ti-vpe/cal.c +++ b/drivers/media/platform/ti-vpe/cal.c @@ -678,12 +678,13 @@ static void pix_proc_config(struct cal_ctx *ctx) } static void cal_wr_dma_config(struct cal_ctx *ctx, - unsigned int width) + unsigned int width, unsigned int height) { u32 val; val = reg_read(ctx->dev, CAL_WR_DMA_CTRL(ctx->csi2_port)); set_field(&val, ctx->csi2_port, CAL_WR_DMA_CTRL_CPORT_MASK); + set_field(&val, height, CAL_WR_DMA_CTRL_YSIZE_MASK); set_field(&val, CAL_WR_DMA_CTRL_DTAG_PIX_DAT, CAL_WR_DMA_CTRL_DTAG_MASK); set_field(&val, CAL_WR_DMA_CTRL_MODE_CONST, @@ -1306,7 +1307,8 @@ static int cal_start_streaming(struct vb2_queue *vq, unsigned int count) csi2_lane_config(ctx); csi2_ctx_config(ctx); pix_proc_config(ctx); - cal_wr_dma_config(ctx, ctx->v_fmt.fmt.pix.bytesperline); + cal_wr_dma_config(ctx, ctx->v_fmt.fmt.pix.bytesperline, + ctx->v_fmt.fmt.pix.height); cal_wr_dma_addr(ctx, addr); csi2_ppi_enable(ctx); -- 2.25.1