Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/20211217071209.GF26548@kili
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

authored by

Dan Carpenter and committed by
Hans de Goede
72e4d07d 85504587

+1 -1
+1 -1
drivers/platform/x86/think-lmi.c
··· 573 573 if (err < 0) 574 574 return err; 575 575 576 - if (val > TLMI_INDEX_MAX) 576 + if (val < 0 || val > TLMI_INDEX_MAX) 577 577 return -EINVAL; 578 578 579 579 setting->index = val;