Skip to contentSkip to conversation

accel/amdxdna: Validate command buffer payload count

PATCH In review Lizhi Hou 2 participants 2 messages Feb 19 – Feb 20

Subsystems (2)
lore
Share & tools
lore

Lizhi Hou

author maintainer
#0 lore raw

PATCH 1/1 accel/amdxdna: Validate command buffer payload count

The count field in the command header is used to determine the valid payload size. Verify that the valid payload does not exceed the remaining buffer space.

Fixes aac243092b70 ("accel/amdxdna: Add command execution")
---
 drivers/accel/amdxdna/amdxdna_ctx.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/amdxdna_ctx.c +4 -1
index d17aef89a0ad..cf4d3af67bf7 100644
@@ -104,7 +104,10 @@ void *amdxdna_cmd_get_payload(struct amdxdna_gem_obj *abo, u32 *size)
 
 	if (size) {
 		count = FIELD_GET(AMDXDNA_CMD_COUNT, cmd->header);
-		if (unlikely(count <= num_masks)) {
+		if (unlikely(count <= num_masks ||
+			     count * sizeof(u32) +
+			     offsetof(struct amdxdna_cmd, data[0]) >
+			     abo->mem.size)) {
 			*size = 0;
 			return NULL;
 		}
Signature · 1 line
2.34.1
#1 lore raw
Quoted 6 lines · Lizhi Hou

The count field in the command header is used to determine the valid payload size. Verify that the valid payload does not exceed the remaining buffer space.

Fixes aac243092b70 ("accel/amdxdna: Add command execution")
Quoted 20 lines
---
  drivers/accel/amdxdna/amdxdna_ctx.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/amdxdna_ctx.c +4 -1
index d17aef89a0ad..cf4d3af67bf7 100644
@@ -104,7 +104,10 @@ void *amdxdna_cmd_get_payload(struct amdxdna_gem_obj *abo, u32 *size)
 
  	if (size) {
  		count = FIELD_GET(AMDXDNA_CMD_COUNT, cmd->header);
-		if (unlikely(count <= num_masks)) {
+		if (unlikely(count <= num_masks ||
+			     count * sizeof(u32) +
+			     offsetof(struct amdxdna_cmd, data[0]) >
+			     abo->mem.size)) {
  			*size = 0;
  			return NULL;
  		}