Uploaded image for project: 'AI Platform Core Components'
  1. AI Platform Core Components
  2. AIPCC-9570

[BOT][Security] CWE-78 in cpp_builder.py:422-427

XMLWordPrintable

    • False
    • Hide

      None

      Show
      None
    • False

      Vulnerability Details

      CWE Type(s): CWE-78
      Severity: CRITICAL
      Team: PyTorch Compile

      Location

      • File: torch/_inductor/cpp_builder.py
      • Lines: 422-427

      Description

      CRITICAL command injection vulnerability in convert_cubin_to_obj function. The vulnerability occurs when:

      1. File paths with spaces break cmd.split()
      2. kernel_name parameter can inject command arguments
      3. Multiple subprocess.run() calls use unsafe string interpolation

      Three instances of f-string command construction with cmd.split() enable argument injection via filenames and kernel_name parameter.

      Impact

      • Argument confusion from filenames with spaces
      • Command injection via cubin_file parameter
      • Argument injection via kernel_name parameter
      • Potential for arbitrary code execution during CUDA compilation

      Root Cause

      Using f-string command construction with cmd.split() breaks on filenames with spaces. Three instances in convert_cubin_to_obj function enable argument injection via filenames and kernel_name parameter.

      Fix Status

      MR Link: https://gitlab.com/redhat/rhel-ai/team-pytorch/pytorch/-/merge_requests/54
      Fix Branch: security-fix-cwe78-cpp-builder-cubin
      Status: IMPLEMENTED

      Fix Implementation

      Replaced all three instances of f-string command construction and cmd.split() with proper list-based command construction:

      1. Line 422: ld command for converting .cubin to .o
      2. Line 425: objcopy command for renaming .data to .rodata
      3. Line 436: objcopy command for symbol renaming

      This eliminates the risk of:

      • Argument confusion from filenames with spaces
      • Command injection via cubin_file parameter
      • Argument injection via kernel_name parameter

      Related Exploit Files

      • test_cmd_injection_cpp_builder_502.py

      Exploit Code Sample

      # VULNERABLE CODE:
      cmd = f"{ld} -r -b binary -z noexecstack -o {obj_file} {cubin_file}"
      subprocess.run(cmd.split(), capture_output=True, text=True, check=True)
      
      # ATTACK:
      # cubin_file = "kernel.cubin --flag malicious.so"
      # kernel_name = "kernel; rm -rf /"
      
      # FIXED CODE:
      cmd = [ld, "-r", "-b", "binary", "-z", "noexecstack", "-o", obj_file, cubin_file]
      subprocess.run(cmd, capture_output=True, text=True, check=True)
      

      References


      Generated by CI Security Bot on 2026-01-31

              Unassigned Unassigned
              rh-ee-rpunia Riya Punia
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: