diff options
author | Kaike Wan <kaike.wan@intel.com> | 2019-06-07 08:25:25 -0400 |
---|---|---|
committer | Jason Gunthorpe <jgg@mellanox.com> | 2019-06-11 16:06:37 -0400 |
commit | 5f90677ed31963abb184ee08ebee4a4a68225dd8 (patch) | |
tree | 4cb3055c9b4d42d9155f80a993805848ed6aa563 | |
parent | d1fdb6d8f6a4109a4263176c84b899076a5f8008 (diff) |
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: a74d5307caba ("IB/hfi1: Rework fault injection machinery")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Kaike Wan <kaike.wan@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
-rw-r--r-- | drivers/infiniband/hw/hfi1/fault.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/infiniband/hw/hfi1/fault.c b/drivers/infiniband/hw/hfi1/fault.c index 3fd3315d0fb0..93613e5def9b 100644 --- a/drivers/infiniband/hw/hfi1/fault.c +++ b/drivers/infiniband/hw/hfi1/fault.c | |||
@@ -153,6 +153,7 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf, | |||
153 | char *dash; | 153 | char *dash; |
154 | unsigned long range_start, range_end, i; | 154 | unsigned long range_start, range_end, i; |
155 | bool remove = false; | 155 | bool remove = false; |
156 | unsigned long bound = 1U << BITS_PER_BYTE; | ||
156 | 157 | ||
157 | end = strchr(ptr, ','); | 158 | end = strchr(ptr, ','); |
158 | if (end) | 159 | if (end) |
@@ -178,6 +179,10 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf, | |||
178 | BITS_PER_BYTE); | 179 | BITS_PER_BYTE); |
179 | break; | 180 | break; |
180 | } | 181 | } |
182 | /* Check the inputs */ | ||
183 | if (range_start >= bound || range_end >= bound) | ||
184 | break; | ||
185 | |||
181 | for (i = range_start; i <= range_end; i++) { | 186 | for (i = range_start; i <= range_end; i++) { |
182 | if (remove) | 187 | if (remove) |
183 | clear_bit(i, fault->opcodes); | 188 | clear_bit(i, fault->opcodes); |