make -DC work with yama ptrace protection
This commit is contained in:
		
							parent
							
								
									bee4fc54e7
								
							
						
					
					
						commit
						121448ceb9
					
				
					 1 changed files with 20 additions and 0 deletions
				
			
		
							
								
								
									
										20
									
								
								src/main.c
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								src/main.c
									
										
									
									
									
								
							|  | @ -30,6 +30,9 @@ | ||||||
| #include <signal.h> | #include <signal.h> | ||||||
| #include <time.h> | #include <time.h> | ||||||
| #include <sys/wait.h> | #include <sys/wait.h> | ||||||
|  | #ifdef __linux__ | ||||||
|  | # include <sys/prctl.h> | ||||||
|  | #endif | ||||||
| 
 | 
 | ||||||
| int DFlags; | int DFlags; | ||||||
| int JLimit; | int JLimit; | ||||||
|  | @ -144,17 +147,34 @@ crashHandler( int n ) | ||||||
| 	dup2( 0, 1 ); | 	dup2( 0, 1 ); | ||||||
| 	dup2( 0, 2 ); | 	dup2( 0, 2 ); | ||||||
| 	error( "*** " EXE " caught signal %d. Starting debugger ...\n", n ); | 	error( "*** " EXE " caught signal %d. Starting debugger ...\n", n ); | ||||||
|  | #ifdef PR_SET_PTRACER | ||||||
|  | 	int pip[2]; | ||||||
|  | 	if (pipe( pip ) < 0) { | ||||||
|  | 		perror( "pipe()" ); | ||||||
|  | 		exit( 3 ); | ||||||
|  | 	} | ||||||
|  | #endif | ||||||
| 	switch ((dpid = fork())) { | 	switch ((dpid = fork())) { | ||||||
| 	case -1: | 	case -1: | ||||||
| 		perror( "fork()" ); | 		perror( "fork()" ); | ||||||
| 		break; | 		break; | ||||||
| 	case 0: | 	case 0: | ||||||
|  | #ifdef PR_SET_PTRACER | ||||||
|  | 		close( pip[1] ); | ||||||
|  | 		read( pip[0], pbuf, 1 ); | ||||||
|  | 		close( pip[0] ); | ||||||
|  | #endif | ||||||
| 		sprintf( pbuf, "%d", Pid ); | 		sprintf( pbuf, "%d", Pid ); | ||||||
| 		sprintf( pabuf, "/proc/%d/exe", Pid ); | 		sprintf( pabuf, "/proc/%d/exe", Pid ); | ||||||
| 		execlp( "gdb", "gdb", pabuf, pbuf, (char *)0 ); | 		execlp( "gdb", "gdb", pabuf, pbuf, (char *)0 ); | ||||||
| 		perror( "execlp()" ); | 		perror( "execlp()" ); | ||||||
| 		_exit( 1 ); | 		_exit( 1 ); | ||||||
| 	default: | 	default: | ||||||
|  | #ifdef PR_SET_PTRACER | ||||||
|  | 		prctl( PR_SET_PTRACER, (ulong)dpid ); | ||||||
|  | 		close( pip[1] ); | ||||||
|  | 		close( pip[0] ); | ||||||
|  | #endif | ||||||
| 		waitpid( dpid, 0, 0 ); | 		waitpid( dpid, 0, 0 ); | ||||||
| 		break; | 		break; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue