Skip to content

cuda: honour the documented 64-byte d_name buffer in af_device_info - #3717

Draft
melonakos wants to merge 2 commits into
masterfrom
fix/3712-cuda-device-info-overflow
Draft

melonakos wants to merge 2 commits into
masterfrom
fix/3712-cuda-device-info-overflow

Conversation

@melonakos

Copy link
Copy Markdown
Member

The CUDA backend wrote up to 256 bytes into d_name and then scanned 256 bytes sanitizing it, while af_device_info documents 64 and the CPU and OpenCL backends respect that, so conforming callers overflowed. Write and scan within 64 bytes and stop at the terminator. Fixes #3712.

af_device_info documents a recommended minimum size of 64 bytes for
d_name (docs/details/device.dox, device_func_prop), and the CPU and
OpenCL backends write at most 64. The CUDA backend wrote up to 256 and
its sanitize loop then read d_name[256], touching 257 bytes of a buffer
callers were told to size at 64.

Clamp the write to 64 and bound the lookahead loop at 63 so it stays
inside the documented buffer.

Confirmed with AddressSanitizer against a 64-byte heap allocation:
before, "heap-buffer-overflow ... WRITE of size 84"; after, clean.

Fixes #3712

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012SRueobKykUocB1SRdHsEE
@melonakos
melonakos force-pushed the fix/3712-cuda-device-info-overflow branch from 0257d17 to 854e5ce Compare September 10, 2026 18:47
The OpenCL sanitizer looped to 31 with no terminator check, so it read and wrote past the end of any shorter device name. Stop at the terminator and stay within the 64-byte buffer.
@melonakos
melonakos force-pushed the fix/3712-cuda-device-info-overflow branch from 854e5ce to d42cdcb Compare September 10, 2026 18:47
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.

[BUG] af_device_info: CUDA backend writes 257 bytes into buffers documented as 64

1 participant