1 /*
2 * mmap() call with MAP_FIXED flag does not guarantee that the allocated memory
3 * region is not overlapped with the previously existant mappings. According to
4 * POSIX, old mappings are silently discarded. There is no generic way to
5 * detect overlap. If a silent overlap occurs, strange runtime errors might
6 * happen, because we might overlap stack, libraries, anything else.
7 *
8 * Since we always fork+exec same binary (filebench), theoretically all the
9 * mappings should be the same, so no overlap should happen. However, if
10 * virtual Address Space Layout Randomization (ASLR) is enabled on the target
11 * machine - overlap is very likely (especially if workload defines a lot of
12 * processes). We observed numerous segmentation faults on CentOS because of
13 * that.
14 *
15 * The function below disables ASLR in Linux. In future, more platform-specific
16 * functions should be added.
17 */
18
19 #include "config.h"
20 #if defined(HAVE_SYS_PERSONALITY_H)
21 #include <sys/personality.h>
22 #endif
23
24 #include "filebench.h"
25 #include "aslr.h"
26
27 #if defined(HAVE_SYS_PERSONALITY_H) && defined(HAVE_ADDR_NO_RANDOMIZE)
28 void
linux_disable_aslr()29 linux_disable_aslr()
30 {
31 int r;
32
33 (void) personality(0xffffffff);
34 r = personality(0xffffffff | ADDR_NO_RANDOMIZE);
35 if (r == -1)
36 filebench_log(LOG_ERROR, "Could not disable ASLR");
37 }
38 #else /* HAVE_SYS_PERSONALITY_H && HAVE_ADDR_NO_RANDOMIZE */
39 void
other_disable_aslr()40 other_disable_aslr()
41 {
42 filebench_log(LOG_INFO, "Per-process disabling of ASLR is not "
43 "supported on this system. "
44 "For Filebench to work properly, "
45 "disable ASLR manually for the whole system. "
46 "On Linux it can be achieved by "
47 "\"sysctl kernel.randomize_va_space=0\" command. "
48 "(the change does not persist across reboots)");
49 }
50 #endif /* HAVE_SYS_PERSONALITY_H && HAVE_ADDR_NO_RANDOMIZE */
51