1 From 5f90677ed31963abb184ee08ebee4a4a68225dd8 Mon Sep 17 00:00:00 2001
2 From: Kaike Wan <kaike.wan@intel.com>
3 Date: Fri, 7 Jun 2019 08:25:25 -0400
4 Subject: IB/hfi1: Validate fault injection opcode user input
6 From: Kaike Wan <kaike.wan@intel.com>
8 commit 5f90677ed31963abb184ee08ebee4a4a68225dd8 upstream.
10 The opcode range for fault injection from user should be validated before
11 it is applied to the fault->opcodes[] bitmap to avoid out-of-bound
14 Cc: <stable@vger.kernel.org>
15 Fixes: a74d5307caba ("IB/hfi1: Rework fault injection machinery")
16 Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
17 Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
18 Signed-off-by: Kaike Wan <kaike.wan@intel.com>
19 Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
20 Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
21 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24 drivers/infiniband/hw/hfi1/fault.c | 5 +++++
25 1 file changed, 5 insertions(+)
27 --- a/drivers/infiniband/hw/hfi1/fault.c
28 +++ b/drivers/infiniband/hw/hfi1/fault.c
29 @@ -153,6 +153,7 @@ static ssize_t fault_opcodes_write(struc
31 unsigned long range_start, range_end, i;
33 + unsigned long bound = 1U << BITS_PER_BYTE;
35 end = strchr(ptr, ',');
37 @@ -178,6 +179,10 @@ static ssize_t fault_opcodes_write(struc
41 + /* Check the inputs */
42 + if (range_start >= bound || range_end >= bound)
45 for (i = range_start; i <= range_end; i++) {
47 clear_bit(i, fault->opcodes);