Skip to contentSkip to conversation

gem: fix "refcount_t: underflow; use-after-free"

RFC In review Karol Herbst 2 participants 2 messages Oct 6, 2020 – Oct 7, 2020 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

RFC 1/1 gem: fix "refcount_t: underflow; use-after-free"

we can't use nouveau_bo_ref here as no ttm object was allocated and nouveau_bo_ref mainly deals with that. Simply deallocate the object.

---
 drm/nouveau/nouveau_gem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drm/nouveau/nouveau_gem.c +2 -1
index e11303fbc..45582a8dc 100644
@@ -198,7 +198,8 @@ nouveau_gem_new(struct nouveau_cli *cli, u64 size, int align, uint32_t domain,
 	 * to the caller, instead of a normal nouveau_bo ttm reference. */
 	ret = drm_gem_object_init(drm->dev, &nvbo->bo.base, size);
 	if (ret) {
-		nouveau_bo_ref(NULL, &nvbo);
+		drm_gem_object_release(&nvbo->bo.base);
+		kfree(nvbo);
 		return ret;
 	}
 
Signature · 1 line
2.26.2

A message that is not in the archive (sent off-list or not yet received): 20201006220809.14240-1-kherbst-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#2 lore raw
Quoted 3 lines · Karol Herbst

we can't use nouveau_bo_ref here as no ttm object was allocated and nouveau_bo_ref mainly deals with that. Simply deallocate the object.

I suspect this was fallout from when that whole process was split into stages, seems reasonable to me, applied.

Ben.

Quoted 27 lines
---
 drm/nouveau/nouveau_gem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drm/nouveau/nouveau_gem.c +2 -2
index e11303fbc..45582a8dc 100644
@@ -198,7 +198,8 @@ nouveau_gem_new(struct nouveau_cli *cli, u64 size, int align, uint32_t domain,
         * to the caller, instead of a normal nouveau_bo ttm reference. */
        ret = drm_gem_object_init(drm->dev, &nvbo->bo.base, size);
        if (ret) {
-               nouveau_bo_ref(NULL, &nvbo);
+               drm_gem_object_release(&nvbo->bo.base);
+               kfree(nvbo);
                return ret;
        }
 
--

2.26.2

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