fix(security): harden Python driver/codegen tools - #5170
Open
causten wants to merge 1 commit into
Open
Conversation
Addresses ROCM-26621, ROCM-26353. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
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=Trueusage in tooling withsubprocess.run([...], check=True)patterns. - Add an AST-node allowlist around template expression evaluation in the codegen/template tools.
- Refactor
clang-formatinvocation 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 on lines
+503
to
+507
| ast.Subscript, | ||
| ast.Slice, | ||
| ast.Call, | ||
| ast.Attribute, | ||
| ast.keyword, |
Comment on lines
+1320
to
+1324
| ast.Subscript, | ||
| ast.Slice, | ||
| ast.Call, | ||
| ast.Attribute, | ||
| ast.keyword, |
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 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
JIRA
Test plan
Made with Cursor