GHSA-m549-qq94-fvhg LMDeploy: Arbitrary code execution via hardcoded trust_remote_code=True in lmdeploy model initialization
Summarylmdeploy hardcodes `trust_remote_code=True` in multiple HuggingFace model-loading call sites.The affected code paths are in:The vulnerable call sites pass `trust_remote_code=True` into HuggingFace Transformers APIs such as `AutoConfig.from_pretrained()`, `PretrainedConfig.get_config_dict()`, and `GenerationConfig.from_pretrained()`.Because the model path is supplied by the operator or deployment configuration, an attacker who can control the `model_path` used by an lmdeploy serving process can point it to an attacker-controlled HuggingFace model repository. When lmdeploy starts and initializes the model, Transformers may download and execute remote Python code from that repository.Successful exploitation results in arbitrary code execution with the privileges of the lmdeploy serving process.Affected versionConfirmed affected:The issue was verified on `v0.12.3` and on `main`.Vulnerable codeConfirmed call sites:The vulnerable pattern is:and:The risk is that `trust_remote_code=True` is enabled unconditionally. Users are not required to explicitly opt in through a CLI flag or configuration option.Attack scenarioAn attacker obtains the ability to control or modify the model path used by an lmdeploy deployment. Examples include deployment configuration access, CI/CD configuration access, Kubernetes or container configuration access, or a managed environment where users can submit model IDs for serving.The attacker sets the model path to an attacker-controlled HuggingFace repository, for example:The lmdeploy serving process starts with that model path:During model initialization, lmdeploy calls HuggingFace Transformers APIs with `trust_remote_code=True`.Transformers loads and executes remote Python code from the attacker-controlled model repository.The payload runs with the privileges of the lmdeploy serving process.Why this is security-sensitive`trust_remote_code=True` is a dangerous HuggingFace option because it allows model repositories to execute custom Python code during model loading.In lmdeploy, this option is hardcoded at multiple call sites. This removes the explicit trust decision from the user or deployment operator. A safer design would require an explicit CLI flag or configuration option such as `--trust-remote-code`.lmdeploy is commonly used as a model serving daemon. The serving process may have access to model weights, GPU resources, API credentials, cloud credentials, request data, and internal network resources.Proof of conceptThe following PoC demonstrates the vulnerable primitive in a local, non-destructive way. It simulates lmdeploy calling a HuggingFace model-loading path with `trust_remote_code=True` and shows that remote model code would execute during initialization.Expected result:The marker file is written to:ImpactAn attacker who can control the model path used by an lmdeploy deployment can execute arbitrary Python code during model initialization.The attacker may be able to:Read files accessible to the lmdeploy process.Access environment variables, model provider credentials, HuggingFace tokens, cloud credentials, and API keys.Modify model-serving behavior or tamper with responses.Execute arbitrary operating-system commands.Access request data or internal service credentials available to the serving process.Cause denial of service by crashing or destabilizing the serving daemon.Pivot to internal services reachable from the lmdeploy host or container.
CVSS v3.1 score: 7.8