Skip to contentSkip to conversation

scsi: megaraid_sas: Use array_size() helper

PATCH In review Gustavo A. R. Silva 2 participants 2 messages Jun 15, 2020

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

PATCH 1/1 scsi: megaraid_sas: Use array_size() helper

The get_order() function has no 2-factor argument form, so multiplication factors need to be wrapped in array_size().

This issue was found with the help of Coccinelle and, audited and fixed manually.

Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83

---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/megaraid/megaraid_sas_fusion.c +4 -4
index 319f241da4b6..6de44ed4cde7 100644
@@ -5180,8 +5180,8 @@ megasas_alloc_fusion_context(struct megasas_instance *instance)
 
 	fusion = instance->ctrl_context;
 
-	fusion->log_to_span_pages = get_order(MAX_LOGICAL_DRIVES_EXT *
-					      sizeof(LD_SPAN_INFO));
+	fusion->log_to_span_pages = get_order(array_size(MAX_LOGICAL_DRIVES_EXT,
+					      sizeof(LD_SPAN_INFO)));
 	fusion->log_to_span =
 		(PLD_SPAN_INFO)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
 						fusion->log_to_span_pages);
@@ -5196,8 +5196,8 @@ megasas_alloc_fusion_context(struct megasas_instance *instance)
 		}
 	}
 
-	fusion->load_balance_info_pages = get_order(MAX_LOGICAL_DRIVES_EXT *
-		sizeof(struct LD_LOAD_BALANCE_INFO));
+	fusion->load_balance_info_pages = get_order(array_size(MAX_LOGICAL_DRIVES_EXT,
+		sizeof(struct LD_LOAD_BALANCE_INFO)));
 	fusion->load_balance_info =
 		(struct LD_LOAD_BALANCE_INFO *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
 		fusion->load_balance_info_pages);
Signature · 1 line
2.27.0
#1 lore raw
Quoted 30 lines · Gustavo A. R. Silva

The get_order() function has no 2-factor argument form, so multiplication
factors need to be wrapped in array_size().

This issue was found with the help of Coccinelle and, audited and fixed
manually.

Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83

---
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/megaraid/megaraid_sas_fusion.c +2 -2
index 319f241da4b6..6de44ed4cde7 100644
@@ -5180,8 +5180,8 @@ megasas_alloc_fusion_context(struct
 megasas_instance *instance)
 
 	fusion = instance->ctrl_context;
 
-	fusion->log_to_span_pages = get_order(MAX_LOGICAL_DRIVES_EXT
 *
-					      sizeof(LD_SPAN_INFO));
+	fusion->log_to_span_pages =
 get_order(array_size(MAX_LOGICAL_DRIVES_EXT,
+					      sizeof(LD_SPAN_INFO)))
Quoted 1 line

;

What's the point of this? You're replacing a constant multiplication the compiler can compute with one it can't on the theory there might be an overflow, which is pretty far fetched given MAX_LOGICAL_DRIVES_EXT is 256 and sizeof(LD_SPAN_INFO) is around 82.

I thought the whole point of overflow detection was to use it for instances where we could be tricked into triggering one by userspace which may result in a buffer under or overflow ... this is two constants, how could this ever be a source of an exploit?

James