Skip to contentSkip to conversation

drm/nouveau: fix ramht wraparound

PATCH In review Marcin Slusarz 2 participants 3 messages Dec 20, 2012 – Dec 21, 2012 2 messages not in the archive

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

PATCH 1/1 drm/nouveau: fix ramht wraparound

When hash collision occurs and it's near ramht object boundary, we could read and possibly overwrite some memory after ramht object.

---
 drivers/gpu/drm/nouveau/core/core/ramht.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/core/core/ramht.c +1 -1
index 86a6404..6da314c 100644
@@ -59,7 +59,7 @@ nouveau_ramht_insert(struct nouveau_ramht *ramht, int chid,
 		}
 
 		co += 8;
-		if (co >= nv_gpuobj(ramht)->size)
+		if (co + 8 > nv_gpuobj(ramht)->size)
 			co = 0;
 	} while (co != ho);
 
Signature · 1 line
1.8.0.2

A message that is not in the archive (sent off-list or not yet received): 1356043034-25739-5-git-send-email-marcin.slusarz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw
Quoted 14 lines · Marcin Slusarz

When hash collision occurs and it's near ramht object boundary, we could read and possibly overwrite some memory after ramht object.

---
 drivers/gpu/drm/nouveau/core/core/ramht.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/core/core/ramht.c +0 -0
index 86a6404..6da314c 100644

drivers/gpu/drm/nouveau/core/core/ramht.c nouveau_ramht_insert(struct nouveau_ramht *ramht, int chid, · line 62

Quoted 5 lines
drivers/gpu/drm/nouveau/core/core/ramht.c +1 -1
@@ -59,7 +59,7 @@ nouveau_ramht_insert(struct nouveau_ramht *ramht, int chid,
 		}
 
 		co += 8;
-		if (co >= nv_gpuobj(ramht)->size)
+		if (co + 8 > nv_gpuobj(ramht)->size)

I might just be really tired, but, how exactly is the original wrong? The original could even just be (co == size) and still work correctly as far as I can tell.

Ben.

Quoted 10 lines
drivers/gpu/drm/nouveau/core/core/ramht.c +0 -0
 			co = 0;
 	} while (co != ho);
 
Signature · 6 lines
1.8.0.2

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): 20121221001548.GA3839-6RkuLLNOGXsZ315U/[email protected]

#4 lore raw
Quoted 17 lines · Ben Skeggs
Quoted 16 lines · Marcin Slusarz

When hash collision occurs and it's near ramht object boundary, we could read and possibly overwrite some memory after ramht object.

---
 drivers/gpu/drm/nouveau/core/core/ramht.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/core/core/ramht.c +0 -0
index 86a6404..6da314c 100644
@@ -59,7 +59,7 @@ nouveau_ramht_insert(struct nouveau_ramht *ramht, int chid,
 		}
 
Quoted 6 lines

drivers/gpu/drm/nouveau/core/core/ramht.c nouveau_ramht_insert(struct nouveau_ramht *ramht, int chid, · line 62

Quoted 3 lines
drivers/gpu/drm/nouveau/core/core/ramht.c +1 -1
 		co += 8;
-		if (co >= nv_gpuobj(ramht)->size)
+		if (co + 8 > nv_gpuobj(ramht)->size)

I might just be really tired, but, how exactly is the original wrong? The original could even just be (co == size) and still work correctly as far as I can tell.

Ah, crap, I didn't see that both hash value and ramht->size are divisible by 8. So original code is correct (although it relies on the above) and my version does not really fix anything.

Marcin