Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2680221pxj; Mon, 31 May 2021 08:06:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBmtgGSfih5YK1J1V8j6fih51BONKioF4GeHnIhSW4NtlhcrMwRSzJlhxSaMtLiXmfHCGM X-Received: by 2002:a92:d24a:: with SMTP id v10mr1644172ilg.246.1622473613263; Mon, 31 May 2021 08:06:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622473613; cv=none; d=google.com; s=arc-20160816; b=l40Kj0Ii1YFR7RnEgXEx/8mE7y0+xFQmE4pTK/9ZYS1OWKVtKovjVSSk4rRqLI6Yqc LE4jTSY2JcRNTcR32rShV+6q/QYtJ4/cX/Vu2f+Nj0utG6qwVUcUxrD91bbWpZSE18JK x9WWn1flKvqYHZ5Bc7OiBxarb754SfvrCoMd5lZcSrofCtvTUPm7rug6Lwd4JTDdU3H9 UslI4GPqq49JK5jzg6pqOFCNuE3RddBFn57/lNoal7MhwlZzwjMtaP/mm3SWQx+R5ryW ecGh/QDyatkhqET6ZVfmAoZ9QK9x0DAwQZjo8U/hG41JtkIH+xYSiMUUfw4L8LFKgxVa Z77Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1JDQzYcIpnZZ0qhNIqU6I4Bb7R/jJ/pWqScayU4He0s=; b=p8diMVNIj07YbUkiqyMOSWX9k8y9wD8JdzLH15KGjwQoMUI7HSYvgGIXDULbwYOko7 rbQGVNsEcSJVj9B1WXVplLIctSChKJRtrW47eF7SXsqIyHMfDnZrx6WkmzZiX39PPpLs dSMkqbnp8p9nY5e8ORZgNpxj6G+EyTyfrLQ2FXpVvovtk31r5n5t0aEBXw0E1O9pZJMV 6z/tBnPMwe0+0snmMGYuZQEqHxz+NDJGQwzgmeKh1KEBN8svr5IV/trXRTwyRo6L3FEV EJHy+jGaCaonLuHK7cx1W7Q9e03SqyANIxV31x1uu4fc5ypRmNvRsSltS0IBLe/TVu24 KVvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kpkHWWam; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w17si12892586iot.47.2021.05.31.08.06.39; Mon, 31 May 2021 08:06:53 -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=@linuxfoundation.org header.s=korg header.b=kpkHWWam; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232874AbhEaPHg (ORCPT + 99 others); Mon, 31 May 2021 11:07:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:41002 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233097AbhEaOJD (ORCPT ); Mon, 31 May 2021 10:09:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1E9BB61977; Mon, 31 May 2021 13:40:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468405; bh=3sQMk0epr6E0X7al4cR/3xUgG5Bj/7N9ASpnMkjs0QI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kpkHWWam73BPi1YfZ+Cv3+h+T7nGbHgBlwTJp+m+LHW8ZCpbSfsvd9jxQl4VJ8lJC NgoOW4W19/NysKwTdOSUU59+pmkLvPT4rZL3bIFFU+9bIb9OCTWekV/qAJONJtgTIL rNpTjyPkfWgFGJzhme9yf9tGOeDplPmRFauN0fFg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alex Elder , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 195/252] net: ipa: memory region array is variable size Date: Mon, 31 May 2021 15:14:20 +0200 Message-Id: <20210531130704.636600929@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alex Elder [ Upstream commit 440c3247cba3d9433ac435d371dd7927d68772a7 ] IPA configuration data includes an array of memory region descriptors. That was a fixed-size array at one time, but at some point we started defining it such that it was only as big as required for a given platform. The actual number of entries in the array is recorded in the configuration data along with the array. A loop in ipa_mem_config() still assumes the array has entries for all defined memory region IDs. As a result, this loop can go past the end of the actual array and attempt to write "canary" values based on nonsensical data. Fix this, by stashing the number of entries in the array, and using that rather than IPA_MEM_COUNT in the initialization loop found in ipa_mem_config(). The only remaining use of IPA_MEM_COUNT is in a validation check to ensure configuration data doesn't have too many entries. That's fine for now. Fixes: 3128aae8c439a ("net: ipa: redefine struct ipa_mem_data") Signed-off-by: Alex Elder Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ipa/ipa.h | 2 ++ drivers/net/ipa/ipa_mem.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/ipa/ipa.h b/drivers/net/ipa/ipa.h index 6c2371084c55..da862db09d7b 100644 --- a/drivers/net/ipa/ipa.h +++ b/drivers/net/ipa/ipa.h @@ -56,6 +56,7 @@ enum ipa_flag { * @mem_virt: Virtual address of IPA-local memory space * @mem_offset: Offset from @mem_virt used for access to IPA memory * @mem_size: Total size (bytes) of memory at @mem_virt + * @mem_count: Number of entries in the mem array * @mem: Array of IPA-local memory region descriptors * @imem_iova: I/O virtual address of IPA region in IMEM * @imem_size; Size of IMEM region @@ -102,6 +103,7 @@ struct ipa { void *mem_virt; u32 mem_offset; u32 mem_size; + u32 mem_count; const struct ipa_mem *mem; unsigned long imem_iova; diff --git a/drivers/net/ipa/ipa_mem.c b/drivers/net/ipa/ipa_mem.c index 2d45c444a67f..a78d66051a17 100644 --- a/drivers/net/ipa/ipa_mem.c +++ b/drivers/net/ipa/ipa_mem.c @@ -181,7 +181,7 @@ int ipa_mem_config(struct ipa *ipa) * for the region, write "canary" values in the space prior to * the region's base address. */ - for (mem_id = 0; mem_id < IPA_MEM_COUNT; mem_id++) { + for (mem_id = 0; mem_id < ipa->mem_count; mem_id++) { const struct ipa_mem *mem = &ipa->mem[mem_id]; u16 canary_count; __le32 *canary; @@ -488,6 +488,7 @@ int ipa_mem_init(struct ipa *ipa, const struct ipa_mem_data *mem_data) ipa->mem_size = resource_size(res); /* The ipa->mem[] array is indexed by enum ipa_mem_id values */ + ipa->mem_count = mem_data->local_count; ipa->mem = mem_data->local; ret = ipa_imem_init(ipa, mem_data->imem_addr, mem_data->imem_size); -- 2.30.2