Downloads · 30 days
0
pragnyanramtha/onnxruntime-optimized-hardlink-write-poc
onnxruntime-optimized-hardlink-write-poc is a machine learning model from pragnyanramtha. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for onnx. The card lists the license as apache-2.0.
Benign security proof-of-concept for a conditional ONNX Runtime optimized-model serialization hardlink overwrite.
Downloads · 30 days
0
Access
Public
Updated May 12, 2026
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md3.7 KB · 40%
From the Hugging Face model README
Benign security proof-of-concept for a conditional ONNX Runtime optimized-model serialization hardlink overwrite.
ONNX Runtime 1.26.0 can overwrite a controlled file outside the optimized-model output directory when optimized external initializers are written to a filename that already exists as a hardlink.
The PoC creates:
outside_dir/outside_target.bin containing BEFORE_ORT_OPT_HARDLINK_WRITEmodel_dir/optimized.data as a hardlink to that outside targetmodel_dir/source.onnx, a simple ONNX model with a float initializerThen it runs ONNX Runtime with:
so.optimized_model_filepath = "model_dir/optimized.onnx"
so.add_session_config_entry(
"session.optimized_model_external_initializers_file_name",
"optimized.data",
)
so.add_session_config_entry(
"session.optimized_model_external_initializers_min_size_in_bytes",
"1",
)
ORT opens model_dir/optimized.data with truncating write semantics and writes optimized external initializer bytes. Because that path is a hardlink, the outside target is overwritten too.
Medium, CVSS 5.3.
Rationale: controlled local file overwrite under hardlink constraints in an optimizer/converter path. This is weaker than a default loader issue because the application must save optimized external initializers to a predictable filename in an attacker-influenced directory.
onnxruntime==1.26.0onnx==1.21.0verify_poc.py: Generates the model, creates the hardlink, runs ONNX Runtime optimized serialization, and verifies the overwrite.results/runtime_output.txt: Captured local validation output.requirements.txt: Tested dependency versions.python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
python verify_poc.py
Expected key output:
outside_before=BEFORE_ORT_OPT_HARDLINK_WRITE
hardlink_same_inode=True
hardlink_count=2
outside_after_size=64
outside_after_sha256=58dda328598e2f7fe472621bfc54935aaa354d1a6ebcaf9562cd743fd575eb19
impact=optimized_external_initializer_writer_overwrote_hardlink_target
If a service optimizes untrusted ONNX models in place or writes optimized external initializer data to a predictable filename inside an attacker-influenced model/output directory, an attacker can pre-place that filename as a hardlink and cause ONNX Runtime to truncate and overwrite the linked outside target.
The PoC is benign and overwrites only a controlled marker file created inside the PoC directory.
InferenceSession(model_path) loader issue.1df4fa9449805b590e87ac03abbe6eb0076f2dca8d7908b28ecc072926a0d662 verify_poc.py
The generated runtime files are intentionally not committed because the verifier rebuilds them with local absolute paths.
When writing optimized external initializer files, open output files defensively and reject existing files with link count greater than one. Prefer exclusive create semantics or post-open inode/link-count validation before truncating external initializer outputs.