Browse Source

After a day of figuring that only strstr was required, this new change

will set things so that nested umls can work with a tt host
kernel. Since everything looks like skas under a uml even if the host
kernel is tt.  So /proc/cmdline is looked at since skas-or-tt
automatically adds the mode={tt,skas} option.
master
freesource 22 years ago
parent
commit
f845aab17f
  1. 91
      skas-or-tt/skas-or-tt.c

91
skas-or-tt/skas-or-tt.c

@ -21,47 +21,84 @@ process.c. This is a good way to learn about clone() and ptrace().
int main(void) int main(void)
{ {
int n, pid, ret = 1; int n, pid, ret = 1, cmdline_value;
void *stack; void *stack;
struct ptrace_faultinfo { struct ptrace_faultinfo {
int is_write; int is_write;
unsigned long addr; unsigned long addr;
}; };
struct ptrace_faultinfo fi; struct ptrace_faultinfo fi;
printf("Checking for the skas3 patch in the host..."); cmdline_value = host_cmdline();
pid = start_ptraced_child(&stack);
n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi); if ( cmdline_value == 1 ) {
if(n < 0){ printf("Checking for the skas3 patch in the host...not found\nChecking for /proc/mm...not found\n");
if(errno == EIO) return(0);
printf("not found\n"); }
else printf("No (unexpected errno - %d)\n", errno); else if ( cmdline_value == 2 ) {
ret = 0; printf("Checking for the skas3 patch in the host...found\nChecking for /proc/mm...found\n");
return(0);
} }
else printf("found\n");
printf("Checking for the skas3 patch in the host...");
pid = start_ptraced_child(&stack);
n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi);
if(n < 0){
if(errno == EIO)
printf("not found\n");
else printf("No (unexpected errno - %d)\n", errno);
ret = 0;
}
else printf("found\n");
printf("Checking for /proc/mm...");
if(access("/proc/mm", W_OK)){
printf("not found\n");
ret = 0;
}
else printf("found\n");
kill(pid, SIGKILL); printf("Checking for /proc/mm...");
return(ret); if(access("/proc/mm", W_OK)){
printf("not found\n");
ret = 0;
}
else printf("found\n");
kill(pid, SIGKILL);
return(ret);
} }
int threadFunction( void* argument ) int host_cmdline (void)
{ {
printf( "child thread exiting\n" );
exit(0); char s[500]; /* should be the max cmdline size */
FILE *f;
char *tt = "mode=tt";
char *skas = "mode=skas";
char *ptt, *pskas;
f = fopen("/proc/cmdline","r");
if ( f == NULL ) {
printf("Error: unable to open /proc/cmdline for reading\n");
return(0);
}
if (fgets(s, sizeof s, f) != NULL) {
ptt = strstr(s, tt);
pskas = strstr(s, skas);
if ( ptt != NULL )
return(1);
else if ( pskas != NULL )
return(2);
else
return(0);
}
return(1); /* safety default */
} }

Loading…
Cancel
Save