DPDK patches and discussions
 help / color / mirror / Atom feed
From: Richael Zhuang <richael.zhuang@arm.com>
To: dev@dpdk.org
Cc: David Hunt <david.hunt@intel.com>
Subject: [dpdk-dev] [PATCH v1 1/1] power: check freq count before filling the freqs array
Date: Wed, 21 Jul 2021 17:27:50 +0800	[thread overview]
Message-ID: <20210721092750.13202-2-richael.zhuang@arm.com> (raw)
In-Reply-To: <20210721092750.13202-1-richael.zhuang@arm.com>

The freqs array size is RTE_MAX_LCORE_FREQS. Before filling the
array with num_freqs elements, restrict the total num to
RTE_MAX_LCORE_FREQS. This fix aims to fix the coverity scan issue
like:
Overrunning array "pi->freqs" of 256 bytes by passing it to a
function which accesses it at byte offset 464.

Coverity issue: 371913

Signed-off-by: Richael Zhuang <richael.zhuang@arm.com>
---
 lib/power/power_cppc_cpufreq.c   | 5 +++++
 lib/power/power_pstate_cpufreq.c | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/lib/power/power_cppc_cpufreq.c b/lib/power/power_cppc_cpufreq.c
index e92973ab54..db63c2cc10 100644
--- a/lib/power/power_cppc_cpufreq.c
+++ b/lib/power/power_cppc_cpufreq.c
@@ -246,6 +246,11 @@ power_get_available_freqs(struct cppc_power_info *pi)
 			pi->nominal_perf * UNIT_DIFF : pi->nominal_perf;
 	num_freqs = (nominal_perf - scaling_min_freq) / BUS_FREQ + 1 +
 		pi->turbo_available;
+	if (num_freqs >= RTE_MAX_LCORE_FREQS) {
+		RTE_LOG(ERR, POWER, "Too many available frequencies : %d\n",
+				num_freqs);
+		goto out;
+	}
 
 	/* Generate the freq bucket array. */
 	for (i = 0, pi->nb_freqs = 0; i < num_freqs; i++) {
diff --git a/lib/power/power_pstate_cpufreq.c b/lib/power/power_pstate_cpufreq.c
index 3b607515fd..619090c8d1 100644
--- a/lib/power/power_pstate_cpufreq.c
+++ b/lib/power/power_pstate_cpufreq.c
@@ -419,6 +419,11 @@ power_get_available_freqs(struct pstate_power_info *pi)
 	 */
 	num_freqs = (base_max_freq - sys_min_freq) / BUS_FREQ + 1 +
 		pi->turbo_available;
+	if (num_freqs >= RTE_MAX_LCORE_FREQS) {
+		RTE_LOG(ERR, POWER, "Too many available frequencies : %d\n",
+				num_freqs);
+		goto out;
+	}
 
 	/* Generate the freq bucket array.
 	 * If turbo is available the freq bucket[0] value is base_max +1
-- 
2.20.1


  reply	other threads:[~2021-07-21  9:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-21  9:27 [dpdk-dev] [PATCH v1 0/1] " Richael Zhuang
2021-07-21  9:27 ` Richael Zhuang [this message]
2021-07-22 19:43   ` [dpdk-dev] [PATCH v1 1/1] " Thomas Monjalon
2021-07-23  2:07     ` Richael Zhuang
2021-07-23  2:13   ` [dpdk-dev] [PATCH v2 0/1] power: check freq count before filling the freqs Richael Zhuang
2021-07-23  2:13     ` [dpdk-dev] [PATCH v2 1/1] power: check freq count before filling the freqs array Richael Zhuang
2021-07-23  2:22       ` [dpdk-dev] [PATCH v3 0/1] " Richael Zhuang
2021-07-23  2:22         ` [dpdk-dev] [PATCH v3 1/1] " Richael Zhuang
2021-07-23  8:37           ` David Hunt
2021-07-24  8:11             ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210721092750.13202-2-richael.zhuang@arm.com \
    --to=richael.zhuang@arm.com \
    --cc=david.hunt@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).