CORE: various fixes for ucc_mem_map#1306
Conversation
|
| Filename | Overview |
|---|---|
| src/core/ucc_context.c | Fixes several correctness bugs in mem_map/mem_unmap, but introduces new issues in the EXPORT_OFFLOAD error path: the packed_buffers array itself is never freed on failure, wrong indices are used to clean up packed buffers in EXPORT_OFFLOAD mode, and failed_mem_map unconditionally frees local_memh (= the caller's *memh). |
| src/components/tl/ucp/tl_ucp_context.c | Fixes offset calculation in offload-import TL scan, adds NULL guard for tl_data on import failure, adds ucp_mem_unmap for IMPORT_OFFLOAD in unmap, and zeroes pointers after releasing buffers in error paths. Changes look correct. |
Comments Outside Diff (3)
-
src/core/ucc_context.c, line 1520-1524 (link)packed_buffersarray pointer leaked in every error pathfailed_packfrees individual entries via thefor jloop, but never callsucc_free(packed_buffers)for the array itself. Becausefailed_mem_mapcan be reached viagotobeforepacked_buffersis even allocated (from the mem-map loop), adding a free there would require a NULL guard. The clean fix is to free the array immediately after the per-entry loop and before falling through tofailed_mem_map. This leak is triggered on everygoto failed_pack(pack failure,exported_memhalloc failure) in both EXPORT and EXPORT_OFFLOAD modes. -
src/core/ucc_context.c, line 1520-1538 (link)EXPORT_OFFLOAD error path frees the caller's memory handle and may access
tl_hout-of-boundsIn EXPORT_OFFLOAD mode
local_memh = *memh(the user-supplied handle, not a locally allocated one). When packing fails,failed_packfalls through tofailed_mem_mapwhich unconditionally callsucc_free(local_memh)and*memh = NULL, destroying the caller's handle and causing a use-after-free on any subsequent access.Additionally,
failed_mem_maploopsjin[0, ctx->n_tl_ctx)and accesseslocal_memh->tl_h[j]. For EXPORT_OFFLOAD,local_memh->tl_honly haslocal_memh->num_tlsentries. Whenctx->n_tl_ctx > local_memh->num_tls, this produces an out-of-bounds read. Both theucc_freeand the unmap loop should be guarded byif (mode == UCC_MEM_MAP_MODE_EXPORT); EXPORT_OFFLOAD mode doesn't map any memory in this call so there is nothing to unmap on failure. -
src/core/ucc_context.c, line 1520-1523 (link)EXPORT_OFFLOAD:
failed_packfrees buffers at wrong indices, leaking packed dataFor EXPORT_OFFLOAD,
memh_packstores results atpacked_buffers[tlh_index]wheretlh_indexis the exporter slot (0..num_tls-1). The cleanup loop freespacked_buffers[0..i-1]whereiis the importer TL-context loop counter — an unrelated index space. Any buffer stored at an exporter slot that doesn't coincide with[0, i)is silently leaked. For example, if the first importer iteration (i=0) resolved totlh_index=2, then a failure on the second iteration (i=1) leavespacked_buffers[2]unreleased. The cleanup should iterate all slots up toucc_max(ctx->n_tl_ctx, num_tls)rather than[0, i).
Reviews (2): Last reviewed commit: "TL/UCP: various memh fixes" | Re-trigger Greptile
946134e to
0d2e3cb
Compare
What
Fix a collection of correctness bugs in the ucc_mem_map/ucc_mem_unmap path and specifically TL/UCP that can lead to failures or memory leaks.