RDMA/rxe: match a duplicate request to a resource of its own type
Subsystems (3)
PATCH 1/1 RDMA/rxe: match a duplicate request to a resource of its own type
find_resource() matches a retransmitted request to a responder resource by PSN alone, and rxe_prepare_res() never sets the PSN range of a FLUSH resource, so it keeps the PSNs of the request that last used the slot. duplicate_request() then gives a retransmitted READ the FLUSH resource and reads res->read through the union, so read.rkey and read.length come from the FLUSH's RETH va, chosen by the requester. read_reply() replays the READ through rxe_recheck_mr(), which only checks that the rkey names a valid MR.
A FLUSH with no persistence type needs no QP access bit. A connected RC peer holding one rkey of the QP's PD can thus read any valid MR on the device, including MRs of other PDs without remote access and the DMA MR that each kernel PD gets on rxe, which reads kernel memory at the address the peer gives.
Record the PSNs of a FLUSH resource, and match a duplicate only to a resource of its own type.
Found with afb-afl, an LLM-driven kernel audit/repro pipeline; the fix and this changelog were also drafted with LLM assistance. Reproduced on an unmodified KASAN build of mainline, with raw RoCEv2 packets to an rxe RC QP: four zero-length READs, a FLUSH, then a READ with the first PSN. The replayed READ returned 64 bytes of an MR that another process had registered in another PD with local access only and, against the kernel DMA MR of rxe0 (key byte found in at most 256 tries), 64 bytes of linux_banner. With this patch the replayed READ is dropped in both cases. Retransmitted READ, FETCH_ADD and ATOMIC WRITE requests are replayed as before, a READ with a foreign rkey is NAKed, and a retransmitted FLUSH is now acknowledged instead of dropped. The rdma-core v65.0 tests pass on rxe with and without this patch.
---
Tested on mainline 4405c18c95d2 (v7.4-rc3+) in QEMU. Applies to rdma.git for-rc and for-next.
A reproducer and the test logs are available on request.
drivers/infiniband/sw/rxe/rxe_resp.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/infiniband/sw/rxe/rxe_resp.c +9 -5
@@ -688,6 +688,9 @@ static struct resp_res *rxe_prepare_res(struct rxe_qp *qp, res->flush.length = qp->resp.length; res->flush.type =feth_plt (pkt); res->flush.level =feth_sel (pkt); + res->first_psn = pkt->psn; + res->last_psn = pkt->psn; + res->cur_psn = pkt->psn; }return res;
@@ -1327,14 +1330,14 @@ static enum resp_states cleanup(struct rxe_qp *qp,return RESPST_DONE ; } -static struct resp_res *find_resource (struct rxe_qp *qp,u32 psn) +static struct resp_res *find_resource (struct rxe_qp *qp,u32 psn,int type) {int i;for (i =0 ; i < qp->attr.max_dest_rd_atomic; i++) {struct resp_res *res = &qp->resp.resources[i]; -if (res->type ==0 ) +if (res->type != type)continue ; if (psn_compare(psn, res->first_psn) >= 0 &&
@@ -1361,7 +1364,7 @@ static enum resp_states duplicate_request(struct rxe_qp *qp,struct resp_res *res;/* Find the operation in our list of responder resources. */ - res =find_resource (qp, pkt->psn); + res =find_resource (qp, pkt->psn,RXE_FLUSH_MASK );if (res) { res->replay =1 ; res->cur_psn = pkt->psn;
@@ -1376,7 +1379,7 @@ static enum resp_states duplicate_request(struct rxe_qp *qp, }else if (pkt->mask &RXE_READ_MASK ) {struct resp_res *res; - res =find_resource (qp, pkt->psn); + res =find_resource (qp, pkt->psn,RXE_READ_MASK );if (!res) {/* Resource not found. Class D error. Drop the * request.
@@ -1423,7 +1426,8 @@ static enum resp_states duplicate_request(struct rxe_qp *qp,struct resp_res *res;/* Find the operation in our list of responder resources. */ - res =find_resource (qp, pkt->psn); + res =find_resource (qp, pkt->psn, pkt->mask &RXE_ATOMIC_MASK ? +RXE_ATOMIC_MASK :RXE_ATOMIC_WRITE_MASK );if (res) { res->replay =1 ; res->cur_psn = pkt->psn;
Signature · 1 line
2.56.1
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 15 lines
find_resource()matches a retransmitted request to a responder resource by PSN alone, andrxe_prepare_res()never sets the PSN range of a FLUSH resource, so it keeps the PSNs of the request that last used the slot.duplicate_request()then gives a retransmitted READ the FLUSH resource and readsres->readthrough the union, so read.rkey and read.length come from the FLUSH's RETH va, chosen by the requester.read_reply()replays the READ throughrxe_recheck_mr(), which only checks that the rkey names a valid MR.A FLUSH with no persistence type needs no QP access bit. A connected RC peer holding one rkey of the QP's PD can thus read any valid MR on the device, including MRs of other PDs without remote access and the DMA MR that each kernel PD gets on rxe, which reads kernel memory at the address the peer gives.
Quoted 6 lines
[ ... ]
rdma-core v65.0 tests pass on rxe with and without this patch.Fixes ea1bb00ee9a5 ("RDMA/rxe: Implement flush execution in responder side")Signed-off-by Yiran Qiu <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 31 lines · Yiran Qiu
find_resource()matches a retransmitted request to a responder resource by PSN alone, andrxe_prepare_res()never sets the PSN range of a FLUSH resource, so it keeps the PSNs of the request that last used the slot.duplicate_request()then gives a retransmitted READ the FLUSH resource and readsres->readthrough the union, so read.rkey and read.length come from the FLUSH's RETH va, chosen by the requester.read_reply()replays the READ throughrxe_recheck_mr(), which only checks that the rkey names a valid MR.A FLUSH with no persistence type needs no QP access bit. A connected RC peer holding one rkey of the QP's PD can thus read any valid MR on the device, including MRs of other PDs without remote access and the DMA MR that each kernel PD gets on rxe, which reads kernel memory at the address the peer gives.
Record the PSNs of a FLUSH resource, and match a duplicate only to a resource of its own type.
Found with afb-afl, an LLM-driven kernel audit/repro pipeline; the fix and this changelog were also drafted with LLM assistance. Reproduced on an unmodified KASAN build of mainline, with raw RoCEv2 packets to an rxe RC QP: four zero-length READs, a FLUSH, then a READ with the first PSN. The replayed READ returned 64 bytes of an MR that another process had registered in another PD with local access only and, against the kernel DMA MR of rxe0 (key byte found in at most 256 tries), 64 bytes of
linux_banner. With this patch the replayed READ is dropped in both cases. Retransmitted READ,FETCH_ADDand ATOMIC WRITE requests are replayed as before, a READ with a foreign rkey is NAKed, and a retransmitted FLUSH is now acknowledged instead of dropped. The rdma-core v65.0 tests pass on rxe with and without this patch.
Quoted 7 lines
Fixes ea1bb00ee9a5 ("RDMA/rxe: Implement flush execution in responder side")Signed-off-by Yiran Qiu <[email protected]>---
Tested on mainline4405c18c95d2(v7.4-rc3+) in QEMU. Applies to rdma.git for-rc and for-next.
A reproducer and the test logs are available on request.
Thanks a lot. If you can share the reproducer and the test logs with me,
I can reproduce this problem in my local host.
Except that, I am fine with this commit.
Zhu Yanjun
Quoted 63 lines
drivers/infiniband/sw/rxe/rxe_resp.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)drivers/infiniband/sw/rxe/rxe_resp.c +9
-5@@ -688,6 +688,9 @@ static struct resp_res *rxe_prepare_res(struct rxe_qp *qp, res->flush.length = qp->resp.length; res->flush.type =feth_plt (pkt); res->flush.level =feth_sel (pkt); + res->first_psn = pkt->psn; + res->last_psn = pkt->psn; + res->cur_psn = pkt->psn; }return res;@@ -1327,14 +1330,14 @@ static enum resp_states cleanup(struct rxe_qp *qp,return RESPST_DONE ; } -static struct resp_res *find_resource (struct rxe_qp *qp,u32 psn) +static struct resp_res *find_resource (struct rxe_qp *qp,u32 psn,int type) {int i;for (i =0 ; i < qp->attr.max_dest_rd_atomic; i++) {struct resp_res *res = &qp->resp.resources[i]; -if (res->type ==0 ) +if (res->type != type)continue ; if (psn_compare(psn, res->first_psn) >= 0 &&@@ -1361,7 +1364,7 @@ static enum resp_states duplicate_request(struct rxe_qp *qp,struct resp_res *res;/* Find the operation in our list of responder resources. */ - res =find_resource (qp, pkt->psn); + res =find_resource (qp, pkt->psn,RXE_FLUSH_MASK );if (res) { res->replay =1 ; res->cur_psn = pkt->psn;@@ -1376,7 +1379,7 @@ static enum resp_states duplicate_request(struct rxe_qp *qp, }else if (pkt->mask &RXE_READ_MASK ) {struct resp_res *res; - res =find_resource (qp, pkt->psn); + res =find_resource (qp, pkt->psn,RXE_READ_MASK );if (!res) {/* Resource not found. Class D error. Drop the * request. @@ -1423,7 +1426,8 @@ static enum resp_states duplicate_request(struct rxe_qp *qp,struct resp_res *res;/* Find the operation in our list of responder resources. */ - res =find_resource (qp, pkt->psn); + res =find_resource (qp, pkt->psn, pkt->mask &RXE_ATOMIC_MASK ? +RXE_ATOMIC_MASK :RXE_ATOMIC_WRITE_MASK );if (res) { res->replay =1 ; res->cur_psn = pkt->psn;
Signature · 2 lines
Best Regards, Yanjun.Zhu