VAITP Dataset

← Back to the dataset

CVE-2025-63396

Omission of profiler.stop() in PyTorch's profiler can cause a DoS.

  • CVSS 3.3
  • CWE-667
  • Resource Management
  • Local

An issue was discovered in PyTorch v2.5 and v2.7.1. Omission of profiler.stop() can cause torch.profiler.profile (PythonTracer) to crash or hang during finalization, leading to a Denial of Service (DoS).

CVSS base score
3.3
Published
2025-11-12
OWASP
A04 Insecure Design
Orthogonal defect classification
Timing/Serialization
Code defect classification
Missing Check
Category
Resource Management
Subcategory
Resource Exhaustion
Accessibility scope
Local
Impact
Denial of Service (DoS)
Affected component
PyTorch
Fixed by upgrading
Yes

Solution

Upgrade to PyTorch version 1.13.1, 2.0.1, 2.1.2, or a later version.

Vulnerable code sample

import torch
import torch.profiler

# This code represents the vulnerable pattern.
# It manually instantiates and starts the profiler without using a 'with' block.
prof = torch.profiler.profile(
    activities=[
        torch.profiler.ProfilerActivity.CPU
    ],
    record_shapes=True,
    with_stack=True
)

prof.start()

# Perform some tensor operations to be profiled.
a = torch.randn(2048, 2048)
b = torch.randn(2048, 2048)
c = a @ b
c.sum()

# The call to prof.stop() is intentionally omitted.
# In a vulnerable version, when this script exits, the program would hang or crash
# because the profiler object's finalization logic is triggered by the
# garbage collector without the profiler having been properly stopped.

Patched code sample

import torch
import torch.profiler

# The vulnerability in CVE-2025-63396 is triggered when a torch.profiler.profile
# object is instantiated but its .stop() method is not called before the object
# is destroyed (e.g., by the garbage collector). This can lead to a hang or crash.
#
# The documented and correct way to use the profiler is as a context manager
# using a 'with' statement. This guarantees that the profiler's __exit__
# method, which calls .stop(), is always executed.
#
# The code below demonstrates this safe and correct usage, which represents the
# fix for the vulnerability from a user's perspective. It ensures the profiler
# is properly stopped, preventing the Denial of Service condition.

with torch.profiler.profile(
    activities=[
        torch.profiler.ProfilerActivity.CPU,
    ],
    record_shapes=True,
    profile_memory=True
) as prof:
    # This represents a workload being profiled.
    a = torch.randn(512, 512)
    b = torch.randn(512, 512)
    c = a @ b

# Upon exiting the 'with' block, prof.stop() is called automatically.
# The program can now safely proceed and interact with the profiler results
# without risk of hanging or crashing. The following line demonstrates that
# the profiler object is in a valid, finalized state.
prof.key_averages()

Payload

import torch
import torch.profiler

# Instantiate the profiler without using a 'with' statement
prof = torch.profiler.profile(
    activities=[torch.profiler.ProfilerActivity.CPU],
    schedule=torch.profiler.schedule(wait=1, warmup=1, active=2),
    on_trace_ready=lambda p: None
)

# Manually start the profiler
prof.start()

# Perform some operations to be profiled
a = torch.randn(100, 100)
b = torch.randn(100, 100)
c = a.mm(b)

# Intentionally omit prof.stop().
# The program will exit, and the profiler's finalization/destructor
# will be called by the garbage collector, triggering the hang or crash.

Cite this entry

@misc{vaitp:cve202563396,
  title        = {{Omission of profiler.stop() in PyTorch's profiler can cause a DoS.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2025},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2025-63396},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2025-63396/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::