29
29
#include <errno.h>
30
30
#include <sched.h>
31
31
#include <signal.h>
32
+ #include <stdbool.h>
32
33
#include <stdint.h>
33
34
#include <stdio.h>
34
35
#include <string.h>
35
36
#include <stdlib.h>
36
37
#include <sys/mount.h>
37
38
#include <sys/types.h>
38
39
#include <sys/stat.h>
40
+ #include <sys/wait.h>
39
41
#include <fcntl.h>
40
42
#include <unistd.h>
41
43
#include <sys/syscall.h>
42
44
#include <sys/uio.h>
43
45
#include <linux/kdev_t.h>
46
+ #include <sys/time.h>
47
+ #include <sys/resource.h>
44
48
45
49
static inline long sys_execveat (int dirfd , const char * pathname , char * * argv , char * * envp , int flags )
46
50
{
@@ -205,12 +209,44 @@ static int make_exe(const uint8_t *payload, size_t len)
205
209
}
206
210
#endif
207
211
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
+
208
217
#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
+
209
243
int main (void )
210
244
{
211
245
int pipefd [2 ];
212
246
int exec_fd ;
213
247
248
+ vsyscall ();
249
+
214
250
atexit (ate );
215
251
216
252
make_private_tmp ();
@@ -261,9 +297,9 @@ int main(void)
261
297
snprintf (buf0 + MAPS_OFFSET , sizeof (buf0 ) - MAPS_OFFSET ,
262
298
"/tmp/#%llu (deleted)\n" , (unsigned long long )st .st_ino );
263
299
264
-
265
300
/* Test /proc/$PID/maps */
266
301
{
302
+ const size_t len = strlen (buf0 ) + (g_vsyscall ? strlen (str_vsyscall ) : 0 );
267
303
char buf [256 ];
268
304
ssize_t rv ;
269
305
int fd ;
@@ -274,13 +310,16 @@ int main(void)
274
310
return 1 ;
275
311
}
276
312
rv = read (fd , buf , sizeof (buf ));
277
- assert (rv == strlen ( buf0 ) );
313
+ assert (rv == len );
278
314
assert (memcmp (buf , buf0 , strlen (buf0 )) == 0 );
315
+ if (g_vsyscall ) {
316
+ assert (memcmp (buf + strlen (buf0 ), str_vsyscall , strlen (str_vsyscall )) == 0 );
317
+ }
279
318
}
280
319
281
320
/* Test /proc/$PID/smaps */
282
321
{
283
- char buf [1024 ];
322
+ char buf [4096 ];
284
323
ssize_t rv ;
285
324
int fd ;
286
325
@@ -319,6 +358,10 @@ int main(void)
319
358
for (i = 0 ; i < sizeof (S )/sizeof (S [0 ]); i ++ ) {
320
359
assert (memmem (buf , rv , S [i ], strlen (S [i ])));
321
360
}
361
+
362
+ if (g_vsyscall ) {
363
+ assert (memmem (buf , rv , str_vsyscall , strlen (str_vsyscall )));
364
+ }
322
365
}
323
366
324
367
/* Test /proc/$PID/smaps_rollup */
0 commit comments