From: Alex Williamson Date: Tue, 18 Feb 2025 22:22:01 +0000 (-0700) Subject: vfio/type1: Catch zero from pin_user_pages_remote() X-Git-Tag: v6.15-rc1~67^2~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=afe84f3b7a26037b258be0f0a1e1754fc1db37e8;p=thirdparty%2Fkernel%2Fstable.git vfio/type1: Catch zero from pin_user_pages_remote() pin_user_pages_remote() can currently return zero for invalid args or zero nr_pages, neither of which should ever happen. However vaddr_get_pfns() indicates it should only ever return a positive value or -errno and there's a theoretical case where this can slip through and be unhandled by callers. Therefore convert zero to -EFAULT. Reviewed-by: Peter Xu Reviewed-by: Mitchell Augustin Tested-by: Mitchell Augustin Reviewed-by: Jason Gunthorpe Link: https://lore.kernel.org/r/20250218222209.1382449-2-alex.williamson@redhat.com Signed-off-by: Alex Williamson --- diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 50ebc9593c9d7..119cf886d8c03 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -564,6 +564,8 @@ static int vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr, if (ret > 0) { *pfn = page_to_pfn(pages[0]); goto done; + } else if (!ret) { + ret = -EFAULT; } vaddr = untagged_addr_remote(mm, vaddr);