sklearn DecisionTree Heap Information Leak via node_count Mismatch
Security research artifact. Do not use in production.
Summary
scikit-learn 1.8.0's Tree.__setstate__ (Cython, _tree.pyx line 824) sets self.node_count directly from the deserialized pickle state without validating that node_count <= capacity (the actual size of the nodes array). When node_count exceeds the actual array size, tree properties (.feature, .threshold, .value) return NumPy slices that read past the allocated C buffer into adjacent heap memory.
The OOB heap data is captured into the serialized model file via __getstate__ + memcpy, making it persistent and transferable.
Impact
- CWE-125: Out-of-bounds Read
- Heap data disclosure: Positions beyond the legitimate node count contain raw heap data (pointers, strings, other allocations)
- Training data exfiltration: When the malicious model is created after
fit(), the OOB heap read captures ACTUAL TRAINING DATA (numpy float64 values from X_train). Verified: 70% of unique training feature values recovered in a 5000-position scan. Training data appears in contiguous, repeating sequences matching the original array layout. - Persistent: The leaked data is frozen into the .joblib/.pkl file and readable by anyone who loads it
- Affects ALL tree-based estimators: DecisionTree, RandomForest, GradientBoosting, ExtraTrees, AdaBoost, BaggingClassifier
Files
poc_heap_leak.joblib-- Pre-built malicious model (regenerated by PoC script)poc_sklearn_heap_leak.py-- Full PoC: creates malicious .joblib, demonstrates heap data leak
Reproduction
pip install scikit-learn==1.8.0 joblib numpy
python3 poc_sklearn_heap_leak.py
Output shows leaked heap data as ASCII strings, hex dumps, and non-zero value counts proving the read extends past the allocated buffer into adjacent process memory.
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐ Ask for provider support