Skip to contentSkip to conversation

nouveau/svm: Use struct_size() helper in nouveau_pfns_map()

PATCH In review Gustavo A. R. Silva 2 participants 2 messages Feb 7, 2022 – Feb 8, 2022

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

PATCH 1/1 nouveau/svm: Use struct_size() helper in nouveau_pfns_map()

Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worse scenario, could lead to heap overflows.

---
 drivers/gpu/drm/nouveau/nouveau_svm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/nouveau/nouveau_svm.c +2 -2
index 266809e511e2..46a5a1016e37 100644
@@ -925,8 +925,8 @@ nouveau_pfns_map(struct nouveau_svmm *svmm, struct mm_struct *mm,
 
 	mutex_lock(&svmm->mutex);
 
-	ret = nvif_object_ioctl(&svmm->vmm->vmm.object, args, sizeof(*args) +
-				npages * sizeof(args->p.phys[0]), NULL);
+	ret = nvif_object_ioctl(&svmm->vmm->vmm.object, args,
+				struct_size(args, p.phys, npages), NULL);
 
 	mutex_unlock(&svmm->mutex);
 }
Signature · 1 line
2.27.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Will push this to drm-misc-next, thanks!

Quoted 28 lines · Gustavo A. R. Silva

Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worse scenario, could lead to heap overflows.

---
 drivers/gpu/drm/nouveau/nouveau_svm.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/nouveau/nouveau_svm.c +0 -0
index 266809e511e2..46a5a1016e37 100644
@@ -925,8 +925,8 @@ nouveau_pfns_map(struct nouveau_svmm *svmm, struct
 mm_struct *mm,


        mutex_lock(&svmm->mutex);

-       ret = nvif_object_ioctl(&svmm->vmm->vmm.object, args, sizeof(*args) +
-                               npages * sizeof(args->p.phys[0]), NULL); +       ret = nvif_object_ioctl(&svmm->vmm->vmm.object, args,
+                               struct_size(args, p.phys, npages), NULL);
        mutex_unlock(&svmm->mutex);
 }

Signature · 3 lines
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat