drm/i915: Fix vmap_batch page iterator overrun
Subsystems (2)
PATCH 1/1 drm/i915: Fix vmap_batch page iterator overrun
vmap_batch() calculates amount of needed pages for the mapping we are going to create. And it uses this page count as an argument for the for_each_sg_pages() macro. The macro takes the number of sg list entities as an argument, not the page count. So we ended up iterating through all the pages on the mapped object, corrupting memory past the smaller pages[] array.
Fix this by bailing out when we have enough pages.
--- drivers/gpu/drm/i915/i915_cmd_parser.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_cmd_parser.c +4 -1
@@ -836,8 +836,11 @@ static u32 *vmap_batch(struct drm_i915_gem_object *obj, } i =0 ; -for_each_sg_page (obj->pages->sgl, &sg_iter, npages, first_page) +for_each_sg_page (obj->pages->sgl, &sg_iter, obj->pages->nents, first_page) { pages[i++] =sg_page_iter_page (&sg_iter); +if (i == npages) +break ; + } addr =vmap (pages, i,0 ,PAGE_KERNEL );if (addr ==NULL ) {
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 20 lines · Mika Kuoppala
vmap_batch()calculates amount of needed pages for the mapping we are going to create. And it uses this page count as an argument for thefor_each_sg_pages()macro. The macro takes the number of sg list entities as an argument, not the page count. So we ended up iterating through all the pages on the mapped object, corrupting memory past the smaller pages[] array.Fix this by bailing out when we have enough pages.
Cc Chris Wilson <[email protected]>Signed-off-by Mika Kuoppala <[email protected]>--- drivers/gpu/drm/i915/i915_cmd_parser.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/i915_cmd_parser.c +0
-0
drivers/gpu/drm/i915/i915_cmd_parser.c static u32 *vmap_batch(struct drm_i915_gem_object *obj, · line 843
Quoted 9 lines
drivers/gpu/drm/i915/i915_cmd_parser.c +4
-1@@ -836,8 +836,11 @@ static u32 *vmap_batch(struct drm_i915_gem_object *obj, } i =0 ; -for_each_sg_page (obj->pages->sgl, &sg_iter, npages, first_page) +for_each_sg_page (obj->pages->sgl, &sg_iter, obj->pages->nents, first_page) { pages[i++] =sg_page_iter_page (&sg_iter); +if (i == npages) +break ; + }
Are you sure this manual check is needed now that you fixed for_each_sg_page?
Pages array looks pessimistically big enough so I don't see that memory was getting overwritten. It looks more like our sg table was not properly terminated which made for_each_sg_page go into random memory and return random page pointers.
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 11 lines · Mika Kuoppala
vmap_batch()calculates amount of needed pages for the mapping we are going to create. And it uses this page count as an argument for thefor_each_sg_pages()macro. The macro takes the number of sg list entities as an argument, not the page count. So we ended up iterating through all the pages on the mapped object, corrupting memory past the smaller pages[] array.Fix this by bailing out when we have enough pages.
Cc Chris Wilson <[email protected]>Signed-off-by Mika Kuoppala <[email protected]>
Can I ask for a st_for_each_page(&obj->pages, &sg_iter, n)?
That would simplify all of our users, and stop me from making the same mistake again.
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Daniel Vetter
AppliedQuoted 9 lines · Chris Wilson
Quoted 8 lines · Mika Kuoppala
vmap_batch()calculates amount of needed pages for the mapping we are going to create. And it uses this page count as an argument for thefor_each_sg_pages()macro. The macro takes the number of sg list entities as an argument, not the page count. So we ended up iterating through all the pages on the mapped object, corrupting memory past the smaller pages[] array.Fix this by bailing out when we have enough pages.
Reference to the commit which has introduced this regression is missing, I've added that. Also for next time around pls cc everyone on that patch, especially also reviewers.
Quoted 4 lines
Quoted 3 lines
Cc Chris Wilson <[email protected]>Signed-off-by Mika Kuoppala <[email protected]>Reviewed-by Chris Wilson <[email protected]>
Queued for -next, thanks for the patch.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Task id: 5947 -------------------------------------Summary-------------------------------------
Platform Delta drm-intel-nightly Series Applied
PNV 276/276 276/276 ILK 303/303 303/303 SNB 279/279 279/279 IVB 343/343 343/343 BYT 287/287 287/287 HSW 363/363 363/363 BDW 308/308 308/308
-------------------------------------Detailed-------------------------------------
Platform Test drm-intel-nightly Series Applied
Note: You need to pay more attention to line start with '*'
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx