drm/amdgpu: Fix TOCTOU on UniRAS command response size
authorChenglei Xie <Chenglei.Xie@amd.com>
Mon, 11 May 2026 18:13:45 +0000 (14:13 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 27 May 2026 14:48:30 +0000 (10:48 -0400)
commit26057fb8e17e4ac9b95a6988ae37089f1b0cef9e
tree1a15c68724eaf6628657d7147e7886fe244401cc
parentebbd73d089bd47021e67a43bed665178adb55b4b
drm/amdgpu: Fix TOCTOU on UniRAS  command response size

The guest maps the PF response in shared VRAM (struct ras_cmd_ctx in the
command buffer). After amdgpu_virt_send_remote_ras_cmd() returns, the code
validated rcmd->output_size against the caller buffer, then copied
rcmd->output_buff_raw using rcmd->output_size again. A malicious PF could
change output_size between those reads so the memcpy length exceeds the
caller’s output_size and overflows guest stack or heap buffers.

Snapshot output_size with READ_ONCE() once, assign cmd->output_size from
that value, and use the same snapshot for the bounds check and memcpy.
Also read cmd_res once with READ_ONCE() so the error branch and
cmd->cmd_res assignment do not observe different values from shared memory.

Signed-off-by: Chenglei Xie <Chenglei.Xie@amd.com>
Reviewed-by: YiPeng Chai <YiPeng.Chai@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c