VAITP Dataset

← Back to the dataset

CVE-2024-5480

RCE vulnerability in PyTorch RPC allows arbitrary command execution.

  • CVSS 10.0
  • CWE-77
  • Input Validation and Sanitization
  • Remote

A vulnerability in the PyTorch's torch.distributed.rpc framework, specifically in versions prior to 2.2.2, allows for remote code execution (RCE). The framework, which is used in distributed training scenarios, does not properly verify the functions being called during RPC (Remote Procedure Call) operations. This oversight permits attackers to execute arbitrary commands by leveraging built-in Python functions such as eval during multi-cpu RPC communication. The vulnerability arises from the lack of restriction on function calls when a worker node serializes and sends a PythonUDF (User Defined Function) to the master node, which then deserializes and executes the function without validation. This flaw can be exploited to compromise master nodes initiating distributed training, potentially leading to the theft of sensitive AI-related data.

CVSS base score
10.0
Published
2024-06-06
OWASP
A01 Broken Access Control
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Command Injection
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
PyTorch
Fixed by upgrading
Yes

Solution

Upgrade to PyTorch version 2.2.2 or later.

Vulnerable code sample

import torch
import torch.distributed.rpc as rpc

def function(code):
    """Vulnerable function that demonstrates the security issue."""
    return eval(code)

def start_rpc():
    """Vulnerable function that demonstrates the security issue."""
    rpc.init_rpc("worker", rank=0, world_size=1)
    rpc.register_function("function", function)

if __name__ == "__main__":
    start_rpc()
    result = rpc.rpc_sync("worker", "function", args=("print('Executing arbitrary code!')",))
    print(result)
    rpc.shutdown()

Patched code sample

import torch
import torch.distributed.rpc as rpc
import ast

def function(code):
    """Secure function that fixes the vulnerability."""
    # SECURE: This version prevents command injection
    return ast.literal_eval(code)

def start_rpc():
    """Secure function that fixes the vulnerability."""
    rpc.init_rpc("worker", rank=0, world_size=1)
    rpc.register_function("function", function)

if __name__ == "__main__":
    start_rpc()
    result = rpc.rpc_sync("worker", "function", args=("print('Executing arbitrary code!')"))
    print(result)
    rpc.shutdown()

Payload

"__import__('os').system('cat /etc/passwd')"

Cite this entry

@misc{vaitp:cve20245480,
  title        = {{RCE vulnerability in PyTorch RPC allows arbitrary command execution.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-5480},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-5480/}}
}
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 ::