fix(disagg): use JSON instead of pickle for P2P ZMQ requests (#4804) - #4812
Open
Anai-Guo wants to merge 2 commits into
Open
fix(disagg): use JSON instead of pickle for P2P ZMQ requests (#4804)#4812Anai-Guo wants to merge 2 commits into
Anai-Guo wants to merge 2 commits into
Conversation
…M#4804) recv_pyobj()/send_pyobj() call pickle.loads() on peer-supplied bytes in the disaggregated-serving P2P connector, and the reachable path is an unauthenticated POST to /distserve/p2p_connect that makes the engine's PULL socket connect to a caller-chosen address. A crafted pickle payload on that address is arbitrary code execution on the engine node. Switch the connector's only wire message (DistServeCacheFreeRequest) to send_json()/recv_json() and validate it with model_validate before use, so decoding is json.loads (no code execution) and the schema check runs before the payload is acted on. Malformed/off-schema messages are logged and skipped instead of tearing down the detached receive loop.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR mitigates a remote code execution risk in the disaggregated-serving P2P (ZMQ) connector by removing pickle-based deserialization and replacing it with JSON + schema validation in EngineP2PConnection.
Changes:
- Switch P2P ZMQ message sending from
send_pyobj()(pickle) tosend_json()usingDistServeCacheFreeRequest.model_dump(). - Switch receiving from
recv_pyobj()(pickle.loads) torecv_json()followed byDistServeCacheFreeRequest.model_validate(...). - Add error handling to log and skip malformed/off-schema messages rather than crashing the receive loop.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Motivation
Fixes #4804.
The disaggregated-serving P2P connector deserializes peer-supplied bytes with
pickle:recv_pyobj()callspickle.loads()on the raw frame, so theisinstanceguard runs only after any__reduce__payload has already executed. As analysed in the issue, the reachable path is not the boundPUSHsocket but the HTTP endpoint: an unauthenticatedPOST /distserve/p2p_connectsupplieszmq_address, the engine'sPULLsocketconnect()s to that caller-chosen address, andhandle_zmq_recvthenpickle.loads()whatever that address sends → remote code execution on the engine node (AuthenticationMiddlewareis only installed whenapi_keysis set, and the/distserve/*routes carry no auth dependency).Modification
The connector's only wire message is
DistServeCacheFreeRequest, a pydantic model with two scalar fields (remote_engine_id: str,remote_session_id: int). Both send and receive live in the same class and upgrade together, so switching the codec has no protocol-mismatch risk:zmq_send:send_pyobj(...)→send_json(req.model_dump())handle_zmq_recv:recv_pyobj()→recv_json()+DistServeCacheFreeRequest.model_validate(...)recv_json()decodes withjson.loads(no code execution) andmodel_validateenforces the schema before the payload is used, making the oldisinstancecheck redundant. Malformed or off-schema messages are now logged and skipped rather than raising out of the barewhile Truein the detached task (which previously surfaced only as a task-destroyed warning).No wire-format compatibility break beyond the coordinated both-ends change here.
Checklist
mainengine_conn.py🤖 Generated with Claude Code