Skip to contentSkip to conversation

drm/radeon: Fix integer overflow in radeon_cs_parser_init

PATCH Superseded hackyzh002 2 participants 2 messages Apr 19, 2023

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

hackyzh002

author
#0 lore raw

PATCH 1/2 drm/radeon: Fix integer overflow in radeon_cs_parser_init

The type of size is unsigned, if size is 0x40000000, there will be an integer overflow, size will be zero after size *= sizeof(uint32_t), will cause uninitialized memory to be referenced later

---
 drivers/gpu/drm/radeon/radeon_cs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_cs.c +2 -2
index 46a27ebf4..472c29050 100644
@@ -270,7 +270,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
 {
 	struct drm_radeon_cs *cs = data;
 	uint64_t *chunk_array_ptr;
-	unsigned size, i;
+	u64 size, i;
 	u32 ring = RADEON_CS_RING_GFX;
 	s32 priority = 0;
 
@@ -347,7 +347,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
 				continue;
 		}
 
-		p->chunks[i].kdata = kvmalloc_array(size, sizeof(uint32_t), GFP_KERNEL);
+		p->chunks[i].kdata = kvcalloc(size, sizeof(uint32_t), GFP_KERNEL);
 		size *= sizeof(uint32_t);
 		if (p->chunks[i].kdata == NULL) {
 			return -ENOMEM;
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Am 19.04.23 um 06:24 schrieb hackyzh002:

Quoted 3 lines

The type of size is unsigned, if size is 0x40000000, there will be an integer overflow, size will be zero after size *= sizeof(uint32_t), will cause uninitialized memory to be referenced later

Well good catch, but this is actually harmless.

Userspace can control the memory which is referenced here anyway and since the size would be zero when copying anything back to userspace this is also not an information leak.

Quoted 11 lines
---
  drivers/gpu/drm/radeon/radeon_cs.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_cs.c +0 -0
index 46a27ebf4..472c29050 100644

drivers/gpu/drm/radeon/radeon_cs.c int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data) · line 273

Quoted 5 lines
drivers/gpu/drm/radeon/radeon_cs.c +1 -1
@@ -270,7 +270,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
  {
  	struct drm_radeon_cs *cs = data;
  	uint64_t *chunk_array_ptr;
-	unsigned size, i;
+	u64 size, i;

Please use size_t for size only and not "i".

drivers/gpu/drm/radeon/radeon_cs.c int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data) · line 350

Quoted 9 lines
drivers/gpu/drm/radeon/radeon_cs.c +1 -1
  	u32 ring = RADEON_CS_RING_GFX;
  	s32 priority = 0;
 
@@ -347,7 +347,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
  				continue;
  		}
 
-		p->chunks[i].kdata = kvmalloc_array(size, sizeof(uint32_t), GFP_KERNEL);
+		p->chunks[i].kdata = kvcalloc(size, sizeof(uint32_t), GFP_KERNEL);

Please drop that chunk.

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/radeon/radeon_cs.c +0 -0
  		size *= sizeof(uint32_t);
  		if (p->chunks[i].kdata == NULL) {
  			return -ENOMEM;