check that there's no panic if user process tries to write >= MAXVA

This commit is contained in:
Robert Morris 2021-08-06 11:06:24 -04:00
parent 08c9eda85f
commit 3b3f83f100

View file

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