Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mshv: Fix error handling in mshv_region_pin

The current error handling has two issues:

First, pin_user_pages_fast() can return a short pin count (less than
requested but greater than zero) when it cannot pin all requested pages.
This is treated as success, leading to partially pinned regions being
used, which causes memory corruption.

Second, when an error occurs mid-loop, already pinned pages from the
current batch are not properly accounted for before calling
mshv_region_invalidate_pages(), causing a page reference leak.

Treat short pins as errors and fix partial batch accounting before
cleanup.

Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>

authored by

Stanislav Kinsburskii and committed by
Wei Liu
c0e296f2 b2ae73d9

+4 -2
+4 -2
drivers/hv/mshv_regions.c
··· 314 314 ret = pin_user_pages_fast(userspace_addr, nr_pages, 315 315 FOLL_WRITE | FOLL_LONGTERM, 316 316 pages); 317 - if (ret < 0) 317 + if (ret != nr_pages) 318 318 goto release_pages; 319 319 } 320 320 321 321 return 0; 322 322 323 323 release_pages: 324 + if (ret > 0) 325 + done_count += ret; 324 326 mshv_region_invalidate_pages(region, 0, done_count); 325 - return ret; 327 + return ret < 0 ? ret : -ENOMEM; 326 328 } 327 329 328 330 static int mshv_region_chunk_unmap(struct mshv_mem_region *region,