Commit 9b73bde
drm/msm: Fix use-after-free in msm_gem with carveout
When using gem with vram carveout the page allocation is managed via
drm_mm. The necessary drm_mm_node is allocated in add_vma, but it is
referenced in msm_gem_object as well. It is freed before the drm_mm_node
has been deallocated leading to use-after-free on every single vram
allocation.
Currently put_iova is called before put_pages in both
msm_gem_free_object and msm_gem_purge:
put_iova -> del_vma -> kfree(vma) // vma holds drm_mm_node
/* later */
put_pages -> put_pages_vram -> drm_mm_remove_node(
msm_obj->vram_node)
// vram_node is a ref to
// drm_mm_node; in _msm_gem_new
It looks like del_vma does nothing else other than freeing the vma
object and removing it from it's list, so delaying the deletion should
be harmless.
This patch splits put_iova in put_iova_spaces and put_iova_vmas, so the
vma can be freed after the mm_node has been deallocated with the mm.
Note: The breaking commit separated the vma allocation from within
msm_gem_object to outside, so the vram_node reference became outside the
msm_gem_object allocation, and freeing order was therefore overlooked.
Fixes: 4b85f7f ("drm/msm: support for an arbitrary number of address spaces")
Signed-off-by: Iskren Chernev <iskren.chernev@gmail.com>
Signed-off-by: Rob Clark <robdclark@chromium.org>1 parent c58eb1b commit 9b73bde
1 file changed
+22
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
361 | | - | |
| 361 | + | |
362 | 362 | | |
363 | 363 | | |
364 | | - | |
| 364 | + | |
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
368 | | - | |
| 368 | + | |
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
373 | 386 | | |
374 | 387 | | |
375 | 388 | | |
| |||
697 | 710 | | |
698 | 711 | | |
699 | 712 | | |
700 | | - | |
| 713 | + | |
701 | 714 | | |
702 | 715 | | |
703 | 716 | | |
704 | 717 | | |
705 | 718 | | |
| 719 | + | |
| 720 | + | |
706 | 721 | | |
707 | 722 | | |
708 | 723 | | |
| |||
964 | 979 | | |
965 | 980 | | |
966 | 981 | | |
967 | | - | |
| 982 | + | |
968 | 983 | | |
969 | 984 | | |
970 | 985 | | |
| |||
987 | 1002 | | |
988 | 1003 | | |
989 | 1004 | | |
| 1005 | + | |
| 1006 | + | |
990 | 1007 | | |
991 | 1008 | | |
992 | 1009 | | |
| |||
0 commit comments