Commit 5f90677e authored by Kaike Wan's avatar Kaike Wan Committed by Jason Gunthorpe

IB/hfi1: Validate fault injection opcode user input

The opcode range for fault injection from user should be validated before
it is applied to the fault->opcodes[] bitmap to avoid out-of-bound
error.

Cc: <stable@vger.kernel.org>
Fixes: a74d5307 ("IB/hfi1: Rework fault injection machinery")
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: default avatarMike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: default avatarKaike Wan <kaike.wan@intel.com>
Signed-off-by: default avatarDennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent d1fdb6d8
...@@ -153,6 +153,7 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf, ...@@ -153,6 +153,7 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf,
char *dash; char *dash;
unsigned long range_start, range_end, i; unsigned long range_start, range_end, i;
bool remove = false; bool remove = false;
unsigned long bound = 1U << BITS_PER_BYTE;
end = strchr(ptr, ','); end = strchr(ptr, ',');
if (end) if (end)
...@@ -178,6 +179,10 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf, ...@@ -178,6 +179,10 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf,
BITS_PER_BYTE); BITS_PER_BYTE);
break; break;
} }
/* Check the inputs */
if (range_start >= bound || range_end >= bound)
break;
for (i = range_start; i <= range_end; i++) { for (i = range_start; i <= range_end; i++) {
if (remove) if (remove)
clear_bit(i, fault->opcodes); clear_bit(i, fault->opcodes);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment