Skip to contentSkip to conversation

IB/rdmavt: Fix target union member for rvt_post_one_wr()

PATCH Applied Kees Cook 3 participants 4 messages Feb 18, 2023 – Mar 13, 2023

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 IB/rdmavt: Fix target union member for rvt_post_one_wr()

The "cplen" result used by the memcpy() into struct rvt_swqe "wqe" may be sized to 80 for struct rvt_ud_wr (which is member "ud_wr", not "wr" which is only 40 bytes in size). Change the destination union member so the compiler can use the correct bounds check.

struct rvt_swqe {
        union {
                struct ib_send_wr wr;   /* don't use wr.sg_list */
                struct rvt_ud_wr ud_wr;
		...
	};
	...
};

Silences false positive memcpy() run-time warning:

memcpy: detected field-spanning write (size 80) of single field "&wqe->wr" at drivers/infiniband/sw/rdmavt/qp.c:2043 (size 40)

---
 drivers/infiniband/sw/rdmavt/qp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rdmavt/qp.c +1 -1
index 3acab569fbb9..3f707e1fa517 100644
@@ -2040,7 +2040,7 @@ static int rvt_post_one_wr(struct rvt_qp *qp,
 	wqe = rvt_get_swqe_ptr(qp, qp->s_head);
 
 	/* cplen has length from above */
-	memcpy(&wqe->wr, wr, cplen);
+	memcpy(&wqe->ud_wr, wr, cplen);
 
 	wqe->length = 0;
 	j = 0;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 34 lines · Kees Cook

The "cplen" result used by the memcpy() into struct rvt_swqe "wqe" may be sized to 80 for struct rvt_ud_wr (which is member "ud_wr", not "wr" which is only 40 bytes in size). Change the destination union member so the compiler can use the correct bounds check.

struct rvt_swqe {
        union {
                struct ib_send_wr wr;   /* don't use wr.sg_list */
                struct rvt_ud_wr ud_wr;
		...
	};
	...
};

Silences false positive memcpy() run-time warning:

memcpy: detected field-spanning write (size 80) of single field "&wqe->wr" at drivers/infiniband/sw/rdmavt/qp.c:2043 (size 40)

---
 drivers/infiniband/sw/rdmavt/qp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rdmavt/qp.c +0 -0
index 3acab569fbb9..3f707e1fa517 100644

drivers/infiniband/sw/rdmavt/qp.c static int rvt_post_one_wr(struct rvt_qp *qp, · line 2046

Quoted 8 lines
drivers/infiniband/sw/rdmavt/qp.c +1 -1
@@ -2040,7 +2040,7 @@ static int rvt_post_one_wr(struct rvt_qp *qp,
 	wqe = rvt_get_swqe_ptr(qp, qp->s_head);
 
 	/* cplen has length from above */
-	memcpy(&wqe->wr, wr, cplen);
+	memcpy(&wqe->ud_wr, wr, cplen);
 
 	wqe->length = 0;
 	j = 0;

Thanks for the patch. We've been debating this issue internally since last week. The problem I have is this makes it look like everything is a "UD" req when it could be a different QP type. Maybe we just need a comment explaining.

-Denny

maintainer Reviewed-by
#2 lore raw
Quoted 41 lines · Dennis Dalessandro
Quoted 40 lines · Kees Cook

The "cplen" result used by the memcpy() into struct rvt_swqe "wqe" may be sized to 80 for struct rvt_ud_wr (which is member "ud_wr", not "wr" which is only 40 bytes in size). Change the destination union member so the compiler can use the correct bounds check.

struct rvt_swqe {
        union {
                struct ib_send_wr wr;   /* don't use wr.sg_list */
                struct rvt_ud_wr ud_wr;
		...
	};
	...
};

Silences false positive memcpy() run-time warning:

memcpy: detected field-spanning write (size 80) of single field "&wqe->wr" at drivers/infiniband/sw/rdmavt/qp.c:2043 (size 40)

---
 drivers/infiniband/sw/rdmavt/qp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rdmavt/qp.c +1 -1
index 3acab569fbb9..3f707e1fa517 100644
@@ -2040,7 +2040,7 @@ static int rvt_post_one_wr(struct rvt_qp *qp,
 	wqe = rvt_get_swqe_ptr(qp, qp->s_head);
 
 	/* cplen has length from above */
-	memcpy(&wqe->wr, wr, cplen);
+	memcpy(&wqe->ud_wr, wr, cplen);
 
Quoted 6 lines

drivers/infiniband/sw/rdmavt/qp.c static int rvt_post_one_wr(struct rvt_qp *qp, · line 2046

Quoted 2 lines
drivers/infiniband/sw/rdmavt/qp.c +0 -0
 	wqe->length = 0;
 	j = 0;

Thanks for the patch. We've been debating this issue internally since last week. The problem I have is this makes it look like everything is a "UD" req when it could be a different QP type. Maybe we just need a comment explaining.

For what it's worth I did test this patch. If you could add the comment that'd be great. If not I can touch it up later.

#3 lore raw
In reply to Kees Cook
Quoted 14 lines · Kees Cook

The "cplen" result used by the memcpy() into struct rvt_swqe "wqe" may be sized to 80 for struct rvt_ud_wr (which is member "ud_wr", not "wr" which is only 40 bytes in size). Change the destination union member so the compiler can use the correct bounds check.

struct rvt_swqe {
        union {
                struct ib_send_wr wr;   /* don't use wr.sg_list */
                struct rvt_ud_wr ud_wr;
		...
	};
	...
};
Quoted 1 line

[...]

Applied, thanks!

[1/1] IB/rdmavt: Fix target union member for rvt_post_one_wr()

      https://git.kernel.org/rdma/rdma/c/f2f6e1661d38fb

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>