net/ib: fix out-of-bounds write when active ports exceed MAX_IB_DEVS - #2283
Open
Peng-Xu wants to merge 1 commit into
Open
net/ib: fix out-of-bounds write when active ports exceed MAX_IB_DEVS#2283Peng-Xu wants to merge 1 commit into
Peng-Xu wants to merge 1 commit into
Conversation
The device enumeration loop in ncclIbInitDevices() only checks `ncclNIbDevs < MAX_IB_DEVS` in the outer per-device loop condition. The inner per-port loop and the data-direct sub-loop both write to ncclIbDevs[ncclNIbDevs] and increment ncclNIbDevs without re-checking the bound, so a single device with many active ports (e.g. a multi-port RoCE NIC) can push ncclNIbDevs past MAX_IB_DEVS within one outer iteration. Once ncclNIbDevs >= MAX_IB_DEVS the code writes past the end of the global ncclIbDevs[MAX_IB_DEVS] array, corrupting adjacent globals and crashing. The same overflowed index is also handed to the per-device async thread and later to qsort(). This was observed on a host with 54 active RoCE ports. Guard both inner loops with `ncclNIbDevs < MAX_IB_DEVS` so enumeration stops cleanly at the limit, and warn once when the limit is reached so the ignored ports are not silent. Signed-off-by: Pxu <xup2012@outlook.com>
Peng-Xu
force-pushed
the
fix/net-ib-oob-max-ib-devs
branch
from
July 13, 2026 06:04
fd50520 to
afca060
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix an out-of-bounds write in the NET/IB device enumeration (
ncclIbInitDevices,src/transport/net_ib/init.cc) that crashes NCCL initialization on hosts with morethan
MAX_IB_DEVSactive IB/RoCE ports.The bound
ncclNIbDevs < MAX_IB_DEVSis only evaluated in the outer per-device loopcondition. The inner per-port loop and the data-direct sub-loop both write to
ncclIbDevs[ncclNIbDevs]and incrementncclNIbDevswithout re-checking the bound,so a single multi-port device can push
ncclNIbDevspastMAX_IB_DEVSwithin oneouter iteration and write past the end of the global
ncclIbDevs[MAX_IB_DEVS]array.The overflowed index is also handed to the per-device async thread and later to
qsort().This guards both inner loops with the same
ncclNIbDevs < MAX_IB_DEVScheck soenumeration stops cleanly at the limit, and adds a one-time
WARNwhen the limit isreached so the ignored ports are not silent.
MAX_IB_DEVSitself is intentionallyleft unchanged -- this PR only prevents the overflow; whether the limit should be
raised/made dynamic is a separate discussion.
Related Issues
Fixes #2282
Changes & Impact
src/transport/net_ib/init.cc:&& ncclNIbDevs < MAX_IB_DEVSto the per-port loop and the data-direct(
dev < devCount) loop conditions;WARNafter enumeration whenncclNIbDevs >= MAX_IB_DEVS,pointing users to
NCCL_IB_HCAfor device selection.MAX_IB_DEVSactive ports: previouslyundefined behavior / crash, now capped at
MAX_IB_DEVSwith a warning. Nodes with<=
MAX_IB_DEVSactive ports are byte-for-byte unaffected (the guard never fires).Performance Impact
None. The added checks are integer comparisons on the cold initialization path;
the data path is untouched.
Testing
MAX_IB_DEVS=32, unpatched): NCCL crashes duringncclIbInitDevices(out-of-bounds write onncclIbDevs[32]).MAX_IB_DEVS=32):all_reduce_perf -g 8initializes andcompletes correctly (
# Out of bounds values : 0 OK), and NCCL prints exactlyone warning from
net_ib/init.cc:NET/IB : Reached MAX_IB_DEVS=32 IB devices; any additional ports are not used.