IB/hfi1: Ensure VL index is within bounds
authorMichael J. Ruhl <michael.j.ruhl@intel.com>
Tue, 21 Mar 2017 00:26:07 +0000 (17:26 -0700)
committerDoug Ledford <dledford@redhat.com>
Wed, 5 Apr 2017 18:45:09 +0000 (14:45 -0400)
Improve the safety of the code and ensure the array cannot be indexed
out of bounds when picking the CPU for a given SDMA engine.

Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Michael J. Ruhl <michael.j.ruhl@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/hw/hfi1/sdma.c

index d89852b1f9845b8207392bb0501e44a27677cdd7..bfd0d5187e9b003f676327cf3d906acdf8bf676f 100644 (file)
@@ -962,6 +962,11 @@ ssize_t sdma_set_cpu_to_sde_map(struct sdma_engine *sde, const char *buf,
                        continue;
                }
 
+               if (vl >= ARRAY_SIZE(rht_node->map)) {
+                       ret = -EINVAL;
+                       goto out;
+               }
+
                rht_node = rhashtable_lookup_fast(dd->sdma_rht, &cpu,
                                                  sdma_rht_params);
                if (!rht_node) {