]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
RDMA/rxe: Prevent access to wr->next ptr afrer wr is posted to send queue
authorMikhail Malygin <m.malygin@yadro.com>
Thu, 16 Jul 2020 19:03:41 +0000 (22:03 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Aug 2020 06:26:36 +0000 (08:26 +0200)
[ Upstream commit 5f0b2a6093a4d9aab093964c65083fe801ef1e58 ]

rxe_post_send_kernel() iterates over linked list of wr's, until the
wr->next ptr is NULL.  However if we've got an interrupt after last wr is
posted, control may be returned to the code after send completion callback
is executed and wr memory is freed.

As a result, wr->next pointer may contain incorrect value leading to
panic. Store the wr->next on the stack before posting it.

Fixes: 8700e3e7c485 ("Soft RoCE driver")
Link: https://lore.kernel.org/r/20200716190340.23453-1-m.malygin@yadro.com
Signed-off-by: Mikhail Malygin <m.malygin@yadro.com>
Signed-off-by: Sergey Kojushev <s.kojushev@yadro.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/infiniband/sw/rxe/rxe_verbs.c

index b8a22af724e8b55fcc98f714f88d4ad9f66a76c0..84fec5fd798d569a5be5dbaf3f9636e00d94ba02 100644 (file)
@@ -684,6 +684,7 @@ static int rxe_post_send_kernel(struct rxe_qp *qp, const struct ib_send_wr *wr,
        unsigned int mask;
        unsigned int length = 0;
        int i;
+       struct ib_send_wr *next;
 
        while (wr) {
                mask = wr_opcode_mask(wr->opcode, qp);
@@ -700,6 +701,8 @@ static int rxe_post_send_kernel(struct rxe_qp *qp, const struct ib_send_wr *wr,
                        break;
                }
 
+               next = wr->next;
+
                length = 0;
                for (i = 0; i < wr->num_sge; i++)
                        length += wr->sg_list[i].length;
@@ -710,7 +713,7 @@ static int rxe_post_send_kernel(struct rxe_qp *qp, const struct ib_send_wr *wr,
                        *bad_wr = wr;
                        break;
                }
-               wr = wr->next;
+               wr = next;
        }
 
        rxe_run_task(&qp->req.task, 1);