Skip to content

Commit 8891adc

Browse files
amlutotorvalds
authored andcommitted
selftests/x86/test_vsyscall: Improve the process_vm_readv() test
The existing code accepted process_vm_readv() success or failure as long as it didn't return garbage. This is too weak: if the vsyscall page is readable, then process_vm_readv() should succeed and, if the page is not readable, then it should fail. Signed-off-by: Andy Lutomirski <luto@kernel.org> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: x86@kernel.org Cc: Peter Zijlstra <peterz@infradead.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Jann Horn <jannh@google.com> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9fa2dd9 commit 8891adc

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

‎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)