Skip to content

Commit 1741560

Browse files
Alexey Dobriyantorvalds
authored andcommitted
tools/testing/selftests/proc/proc-pid-vm.c: test with vsyscall in mind
: selftests: proc: proc-pid-vm : ======================================== : proc-pid-vm: proc-pid-vm.c:277: main: Assertion `rv == strlen(buf0)' failed. : Aborted Because the vsyscall mapping is enabled. Read from vsyscall page to tell if vsyscall is being used. Link: http://lkml.kernel.org/r/20190307183204.GA11405@avx2 Link: http://lkml.kernel.org/r/20190219094722.GB28258@shao2-debian Fixes: 34aab6b ("proc: test /proc/*/maps, smaps, smaps_rollup, statm") Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Reported-by: kernel test robot <rong.a.chen@intel.com> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ce82f19 commit 1741560

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

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

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,22 @@
2929
#include <errno.h>
3030
#include <sched.h>
3131
#include <signal.h>
32+
#include <stdbool.h>
3233
#include <stdint.h>
3334
#include <stdio.h>
3435
#include <string.h>
3536
#include <stdlib.h>
3637
#include <sys/mount.h>
3738
#include <sys/types.h>
3839
#include <sys/stat.h>
40+
#include <sys/wait.h>
3941
#include <fcntl.h>
4042
#include <unistd.h>
4143
#include <sys/syscall.h>
4244
#include <sys/uio.h>
4345
#include <linux/kdev_t.h>
46+
#include <sys/time.h>
47+
#include <sys/resource.h>
4448

4549
static inline long sys_execveat(int dirfd, const char *pathname, char **argv, char **envp, int flags)
4650
{
@@ -205,12 +209,44 @@ static int make_exe(const uint8_t *payload, size_t len)
205209
}
206210
#endif
207211

212+
static bool g_vsyscall = false;
213+
214+
static const char str_vsyscall[] =
215+
"ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]\n";
216+
208217
#ifdef __x86_64__
218+
/*
219+
* vsyscall page can't be unmapped, probe it with memory load.
220+
*/
221+
static void vsyscall(void)
222+
{
223+
pid_t pid;
224+
int wstatus;
225+
226+
pid = fork();
227+
if (pid < 0) {
228+
fprintf(stderr, "fork, errno %d\n", errno);
229+
exit(1);
230+
}
231+
if (pid == 0) {
232+
struct rlimit rlim = {0, 0};
233+
(void)setrlimit(RLIMIT_CORE, &rlim);
234+
*(volatile int *)0xffffffffff600000UL;
235+
exit(0);
236+
}
237+
wait(&wstatus);
238+
if (WIFEXITED(wstatus)) {
239+
g_vsyscall = true;
240+
}
241+
}
242+
209243
int main(void)
210244
{
211245
int pipefd[2];
212246
int exec_fd;
213247

248+
vsyscall();
249+
214250
atexit(ate);
215251

216252
make_private_tmp();
@@ -261,9 +297,9 @@ int main(void)
261297
snprintf(buf0 + MAPS_OFFSET, sizeof(buf0) - MAPS_OFFSET,
262298
"/tmp/#%llu (deleted)\n", (unsigned long long)st.st_ino);
263299

264-
265300
/* Test /proc/$PID/maps */
266301
{
302+
const size_t len = strlen(buf0) + (g_vsyscall ? strlen(str_vsyscall) : 0);
267303
char buf[256];
268304
ssize_t rv;
269305
int fd;
@@ -274,13 +310,16 @@ int main(void)
274310
return 1;
275311
}
276312
rv = read(fd, buf, sizeof(buf));
277-
assert(rv == strlen(buf0));
313+
assert(rv == len);
278314
assert(memcmp(buf, buf0, strlen(buf0)) == 0);
315+
if (g_vsyscall) {
316+
assert(memcmp(buf + strlen(buf0), str_vsyscall, strlen(str_vsyscall)) == 0);
317+
}
279318
}
280319

281320
/* Test /proc/$PID/smaps */
282321
{
283-
char buf[1024];
322+
char buf[4096];
284323
ssize_t rv;
285324
int fd;
286325

@@ -319,6 +358,10 @@ int main(void)
319358
for (i = 0; i < sizeof(S)/sizeof(S[0]); i++) {
320359
assert(memmem(buf, rv, S[i], strlen(S[i])));
321360
}
361+
362+
if (g_vsyscall) {
363+
assert(memmem(buf, rv, str_vsyscall, strlen(str_vsyscall)));
364+
}
322365
}
323366

324367
/* Test /proc/$PID/smaps_rollup */

0 commit comments

Comments
 (0)