From c0817574622f2f58968353992ce13d4d67fc1c64 Mon Sep 17 00:00:00 2001 From: Mark Allen Date: Tue, 23 Apr 2019 15:44:16 -0400 Subject: [PATCH] fixing an unsafe usage of integer disps[] (romio321 gpfs) There are a couple MPI_Alltoallv calls in ad_gpfs_aggrs.c where the send/recv data comes from places like req[r].lens, and the send buffer and send displacements for example were being calculated as sbuf = pick one of the reqs: req[bottom].lens sdisps[r] = req[r].lens - req[bottom].lens which might be okay if the .lens was data inside of req[] so they'd all be close to each other. But each .lens field is just a pointer that's malloced, so those addresses can be all over the place, so the integer-sized sdisps[] isn't safe. I changed it to have a new extra array sbuf and rbuf for those two Alltoallv calls, and copied the data into the sbuf from the same locations it used to be setting up the sdisps[] at, and after the Alltoallv I copy the data out of the new rbuf into the same locations it used to be setting up the rdisps[] at. For what it's worth I was able to get this to fail -np 2 on a GPFS filesystem with hints romio_cb_write enable. I didn't whittle the test down to something small, but it was failing in an MPI_File_write_all call. Signed-off-by: Mark Allen (cherry picked from commit d85cac8f1a11495415b67ecab69d2ae1cd19d155) --- .../romio/adio/ad_gpfs/ad_gpfs_aggrs.c | 123 +++++++----------- 1 file changed, 47 insertions(+), 76 deletions(-) diff --git a/ompi/mca/io/romio321/romio/adio/ad_gpfs/ad_gpfs_aggrs.c b/ompi/mca/io/romio321/romio/adio/ad_gpfs/ad_gpfs_aggrs.c index 3eb3d84969..f6df24748f 100644 --- a/ompi/mca/io/romio321/romio/adio/ad_gpfs/ad_gpfs_aggrs.c +++ b/ompi/mca/io/romio321/romio/adio/ad_gpfs/ad_gpfs_aggrs.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------- */ -/* (C)Copyright IBM Corp. 2007, 2008 */ +/* (C)Copyright IBM Corp. 2007, 2008, 2019 */ /* ---------------------------------------------------------------- */ /** * \file ad_gpfs_aggrs.c @@ -663,16 +663,6 @@ void ADIOI_GPFS_Calc_others_req(ADIO_File fd, int count_my_req_procs, /* Parameters for MPI_Alltoallv */ int *scounts, *sdispls, *rcounts, *rdispls; - /* Parameters for MPI_Alltoallv. These are the buffers, which - * are later computed to be the lowest address of all buffers - * to be sent/received for offsets and lengths. Initialize to - * the highest possible address which is the current minimum. - */ - void *sendBufForOffsets=(void*)0xFFFFFFFFFFFFFFFF, - *sendBufForLens =(void*)0xFFFFFFFFFFFFFFFF, - *recvBufForOffsets=(void*)0xFFFFFFFFFFFFFFFF, - *recvBufForLens =(void*)0xFFFFFFFFFFFFFFFF; - /* first find out how much to send/recv and from/to whom */ #ifdef AGGREGATION_PROFILE MPE_Log_event (5026, 0, NULL); @@ -719,11 +709,6 @@ void ADIOI_GPFS_Calc_others_req(ADIO_File fd, int count_my_req_procs, others_req[i].lens = ADIOI_Malloc(count_others_req_per_proc[i]*sizeof(ADIO_Offset)); - if ( (MPIU_Upint)others_req[i].offsets < (MPIU_Upint)recvBufForOffsets ) - recvBufForOffsets = others_req[i].offsets; - if ( (MPIU_Upint)others_req[i].lens < (MPIU_Upint)recvBufForLens ) - recvBufForLens = others_req[i].lens; - others_req[i].mem_ptrs = (MPI_Aint *) ADIOI_Malloc(count_others_req_per_proc[i]*sizeof(MPI_Aint)); @@ -736,9 +721,6 @@ void ADIOI_GPFS_Calc_others_req(ADIO_File fd, int count_my_req_procs, others_req[i].lens = NULL; } } - /* If no recv buffer was allocated in the loop above, make it NULL */ - if ( recvBufForOffsets == (void*)0xFFFFFFFFFFFFFFFF) recvBufForOffsets = NULL; - if ( recvBufForLens == (void*)0xFFFFFFFFFFFFFFFF) recvBufForLens = NULL; /* Now send the calculated offsets and lengths to respective processes */ @@ -746,56 +728,53 @@ void ADIOI_GPFS_Calc_others_req(ADIO_File fd, int count_my_req_procs, /* Exchange the offsets */ /************************/ - /* Determine the lowest sendBufForOffsets/Lens */ - for (i=0; icomm); + for (i=0; icomm); + for (i=0; i