Skip to content

Commit

Permalink
check that there's no panic if user process tries to write >= MAXVA
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Morris committed Aug 6, 2021
1 parent 08c9eda commit 3b3f83f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions user/usertests.c
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,30 @@ kernmem(char *s)
}
}

// user code should not be able to write to addresses above MAXVA.
void
MAXVAplus(char *s)
{
volatile uint64 a = MAXVA;
for( ; a != 0; a <<= 1){
int pid;
pid = fork();
if(pid < 0){
printf("%s: fork failed\n", s);
exit(1);
}
if(pid == 0){
*(char*)a = 99;
printf("%s: oops wrote %x\n", s, a);
exit(1);
}
int xstatus;
wait(&xstatus);
if(xstatus != -1) // did kernel kill child?
exit(1);
}
}

// if we run the system out of memory, does it clean up the last
// failed allocation?
void
Expand Down Expand Up @@ -2802,6 +2826,7 @@ main(int argc, char *argv[])
void (*f)(char *);
char *s;
} tests[] = {
{MAXVAplus, "MAXVAplus"},
{manywrites, "manywrites"},
{execout, "execout"},
{copyin, "copyin"},
Expand Down

0 comments on commit 3b3f83f

Please sign in to comment.