-
Bug
-
Resolution: Duplicate
-
Undefined
-
None
-
None
-
False
-
-
False
-
-
Vulnerability Types: CWE-476 (NULL Pointer Dereference), CWE-125 (Out-of-bounds Read), CWE-787 (Out-of-bounds Write), CWE-118 (Incorrect Access of Indexable Resource), CWE-119 (Improper Restriction of Operations within Memory Buffer Bounds), CWE-129 (Improper Validation of Array Index), CWE-664 (Improper Control of a Resource Through its Lifetime), CWE-20 (Improper Input Validation)
Location:
- File: aten/src/ATen/native/cpu/SpmmReduceKernel.cpp
- Lines: 60-62
Related Exploit Files:
- exploit_cve_null_pointer_spmm_reduce.py
Details:
A critical NULL pointer dereference vulnerability has been identified and successfully exploited in PyTorch's sparse matrix multiplication kernel. The _update function template dereferences pointers without validation, leading to segmentation faults when processing malformed sparse CSR matrices.
Root Cause:
The function _update is called from spmm_reduce_kernel_impl (line 133) without validating that other_data and out_data pointers are non-NULL. The vulnerability occurs when:
1. Sparse CSR matrix with malformed indices (out of bounds column indices)
2. Empty or improperly initialized 'other' tensor
3. Invalid tensor layouts causing data_ptr() to return NULL
4. Pointer arithmetic on out-of-bounds column indices produces invalid addresses
Vulnerable Code:
opmath_t out_val = opmath_t(out_ptr[k]); // Line 60 - VULNERABLE DEREFERENCE out_val = update<opmath_t, reduce>(out_val, opmath_t(other_ptr[k]) * opmath_t(val)); // Line 61 out_ptr[k] = out_val; // Line 62 - VULNERABLE DEREFERENCE
Impact:
- CONFIRMED: Denial of Service (DoS) - Process crash via segmentation fault (exit code 139)
- CONFIRMED: Memory Safety Violation - Invalid memory access
- POTENTIAL: Information Disclosure - Reading from out-of-bounds memory could leak sensitive data
- POTENTIAL: Memory Corruption - Writing to out-of-bounds locations could corrupt heap/stack
- POTENTIAL: Arbitrary Code Execution - In rare cases, precise memory corruption could enable RCE
Exploit Test Results:
The exploit script successfully triggered a segmentation fault, confirming the NULL pointer dereference vulnerability. The crash occurred during the out-of-bounds column indices attack vector.
Minimal Proof of Concept:
import torch sparse = torch.sparse_csr_tensor([0, 1], [999999], [1.0], size=(1, 2)) other = torch.randn(2, 2) torch.sparse.mm(sparse, other, reduce='sum') # CRASH!
Recommendations:
1. Add NULL pointer checks before dereferencing out_ptr and other_ptr
2. Validate column indices are within bounds (0 <= c < other.size(0))
3. Validate CSR structure integrity (monotonic crow_indices, valid col_indices)
4. Add bounds checking in vectorized loops
5. Implement input sanitization at Python level
Severity: CRITICAL - Exploitability CONFIRMED