rxe: Prevent overflow in wr_set_inline_data_list() bound check

[ Upstream commit fc07a90f173538484d0ed68c47f96e1ab297ceb7 ]

wr_set_inline_data_list() accumulates the length of the caller's buffers
and compares the running total against the send queue's inline limit:

    while (num_buf--) {
        length = buf_list->length;

        if (tot_length + length > qp->sq.max_inline) {
            qp->err = ENOSPC;
            return;
        }

        memcpy(data, buf_list->addr, length);

        tot_length += length;

Both operands are size_t and both are caller controlled, so the addition in
the comparison can wrap.  A first buffer that leaves tot_length non-zero
followed by a second buffer of length SIZE_MAX makes the sum zero, which
satisfies the comparison, and memcpy() is then asked to copy that length
into the inline area of the work queue element.  The single buffer variant
wr_set_inline_data() compares the length against max_inline directly and
does not have this problem.

Compare the length against the remaining budget, which cannot wrap because
tot_length never exceeds max_inline.

Fixes: 1a894ca10105 ("Providers/rxe: Implement ibv_create_qp_ex verb")
Signed-off-by: Li Bingzhuo <lbz2770828522@gmail.com>
Signed-off-by: Nicolas Morey <nmorey@suse.com>
diff --git a/providers/rxe/rxe.c b/providers/rxe/rxe.c
index 1f4b135..35e0863 100644
--- a/providers/rxe/rxe.c
+++ b/providers/rxe/rxe.c
@@ -1097,7 +1097,7 @@
 	while (num_buf--) {
 		length = buf_list->length;
 
-		if (tot_length + length > qp->sq.max_inline) {
+		if (length > qp->sq.max_inline - tot_length) {
 			qp->err = ENOSPC;
 			return;
 		}