Repository navigation
Implement import allowlist in AutoPeftModel, limit access in megatron - #3090
Conversation
Partially resolves huggingface#3085. AutoPeftModel resolves the base model's class by importing the parent library mentioned in the adapter config which makes way for potentially executing malicious code on the adapter creator's behalf. While this is not a remote code execution vulnerability by itself (since the attacker still needs to install a malicious package on the system) it can be used for code execution in case the attacker has file system access, for example.
I haven't found any evidence that one wants to load other modules than `megatron.*`, so we limit it to that.
|
cc @spartan8806 |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
Thanks for the quick turnaround. |
|
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. |
BenjaminBossan
left a comment
There was a problem hiding this comment.
We can give it a try and roll back if it causes trouble.
| target_base_layer = target | ||
|
|
||
| if config.megatron_config: | ||
| if not config.megatron_core.startswith("megatron."): |
There was a problem hiding this comment.
I don't remember the specifics anymore and after checking the PR from back then couldn't find anything, but I vaguely remember that there were explicit cases where another lib might be needed. How about solving this similarly to below with a patch-able allow list?
BenjaminBossan
left a comment
There was a problem hiding this comment.
Thanks for the update, LGTM.
## Fix `peft` 0.20 ([huggingface/peft#3090](huggingface/peft#3090)) enforces an import allowlist when resolving a LoRA adapter's `auto_mapping.parent_library`. For Chronos-2 adapters this is `chronos.chronos2.model`, which is not in the default allowlist, so `Chronos2Pipeline.from_pretrained` on an adapter raises: ``` ValueError: The auto mapping wants to import 'chronos.chronos2.model' which is not in the import allowlist. ``` This broke `test_chronos2_lora_pipeline_loads_from_disk` in CI once `peft` 0.20 was pulled in. We now pass `import_allowlist=["chronos"]` (peft matches on the module prefix, so this covers any submodule under our own package) when loading an adapter. The call is guarded on `peft>=0.20.0` since the kwarg does not exist in older versions within our supported range (`peft>=0.18.1`); the guard can be dropped once the minimum is 0.20. ## Testing `test/test_chronos2.py::test_chronos2_lora_pipeline_loads_from_disk` passes with `peft` 0.20.0 installed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Abdul Fatir Ansari <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Resolves #3085.
AutoPeftModelresolves the base model's class by importing the parent library mentioned in the adapter config which makes way for potentially executing malicious code on the adapter creator's behalf. While this is not a remote code execution vulnerability by itself (since the attacker still needs to install a malicious package on the system) it can be used for code execution in case the attacker has file system access, for example.The same is happening for the
megatron.coreconfig key. I haven't found any evidence thatmegatronwants to load other modules thanmegatron.*, so we limit it to that.There was a bit of missing documentation, typo, missing
hub_online_once, so I took the opportunity to fix that along the way.