Skip to content

Commit 5316a01

Browse files
Alexey Dobriyanakpm00
authored andcommitted
proc: fix PIE proc-empty-vm, proc-pid-vm tests
vsyscall detection code uses direct call to the beginning of the vsyscall page: asm ("call %P0" :: "i" (0xffffffffff600000)) It generates "call rel32" instruction but it is not relocated if binary is PIE, so binary segfaults into random userspace address and vsyscall page status is detected incorrectly. Do more direct: asm ("call *%rax") which doesn't do need any relocaltions. Mark g_vsyscall as volatile for a good measure, I didn't find instruction setting it to 0. Now the code is obviously correct: xor eax, eax mov rdi, rbp mov rsi, rbp mov DWORD PTR [rip+0x2d15], eax # g_vsyscall = 0 mov rax, 0xffffffffff600000 call rax mov DWORD PTR [rip+0x2d02], 1 # g_vsyscall = 1 mov eax, DWORD PTR ds:0xffffffffff600000 mov DWORD PTR [rip+0x2cf1], 2 # g_vsyscall = 2 mov edi, [rip+0x2ceb] # exit(g_vsyscall) call exit Note: fixed proc-empty-vm test oopses 5.19.0-28-generic kernel but this is separate story. Link: https://lkml.kernel.org/r/Y7h2xvzKLg36DSq8@p183 Fixes: 5bc73bb ("proc: test how it holds up with mapping'less process") Signed-off-by: Alexey Dobriyan <[email protected]> Reported-by: Mirsad Goran Todorovac <[email protected]> Tested-by: Mirsad Goran Todorovac <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 8651a13 commit 5316a01

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

tools/testing/selftests/proc/proc-empty-vm.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#undef NDEBUG
2626
#include <assert.h>
2727
#include <errno.h>
28+
#include <stdint.h>
2829
#include <stdio.h>
2930
#include <stdlib.h>
3031
#include <string.h>
@@ -41,7 +42,7 @@
4142
* 1: vsyscall VMA is --xp vsyscall=xonly
4243
* 2: vsyscall VMA is r-xp vsyscall=emulate
4344
*/
44-
static int g_vsyscall;
45+
static volatile int g_vsyscall;
4546
static const char *g_proc_pid_maps_vsyscall;
4647
static const char *g_proc_pid_smaps_vsyscall;
4748

@@ -147,11 +148,12 @@ static void vsyscall(void)
147148

148149
g_vsyscall = 0;
149150
/* gettimeofday(NULL, NULL); */
151+
uint64_t rax = 0xffffffffff600000;
150152
asm volatile (
151-
"call %P0"
152-
:
153-
: "i" (0xffffffffff600000), "D" (NULL), "S" (NULL)
154-
: "rax", "rcx", "r11"
153+
"call *%[rax]"
154+
: [rax] "+a" (rax)
155+
: "D" (NULL), "S" (NULL)
156+
: "rcx", "r11"
155157
);
156158

157159
g_vsyscall = 1;

tools/testing/selftests/proc/proc-pid-vm.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,12 @@ static void vsyscall(void)
257257

258258
g_vsyscall = 0;
259259
/* gettimeofday(NULL, NULL); */
260+
uint64_t rax = 0xffffffffff600000;
260261
asm volatile (
261-
"call %P0"
262-
:
263-
: "i" (0xffffffffff600000), "D" (NULL), "S" (NULL)
264-
: "rax", "rcx", "r11"
262+
"call *%[rax]"
263+
: [rax] "+a" (rax)
264+
: "D" (NULL), "S" (NULL)
265+
: "rcx", "r11"
265266
);
266267

267268
g_vsyscall = 1;

0 commit comments

Comments
 (0)