Skip to contentSkip to conversation

drm/amdgpu/vcn3: Avoid overflow on msg bound check

PATCH In review Benjamin Cheng 2 participants 3 messages Apr 13 – Apr 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu/vcn3: Avoid overflow on msg bound check

As pointed out by SDL, the previous condition may be vulnerable to overflow.

Fixes fbc309508fae ("drm/amdgpu/vcn3: Prevent OOB reads when parsing dec msg")
---
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +3 -1
index 6fb4fcdbba4f..2fe5b3fe287f 100644
@@ -1972,6 +1972,7 @@ static int vcn_v3_0_dec_msg(struct amdgpu_cs_parser *p, struct amdgpu_job *job,
 
 	for (i = 0, msg = &msg[6]; i < num_buffers; ++i, msg += 4) {
 		uint32_t offset, size, *create;
+		uint64_t buf_end;
 
 		if (msg[0] != RDECODE_MESSAGE_CREATE)
 			continue;
@@ -1979,7 +1980,8 @@ static int vcn_v3_0_dec_msg(struct amdgpu_cs_parser *p, struct amdgpu_job *job,
 		offset = msg[1];
 		size = msg[2];
 
-		if (size < 4 || offset + size > end - addr) {
+		if (size < 4 || check_add_overflow(offset, size, &buf_end) ||
+		    buf_end > end - addr) {
 			DRM_ERROR("VCN message buffer exceeds BO bounds!\n");
 			r = -EINVAL;
 			goto out;
Signature · 1 line
2.53.0
#1 lore raw

PATCH 2/2 drm/amdgpu/vcn4: Avoid overflow on msg bound check

As pointed out by SDL, the previous condition may be vulnerable to overflow.

Fixes f405753b0751 ("drm/amdgpu/vcn4: Prevent OOB reads when parsing dec msg")
---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +3 -1
index 5dec92691f73..63d37b475c2c 100644
@@ -1889,6 +1889,7 @@ static int vcn_v4_0_dec_msg(struct amdgpu_cs_parser *p, struct amdgpu_job *job,
 
 	for (i = 0, msg = &msg[6]; i < num_buffers; ++i, msg += 4) {
 		uint32_t offset, size, *create;
+		uint64_t buf_end;
 
 		if (msg[0] != RDECODE_MESSAGE_CREATE)
 			continue;
@@ -1896,7 +1897,8 @@ static int vcn_v4_0_dec_msg(struct amdgpu_cs_parser *p, struct amdgpu_job *job,
 		offset = msg[1];
 		size = msg[2];
 
-		if (size < 4 || offset + size > end - addr) {
+		if (size < 4 || check_add_overflow(offset, size, &buf_end) ||
+		    buf_end > end - addr) {
 			DRM_ERROR("VCN message buffer exceeds BO bounds!\n");
 			r = -EINVAL;
 			goto out;
Signature · 1 line
2.53.0
#2 lore raw

RE: [PATCH 2/2] drm/amdgpu/vcn4: Avoid overflow on msg bound check

AMD General

The series is
Reviewed-by: Ruijing Dong <[email protected]>

Thanks,
Ruijing

-----Original Message-----
From: Benjamin Cheng <[email protected]>
Sent: Monday, April 13, 2026 10:21 AM
To: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Cc: Wu, David <[email protected]>; Dong, Ruijing <[email protected]>; Liu, Leo <[email protected]>; Cheng, Benjamin <[email protected]>; SDL <[email protected]>
Subject: [PATCH 2/2] drm/amdgpu/vcn4: Avoid overflow on msg bound check

As pointed out by SDL, the previous condition may be vulnerable to overflow.

Fixes f405753b0751 ("drm/amdgpu/vcn4: Prevent OOB reads when parsing dec msg")
---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +3 -1
index 5dec92691f73..63d37b475c2c 100644
@@ -1889,6 +1889,7 @@ static int vcn_v4_0_dec_msg(struct amdgpu_cs_parser *p, struct amdgpu_job *job,
 
        for (i = 0, msg = &msg[6]; i < num_buffers; ++i, msg += 4) {
                uint32_t offset, size, *create;
+               uint64_t buf_end;
 
                if (msg[0] != RDECODE_MESSAGE_CREATE)
                        continue;
@@ -1896,7 +1897,8 @@ static int vcn_v4_0_dec_msg(struct amdgpu_cs_parser *p, struct amdgpu_job *job,
                offset = msg[1];
                size = msg[2];
 
-               if (size < 4 || offset + size > end - addr) {
+               if (size < 4 || check_add_overflow(offset, size, &buf_end) ||
+                   buf_end > end - addr) {
                        DRM_ERROR("VCN message buffer exceeds BO bounds!\n");
                        r = -EINVAL;
                        goto out;

--
2.53.0