Skip to contentSkip to conversation

IB/rdmavt: Call check_modify_qp after validating QP attributes

PATCH New Serhat Kumral 2 participants 2 messages Nov 9 – Nov 10

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IB/rdmavt: Call check_modify_qp after validating QP attributes

rvt_modify_qp() calls the driver's check_modify_qp() hook before it validates the address handle attributes with rvt_check_ah().

hfi1_check_modify_qp() uses the user-supplied SL in ah_to_sc() to index ibp->sl_to_sc[32]. The SL is a u8 that is bounds-checked only in hfi1_check_ah(), which runs later so an SL >= 32 causes an possible out-of-bounds read.

Move the check_modify_qp() call after all generic attribute checks.

Fixes e85ec33d820e ("IB/rdmavt: add modify queue pair driver helpers")

---
found by smatch:
- drivers/infiniband/hw/hfi1/verbs.c:1474 ah_to_sc() error: buffer overflow 'ibp->sl_to_sc' 32 <= 255 user_rl='0-255' --This fix relies on the SL bounds check added by commit 0dbfaa9f2813

 drivers/infiniband/sw/rdmavt/qp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/infiniband/sw/rdmavt/qp.c +4 -4
index 3602b9ff2196..abd33f42c888 100644
@@ -1422,10 +1422,6 @@ int rvt_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
 				attr_mask))
 		goto inval;
 
-	if (rdi->driver_f.check_modify_qp &&
-	    rdi->driver_f.check_modify_qp(qp, attr, attr_mask, udata))
-		goto inval;
-
 	if (attr_mask & IB_QP_AV) {
 		if (opa_ah) {
 			if (rdma_ah_get_dlid(&attr->ah_attr) >=
@@ -1521,6 +1517,10 @@ int rvt_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
 		if (attr->max_dest_rd_atomic > rdi->dparms.max_rdma_atomic)
 			goto inval;
 
+	if (rdi->driver_f.check_modify_qp &&
+	    rdi->driver_f.check_modify_qp(qp, attr, attr_mask, udata))
+		goto inval;
+
 	switch (new_state) {
 	case IB_QPS_RESET:
 		if (qp->state != IB_QPS_RESET)
Signature · 1 line
2.53.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

rvt_modify_qp() calls the driver's check_modify_qp() hook before it validates the address handle attributes with rvt_check_ah().

hfi1_check_modify_qp() uses the user-supplied SL in ah_to_sc() to index ibp->sl_to_sc[32]. The SL is a u8 that is bounds-checked only in hfi1_check_ah(), which runs later so an SL >= 32 causes an possible out-of-bounds read.

Quoted 4 lines

Move the check_modify_qp() call after all generic attribute checks.

Fixes e85ec33d820e ("IB/rdmavt: add modify queue pair driver helpers")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1