Skip to content

Fix parser and env-var inputs that crash or are silently accepted - #369

Open
bernardogv wants to merge 3 commits into
ROCm:developfrom
bernardogv:fix/parser-envvar-crashes
Open

bernardogv wants to merge 3 commits into
ROCm:developfrom
bernardogv:fix/parser-envvar-crashes

Conversation

@bernardogv

Copy link
Copy Markdown

Fixes for parser and environment-variable inputs that crash, read out of bounds, or are silently accepted with wrong values. Three commits, independent of #368.

Parser (167a8d4)

  • N executor token: ParseExeType dereferenced endPtr inside if (!endPtr). At -O3 clang removes the check, so malformed tokens such as Nx and N.1 were silently accepted as a bare N. It now checks *ptr as intended. A bare N is still accepted.
  • Missing type letter: strchr also matches the terminating NUL, so a token like R0 (rank prefix with no type letter) was accepted with an out-of-range type, and parsing continued past the end of the string. It is now rejected with "Missing memory/executor type".

Config validation (2778012)

  • data.blockBytes <= 0 and gfx.blockSize <= 0 are now rejected. Previously, negative BLOCK_BYTES caused destination mismatches, and GFX_BLOCK_SIZE=0 with GFX_SE_TYPE=1 divided by zero in CalculateGridY.

Environment variables (197f253)

  • GetEnvVar: K/M/G suffixes overflowed int (BLOCK_BYTES=2G → -2147483648). The value is now parsed as 64-bit, and anything that doesn't fit in an int is rejected.
  • CU_MASK: indices outside 0..63 wrote past the end of the per-XCC mask vector, and negative indices were accepted. Both are now rejected.
  • SAMPLING_FACTOR: 0 divided by zero on every run. It must now be ≥ 1.
  • NIC_CHUNK_BYTES display: the int was printed with %lu; it now uses %d.

Testing

Built with make TransferBench (-Wall, no warnings) and run on a single-GPU ROCm 7 system, comparing develop with this branch:

Input develop This branch
dryrun 1M "1 4 (G0 Nx G0)" accepted, exit 0 parse error, exit 1
dryrun 1M "1 4 (G0 N.1 G0)" accepted, exit 0 parse error, exit 1
dryrun 1M "1 4 (G0 R0 G0)" "Unable to parse device index" (after reading past the string) "Missing executor type"
CU_MASK=0-5000 abort (134) / segfault (139) "CU_MASK index out of range"
CU_MASK=-5 accepted rejected
SAMPLING_FACTOR=0 SIGFPE (136) "must be at least 1"
BLOCK_BYTES=2G runs with blockBytes = -2147483648 "out of range"
BLOCK_BYTES=-256 576992 mismatched bytes "must be positive multiple of 4"
GFX_BLOCK_SIZE=0 GFX_SE_TYPE=1 SIGFPE (136) "must be positive multiple of 64…"

These inputs still behave the same on both builds: a bare N, CU_MASK=0-3, BLOCK_BYTES=1K, SAMPLING_FACTOR=2, and the default config.

ParseExeType dereferenced endPtr inside `if (!endPtr)` when checking for a
bare nearest-NIC executor (`N`). That is a null dereference; at -O3 clang
removes the check, so malformed tokens such as `Nx` or `N.1` were silently
accepted as a bare `N`. Check `*ptr` as intended.

CharToMemType/CharToExeType used strchr on the type string, which also
matches the terminating NUL. A token with a rank prefix but no type letter
(e.g. `R0`) was therefore accepted with an out-of-range type, and parsing
continued past the end of the string. Reject a missing type explicitly and
report it as such.
Validation only rejected blockBytes == 0 and blockSize < 0.
- Negative blockBytes (e.g. BLOCK_BYTES=-256) passed, corrupted the
  sub-executor partitioning and produced destination mismatches.
- blockSize == 0 passed and, with GFX_SE_TYPE=1, divided by zero in
  CalculateGridY (SIGFPE).
- GetEnvVar: K/M/G suffixes were applied to an int and overflowed
  (e.g. BLOCK_BYTES=2G became -2147483648, NIC_CHUNK_BYTES=2G a huge
  size_t). Parse as 64-bit and reject values that don't fit in an int.
- CU_MASK: indices outside 0..63 wrote past the end of the per-XCC mask
  vector (CU_MASK=0-5000 crashes); negative indices were accepted.
- SAMPLING_FACTOR: 0 caused a divide-by-zero on every run; negative values
  wrapped. Require >= 1.
- Print nicChunkBytes (an int) with %d instead of %lu.
@bernardogv
bernardogv requested a review from a team as a code owner November 13, 2026 01:54
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.

1 participant