Skip to content

Commit f4068af

Browse files
Brian Fosterakpm00
authored andcommitted
proc: save LOC in vsyscall test
Do one fork in vsyscall detection code and let SIGSEGV handler exit and carry information to the parent saving LOC. [[email protected]: redo original patch, delete unnecessary variables, minimise code changes] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Alexey Dobriyan <[email protected]> Signed-off-by: Brian Foster <[email protected]> Reviewed-by: Brian Foster <[email protected]> Tested-by: Brian Foster <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 4f1d2a0 commit f4068af

File tree

1 file changed

+16
-40
lines changed

1 file changed

+16
-40
lines changed

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

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -213,22 +213,22 @@ static int make_exe(const uint8_t *payload, size_t len)
213213

214214
/*
215215
* 0: vsyscall VMA doesn't exist vsyscall=none
216-
* 1: vsyscall VMA is r-xp vsyscall=emulate
217-
* 2: vsyscall VMA is --xp vsyscall=xonly
216+
* 1: vsyscall VMA is --xp vsyscall=xonly
217+
* 2: vsyscall VMA is r-xp vsyscall=emulate
218218
*/
219-
static int g_vsyscall;
219+
static volatile int g_vsyscall;
220220
static const char *str_vsyscall;
221221

222222
static const char str_vsyscall_0[] = "";
223223
static const char str_vsyscall_1[] =
224-
"ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]\n";
225-
static const char str_vsyscall_2[] =
226224
"ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]\n";
225+
static const char str_vsyscall_2[] =
226+
"ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]\n";
227227

228228
#ifdef __x86_64__
229229
static void sigaction_SIGSEGV(int _, siginfo_t *__, void *___)
230230
{
231-
_exit(1);
231+
_exit(g_vsyscall);
232232
}
233233

234234
/*
@@ -255,52 +255,28 @@ static void vsyscall(void)
255255
act.sa_sigaction = sigaction_SIGSEGV;
256256
(void)sigaction(SIGSEGV, &act, NULL);
257257

258+
g_vsyscall = 0;
258259
/* gettimeofday(NULL, NULL); */
259260
asm volatile (
260261
"call %P0"
261262
:
262263
: "i" (0xffffffffff600000), "D" (NULL), "S" (NULL)
263264
: "rax", "rcx", "r11"
264265
);
265-
exit(0);
266-
}
267-
waitpid(pid, &wstatus, 0);
268-
if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == 0) {
269-
/* vsyscall page exists and is executable. */
270-
} else {
271-
/* vsyscall page doesn't exist. */
272-
g_vsyscall = 0;
273-
return;
274-
}
275-
276-
pid = fork();
277-
if (pid < 0) {
278-
fprintf(stderr, "fork, errno %d\n", errno);
279-
exit(1);
280-
}
281-
if (pid == 0) {
282-
struct rlimit rlim = {0, 0};
283-
(void)setrlimit(RLIMIT_CORE, &rlim);
284-
285-
/* Hide "segfault at ffffffffff600000" messages. */
286-
struct sigaction act;
287-
memset(&act, 0, sizeof(struct sigaction));
288-
act.sa_flags = SA_SIGINFO;
289-
act.sa_sigaction = sigaction_SIGSEGV;
290-
(void)sigaction(SIGSEGV, &act, NULL);
291266

267+
g_vsyscall = 1;
292268
*(volatile int *)0xffffffffff600000UL;
293-
exit(0);
269+
270+
g_vsyscall = 2;
271+
exit(g_vsyscall);
294272
}
295273
waitpid(pid, &wstatus, 0);
296-
if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == 0) {
297-
/* vsyscall page is readable and executable. */
298-
g_vsyscall = 1;
299-
return;
274+
if (WIFEXITED(wstatus)) {
275+
g_vsyscall = WEXITSTATUS(wstatus);
276+
} else {
277+
fprintf(stderr, "error: wstatus %08x\n", wstatus);
278+
exit(1);
300279
}
301-
302-
/* vsyscall page is executable but unreadable. */
303-
g_vsyscall = 2;
304280
}
305281

306282
int main(void)

0 commit comments

Comments
 (0)