[Security] Fix remote DoS via invalid recovered token reinjection (#44744)

Signed-off-by: jperezde <jperezde@redhat.com>
This commit is contained in:
Juan Pérez de Algaba
2026-06-10 02:31:43 -07:00
committed by GitHub
parent fe1d923afc
commit 8a5cf1ccd6
2 changed files with 99 additions and 1 deletions
+6 -1
View File
@@ -921,12 +921,17 @@ def sample_recovered_tokens_kernel(
other=0.0,
)
# Local tile reduction
# Local tile reduction.
# Mask out-of-vocabulary entries to -inf so they can never win
# the argmax — prevents producing recovered_id >= vocab_size
# when all valid entries in the last tile have zero probability.
score = prob * inv_q
score = tl.where(vocab_mask, score, float("-inf"))
local_max, local_id = tl.max(score, axis=0, return_indices=True)
if local_max > max_val:
max_val = local_max
recovered_id = v + local_id
recovered_id = tl.minimum(recovered_id, vocab_size - 1)
tl.store(output_token_ids_ptr + token_idx, recovered_id)