drm/amdgpu/vcn4: Fix TOCTOU and overflow in ib parsing
Subsystems (2)
PATCH 1/1 drm/amdgpu/vcn4: Fix TOCTOU and overflow in ib parsing
From: Boyuan Zhang <[email protected]>
Fix security vulnerabilities in VCN 4 encoder IB parameter parsing.
With userptr-backed IBs, userspace can race and modify the length field between validation and use, causing an infinite loop (i += 0) that hangs the kernel with VCN lock held, resulting in GPU-wide DoS.
Additional issues: out-of-bounds access when i reaches length_dw-1 but code reads ib[i+1], and missing validation of the start parameter.
Fix by validating start, using i+2 <= length_dw loop condition, reading length once to prevent TOCTOU, and adding comprehensive bounds checking.
--- drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +11 -1
@@ -1932,9 +1932,19 @@ static int vcn_v4_0_enc_find_ib_param(struct amdgpu_ib *ib, uint32_t id, int staint i;uint32_t len; -for (i = start; (len =amdgpu_ib_get_value (ib, i)) >=8 ; i += len /4 ) { +if (start <0 || start >= ib->length_dw) +return -1 ; + +for (i = start; i +2 <= ib->length_dw; ) { + len =amdgpu_ib_get_value (ib, i); + +if (len <8 || (len &3 ) || i + len /4 > ib->length_dw) +break ; +if (amdgpu_ib_get_value (ib, i +1 ) == id)return i; + + i += len /4 ; }return -1 ; }
Signature · 1 line
2.43.0
AMD General
Looks good to me:
Quoted 57 lines
-----Original Message-----
From: Zhang, Boyuan <[email protected]>
Sent: May 19, 2026 1:22 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Liu, Leo <[email protected]>; Zhang, Boyuan <[email protected]>
Subject: [PATCH] drm/amdgpu/vcn4: Fix TOCTOU and overflow in ib parsingFrom: Boyuan Zhang <[email protected]>
Fix security vulnerabilities in VCN 4 encoder IB parameter parsing.
With userptr-backed IBs, userspace can race and modify the length field between validation and use, causing an infinite loop (i += 0) that hangs the kernel with VCN lock held, resulting in GPU-wide DoS.
Additional issues: out-of-bounds access when i reaches length_dw-1 but code reads ib[i+1], and missing validation of the start parameter.
Fix by validating start, using i+2 <=
length_dwloop condition, reading length once to prevent TOCTOU, and adding comprehensive bounds checking.Signed-off-by Boyuan Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +0
-0@@ -1932,9 +1932,19 @@ static int vcn_v4_0_enc_find_ib_param(struct
amdgpu_ib*ib,uint32_tid, int staint i; uint32_t len;drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +11
-2-for (i = start; (len =amdgpu_ib_get_value (ib, i)) >=8 ; i += len /4 ) { +if (start <0 || start >= ib->length_dw) +return -1 ; + +for (i = start; i +2 <= ib->length_dw; ) { + len =amdgpu_ib_get_value (ib, i); + +if (len <8 || (len &3 ) || i + len /4 > ib->length_dw) +break ; +if (amdgpu_ib_get_value (ib, i +1 ) == id)return i; + + i += len /4 ; }return -1 ; } --2.43.0