From 915e1aef742b3c272e176efa5b87a2282fed7075 Mon Sep 17 00:00:00 2001 From: "Paul H. Hargrove" Date: Wed, 13 May 2026 20:37:26 -0700 Subject: [PATCH 1/2] Fix bug4822 missing checks in gex_Segment_Attach This commit adds checks on the `size` argument to `gex_Segment_Attach()` which were inadvertently lost early in the GASNet-1 to GASNet-EX transition. Specifically, this enforces all three constraints in the following: > [size] must be a non-zero multiple of GASNET_PAGESIZE, not larger > than gasnet_getMaxLocalSegmentSize() For all three error cases (zero, not page-aligned, or too large) the behavior is to return `GASNET_ERR_BAD_ARG` with the belief that the client might be able to recover. Additionally, while the documentation does not (currently?) require it, the output location `*segment_p` is set to `GEX_SEGMENT_INVALID` to reduce the scope of cascading errors in any clients which do not check the return value. One example failure message (assuming verbose errors are enabled): ``` *** WARNING (proc 0): GASNet gex_Segment_Attach returning an error code: GASNET_ERR_BAD_ARG (Invalid function parameter passed) at /[redacted]/gasnet_internal.c:623 reason: size is too large, exceeds current value of gasnet_getMaxLocalSegmentSize() ``` --- gasnet_internal.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gasnet_internal.c b/gasnet_internal.c index 0cd1b42ce..05d0d5c2f 100644 --- a/gasnet_internal.c +++ b/gasnet_internal.c @@ -607,10 +607,21 @@ extern int gex_Segment_Attach( if (once) once = 0; else gasneti_fatalerror("gex_Segment_Attach: current implementation can be called at most once"); + // Final value for EVERYTHING, error value for FAST/LARGE + *segment_p = GEX_SEGMENT_INVALID; + #if GASNET_SEGMENT_EVERYTHING - *segment_p = GEX_SEGMENT_INVALID; gex_Event_Wait(gex_Coll_BarrierNB(e_tm, 0)); #else + if (length == 0) { + GASNETI_RETURN_ERRR(BAD_ARG, "size must be non-zero"); + } + if ((length % GASNET_PAGESIZE) != 0) { + GASNETI_RETURN_ERRR(BAD_ARG, "size is not page-aligned"); + } + if (length > gasneti_MaxLocalSegmentSize) { + GASNETI_RETURN_ERRR(BAD_ARG, "size is too large, exceeds current value of gasnet_getMaxLocalSegmentSize()"); + } /* create a segment collectively */ // TODO-EX: this implementation only works *once* // TODO-EX: need to pass proper flags (e.g. pshm and bind) instead of 0 From c50e05363f973c633f3730c8c1a62195e3df0755 Mon Sep 17 00:00:00 2001 From: "Paul H. Hargrove" Date: Wed, 13 May 2026 21:41:04 -0700 Subject: [PATCH 2/2] Update ChangeLog --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 569c5f23b..293e8b624 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,7 @@ GASNet-EX ChangeLog * Notable bugs fixed in this release: (details at https://gasnet-bugs.lbl.gov) - bug4811 - ofi: startup crashes with --enable-segment-everything - bug4821 - Some tests request an incorrectly large segment size + - bug4822 - gex_Segment_Attach() does not validate the size argument ---------------------------------------------------------------------- 2025-08-28: GASNet-EX 2025.8.0