Skip to content

Commit a81072a

Browse files
Souptick Joardergregkh
Souptick Joarder
authored andcommitted
misc: mic: scif: Fix error handling path
Inside __scif_pin_pages(), when map_flags != SCIF_MAP_KERNEL it will call pin_user_pages_fast() to map nr_pages. However, pin_user_pages_fast() might fail with a return value -ERRNO. The return value is stored in pinned_pages->nr_pages. which in turn is passed to unpin_user_pages(), which expects pinned_pages->nr_pages >=0, else disaster. Fix this by assigning pinned_pages->nr_pages to 0 if pin_user_pages_fast() returns -ERRNO. Fixes: ba612aa ("misc: mic: SCIF memory registration and unregistration") Cc: John Hubbard <[email protected]> Cc: Ira Weiny <[email protected]> Cc: Dan Carpenter <[email protected]> Reviewed-by: John Hubbard <[email protected]> Signed-off-by: Souptick Joarder <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a2e7408 commit a81072a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/misc/mic/scif/scif_rma.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,8 @@ int __scif_pin_pages(void *addr, size_t len, int *out_prot,
13921392
(prot & SCIF_PROT_WRITE) ? FOLL_WRITE : 0,
13931393
pinned_pages->pages);
13941394
if (nr_pages != pinned_pages->nr_pages) {
1395+
if (pinned_pages->nr_pages < 0)
1396+
pinned_pages->nr_pages = 0;
13951397
if (try_upgrade) {
13961398
if (ulimit)
13971399
__scif_dec_pinned_vm_lock(mm, nr_pages);
@@ -1408,7 +1410,6 @@ int __scif_pin_pages(void *addr, size_t len, int *out_prot,
14081410

14091411
if (pinned_pages->nr_pages < nr_pages) {
14101412
err = -EFAULT;
1411-
pinned_pages->nr_pages = nr_pages;
14121413
goto dec_pinned;
14131414
}
14141415

@@ -1421,7 +1422,6 @@ int __scif_pin_pages(void *addr, size_t len, int *out_prot,
14211422
__scif_dec_pinned_vm_lock(mm, nr_pages);
14221423
/* Something went wrong! Rollback */
14231424
error_unmap:
1424-
pinned_pages->nr_pages = nr_pages;
14251425
scif_destroy_pinned_pages(pinned_pages);
14261426
*pages = NULL;
14271427
dev_dbg(scif_info.mdev.this_device,

0 commit comments

Comments
 (0)