amdgpu/vcn: vcn dec_msg integer overflow fix
Subsystems (2)
PATCH 1/1 amdgpu/vcn: vcn dec_msg integer overflow fix
if supplied msg[2] in the header is too large (around 0x40000000 and above), 4 times of this unsigned 32 bit value will overflow and the test could pass.
Widen it with uint64_t instead. Also drop the redundant first check and make the check clear that 6 dwords of header plus 4 dwords of each msg cannot exceed the overall packet size in dwords.
--- drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1 -1
@@ -1965,7 +1965,7 @@ static int vcn_v3_0_dec_msg(struct amdgpu_cs_parser *p, struct amdgpu_job *job, num_buffers = msg[2 ];/* Verify that all indices fit within the claimed length. Each index is 4 DWORDs */ -if (num_buffers > len_dw ||6 + num_buffers *4 > len_dw) { +if ((uint64_t )6 + (uint64_t )num_buffers *4 > len_dw) {DRM_ERROR ("VCN message has too many buffers!\n" ); r = -EINVAL ; goto out;
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1 -1
@@ -1881,7 +1881,7 @@ static int vcn_v4_0_dec_msg(struct amdgpu_cs_parser *p, struct amdgpu_job *job, num_buffers = msg[2 ];/* Verify that all indices fit within the claimed length. Each index is 4 DWORDs */ -if (num_buffers > len_dw ||6 + num_buffers *4 > len_dw) { +if ((uint64_t )6 + (uint64_t )num_buffers *4 > len_dw) {DRM_ERROR ("VCN message has too many buffers!\n" ); r = -EINVAL ; goto out;
Signature · 1 line
2.43.0
Quoted 9 lines · David (Ming Qiang) Wu
if supplied msg[2] in the header is too large (around
0x40000000and above), 4 times of this unsigned 32 bit value will overflow and the test could pass.Widen it with
uint64_tinstead. Also drop the redundant first check and make the check clear that 6 dwords of header plus 4 dwords of each msg cannot exceed the overall packet size in dwords.
Maybe cleaner to use check_mul_overflow() and just return an error in that case?
Alex
Quoted 36 lines
Signed-off-by David (Ming Qiang) Wu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1
-1@@ -1965,7 +1965,7 @@ static int vcn_v3_0_dec_msg(struct amdgpu_cs_parser *p, struct amdgpu_job *job, num_buffers = msg[2 ];/* Verify that all indices fit within the claimed length. Each index is 4 DWORDs */ -if (num_buffers > len_dw ||6 + num_buffers *4 > len_dw) { +if ((uint64_t )6 + (uint64_t )num_buffers *4 > len_dw) {DRM_ERROR ("VCN message has too many buffers!\n" ); r = -EINVAL ; goto out;drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1
-2@@ -1881,7 +1881,7 @@ static int vcn_v4_0_dec_msg(struct amdgpu_cs_parser *p, struct amdgpu_job *job, num_buffers = msg[2 ];/* Verify that all indices fit within the claimed length. Each index is 4 DWORDs */ -if (num_buffers > len_dw ||6 + num_buffers *4 > len_dw) { +if ((uint64_t )6 + (uint64_t )num_buffers *4 > len_dw) {DRM_ERROR ("VCN message has too many buffers!\n" ); r = -EINVAL ; goto out; --2.43.0