]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
IB/hfi1: Validate fault injection opcode user input
authorKaike Wan <kaike.wan@intel.com>
Fri, 7 Jun 2019 12:25:25 +0000 (08:25 -0400)
committerJason Gunthorpe <jgg@mellanox.com>
Tue, 11 Jun 2019 20:06:37 +0000 (17:06 -0300)
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>
drivers/infiniband/hw/hfi1/fault.c

index 3fd3315d0fb0c9d209cc9efb7af1992d3c96e320..93613e5def9b7bd4492e65494abd4d420fc5a6c1 100644 (file)
@@ -153,6 +153,7 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf,
                char *dash;
                unsigned long range_start, range_end, i;
                bool remove = false;
+               unsigned long bound = 1U << BITS_PER_BYTE;
 
                end = strchr(ptr, ',');
                if (end)
@@ -178,6 +179,10 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf,
                                    BITS_PER_BYTE);
                        break;
                }
+               /* Check the inputs */
+               if (range_start >= bound || range_end >= bound)
+                       break;
+
                for (i = range_start; i <= range_end; i++) {
                        if (remove)
                                clear_bit(i, fault->opcodes);