Skip to content

Commit

Permalink
Experiment with being more precise setting permissions for user pages.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kaashoek committed Aug 12, 2022
1 parent 8f58cc7 commit 899cc02
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion kernel/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions kernel/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion kernel/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
4 changes: 2 additions & 2 deletions kernel/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 899cc02

Please sign in to comment.