Experiment with being more precise setting permissions for user pages.
Growing adds R|W pages (without X). Exec() marks the stack only R|W. Probably could setup permissions for text and data better if we call ld with --no-omagic instead of -N.
This commit is contained in:
parent
8f58cc7df9
commit
899cc02660
|
@ -160,7 +160,7 @@ void kvmmap(pagetable_t, uint64, uint64, uint64, int);
|
|||
int mappages(pagetable_t, uint64, uint64, uint64, int);
|
||||
pagetable_t uvmcreate(void);
|
||||
void uvmfirst(pagetable_t, uchar *, uint);
|
||||
uint64 uvmalloc(pagetable_t, uint64, uint64);
|
||||
uint64 uvmalloc(pagetable_t, uint64, uint64, int);
|
||||
uint64 uvmdealloc(pagetable_t, uint64, uint64);
|
||||
int uvmcopy(pagetable_t, pagetable_t, uint64);
|
||||
void uvmfree(pagetable_t, uint64);
|
||||
|
|
|
@ -49,7 +49,7 @@ exec(char *path, char **argv)
|
|||
if(ph.vaddr + ph.memsz < ph.vaddr)
|
||||
goto bad;
|
||||
uint64 sz1;
|
||||
if((sz1 = uvmalloc(pagetable, sz, ph.vaddr + ph.memsz)) == 0)
|
||||
if((sz1 = uvmalloc(pagetable, sz, ph.vaddr + ph.memsz, PTE_X|PTE_W)) == 0)
|
||||
goto bad;
|
||||
sz = sz1;
|
||||
if((ph.vaddr % PGSIZE) != 0)
|
||||
|
@ -69,7 +69,7 @@ exec(char *path, char **argv)
|
|||
// Use the second as the user stack.
|
||||
sz = PGROUNDUP(sz);
|
||||
uint64 sz1;
|
||||
if((sz1 = uvmalloc(pagetable, sz, sz + 2*PGSIZE)) == 0)
|
||||
if((sz1 = uvmalloc(pagetable, sz, sz + 2*PGSIZE, PTE_W)) == 0)
|
||||
goto bad;
|
||||
sz = sz1;
|
||||
uvmclear(pagetable, sz-2*PGSIZE);
|
||||
|
|
|
@ -264,7 +264,7 @@ growproc(int n)
|
|||
|
||||
sz = p->sz;
|
||||
if(n > 0){
|
||||
if((sz = uvmalloc(p->pagetable, sz, sz + n)) == 0) {
|
||||
if((sz = uvmalloc(p->pagetable, sz, sz + n, PTE_W)) == 0) {
|
||||
return -1;
|
||||
}
|
||||
} else if(n < 0){
|
||||
|
|
|
@ -218,7 +218,7 @@ uvmfirst(pagetable_t pagetable, uchar *src, uint sz)
|
|||
// Allocate PTEs and physical memory to grow process from oldsz to
|
||||
// newsz, which need not be page aligned. Returns new size or 0 on error.
|
||||
uint64
|
||||
uvmalloc(pagetable_t pagetable, uint64 oldsz, uint64 newsz)
|
||||
uvmalloc(pagetable_t pagetable, uint64 oldsz, uint64 newsz, int xperm)
|
||||
{
|
||||
char *mem;
|
||||
uint64 a;
|
||||
|
@ -234,7 +234,7 @@ uvmalloc(pagetable_t pagetable, uint64 oldsz, uint64 newsz)
|
|||
return 0;
|
||||
}
|
||||
memset(mem, 0, PGSIZE);
|
||||
if(mappages(pagetable, a, PGSIZE, (uint64)mem, PTE_W|PTE_X|PTE_R|PTE_U) != 0){
|
||||
if(mappages(pagetable, a, PGSIZE, (uint64)mem, PTE_R|PTE_U|xperm) != 0){
|
||||
kfree(mem);
|
||||
uvmdealloc(pagetable, a, oldsz);
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue