Skip to content

Commit 2fc4422

Browse files
author
Luke Robison
committed
MTL/OFI: Fix MPI_Cancel dereferences NULL pointer
This change postpones the use of ofi_req->comm until we are sure it was initialized and we intend to use it. Previously attempting to cancel an IProbe or ISend would crash, even though it should have been a no-op. Additionally we must ensure ofi_req->type was properly initialized, which it was not for a couple of SEND cases. Signed-off-by: Luke Robison <lrbison@amazon.com>
1 parent 6c1e9f7 commit 2fc4422

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ompi/mca/mtl/ofi/mtl_ofi.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ ompi_mtl_ofi_send_excid(struct mca_mtl_base_module_t *mtl,
736736
/**
737737
* Create a send request, start it and wait until it completes.
738738
*/
739+
ofi_req->type = OMPI_MTL_OFI_SEND;
739740
ofi_req->event_callback = ompi_mtl_ofi_send_excid_callback;
740741
ofi_req->error_callback = ompi_mtl_ofi_send_error_callback;
741742
ofi_req->buffer = start;
@@ -1060,6 +1061,7 @@ ompi_mtl_ofi_isend_generic(struct mca_mtl_base_module_t *mtl,
10601061
ompi_ret = ompi_mtl_datatype_pack(convertor, &start, &length, &free_after);
10611062
if (OPAL_UNLIKELY(OMPI_SUCCESS != ompi_ret)) return ompi_ret;
10621063

1064+
ofi_req->type = OMPI_MTL_OFI_SEND;
10631065
ofi_req->buffer = (free_after) ? start : NULL;
10641066
ofi_req->length = length;
10651067
ofi_req->status.MPI_ERROR = OMPI_SUCCESS;
@@ -1774,9 +1776,8 @@ ompi_mtl_ofi_cancel(struct mca_mtl_base_module_t *mtl,
17741776
int ret, ctxt_id = 0;
17751777
ompi_mtl_ofi_request_t *ofi_req = (ompi_mtl_ofi_request_t*) mtl_request;
17761778

1777-
ctxt_id = ompi_mtl_ofi_map_comm_to_ctxt(ofi_req->comm->c_index);
1778-
17791779
switch (ofi_req->type) {
1780+
case OMPI_MTL_OFI_PROBE:
17801781
case OMPI_MTL_OFI_SEND:
17811782
/**
17821783
* Cannot cancel sends yet
@@ -1792,6 +1793,8 @@ ompi_mtl_ofi_cancel(struct mca_mtl_base_module_t *mtl,
17921793
ompi_mtl_ofi_progress();
17931794

17941795
if (!ofi_req->req_started) {
1796+
ctxt_id = ompi_mtl_ofi_map_comm_to_ctxt(ofi_req->comm->c_index);
1797+
17951798
ret = fi_cancel((fid_t)ompi_mtl_ofi.ofi_ctxt[ctxt_id].rx_ep,
17961799
&ofi_req->ctx);
17971800
if (0 == ret) {

0 commit comments

Comments
 (0)