Skip to content

fix(security): harden Python driver/codegen tools - #5170

Open
causten wants to merge 1 commit into
developfrom
mythos/pr-python-tools-security
Open

fix(security): harden Python driver/codegen tools#5170
causten wants to merge 1 commit into
developfrom
mythos/pr-python-tools-security

Conversation

@causten

@causten causten commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Remove shell=True/os.system from driver tools; restrict template eval with AST allowlist

JIRA

  • ROCM-26621, ROCM-26353

Test plan

  • Run make generate
  • Run tools/te.py on template inputs

Made with Cursor

Addresses ROCM-26621, ROCM-26353.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI lite review requested due to automatic review settings August 21, 2026 23:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to harden MIGraphX’s Python-based driver/codegen tooling by removing shell-based subprocess invocation and constraining template evaluation to a restricted AST.

Changes:

  • Replace os.system(...) / shell=True usage in tooling with subprocess.run([...], check=True) patterns.
  • Add an AST-node allowlist around template expression evaluation in the codegen/template tools.
  • Refactor clang-format invocation to use argv lists instead of shell command strings.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
tools/te.py Adds AST-based allowlist to template evaluation (but currently breaks template execution and needs tightening for safety).
tools/api.py Applies the same AST allowlist approach to API template evaluation (same functional/sandbox concerns).
tools/roctx.py Replaces some os.system calls with subprocess.run, but still builds command strings and still contains remaining os.system/os.popen usage.
tools/generate.py Removes shell=True from clang-format invocation by switching to argv list execution.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tools/te.py
Comment on lines +503 to +507
ast.Subscript,
ast.Slice,
ast.Call,
ast.Attribute,
ast.keyword,
Comment thread tools/api.py
Comment on lines +1320 to +1324
ast.Subscript,
ast.Slice,
ast.Call,
ast.Attribute,
ast.keyword,
Comment thread tools/roctx.py
Comment on lines 219 to +225
#configurations
configs = '--hip-trace --roctx-trace --flush-rate 10ms --timestamp on'
output_dir = f"-d {args.out}"
executable = f"/opt/rocm/bin/migraphx-driver roctx {run_args}"
process_args = configs + ' ' + output_dir + ' ' + executable
for i in range(repeat_count):
os.system('rocprof ' + process_args)
subprocess.run(shlex.split('rocprof ' + process_args), check=True)
Comment thread tools/roctx.py
Comment on lines +259 to +268
subprocess.run([
'git', 'clone',
'https://github.com/ROCmSoftwarePlatform/rocmProfileData.git',
rpd_path
],
check=True)
os.chdir(rpd_path + "rocpd_python/")
os.system(python_bin + ' -m pip install --upgrade pip')
os.system(python_bin + ' setup.py install')
subprocess.run([python_bin, '-m', 'pip', 'install', '--upgrade', 'pip'],
check=True)
subprocess.run([python_bin, 'setup.py', 'install'], check=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants