Skip to content

Commit 48490b9

Browse files
committed
Fix bug in MCA_PML_OB1_ADD_ACK_TO_PENDING that causes memory overruns or failure
The MCA_PML_OB1_ADD_ACK_TO_PENDING method creates a mca_pml_ob1_pckt_pending_t to hold an ack to be sent later. This method builds the pending packet then puts it on the mca_pml_ob1.pckt_pending list for later transmission. It does not, however, set the required hdr_size field on the struct. This leads to issues when the packet is later sent because it could contain any value. With some btls this will lead to memory corruption (if the size is not checked against btl_max_send_size) or just allocation failure because the size is too big. In other situations it could lead to a truncated packet being send (if the size previously in hdr_size is smaller than an ack). To fix the issue this commit gets rid of the macro entirely and replaces it with a new inline helper method that does the same thing. This helper uses the existing mca_pml_ob1_add_to_pending helper (which sets hdr_size) to reduce duplicated code. Tested and verified this fixes a critical issue triggered on our hardware. Signed-off-by: Nathan Hjelm <[email protected]>
1 parent 3af7bb8 commit 48490b9

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

ompi/mca/pml/ob1/pml_ob1_recvreq.h

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -407,23 +407,21 @@ static inline void mca_pml_ob1_recv_request_schedule(
407407
(void)mca_pml_ob1_recv_request_schedule_exclusive(req, start_bml_btl);
408408
}
409409

410-
#define MCA_PML_OB1_ADD_ACK_TO_PENDING(P, S, D, O, Sz) \
411-
do { \
412-
mca_pml_ob1_pckt_pending_t *_pckt; \
413-
\
414-
MCA_PML_OB1_PCKT_PENDING_ALLOC(_pckt); \
415-
_pckt->hdr.hdr_common.hdr_type = MCA_PML_OB1_HDR_TYPE_ACK; \
416-
_pckt->hdr.hdr_ack.hdr_src_req.lval = (S); \
417-
_pckt->hdr.hdr_ack.hdr_dst_req.pval = (D); \
418-
_pckt->hdr.hdr_ack.hdr_send_offset = (O); \
419-
_pckt->hdr.hdr_ack.hdr_send_size = (Sz); \
420-
_pckt->proc = (P); \
421-
_pckt->bml_btl = NULL; \
422-
OPAL_THREAD_LOCK(&mca_pml_ob1.lock); \
423-
opal_list_append(&mca_pml_ob1.pckt_pending, \
424-
(opal_list_item_t*)_pckt); \
425-
OPAL_THREAD_UNLOCK(&mca_pml_ob1.lock); \
426-
} while(0)
410+
static inline void mca_pml_ob1_add_ack_to_pending(ompi_proc_t *proc, uintptr_t src_req, void *dst_req,
411+
uint64_t send_offset, uint64_t send_size) {
412+
mca_pml_ob1_hdr_t hdr = {
413+
.hdr_ack = {
414+
.hdr_common = { .hdr_type = MCA_PML_OB1_HDR_TYPE_ACK },
415+
.hdr_src_req = { .lval = src_req },
416+
.hdr_dst_req = { .pval = dst_req },
417+
.hdr_send_offset = send_offset,
418+
.hdr_send_size = send_size,
419+
},
420+
};
421+
422+
mca_pml_ob1_add_to_pending(proc, /*bml_btl=*/NULL, /*order=*/0,
423+
&hdr, sizeof(hdr.hdr_ack));
424+
}
427425

428426
int mca_pml_ob1_recv_request_ack_send_btl(ompi_proc_t* proc,
429427
mca_bml_base_btl_t* bml_btl, uint64_t hdr_src_req, void *hdr_dst_req,
@@ -455,7 +453,7 @@ mca_pml_ob1_recv_request_ack_send(mca_btl_base_module_t* btl,
455453
}
456454
}
457455

458-
MCA_PML_OB1_ADD_ACK_TO_PENDING(proc, hdr_src_req, hdr_dst_req,
456+
mca_pml_ob1_add_ack_to_pending(proc, hdr_src_req, hdr_dst_req,
459457
hdr_send_offset, size);
460458

461459
return OMPI_ERR_OUT_OF_RESOURCE;

0 commit comments

Comments
 (0)