Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4483672ybx; Mon, 4 Nov 2019 14:11:09 -0800 (PST) X-Google-Smtp-Source: APXvYqxs/EOX58di04Fn5Ex3D1Ys61h7iHRqO8LhfSCbxTxHYwhGKHaJr035UTPvvf2ECBBBOvXK X-Received: by 2002:a17:906:6d87:: with SMTP id h7mr26581731ejt.4.1572905469285; Mon, 04 Nov 2019 14:11:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905469; cv=none; d=google.com; s=arc-20160816; b=sDhkkd5RJ4I6zD5vYI+nVhRYNuur+9YyJHbiB9L3TL+TNB3FQCzh/f4uwGKX2qz0L8 TtjtU2L1PXMTl5YCXvnM2a2GJNOacGXMXG619PJjQBJoa8SjmJdTcqICOtWMHVRiVCpR Y0uxz6WU0Lq3H0r+LDjbB09uMZGyCC+jmK956aSfd3dCmSslAnlhGor2FJltV2crH1ot ILJd0XC3ZbmucdkM06vNuxXfRpLkTCMjseVeq8IkoyVEQ8CADpw4Y48MXO2T0r+PZgpK OGClDy3V7KiTkA0BiZZVYG29SuFp7GGkmYyBFXav445AXu+8WjUUzUf2jXAOaMrycj4t vabQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tThd+VMpnSA8rW9LuWiR+EYJMz92IjkRv4IcJUQHK1Y=; b=RF3159E5imebjlYA1DwNCYOHRvn+LLoYJbtVmc+ZHxx8nv2ArZa5duzplytjkVdKkM cCyQCtcDba0DVn+bUaekdv5ugtdJZqFwiyyKvWMzsBkzn3CMNnaGAqyXW/YWcuqsvOHG mwtSicKzeKEbVcQfs2rRZ5CTySg6/8dFYm8aZ2D18KOks9BBCzhAcx4ALmCJt1rf6dFb EgReAtokRWrYKs1XQKGhhal/BpCvxvyOHguOoYCu1H0y9BgFiGOZiyG0XoZd7mv0OAiz LDia9LSWWNBUVQXdFdEQyC84lXWMEvL1SkhJzzQzUEHWrmlBp9ZQHACKz+g0bL+fywha Jgnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=H9lcvuO4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e50si8433917ede.59.2019.11.04.14.10.45; Mon, 04 Nov 2019 14:11:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=H9lcvuO4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389916AbfKDWKS (ORCPT + 99 others); Mon, 4 Nov 2019 17:10:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:43406 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387536AbfKDWKO (ORCPT ); Mon, 4 Nov 2019 17:10:14 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5A6BD20650; Mon, 4 Nov 2019 22:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905412; bh=POiwKFsH0Wle4YX/WH4j8W3xRz5qrUbxx3XDCsvrQbU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H9lcvuO4E8PC6fdOx356cj9B667GuN8Q6RcL3LJttWw4FOuIDgaI/8MTMcBO2fvTg z2Qlfcq8/eKNxagd+9gLvDwETfOgOmjg5Fin4wo/Hok7UnWD4x+6KtBaNNVB2KX3qj pbg/XvtlKMjunDazUa9xzZFGn03Lz/xiMlNOuawI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@vger.kernel, Robin Gong , Jurgen Lambrecht , Vinod Koul Subject: [PATCH 5.3 135/163] dmaengine: imx-sdma: fix size check for sdma script_number Date: Mon, 4 Nov 2019 22:45:25 +0100 Message-Id: <20191104212150.121863340@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robin Gong commit bd73dfabdda280fc5f05bdec79b6721b4b2f035f upstream. Illegal memory will be touch if SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3 (41) exceed the size of structure sdma_script_start_addrs(40), thus cause memory corrupt such as slob block header so that kernel trap into while() loop forever in slob_free(). Please refer to below code piece in imx-sdma.c: for (i = 0; i < sdma->script_number; i++) if (addr_arr[i] > 0) saddr_arr[i] = addr_arr[i]; /* memory corrupt here */ That issue was brought by commit a572460be9cf ("dmaengine: imx-sdma: Add support for version 3 firmware") because SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3 (38->41 3 scripts added) not align with script number added in sdma_script_start_addrs(2 scripts). Fixes: a572460be9cf ("dmaengine: imx-sdma: Add support for version 3 firmware") Cc: stable@vger.kernel Link: https://www.spinics.net/lists/arm-kernel/msg754895.html Signed-off-by: Robin Gong Reported-by: Jurgen Lambrecht Link: https://lore.kernel.org/r/1569347584-3478-1-git-send-email-yibin.gong@nxp.com [vkoul: update the patch title] Signed-off-by: Vinod Koul Signed-off-by: Greg Kroah-Hartman --- drivers/dma/imx-sdma.c | 8 ++++++++ include/linux/platform_data/dma-imx-sdma.h | 3 +++ 2 files changed, 11 insertions(+) --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -1707,6 +1707,14 @@ static void sdma_add_scripts(struct sdma if (!sdma->script_number) sdma->script_number = SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1; + if (sdma->script_number > sizeof(struct sdma_script_start_addrs) + / sizeof(s32)) { + dev_err(sdma->dev, + "SDMA script number %d not match with firmware.\n", + sdma->script_number); + return; + } + for (i = 0; i < sdma->script_number; i++) if (addr_arr[i] > 0) saddr_arr[i] = addr_arr[i]; --- a/include/linux/platform_data/dma-imx-sdma.h +++ b/include/linux/platform_data/dma-imx-sdma.h @@ -51,7 +51,10 @@ struct sdma_script_start_addrs { /* End of v2 array */ s32 zcanfd_2_mcu_addr; s32 zqspi_2_mcu_addr; + s32 mcu_2_ecspi_addr; /* End of v3 array */ + s32 mcu_2_zqspi_addr; + /* End of v4 array */ }; /**