[diffusion] security: pin multimodal-gen ZMQ scheduler ingress to loopback on wildcard --host (#36854)
Co-authored-by: Mick Qian <mickqian@users.noreply.github.com>
This commit is contained in:
@@ -3144,16 +3144,26 @@ class ServerArgs(DisaggServerArgsMixin):
|
||||
def scheduler_endpoint(self):
|
||||
"""
|
||||
Internal endpoint for scheduler.
|
||||
Normalizes localhost and IPv6 hosts to IPv4 loopback for internal ZMQ.
|
||||
Wildcard, localhost, and IPv6 hosts use IPv4 loopback for internal ZMQ.
|
||||
"""
|
||||
return self.scheduler_endpoint_for(0)
|
||||
|
||||
def scheduler_endpoint_for(self, replica: int) -> str:
|
||||
"""Ingress endpoint of one DP replica's driver rank."""
|
||||
"""Ingress endpoint of one DP replica's driver rank.
|
||||
|
||||
The scheduler ingress is an unauthenticated pickle-RPC endpoint
|
||||
(``managers/scheduler.py`` ``recv_reqs`` deserializes client bytes
|
||||
with ``pickle.loads``), so it must never be derived from the public
|
||||
``--host``: binding it to ``0.0.0.0`` would expose unsafe
|
||||
deserialization to the network (CVE-2026-3059 family). Wildcard hosts
|
||||
are pinned to loopback; IPv6 hosts also use IPv4 loopback for internal
|
||||
ZMQ compatibility. Explicit non-wildcard IPv4 hosts and hostnames
|
||||
(used for intentional cross-machine deployments) are honored.
|
||||
"""
|
||||
scheduler_host = self.host
|
||||
if (
|
||||
scheduler_host is None
|
||||
or scheduler_host == "localhost"
|
||||
or scheduler_host in ("localhost", "0.0.0.0")
|
||||
or is_valid_ipv6_address(scheduler_host)
|
||||
):
|
||||
scheduler_host = "127.0.0.1"
|
||||
|
||||
@@ -3,7 +3,7 @@ import os
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from contextlib import contextmanager
|
||||
from contextlib import ExitStack, contextmanager
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import zmq
|
||||
@@ -160,6 +160,15 @@ class TestPlatformLifecycleHooks(unittest.TestCase):
|
||||
apply_defaults.assert_called_once_with(server_args)
|
||||
|
||||
|
||||
class _CudaPlatformTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
# Residency queries inspect the platform after argument construction too.
|
||||
stack = ExitStack()
|
||||
self.addCleanup(stack.close)
|
||||
stack.enter_context(_mock_cuda_platform())
|
||||
|
||||
|
||||
class TestSchedulerEndpoints(unittest.TestCase):
|
||||
def test_host_normalization_preserves_replica_ports(self):
|
||||
args = _from_dict_without_model_resolution({"model_path": "test/model"})
|
||||
@@ -171,7 +180,7 @@ class TestSchedulerEndpoints(unittest.TestCase):
|
||||
("::", "127.0.0.1"),
|
||||
("::1", "127.0.0.1"),
|
||||
("2001:db8::1", "127.0.0.1"),
|
||||
("0.0.0.0", "0.0.0.0"),
|
||||
("0.0.0.0", "127.0.0.1"),
|
||||
("127.0.0.1", "127.0.0.1"),
|
||||
("192.0.2.1", "192.0.2.1"),
|
||||
("scheduler.example", "scheduler.example"),
|
||||
@@ -189,30 +198,39 @@ class TestSchedulerEndpoints(unittest.TestCase):
|
||||
for replica, endpoint in enumerate(expected):
|
||||
self.assertEqual(args.scheduler_endpoint_for(replica), endpoint)
|
||||
|
||||
def test_ipv6_http_host_allows_internal_zmq_round_trip(self):
|
||||
def test_wildcard_and_ipv6_http_hosts_allow_internal_zmq_round_trip(self):
|
||||
args = _from_dict_without_model_resolution({"model_path": "test/model"})
|
||||
args.host = "::1"
|
||||
args.scheduler_port = 0
|
||||
args.scheduler_ports = None
|
||||
self.assertEqual(args.url(), f"http://[::1]:{args.port}")
|
||||
|
||||
with zmq.Context() as context:
|
||||
with context.socket(zmq.REP) as receiver, context.socket(zmq.REQ) as sender:
|
||||
for socket in (receiver, sender):
|
||||
socket.setsockopt(zmq.LINGER, 0)
|
||||
socket.setsockopt(zmq.RCVTIMEO, 2000)
|
||||
socket.setsockopt(zmq.SNDTIMEO, 2000)
|
||||
receiver.bind(args.scheduler_endpoint)
|
||||
bound_endpoint = receiver.getsockopt_string(zmq.LAST_ENDPOINT)
|
||||
args.scheduler_port = int(bound_endpoint.rsplit(":", 1)[1])
|
||||
sender.connect(args.scheduler_endpoint)
|
||||
sender.send(b"ping")
|
||||
self.assertEqual(receiver.recv(), b"ping")
|
||||
receiver.send(b"pong")
|
||||
self.assertEqual(sender.recv(), b"pong")
|
||||
for host, http_host in (
|
||||
("0.0.0.0", "127.0.0.1"),
|
||||
("::", "[::1]"),
|
||||
("::1", "[::1]"),
|
||||
):
|
||||
with self.subTest(host=host), zmq.Context() as context:
|
||||
args.host = host
|
||||
args.scheduler_port = 0
|
||||
self.assertEqual(args.url(), f"http://{http_host}:{args.port}")
|
||||
with (
|
||||
context.socket(zmq.REP) as receiver,
|
||||
context.socket(zmq.REQ) as sender,
|
||||
):
|
||||
for socket in (receiver, sender):
|
||||
socket.setsockopt(zmq.LINGER, 0)
|
||||
socket.setsockopt(zmq.RCVTIMEO, 2000)
|
||||
socket.setsockopt(zmq.SNDTIMEO, 2000)
|
||||
receiver.bind(args.scheduler_endpoint)
|
||||
bound_endpoint = receiver.getsockopt_string(zmq.LAST_ENDPOINT)
|
||||
self.assertTrue(bound_endpoint.startswith("tcp://127.0.0.1:"))
|
||||
args.scheduler_port = int(bound_endpoint.rsplit(":", 1)[1])
|
||||
sender.connect(args.scheduler_endpoint)
|
||||
sender.send(b"ping")
|
||||
self.assertEqual(receiver.recv(), b"ping")
|
||||
receiver.send(b"pong")
|
||||
self.assertEqual(sender.recv(), b"pong")
|
||||
|
||||
|
||||
class TestServerArgsPathExpansion(unittest.TestCase):
|
||||
class TestServerArgsPathExpansion(_CudaPlatformTestCase):
|
||||
def _from_dict_without_model_resolution(self, kwargs):
|
||||
return _from_dict_without_model_resolution(kwargs)
|
||||
|
||||
@@ -1008,7 +1026,7 @@ class TestMiniMaxH3Routing(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class TestOffloadDefaults(unittest.TestCase):
|
||||
class TestOffloadDefaults(_CudaPlatformTestCase):
|
||||
def test_wan_decode_precision_defaults(self):
|
||||
for pipeline_config in (
|
||||
WanT2V480PConfig(),
|
||||
@@ -2532,14 +2550,18 @@ class TestOffloadDefaults(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_explicit_multi_gpu_dit_layerwise_only_selects_dit_group(self):
|
||||
args = self._from_dict_with_pipeline_config(
|
||||
MOVAPipelineConfig(),
|
||||
kwargs={
|
||||
"model_path": "OpenMOSS-Team/MOVA-360p",
|
||||
"num_gpus": 2,
|
||||
"dit_layerwise_offload": True,
|
||||
},
|
||||
)
|
||||
with patch(
|
||||
"sglang.multimodal_gen.registry.maybe_download_model_index",
|
||||
return_value={"_class_name": "MOVAPipeline"},
|
||||
):
|
||||
args = self._from_dict_with_pipeline_config(
|
||||
MOVAPipelineConfig(),
|
||||
kwargs={
|
||||
"model_path": "OpenMOSS-Team/MOVA-360p",
|
||||
"num_gpus": 2,
|
||||
"dit_layerwise_offload": True,
|
||||
},
|
||||
)
|
||||
|
||||
self.assertFalse(args.use_fsdp_inference)
|
||||
self.assertTrue(args.dit_cpu_offload)
|
||||
@@ -3390,6 +3412,13 @@ class TestPerRoleParallelism(unittest.TestCase):
|
||||
class TestPipelineResolutionCliOverride(unittest.TestCase):
|
||||
def setUp(self):
|
||||
_get_config_info.cache_clear()
|
||||
model_index = patch(
|
||||
"sglang.multimodal_gen.registry.maybe_download_model_index",
|
||||
return_value={"_class_name": "QwenImageLayeredPipeline"},
|
||||
)
|
||||
model_index.start()
|
||||
self.addCleanup(model_index.stop)
|
||||
self.addCleanup(_get_config_info.cache_clear)
|
||||
|
||||
def test_resolution_flag_overrides_qwen_image_layered_pipeline_config(self):
|
||||
parser = FlexibleArgumentParser()
|
||||
@@ -3549,7 +3578,7 @@ class TestNcclNvlsArgs(unittest.TestCase):
|
||||
self.assertFalse(disabled_args.enable_nccl_nvls)
|
||||
|
||||
|
||||
class TestDirectGpuWeightLoading(unittest.TestCase):
|
||||
class TestDirectGpuWeightLoading(_CudaPlatformTestCase):
|
||||
def _args(self) -> ServerArgs:
|
||||
args = ServerArgs.__new__(ServerArgs)
|
||||
args.direct_gpu_weight_loading = True
|
||||
@@ -3620,6 +3649,87 @@ class TestDirectGpuWeightLoading(unittest.TestCase):
|
||||
tp_args._validate_direct_gpu_weight_loading()
|
||||
|
||||
|
||||
class TestSchedulerEndpointBinding(unittest.TestCase):
|
||||
"""The scheduler ingress is an unauthenticated pickle-RPC endpoint; it must
|
||||
never follow a wildcard --host (see ServerArgs.scheduler_endpoint_for)."""
|
||||
|
||||
def _args(self, kwargs):
|
||||
# Endpoint formatting does not need model resolution or port allocation.
|
||||
args = ServerArgs.__new__(ServerArgs)
|
||||
for key, value in kwargs.items():
|
||||
setattr(args, key, value)
|
||||
return args
|
||||
|
||||
def test_wildcard_host_pinned_to_loopback(self):
|
||||
args = self._args(
|
||||
{"model_path": "/fake/model", "host": "0.0.0.0", "scheduler_port": 5555}
|
||||
)
|
||||
self.assertEqual(args.scheduler_endpoint_for(0), "tcp://127.0.0.1:5555")
|
||||
|
||||
def test_ipv6_wildcard_host_pinned_to_loopback(self):
|
||||
args = self._args(
|
||||
{"model_path": "/fake/model", "host": "::", "scheduler_port": 5555}
|
||||
)
|
||||
self.assertEqual(args.scheduler_endpoint_for(0), "tcp://127.0.0.1:5555")
|
||||
|
||||
def test_default_host_stays_loopback(self):
|
||||
args = self._args({"model_path": "/fake/model", "scheduler_port": 5555})
|
||||
self.assertEqual(args.scheduler_endpoint_for(0), "tcp://127.0.0.1:5555")
|
||||
|
||||
def test_explicit_host_is_honored(self):
|
||||
args = self._args(
|
||||
{
|
||||
"model_path": "/fake/model",
|
||||
"host": "10.1.2.3",
|
||||
"scheduler_port": 5555,
|
||||
}
|
||||
)
|
||||
self.assertEqual(args.scheduler_endpoint_for(0), "tcp://10.1.2.3:5555")
|
||||
|
||||
def test_explicit_ipv6_host_uses_ipv4_loopback(self):
|
||||
args = self._args(
|
||||
{
|
||||
"model_path": "/fake/model",
|
||||
"host": "::1",
|
||||
"scheduler_port": 5555,
|
||||
}
|
||||
)
|
||||
self.assertEqual(args.scheduler_endpoint_for(0), "tcp://127.0.0.1:5555")
|
||||
|
||||
def test_replica_ports_increment_on_loopback(self):
|
||||
args = self._args(
|
||||
{"model_path": "/fake/model", "host": "0.0.0.0", "scheduler_port": 5555}
|
||||
)
|
||||
self.assertEqual(args.scheduler_endpoint_for(1), "tcp://127.0.0.1:5556")
|
||||
|
||||
def test_explicit_scheduler_ports_on_loopback(self):
|
||||
args = self._args(
|
||||
{
|
||||
"model_path": "/fake/model",
|
||||
"host": "0.0.0.0",
|
||||
"scheduler_port": 5555,
|
||||
"dp_size": 2,
|
||||
}
|
||||
)
|
||||
args.scheduler_ports = [6100, 6200]
|
||||
self.assertEqual(args.scheduler_endpoint, "tcp://127.0.0.1:6100")
|
||||
self.assertEqual(
|
||||
args.scheduler_endpoints,
|
||||
["tcp://127.0.0.1:6100", "tcp://127.0.0.1:6200"],
|
||||
)
|
||||
|
||||
def test_explicit_scheduler_ports_with_ipv6(self):
|
||||
args = self._args(
|
||||
{
|
||||
"model_path": "/fake/model",
|
||||
"host": "::1",
|
||||
"scheduler_port": 5555,
|
||||
}
|
||||
)
|
||||
args.scheduler_ports = [6100, 6200]
|
||||
self.assertEqual(args.scheduler_endpoint_for(1), "tcp://127.0.0.1:6200")
|
||||
|
||||
|
||||
class TestLayerwiseResidencyLifetime(unittest.TestCase):
|
||||
def _help_by_option(self):
|
||||
parser = FlexibleArgumentParser()
|
||||
|
||||
Reference in New Issue
Block a user