Skip to contentSkip to conversation

soc: qcom: socinfo: Fix off-by-one array index bounds check

PATCH Applied Colin King 6 participants 8 messages Jan 18, 2021 – Jan 21, 2021

Subsystems (3)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 soc: qcom: socinfo: Fix off-by-one array index bounds check

From: Colin Ian King <[email protected]>

There is an off-by-one array index bounds check on array pmic_models. Fix this by checking using < rather than <= on the array size.

Addresses-Coverity: ("Out-of-bounds read")

Fixes 734c78e7febf ("soc: qcom: socinfo: add info from PMIC models array")
---
 drivers/soc/qcom/socinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/qcom/socinfo.c +1 -1
index a985ed064669..f449df560d93 100644
@@ -332,7 +332,7 @@ static int qcom_show_pmic_model_array(struct seq_file *seq, void *p)
 		unsigned int model = SOCINFO_MINOR(get_unaligned_le32(ptr + 2 * i * sizeof(u32)));
 		unsigned int die_rev = get_unaligned_le32(ptr + (2 * i + 1) * sizeof(u32));
 
-		if (model <= ARRAY_SIZE(pmic_models) && pmic_models[model])
+		if (model < ARRAY_SIZE(pmic_models) && pmic_models[model])
 			seq_printf(seq, "%s %u.%u\n", pmic_models[model],
 				   SOCINFO_MAJOR(le32_to_cpu(die_rev)),
 				   SOCINFO_MINOR(le32_to_cpu(die_rev)));
Signature · 1 line
2.29.2
#1 lore raw

PATCH 1/1 soc: qcom: socinfo: Fix an off by one in qcom_show_pmic_model()

These need to be < ARRAY_SIZE() instead of <= ARRAY_SIZE() to prevent accessing one element beyond the end of the array.

Fixes e9247e2ce577 ("soc: qcom: socinfo: fix printing of pmic_model")
---
 drivers/soc/qcom/socinfo.c | 2 +-
 1 file changed, 1 insertions(+), 1 deletions(-)
drivers/soc/qcom/socinfo.c +1 -1
index a985ed064669..5b4ad24a022b 100644
@@ -309,7 +309,7 @@ static int qcom_show_pmic_model(struct seq_file *seq, void *p)
 	if (model < 0)
 		return -EINVAL;
 
-	if (model <= ARRAY_SIZE(pmic_models) && pmic_models[model])
+	if (model < ARRAY_SIZE(pmic_models) && pmic_models[model])
 		seq_printf(seq, "%s\n", pmic_models[model]);
 	else
 		seq_printf(seq, "unknown (%d)\n", model);
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#2 lore raw

Re: [PATCH] soc: qcom: socinfo: Fix an off by one in qcom_show_pmic_model()

Hi,

Quoted 9 lines · Dan Carpenter

These need to be < ARRAY_SIZE() instead of <= ARRAY_SIZE() to prevent accessing one element beyond the end of the array.

Fixes e9247e2ce577 ("soc: qcom: socinfo: fix printing of pmic_model")
---
 drivers/soc/qcom/socinfo.c | 2 +-
 1 file changed, 1 insertions(+), 1 deletions(-)
Acked-by on v1 1/1
#3 lore raw

Re: [PATCH] soc: qcom: socinfo: Fix an off by one in qcom_show_pmic_model()

In reply to Dan Carpenter
Quoted 6 lines · Dan Carpenter

These need to be < ARRAY_SIZE() instead of <= ARRAY_SIZE() to prevent accessing one element beyond the end of the array.

Fixes e9247e2ce577 ("soc: qcom: socinfo: fix printing of pmic_model")
Signature · 2 lines
With best wishes
Dmitry
Reviewed-by on v1 1/1
#4 lore raw

Re: [PATCH] soc: qcom: socinfo: Fix an off by one in qcom_show_pmic_model()

In reply to Dan Carpenter

Quoting Dan Carpenter (2021-01-20 01:57:55)

Quoted 6 lines

These need to be < ARRAY_SIZE() instead of <= ARRAY_SIZE() to prevent accessing one element beyond the end of the array.

Fixes e9247e2ce577 ("soc: qcom: socinfo: fix printing of pmic_model")

---

#5 lore raw

Re: [PATCH] soc: qcom: socinfo: Fix an off by one in qcom_show_pmic_model()

In reply to Dan Carpenter
This patch was applied to qcom/linux.git (refs/heads/for-next):

Hello:

This patch was applied to qcom/linux.git (refs/heads/for-next):

Quoted 8 lines · On Wed, 20 Jan 2021 12:57:55 +0300 you wrote:

These need to be < ARRAY_SIZE() instead of <= ARRAY_SIZE() to prevent accessing one element beyond the end of the array.

Fixes e9247e2ce577 ("soc: qcom: socinfo: fix printing of pmic_model")
---
 drivers/soc/qcom/socinfo.c | 2 +-
 1 file changed, 1 insertions(+), 1 deletions(-)

Here is the summary with links:
- soc: qcom: socinfo: Fix an off by one in qcom_show_pmic_model()

    https://git.kernel.org/qcom/c/5fb33d8960dc

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

#7 lore raw
In reply to Colin King
This patch was applied to qcom/linux.git (refs/heads/for-next):

Hello:

This patch was applied to qcom/linux.git (refs/heads/for-next):

Quoted 11 lines · On Mon, 18 Jan 2021 11:36:51 +0000 you wrote:

From: Colin Ian King <[email protected]>

There is an off-by-one array index bounds check on array pmic_models. Fix this by checking using < rather than <= on the array size.

Addresses-Coverity: ("Out-of-bounds read")

Fixes 734c78e7febf ("soc: qcom: socinfo: add info from PMIC models array")

[...]

Here is the summary with links:
- soc: qcom: socinfo: Fix off-by-one array index bounds check

    https://git.kernel.org/qcom/c/e6393818c8d1

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html