diff options
Diffstat (limited to 'tools/testing/selftests/x86/test_vsyscall.c')
| -rw-r--r-- | tools/testing/selftests/x86/test_vsyscall.c | 22 | 
1 files changed, 14 insertions, 8 deletions
| diff --git a/tools/testing/selftests/x86/test_vsyscall.c b/tools/testing/selftests/x86/test_vsyscall.c index 7a744fa7b786..0b4f1cc2291c 100644 --- a/tools/testing/selftests/x86/test_vsyscall.c +++ b/tools/testing/selftests/x86/test_vsyscall.c @@ -33,6 +33,9 @@  # endif  #endif +/* max length of lines in /proc/self/maps - anything longer is skipped here */ +#define MAPS_LINE_LEN 128 +  static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),  		       int flags)  { @@ -98,7 +101,7 @@ static int init_vsys(void)  #ifdef __x86_64__  	int nerrs = 0;  	FILE *maps; -	char line[128]; +	char line[MAPS_LINE_LEN];  	bool found = false;  	maps = fopen("/proc/self/maps", "r"); @@ -108,10 +111,12 @@ static int init_vsys(void)  		return 0;  	} -	while (fgets(line, sizeof(line), maps)) { +	while (fgets(line, MAPS_LINE_LEN, maps)) {  		char r, x;  		void *start, *end; -		char name[128]; +		char name[MAPS_LINE_LEN]; + +		/* sscanf() is safe here as strlen(name) >= strlen(line) */  		if (sscanf(line, "%p-%p %c-%cp %*x %*x:%*x %*u %s",  			   &start, &end, &r, &x, name) != 5)  			continue; @@ -445,7 +450,7 @@ static void sigtrap(int sig, siginfo_t *info, void *ctx_void)  		num_vsyscall_traps++;  } -static int test_native_vsyscall(void) +static int test_emulation(void)  {  	time_t tmp;  	bool is_native; @@ -453,7 +458,7 @@ static int test_native_vsyscall(void)  	if (!vtime)  		return 0; -	printf("[RUN]\tchecking for native vsyscall\n"); +	printf("[RUN]\tchecking that vsyscalls are emulated\n");  	sethandler(SIGTRAP, sigtrap, 0);  	set_eflags(get_eflags() | X86_EFLAGS_TF);  	vtime(&tmp); @@ -469,11 +474,12 @@ static int test_native_vsyscall(void)  	 */  	is_native = (num_vsyscall_traps > 1); -	printf("\tvsyscalls are %s (%d instructions in vsyscall page)\n", +	printf("[%s]\tvsyscalls are %s (%d instructions in vsyscall page)\n", +	       (is_native ? "FAIL" : "OK"),  	       (is_native ? "native" : "emulated"),  	       (int)num_vsyscall_traps); -	return 0; +	return is_native;  }  #endif @@ -493,7 +499,7 @@ int main(int argc, char **argv)  	nerrs += test_vsys_r();  #ifdef __x86_64__ -	nerrs += test_native_vsyscall(); +	nerrs += test_emulation();  #endif  	return nerrs ? 1 : 0; | 

