Skip to content

Commit 8381979

Browse files
committed
Merge branch 'gate-page-refcount' (patches from Dave Hansen)
Merge gate page refcount fix from Dave Hansen: "During the conversion over to pin_user_pages(), gate pages were missed. The fix is pretty simple, and is accompanied by a new test from Andy which probably would have caught this earlier" * emailed patches from Dave Hansen <dave.hansen@linux.intel.com>: selftests/x86/test_vsyscall: Improve the process_vm_readv() test mm: fix pin vs. gup mismatch with gate pages
2 parents e28f010 + 8891adc commit 8381979

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎mm/gup.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ static int get_gate_page(struct mm_struct *mm, unsigned long address,
843843
goto unmap;
844844
*page = pte_page(*pte);
845845
}
846-
if (unlikely(!try_get_page(*page))) {
846+
if (unlikely(!try_grab_page(*page, gup_flags))) {
847847
ret = -ENOMEM;
848848
goto unmap;
849849
}

‎tools/testing/selftests/x86/test_vsyscall.c‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,17 @@ static int test_vsys_x(void)
462462
return 0;
463463
}
464464

465+
/*
466+
* Debuggers expect ptrace() to be able to peek at the vsyscall page.
467+
* Use process_vm_readv() as a proxy for ptrace() to test this. We
468+
* want it to work in the vsyscall=emulate case and to fail in the
469+
* vsyscall=xonly case.
470+
*
471+
* It's worth noting that this ABI is a bit nutty. write(2) can't
472+
* read from the vsyscall page on any kernel version or mode. The
473+
* fact that ptrace() ever worked was a nice courtesy of old kernels,
474+
* but the code to support it is fairly gross.
475+
*/
465476
static int test_process_vm_readv(void)
466477
{
467478
#ifdef __x86_64__
@@ -477,8 +488,12 @@ static int test_process_vm_readv(void)
477488
remote.iov_len = 4096;
478489
ret = process_vm_readv(getpid(), &local, 1, &remote, 1, 0);
479490
if (ret != 4096) {
480-
printf("[OK]\tprocess_vm_readv() failed (ret = %d, errno = %d)\n", ret, errno);
481-
return 0;
491+
/*
492+
* We expect process_vm_readv() to work if and only if the
493+
* vsyscall page is readable.
494+
*/
495+
printf("[%s]\tprocess_vm_readv() failed (ret = %d, errno = %d)\n", vsyscall_map_r ? "FAIL" : "OK", ret, errno);
496+
return vsyscall_map_r ? 1 : 0;
482497
}
483498

484499
if (vsyscall_map_r) {
@@ -488,6 +503,9 @@ static int test_process_vm_readv(void)
488503
printf("[FAIL]\tIt worked but returned incorrect data\n");
489504
return 1;
490505
}
506+
} else {
507+
printf("[FAIL]\tprocess_rm_readv() succeeded, but it should have failed in this configuration\n");
508+
return 1;
491509
}
492510
#endif
493511

0 commit comments

Comments
 (0)