Skip to contentSkip to conversation

platform/x86/intel: pmc: fix ltr decode in pmc_core_ltr_show()

PATCH In review Dmitry Kandybka 3 participants 4 messages Jan 23, 2025 – Jan 28, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 platform/x86/intel: pmc: fix ltr decode in pmc_core_ltr_show()

In pmc_core_ltr_show(), promote 'val' to 'u64' to avoid possible integer overflow. Values (10 bit) are multiplied by the scale, the result of expression is in a range from 1 to 34,326,183,936 which is bigger then UINT32_MAX. Compile tested only.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
v1 -> v2: 'val' variable declared as 'u64' instead of type casting at usage points

 drivers/platform/x86/intel/pmc/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/intel/pmc/core.c +2 -2
index 10f04b944117..1ee0fb5f8250 100644
@@ -626,8 +626,8 @@ static u32 convert_ltr_scale(u32 val)
 static int pmc_core_ltr_show(struct seq_file *s, void *unused)
 {
 	struct pmc_dev *pmcdev = s->private;
-	u64 decoded_snoop_ltr, decoded_non_snoop_ltr;
-	u32 ltr_raw_data, scale, val;
+	u64 decoded_snoop_ltr, decoded_non_snoop_ltr, val;
+	u32 ltr_raw_data, scale;
 	u16 snoop_ltr, nonsnoop_ltr;
 	unsigned int i, index, ltr_index = 0;
 
Signature · 1 line
2.47.1
maintainer Reviewed-by on v2 1/1
#1 lore raw

Looks good to me.

Quoted 34 lines · Dmitry Kandybka

In pmc_core_ltr_show(), promote 'val' to 'u64' to avoid possible integer overflow. Values (10 bit) are multiplied by the scale, the result of expression is in a range from 1 to 34,326,183,936 which is bigger then UINT32_MAX. Compile tested only.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
v1 -> v2: 'val' variable declared as 'u64' instead of type casting at usage points

 drivers/platform/x86/intel/pmc/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/intel/pmc/core.c +2 -3
index 10f04b944117..1ee0fb5f8250 100644
@@ -626,8 +626,8 @@ static u32 convert_ltr_scale(u32 val)
 static int pmc_core_ltr_show(struct seq_file *s, void *unused)
 {
        struct pmc_dev *pmcdev = s->private;
-       u64 decoded_snoop_ltr, decoded_non_snoop_ltr;
-       u32 ltr_raw_data, scale, val;
+       u64 decoded_snoop_ltr, decoded_non_snoop_ltr, val;
+       u32 ltr_raw_data, scale;
        u16 snoop_ltr, nonsnoop_ltr;
        unsigned int i, index, ltr_index = 0;
 
--

2.47.1

Signature · 2 lines
Thanks,
Rajneesh
maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Dmitry Kandybka
Quoted 20 lines · Dmitry Kandybka

In pmc_core_ltr_show(), promote 'val' to 'u64' to avoid possible integer overflow. Values (10 bit) are multiplied by the scale, the result of expression is in a range from 1 to 34,326,183,936 which is bigger then UINT32_MAX. Compile tested only.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
v1 -> v2: 'val' variable declared as 'u64' instead of type casting at usage points

 drivers/platform/x86/intel/pmc/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/intel/pmc/core.c +0 -0
index 10f04b944117..1ee0fb5f8250 100644

drivers/platform/x86/intel/pmc/core.c static u32 convert_ltr_scale(u32 val) · line 632

Quoted 9 lines
drivers/platform/x86/intel/pmc/core.c +2 -2
@@ -626,8 +626,8 @@ static u32 convert_ltr_scale(u32 val)
 static int pmc_core_ltr_show(struct seq_file *s, void *unused)
 {
 	struct pmc_dev *pmcdev = s->private;
-	u64 decoded_snoop_ltr, decoded_non_snoop_ltr;
-	u32 ltr_raw_data, scale, val;
+	u64 decoded_snoop_ltr, decoded_non_snoop_ltr, val;
+	u32 ltr_raw_data, scale;
 	u16 snoop_ltr, nonsnoop_ltr;
 	unsigned int i, index, ltr_index = 0;

Thanks for the update,

Signature · 1 line
 i.
maintainer
#3 lore raw
In reply to Dmitry Kandybka
Quoted 8 lines · Dmitry Kandybka

In pmc_core_ltr_show(), promote 'val' to 'u64' to avoid possible integer overflow. Values (10 bit) are multiplied by the scale, the result of expression is in a range from 1 to 34,326,183,936 which is bigger then UINT32_MAX. Compile tested only.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-fixes branch. Note it will show up in the public platform-drivers-x86/review-ilpo-fixes branch only once I've pushed my local branch there, which might take a while.

The list of commits applied:
[1/1] platform/x86/intel: pmc: fix ltr decode in pmc_core_ltr_show()

      commit: 4afd0e58a6793b8e4d78cb55dbcf6279936730e5

--
i.