[Security] Authenticate shared-memory multimodal cache handles (#59357)

Signed-off-by: Clinton Thomas <1033162+KernelClint@users.noreply.github.com>
Co-authored-by: Lucas Bourtoule <35483370+dhalf@users.noreply.github.com>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
This commit is contained in:
Clinton Thomas
2026-09-30 05:16:26 -07:00
committed by GitHub
co-authored by Lucas Bourtoule Cyrus Leung
parent 72e7874fa6
commit 3d5625cc3c
8 changed files with 574 additions and 41 deletions
@@ -15,14 +15,25 @@ from vllm.entrypoints.openai.models.serving import OpenAIServingModels
from vllm.entrypoints.scale_out.token_in_token_out.mm_features import (
placeholder_ranges_from_engine_input,
)
from vllm.entrypoints.scale_out.token_in_token_out.mm_serde import (
encode_mm_kwargs_item,
)
from vllm.entrypoints.scale_out.token_in_token_out.protocol import (
GenerateRequest,
GenerateResponse,
MultiModalFeatures,
PlaceholderRangeInfo,
)
from vllm.entrypoints.scale_out.token_in_token_out.serving import ServingTokens
from vllm.entrypoints.serve.engine.protocol import ErrorResponse
from vllm.exceptions import GenerationError
from vllm.logprobs import Logprob
from vllm.multimodal.inputs import PlaceholderRange
from vllm.multimodal.inputs import (
MultiModalBatchedField,
MultiModalFieldElem,
MultiModalKwargsItem,
PlaceholderRange,
)
from vllm.outputs import CompletionOutput, RequestOutput
from vllm.renderers import renderer_from_config
from vllm.renderers.online_renderer import OnlineRenderer
@@ -285,6 +296,46 @@ async def test_non_stream_error():
await serving.serve_tokens(request)
@pytest.mark.asyncio
async def test_serve_tokens_rejects_invalid_shm_handle_before_engine_handoff():
engine = _mock_engine()
engine.generate = MagicMock()
serving = _build_serving_tokens(engine)
cache = MagicMock()
cache.validate_input_item.side_effect = ValueError(
"Invalid SHM handle signature for cache key."
)
serving.online_renderer.renderer._mm_processor_cache = cache
forged_item = MultiModalKwargsItem(
{
"address": MultiModalFieldElem(data=224, field=MultiModalBatchedField()),
"monotonic_id": MultiModalFieldElem(
data=4242,
field=MultiModalBatchedField(),
),
}
)
request = GenerateRequest(
token_ids=[1, 2, 3],
sampling_params=SamplingParams(max_tokens=1),
model=MODEL_NAME,
features=MultiModalFeatures(
mm_hashes={"image": ["image_A"]},
mm_placeholders={"image": [PlaceholderRangeInfo(offset=0, length=1)]},
kwargs_data={"image": [encode_mm_kwargs_item(forged_item)]},
),
)
response = await serving.serve_tokens(request)
assert isinstance(response, ErrorResponse)
cache.validate_input_item.assert_called_once()
validated_item, validated_hash = cache.validate_input_item.call_args.args
assert validated_hash == "image_A"
assert validated_item["address"].data == 224
engine.generate.assert_not_called()
@pytest.mark.asyncio
async def test_stream_basic():
"""Streaming returns SSE chunks with correct token_ids and ends with [DONE]."""