Skip to contentSkip to conversation

ACPI: acpi_pcc.c: Fix unintentional integer overflow

PATCH Superseded [email protected] 4 participants 8 messages Oct 13, 2022 – Oct 26, 2022 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: acpi_pcc.c: Fix unintentional integer overflow

From: Manank Patel <[email protected]>

Fixed unintentional u32 overflow by casting it to u64 before multiplication.

---
 drivers/acpi/acpi_pcc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_pcc.c +1 -1
index ee4ce5ba1fb2..b929d2e5c622 100644
@@ -112,7 +112,7 @@ acpi_pcc_address_space_handler(u32 function, acpi_physical_address addr,
 		 * processor could be much slower to reply. So add an arbitrary
 		 * amount of wait on top of Nominal.
 		 */
-		usecs_lat = PCC_CMD_WAIT_RETRIES_NUM * data->pcc_chan->latency;
+		usecs_lat = PCC_CMD_WAIT_RETRIES_NUM * ((u64) data->pcc_chan->latency);
 		ret = wait_for_completion_timeout(&data->done,
 						  usecs_to_jiffies(usecs_lat));
 		if (ret == 0) {
Signature · 1 line
2.38.0
#1 lore raw
Quoted 6 lines · On Thu, Oct 13, 2022 at 7:50 AM <[email protected]> wrote:

From: Manank Patel <[email protected]>

Fixed unintentional u32 overflow by casting it to u64 before multiplication.

A Fixes tag would be nice to have here.

Quoted 9 lines
---
 drivers/acpi/acpi_pcc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_pcc.c +0 -0
index ee4ce5ba1fb2..b929d2e5c622 100644

drivers/acpi/acpi_pcc.c acpi_pcc_address_space_handler(u32 function, acpi_physical_address addr, · line 115

Quoted 5 lines
drivers/acpi/acpi_pcc.c +1 -1
@@ -112,7 +112,7 @@ acpi_pcc_address_space_handler(u32 function, acpi_physical_address addr,
                 * processor could be much slower to reply. So add an arbitrary
                 * amount of wait on top of Nominal.
                 */
-               usecs_lat = PCC_CMD_WAIT_RETRIES_NUM * data->pcc_chan->latency;
+               usecs_lat = PCC_CMD_WAIT_RETRIES_NUM * ((u64) data->pcc_chan->latency);

Or redefine PCC_CMD_WAIT_RETRIES_NUM as 500ULL?

Quoted 6 lines
drivers/acpi/acpi_pcc.c +0 -1
                ret = wait_for_completion_timeout(&data->done,
                                                  usecs_to_jiffies(usecs_lat));
                if (ret == 0) {
--

2.38.0

#2 lore raw

Re: [PATCH] Fixes: 91cefefb6991 ("ACPI: acpi_pcc.c: fixed unintentional u32 overflow by redefining a constant")

changed PCC_CMD_WAIT_RETRIES_NUM to 500ULL

---
 drivers/acpi/acpi_pcc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_pcc.c +1 -1
index ee4ce5ba1fb2..3e252be047b8 100644
@@ -27,7 +27,7 @@
  * Arbitrary retries in case the remote processor is slow to respond
  * to PCC commands
  */
-#define PCC_CMD_WAIT_RETRIES_NUM	500
+#define PCC_CMD_WAIT_RETRIES_NUM	500ULL
 
 struct pcc_data {
 	struct pcc_mbox_chan *pcc_chan;
Signature · 1 line
2.38.0
#3 lore raw

Re: [PATCH] Fixes: 91cefefb6991 ("ACPI: PCC: replace wait_for_completion()")

Fixed unintentional u32 overflow by changing PCC_CMD_WAIT_RETRIES_NUM to 500ULL

---

Sorry for the spam, I made a mistake in the previous patch (I had a confusion in your suggestion about the Fixes tag).As you would have realised, i'm new to this, and not so familiar with the workflow (Though I have read the Documentation). Let me know if you have any suggestions.

 drivers/acpi/acpi_pcc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_pcc.c +1 -1
index ee4ce5ba1fb2..3e252be047b8 100644
@@ -27,7 +27,7 @@
  * Arbitrary retries in case the remote processor is slow to respond
  * to PCC commands
  */
-#define PCC_CMD_WAIT_RETRIES_NUM	500
+#define PCC_CMD_WAIT_RETRIES_NUM	500ULL
 
 struct pcc_data {
 	struct pcc_mbox_chan *pcc_chan;
Signature · 1 line
2.38.0
Acked-by
#4 lore raw

Re: [PATCH] Fixes: 91cefefb6991 ("ACPI: PCC: replace wait_for_completion()")

Quoted 2 lines · Manank Patel

Fixed unintentional u32 overflow by changing PCC_CMD_WAIT_RETRIES_NUM to 500ULL

You just need to add the below fixes line above Signed-off tag. You seemed to have changed the $subject. Please retain the origin subject

Please post it again cleanly marking it as v2(as in the subject must be [PATCH v2] "ACPI: PCC: Fix unintentional integer overflow"

Fixes 91cefefb6991 ("ACPI: PCC: replace wait_for_completion()")
Quoted 8 lines

---

Sorry for the spam, I made a mistake in the previous patch (I had a confusion in your suggestion about the Fixes tag).As you would have realised, i'm new to this, and not so familiar with the workflow (Though I have read the Documentation). Let me know if you have any suggestions.

Add a text here pointing what changed from v1->v2 v1->v2:
Change the macro itself ULL instead typecasting in the code

Hope this helps.

With all these changes incorporated in v2, you can add my

Signature · 2 lines
Regards,
Sudeep
#5 lore raw

PATCH v2 1/1 "ACPI: PCC: Fix unintentional integer overflow"

Fixed unintentional u32 overflow by changing PCC_CMD_WAIT_RETRIES_NUM to 500ULL

Fixes 91cefefb6991 ("ACPI: PCC: replace wait_for_completion()")

---
Thank you so much @sudeep for your clarifications!

Changelog:
v1->v2:
Change the macro itself to ULL instead of typecasting in the code

 drivers/acpi/acpi_pcc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_pcc.c +1 -1
index ee4ce5ba1fb2..3e252be047b8 100644
@@ -27,7 +27,7 @@
  * Arbitrary retries in case the remote processor is slow to respond
  * to PCC commands
  */
-#define PCC_CMD_WAIT_RETRIES_NUM	500
+#define PCC_CMD_WAIT_RETRIES_NUM	500ULL
 
 struct pcc_data {
 	struct pcc_mbox_chan *pcc_chan;
Signature · 1 line
2.38.0
Acked-by on v2 1/1
#6 lore raw

Re: [PATCH v2] "ACPI: PCC: Fix unintentional integer overflow"

Quoted 23 lines · Manank Patel

Fixed unintentional u32 overflow by changing PCC_CMD_WAIT_RETRIES_NUM to 500ULL

Fixes 91cefefb6991 ("ACPI: PCC: replace wait_for_completion()")

---
Thank you so much @sudeep for your clarifications!

Changelog:
v1->v2:
Change the macro itself to ULL instead of typecasting in the code

  drivers/acpi/acpi_pcc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_pcc.c +0 -0
index ee4ce5ba1fb2..3e252be047b8 100644

drivers/acpi/acpi_pcc.c line 33

Quoted 8 lines
drivers/acpi/acpi_pcc.c +1 -1
@@ -27,7 +27,7 @@
   * Arbitrary retries in case the remote processor is slow to respond
   * to PCC commands
   */
-#define PCC_CMD_WAIT_RETRIES_NUM	500
+#define PCC_CMD_WAIT_RETRIES_NUM	500ULL
 
  struct pcc_data {
  	struct pcc_mbox_chan *pcc_chan;
maintainer Applied
#7 lore raw

Re: [PATCH v2] "ACPI: PCC: Fix unintentional integer overflow"

Quoted 32 lines · lihuisong (C)
Quoted 29 lines · Manank Patel

Fixed unintentional u32 overflow by changing PCC_CMD_WAIT_RETRIES_NUM to 500ULL

Fixes 91cefefb6991 ("ACPI: PCC: replace wait_for_completion()")

---
Thank you so much @sudeep for your clarifications!

Changelog:
v1->v2:
Change the macro itself to ULL instead of typecasting in the code

  drivers/acpi/acpi_pcc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_pcc.c +1 -1
index ee4ce5ba1fb2..3e252be047b8 100644
@@ -27,7 +27,7 @@
   * Arbitrary retries in case the remote processor is slow to respond
   * to PCC commands
   */
-#define PCC_CMD_WAIT_RETRIES_NUM     500
+#define PCC_CMD_WAIT_RETRIES_NUM     500ULL
 
Quoted 4 lines

drivers/acpi/acpi_pcc.c line 33

Quoted 2 lines
drivers/acpi/acpi_pcc.c +0 -0
  struct pcc_data {
      struct pcc_mbox_chan *pcc_chan;

Applied as 6.1-rc material, thanks!