Skip to content

Instantly share code, notes, and snippets.

@sumantro93
sumantro93 / txt
Created March 30, 2026 16:45
Helion_example_blog.txt
import torch
import helion
import helion.language as hl
import time
# ============================================================
# Example 1: Matrix Multiplication
# ============================================================
@helion.kernel()
def matmul(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
@sumantro93
sumantro93 / gist:0b60f05efb6984e9e9b18f1acc8398de
Created November 28, 2025 03:37
batch-norm-unsafe-op.py
import torch
... import torch.nn as nn
...
... # The kernel at line 941 computes: buffer_data[t * n_channel + c]
... # If n_channel is extremely large, t * n_channel can overflow int64_t
...
... # Demonstration of overflow math:
... int64_max = (1 << 63) - 1
... n_channel = 2**40 # Hypothetical huge channel count
... num_threads = 8
#!/usr/bin/env python3
"""
Repro: CWE-122 Heap-based Buffer Overflow via strcpy() in libshm/socket.h
Target: torch/lib/libshm/socket.h:39
Vulnerable Code:
strcpy(address.sun_path, path); // No bounds checking!
The sockaddr_un.sun_path buffer is typically 108 bytes on Linux.
If path exceeds this, strcpy() overflows into adjacent memory.
import torch
import gc
def get_memory_mb():
import resource
return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024
initial_mem = get_memory_mb()
print(f"Initial memory: {initial_mem:.2f} MB")
# Repeated operations cause memory leak
for i in range(10000):
t = torch.randn(2, 3, 4, 5, 6) # 5 dims
@sumantro93
sumantro93 / gist:5e29a401e40c5340aab7ad6152876fb4
Created November 27, 2025 17:57
oob-ssmpkernel-ce119.py
#!/usr/bin/env python3
"""
Exploit for SpmmReduceKernel.cpp vulnerabilities
Target File: aten/src/ATen/native/cpu/SpmmReduceKernel.cpp
Vulnerable Code Location: Lines 36, 60-62, 131, 222, 225, 276-277, 280-282, 331-332, 370
=============================================================================
CWE CLASSIFICATION (Reference: https://cwe.mitre.org/data/definitions/699.html)
=============================================================================
@sumantro93
sumantro93 / QuantizedOpKernels.cpp:3385.py
Created November 21, 2025 07:07
QuantizedOpKernels.cpp:3385
#!/usr/bin/env python3
"""
Proof of Concept for Integer Overflow in QuantizedOpKernels.cpp:3385
Target: float* buffer_ptr = buffer_data + t * Bs * 2 * C + n * 2 * C;
This vulnerability has COMPOUND MULTIPLICATIONS making it more severe than previous ones.
"""
import sys
@sumantro93
sumantro93 / kai_kernels.cpp:255.py
Created November 21, 2025 06:59
kai_kernels.cpp:255
#!/usr/bin/env python3
"""
Proof of Concept for Integer Overflow in kai_kernels.cpp:255 (and surrounding lines)
Target: Multiple overflow points in KleidiAI kernel code
"""
import sys
INT64_MAX = 2**63 - 1
SIZE_MAX = 2**64 - 1 # For size_t on 64-bit systems
@sumantro93
sumantro93 / .py
Created November 21, 2025 06:44
poc_batchnorm_overflow
#!/usr/bin/env python3
"""
Attempt to exploit batch_norm_kernel.cpp:922 through PyTorch APIs
Target: tid * n_channel overflow in batch normalization
"""
import sys
import os
print("="*70)
@sumantro93
sumantro93 / .py
Created November 21, 2025 06:33
LOC 137 Parallel_Native
#!/usr/bin/env python3
"""
Proof of Concept for Integer Overflow in PyTorch ParallelNative.cpp:137
Demonstrates the overflow behavior in Python (simulating the C++ logic)
"""
import sys
# Python 3 has arbitrary precision integers, so we need to simulate int64_t behavior
INT64_MAX = 2**63 - 1
@sumantro93
sumantro93 / .md
Created November 11, 2025 08:52
PyTorch Security Roadmap
flowchart LR

A[Static Analysis & Scanning\n(Snyk + Internal Tooling)] --> B[Log Aggregation & Finding Classification]

B --> C[Jira Ticket Creation\n(security: potential vuln)]
C --> D[ProdSec Advisor Review / ACK]

D --> E[Reporter Begins PoC\n(reproduce & validate)]
E --> F[Report to Upstream PyTorch\n(Security Advisory Channels)]