Skip to content

UCP/DT: Fix use of freed IOV memory handles on request restart - #12448

Open
dmitrygx wants to merge 2 commits into
openucx:masterfrom
dmitrygx:topic/ucx/iov-memh-restart
Open

dmitrygx wants to merge 2 commits into
openucx:masterfrom
dmitrygx:topic/ucx/iov-memh-restart

Conversation

@dmitrygx

Copy link
Copy Markdown
Member

What?

Reset the pointer to the IOV memory handle array after
ucp_datatype_iter_iov_cleanup() frees the array.

Why?

On a failover endpoint, a zero-copy request whose operation fails is cleaned
up and then restarted. With UCP_DATATYPE_IOV the cleanup frees the memory
handle array but keeps the pointer, so the restart passes this check,
deregisters handles from the freed array and then registers new ones into it:

} else if (ucp_datatype_iter_is_class(dt_iter, UCP_DATATYPE_IOV, dt_mask)) {
if (dt_iter->type.iov.memh != NULL) {
ucp_datatype_iter_iov_mem_dereg(dt_iter);
}

The new test without the fix
[ RUN      ] rcx/test_ucp_fault_tolerance_iov.zcopy_restart/1 <rc_x/get>
==3262023==ERROR: AddressSanitizer: heap-use-after-free on address 0x60600035af80 at pc 0x7fb7fefca140 bp 0x7fff5d827260 sp 0x7fff5d827250
READ of size 8 at 0x60600035af80 thread T0
    #0 0x7fb7fefca13f in ucp_datatype_iter_mem_dereg_single src/ucp/dt/datatype_iter.inl:306
    #1 0x7fb7fefca13f in ucp_datatype_iter_iov_mem_dereg src/ucp/dt/datatype_iter.c:150
    #2 0x7fb7fefe4bb4 in ucp_datatype_iter_mem_dereg src/ucp/dt/datatype_iter.inl:807
    #3 0x7fb7fefe4bb4 in ucp_proto_request_zcopy_clean src/ucp/proto/proto_common.inl:92
    #4 0x7fb7fefe4bb4 in ucp_proto_request_zcopy_reset src/ucp/proto/proto_common.c:938
    #5 0x7fb7fefe4bb4 in ucp_proto_request_zcopy_reset src/ucp/proto/proto_common.c:935
    #6 0x7fb7fefe6792 in ucp_proto_offload_zcopy_reset src/ucp/proto/proto_common.c:983
    #7 0x7fb7fefe329e in ucp_proto_request_restart src/ucp/proto/proto_common.c:871
    #8 0x7fb7feaee55f in uct_invoke_completion src/uct/base/uct_iface.h:1029
    #9 0x7fb7feaee55f in uct_rc_txqp_purge_outstanding src/uct/ib/rc/base/rc_ep.c:567
    #10 0x7fb7fe7365c0 in uct_rc_mlx5_iface_handle_failure src/uct/ib/mlx5/rc/rc_mlx5_iface.c:256
    ...

0x60600035af80 is located 0 bytes inside of 64-byte region [0x60600035af80,0x60600035afc0)
freed by thread T0 here:
    #0 0x7fb8001747e0 in __interceptor_free (/lib64/libasan.so.5+0xef7e0)
    #1 0x7fb7fefe0df5 in ucp_datatype_iter_iov_cleanup src/ucp/dt/datatype_iter.inl:328
    #2 0x7fb7fefe0df5 in ucp_datatype_iter_cleanup src/ucp/dt/datatype_iter.inl:353
    #3 0x7fb7fefe0df5 in ucp_proto_request_zcopy_complete_cb src/ucp/proto/proto_common.inl:120
    #4 0x7fb7fefe0df5 in ucp_proto_request_zcopy_complete src/ucp/proto/proto_common.inl:134
    #5 0x7fb7fefe0df5 in ucp_proto_request_zcopy_completion src/ucp/proto/proto_common.c:774
    #6 0x7fb7feaee55f in uct_invoke_completion src/uct/base/uct_iface.h:1029
    #7 0x7fb7feaee55f in uct_rc_txqp_purge_outstanding src/uct/ib/rc/base/rc_ep.c:567
    ...

How?

Set the pointer to NULL after the free, as the contiguous and SGL cleanups
do. The new test sends an IOV put or get once to find a lane of its protocol,
invalidates that lane on rc_x and sends the request again, so it restarts.

A zero-copy request on a failover endpoint restarts when one of its
operations completes with an error. The completion releases the
registered memory of the request before the restart, and the restart
registers it again.

Add test_ucp_fault_tolerance_iov.zcopy_restart: an IOV put or get of
eight 1 MB elements is posted again right after a lane which its
protocol sends on is invalidated, so its fragments on that lane complete
with an error and the request restarts on the remaining lanes. The
request must complete and its data must arrive. It fails now: the
restart uses the array of IOV memory handles which the completion
freed.
ucp_datatype_iter_iov_cleanup() freed the array of IOV memory handles,
but left the pointer to it. A zero-copy request which restarts after an
operation error is cleaned up by its completion first. The reset of the
restart then deregistered the handles in the freed array again, the
next registration reused the freed array, and the final cleanup freed
it a second time.

Reset the pointer after the free, as the contiguous and SGL cleanups
already do, so the restart registers the buffers into a new array.
@dmitrygx
dmitrygx requested a review from a team as a code owner November 23, 2026 21:41
@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Starting review — findings will be posted here when done.

@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Review complete — no issues found.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants