]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
vfio/type1: Catch zero from pin_user_pages_remote()
authorAlex Williamson <alex.williamson@redhat.com>
Tue, 18 Feb 2025 22:22:01 +0000 (15:22 -0700)
committerAlex Williamson <alex.williamson@redhat.com>
Thu, 27 Feb 2025 18:55:39 +0000 (11:55 -0700)
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 <peterx@redhat.com>
Reviewed-by: Mitchell Augustin <mitchell.augustin@canonical.com>
Tested-by: Mitchell Augustin <mitchell.augustin@canonical.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20250218222209.1382449-2-alex.williamson@redhat.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/vfio_iommu_type1.c

index 50ebc9593c9d706eb264c2ce7e566555253d72f8..119cf886d8c039404cc4876927f15eced5f7f8f1 100644 (file)
@@ -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);