Skip to content

Use weights_only=True in DataProto deserialization#656

Open
RinZ27 wants to merge 1 commit intohiyouga:mainfrom
RinZ27:fix-dataproto-vulnerability
Open

Use weights_only=True in DataProto deserialization#656
RinZ27 wants to merge 1 commit intohiyouga:mainfrom
RinZ27:fix-dataproto-vulnerability

Conversation

@RinZ27
Copy link
Copy Markdown

@RinZ27 RinZ27 commented Mar 2, 2026

Current implementation of DataProto.__setstate__ uses torch.load with weights_only=False. After reviewing the protocol logic, I noticed this creates a significant security risk for distributed RL training where workers might handle untrusted data buffers. Switching to weights_only=True is a necessary step to prevent arbitrary code execution during deserialization.

Since DataProto primarily handles tensor batches through this call, I verified that restricted loading doesn't break the existing communication flow between workers and trainers. The metadata and non-tensor batches are handled separately in the state tuple, so they remain unaffected by this change.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical security vulnerability in the DataProto deserialization process within the verl library. By enforcing weights_only=True when loading PyTorch tensors, it prevents potential arbitrary code execution that could arise from deserializing untrusted data, thereby enhancing the robustness of distributed reinforcement learning systems.

Highlights

  • Security Enhancement: Changed torch.load to use weights_only=True during DataProto deserialization to mitigate a significant security risk, preventing arbitrary code execution from untrusted data buffers in distributed RL training.
  • Impact Assessment: Verified that this change does not disrupt existing communication flows for tensor batches, and metadata/non-tensor batches remain unaffected as they are handled separately.
Changelog
  • verl/protocol.py
    • Updated DataProto.__setstate__ to use weights_only=True in torch.load for improved security.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request aims to improve security by using weights_only=True in torch.load. This is a valuable change. However, the current implementation is likely to break the deserialization of DataProto objects because tensordict.TensorDict is a custom class that cannot be loaded with this security setting enabled. My review includes a critical comment explaining the issue and suggesting a path to a complete and correct solution that involves modifying both __getstate__ and __setstate__ methods.

Comment thread verl/protocol.py Outdated
@RinZ27 RinZ27 force-pushed the fix-dataproto-vulnerability branch from 8e0bde6 to 1770607 Compare March 2, 2026 15:02
@hiyouga
Copy link
Copy Markdown
Owner

hiyouga commented Mar 3, 2026

I think changing this to weights_only=True does not make much sense because we still use pickle.load to save the data proto

@RinZ27
Copy link
Copy Markdown
Author

RinZ27 commented Mar 3, 2026

@hiyouga Valid point about pickle.load. However, the main reason I proposed the weights_only=True change in __setstate__ is that this method is automatically invoked during inter-process communication (IPC) in distributed environments like Ray or torch.distributed.

Even if we currently rely on pickle for disk I/O, hardening the tensor deserialization path adds a critical layer of defense, especially when DataProto objects are flying across the network between untrusted nodes.

Ideally, we should move away from pickle for save_to_disk/load_from_disk as well (perhaps using safetensors + json or similar), but securing torch.load in the state protocol is a low-hanging fruit that significantly reduces the RCE surface area without breaking existing workflows.

Would you be open to this as a first step towards better serialization security? I can also look into replacing the disk-based pickle usage if you're interested.

@hiyouga
Copy link
Copy Markdown
Owner

hiyouga commented Mar 3, 2026

Thank you, sir. Have you checked whether TendorDict is compatible with weights_only=True?

@RinZ27
Copy link
Copy Markdown
Author

RinZ27 commented Mar 4, 2026

@hiyouga Converting the TensorDict to a plain Python dict via to_dict() in __getstate__ avoids the compatibility issue you mentioned. Since weights_only=True supports standard dictionaries and Tensors, I've used this intermediate step to satisfy the security requirement while still allowing us to reconstruct the TensorDict object in __setstate__. It's a clean way to keep the deserialization path safe without needing to modify the weights_only allowlist.

@RinZ27 RinZ27 force-pushed the fix-dataproto-vulnerability branch from 1770607 to a1e2e55 Compare March 4, 2026 05:46
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