Skip to contentSkip to conversation

platform/x86: think-lmi: Prevent underflow in index_store()

PATCH In review Dan Carpenter 3 participants 3 messages Dec 17, 2021 – Dec 21, 2021

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

PATCH 1/1 platform/x86: think-lmi: Prevent underflow in index_store()

There needs to be a check to prevent negative offsets for setting->index. I have reviewed this code and I think that the "if (block->instance_count <= instance)" check in __query_block() will prevent this from resulting in an out of bounds access. But it's still worth fixing.

Fixes 640a5fa50a42 ("platform/x86: think-lmi: Opcode support")
---
 drivers/platform/x86/think-lmi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/think-lmi.c +1 -1
index 27ab8e4e5b83..0b73e16cccea 100644
@@ -573,7 +573,7 @@ static ssize_t index_store(struct kobject *kobj,
 	if (err < 0)
 		return err;
 
-	if (val > TLMI_INDEX_MAX)
+	if (val < 0 || val > TLMI_INDEX_MAX)
 		return -EINVAL;
 
 	setting->index = val;
Signature · 1 line
2.20.1
#1 lore raw

Thanks Dan

Quoted 18 lines · Dan Carpenter

There needs to be a check to prevent negative offsets for setting->index. I have reviewed this code and I think that the "if (block->instance_count <= instance)" check in __query_block() will prevent this from resulting in an out of bounds access. But it's still worth fixing.

Fixes 640a5fa50a42 ("platform/x86: think-lmi: Opcode support")
---
 drivers/platform/x86/think-lmi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/think-lmi.c +0 -0
index 27ab8e4e5b83..0b73e16cccea 100644

drivers/platform/x86/think-lmi.c static ssize_t index_store(struct kobject *kobj, · line 579

Quoted 8 lines
drivers/platform/x86/think-lmi.c +1 -1
@@ -573,7 +573,7 @@ static ssize_t index_store(struct kobject *kobj,
 	if (err < 0)
 		return err;
 
-	if (val > TLMI_INDEX_MAX)
+	if (val < 0 || val > TLMI_INDEX_MAX)
 		return -EINVAL;
 
 	setting->index = val;

Agreed, it's good to have this check.
Thank you
Mark

#2 lore raw
In reply to Dan Carpenter

Hi,

Quoted 8 lines · Dan Carpenter

There needs to be a check to prevent negative offsets for setting->index. I have reviewed this code and I think that the "if (block->instance_count <= instance)" check in __query_block() will prevent this from resulting in an out of bounds access. But it's still worth fixing.

Fixes 640a5fa50a42 ("platform/x86: think-lmi: Opcode support")

Thank you for your patch, I've applied this patch to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.

Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.

Regards,

Hans

Quoted 18 lines
---
 drivers/platform/x86/think-lmi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/think-lmi.c +1 -1
index 27ab8e4e5b83..0b73e16cccea 100644
@@ -573,7 +573,7 @@ static ssize_t index_store(struct kobject *kobj,
 	if (err < 0)
 		return err;
 
-	if (val > TLMI_INDEX_MAX)
+	if (val < 0 || val > TLMI_INDEX_MAX)
 		return -EINVAL;
 
 	setting->index = val;