Skip to content

Commit 07f24dc

Browse files
amlutosuryasaimadhu
authored andcommitted
selftests/x86/vdso: Fix no-vDSO segfaults
test_vdso would try to call a NULL pointer if the vDSO was missing. vdso_restorer_32 hit a genuine failure: trying to use the kernel-provided signal restorer doesn't work if the vDSO is missing. Skip the test if the vDSO is missing, since the test adds no particular value in that case. Reported-by: kbuild test robot <[email protected]> Signed-off-by: Andy Lutomirski <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/618ea7b8c55b10d08b1cb139e9a3a957934b8647.1584653439.git.luto@kernel.org
1 parent fb33c65 commit 07f24dc

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tools/testing/selftests/x86/test_vdso.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ static void test_one_clock_gettime(int clock, const char *name)
259259

260260
static void test_clock_gettime(void)
261261
{
262+
if (!vdso_clock_gettime) {
263+
printf("[SKIP]\tNo vDSO, so skipping clock_gettime() tests\n");
264+
return;
265+
}
266+
262267
for (int clock = 0; clock < sizeof(clocknames) / sizeof(clocknames[0]);
263268
clock++) {
264269
test_one_clock_gettime(clock, clocknames[clock]);

tools/testing/selftests/x86/vdso_restorer.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <err.h>
1717
#include <stdio.h>
18+
#include <dlfcn.h>
1819
#include <string.h>
1920
#include <signal.h>
2021
#include <unistd.h>
@@ -46,11 +47,23 @@ int main()
4647
int nerrs = 0;
4748
struct real_sigaction sa;
4849

50+
void *vdso = dlopen("linux-vdso.so.1",
51+
RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
52+
if (!vdso)
53+
vdso = dlopen("linux-gate.so.1",
54+
RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
55+
if (!vdso) {
56+
printf("[SKIP]\tFailed to find vDSO. Tests are not expected to work.\n");
57+
return 0;
58+
}
59+
4960
memset(&sa, 0, sizeof(sa));
5061
sa.handler = handler_with_siginfo;
5162
sa.flags = SA_SIGINFO;
5263
sa.restorer = NULL; /* request kernel-provided restorer */
5364

65+
printf("[RUN]\tRaise a signal, SA_SIGINFO, sa.restorer == NULL\n");
66+
5467
if (syscall(SYS_rt_sigaction, SIGUSR1, &sa, NULL, 8) != 0)
5568
err(1, "raw rt_sigaction syscall");
5669

@@ -63,6 +76,8 @@ int main()
6376
nerrs++;
6477
}
6578

79+
printf("[RUN]\tRaise a signal, !SA_SIGINFO, sa.restorer == NULL\n");
80+
6681
sa.flags = 0;
6782
sa.handler = handler_without_siginfo;
6883
if (syscall(SYS_sigaction, SIGUSR1, &sa, 0) != 0)

0 commit comments

Comments
 (0)