Commit 4b90310
Ruizhe Zhou
perftest: Fix double frees during RDMA CM connection retry
When running perftest with RDMA CM enabled (-R), if the connection
request is rejected (RDMA_CM_EVENT_REJECTED), the client enters a retry
loop in `rdma_cm_client_connection`.
However, the previous retry logic contained multiple flaws causing
segmentation faults, double frees, and heap corruption.
The following specific issues were identified and fixed:
1. Double Free of Event Channel:
The `rdma_destroy_event_channel()` was called inside `rdma_cm_destroy_cma()`
during internal cleanup, but the pointer was not cleared. The caller function
`create_rdma_cm_connection()` would then attempt to destroy the same channel
again in its error path.
Fix: Set the channel pointer to NULL after destruction and check for
NULL before attempting to destroy it. The event channel and cm nodes
will be reallocated when entering another retry attempt.
2. Heap Corruption via Index Overflow:
The `ctx->cma_master.connection_index` was incremented on every
connection attempt but was never reset upon failure. During retries,
this index would exceed the bounds of the `nodes` array, leading to
out-of-bound writes and heap metadata corruption. Similar things would
happen for other fields of cma_master.
Fix: Complete reset for fields of cma_master in
`rdma_cm_destroy_cma()`.
3. Context Corruption and Leaks:
`rdma_cm_route_handler()` unconditionally called `ctx_init()` and
`create_qp_main()` on
every retry attempt. This overwrote existing pointers (PD, MR, Buffers)
in the context structure without releasing the old resources, causing
memory leaks and "Bad file descriptor" errors during final cleanup.
Recreating old qp would cause qp creation error causing retry to fail.
Fix: Add a check in `rdma_cm_route_handler()` to ensure `ctx_init()`
and `create_qp_main` are only called if the context has not been
initialized yet.
4. Similar issues happened on server side retry in
`rdma_cm_connection_request_handler`. Apply same fix as in
`rdma_cm_route_handler()`.
Signed-off-by: Ruizhe Zhou <[email protected]>1 parent 07d75db commit 4b90310
2 files changed
+67
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2416 | 2416 | | |
2417 | 2417 | | |
2418 | 2418 | | |
2419 | | - | |
| 2419 | + | |
2420 | 2420 | | |
2421 | 2421 | | |
2422 | 2422 | | |
| |||
2425 | 2425 | | |
2426 | 2426 | | |
2427 | 2427 | | |
2428 | | - | |
2429 | | - | |
2430 | | - | |
2431 | | - | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
2432 | 2437 | | |
2433 | 2438 | | |
2434 | 2439 | | |
| |||
2446 | 2451 | | |
2447 | 2452 | | |
2448 | 2453 | | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
2449 | 2457 | | |
2450 | 2458 | | |
2451 | 2459 | | |
| |||
2484 | 2492 | | |
2485 | 2493 | | |
2486 | 2494 | | |
2487 | | - | |
| 2495 | + | |
2488 | 2496 | | |
2489 | 2497 | | |
2490 | 2498 | | |
| |||
2493 | 2501 | | |
2494 | 2502 | | |
2495 | 2503 | | |
2496 | | - | |
2497 | | - | |
2498 | | - | |
2499 | | - | |
| 2504 | + | |
| 2505 | + | |
| 2506 | + | |
| 2507 | + | |
| 2508 | + | |
| 2509 | + | |
| 2510 | + | |
| 2511 | + | |
| 2512 | + | |
2500 | 2513 | | |
2501 | 2514 | | |
2502 | 2515 | | |
| |||
2859 | 2872 | | |
2860 | 2873 | | |
2861 | 2874 | | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
2862 | 2889 | | |
2863 | 2890 | | |
2864 | 2891 | | |
| |||
2945 | 2972 | | |
2946 | 2973 | | |
2947 | 2974 | | |
2948 | | - | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
2949 | 2979 | | |
2950 | 2980 | | |
2951 | 2981 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2665 | 2665 | | |
2666 | 2666 | | |
2667 | 2667 | | |
| 2668 | + | |
2668 | 2669 | | |
2669 | 2670 | | |
2670 | 2671 | | |
2671 | 2672 | | |
2672 | 2673 | | |
| 2674 | + | |
| 2675 | + | |
2673 | 2676 | | |
2674 | 2677 | | |
2675 | 2678 | | |
| |||
6154 | 6157 | | |
6155 | 6158 | | |
6156 | 6159 | | |
6157 | | - | |
6158 | | - | |
6159 | | - | |
6160 | | - | |
6161 | | - | |
| 6160 | + | |
| 6161 | + | |
| 6162 | + | |
| 6163 | + | |
| 6164 | + | |
| 6165 | + | |
| 6166 | + | |
| 6167 | + | |
| 6168 | + | |
| 6169 | + | |
6162 | 6170 | | |
6163 | 6171 | | |
6164 | 6172 | | |
6165 | | - | |
| 6173 | + | |
| 6174 | + | |
| 6175 | + | |
| 6176 | + | |
6166 | 6177 | | |
6167 | 6178 | | |
| 6179 | + | |
6168 | 6180 | | |
6169 | 6181 | | |
6170 | | - | |
| 6182 | + | |
| 6183 | + | |
| 6184 | + | |
| 6185 | + | |
| 6186 | + | |
| 6187 | + | |
| 6188 | + | |
| 6189 | + | |
6171 | 6190 | | |
6172 | 6191 | | |
6173 | 6192 | | |
| |||
0 commit comments