HomeFreeBSD

linuxkpi: Fix __sg_alloc_table_from_pages loop

Description

linuxkpi: Fix __sg_alloc_table_from_pages loop

Commit 3e0856b63fe0e375a0951e05c2ef98bb2ebd9421 updated
__sg_alloc_table_from_pages to use the same API as linux, but modified
the loop condition when going over the pages in a sg list. Part of the
change included moving the sg_next call out of the for loop and into the
body, which causes an off by one error when traversing the list. Since
sg_next is called before the loop body it will skip the first element
and read one past the last element.

This caused panics when running PRIME with nvidia-drm as the off-by-one
issue causes a NULL dereference.

Reviewed by: bz, hselasky
Differential Revision: https://reviews.freebsd.org/D39628
Fixes: 3e0856b63fe0 ("linuxkpi: Fix sg_alloc_table_from_pages() to have the same API as Linux")

Details

Provenance
ashafer_badland.ioAuthored on Apr 21 2023, 7:56 AM
manuCommitted on Apr 21 2023, 7:56 AM
Reviewer
bz
Differential Revision
D39628: linuxkpi: Fix __sg_alloc_table_from_pages loop
Parents
rG9abba78acc2a: syscalls: regenerate
Branches
Unknown
Tags
Unknown