Blob Blame History Raw
From c862c1384215d5618b148487a84647dc2fcc912c Mon Sep 17 00:00:00 2001
From: aingerson <alexia.ingerson@intel.com>
Date: Thu, 17 Dec 2020 09:25:04 -0800
Subject: [PATCH 1/2] util/shm: add O_EXCL flag to shm_open

Adding the O_EXCL flag forces the shm_open call to fail
if the shared memory region already exists. This prevents
a segfault/miscommunication which can occur when two peers
try to open an endpoint/shared memory region with the same name.

Cherry picked from commit c403cc4f

Signed-off-by: aingerson <alexia.ingerson@intel.com>
---
 prov/util/src/util_shm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/prov/util/src/util_shm.c b/prov/util/src/util_shm.c
index 72301b62dbb6..760b19e15a73 100644
--- a/prov/util/src/util_shm.c
+++ b/prov/util/src/util_shm.c
@@ -151,7 +151,7 @@ int smr_create(const struct fi_provider *prov, struct smr_map *map,
 					&sar_pool_offset, &peer_data_offset,
 					&name_offset);
 
-	fd = shm_open(attr->name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
+	fd = shm_open(attr->name, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
 	if (fd < 0) {
 		FI_WARN(prov, FI_LOG_EP_CTRL, "shm_open error\n");
 		return -errno;
-- 
2.25.4