Skip to content
Snippets Groups Projects
Commit 5b96e295 authored by Vianney Ruhlmann's avatar Vianney Ruhlmann
Browse files

Check vma permissions

parent 695a0fe8
No related branches found
Tags tp2-act-6-5
No related merge requests found
......@@ -384,12 +384,32 @@ int do_allocate(pagetable_t pagetable, struct proc* p, uint64 addr, uint64 scaus
if ((ma = get_memory_area(p, addr)) == 0){
return ENOVMA;
}
switch(scause) {
case CAUSE_R:
if((ma->vma_flags & VMA_R) == 0){
return EBADPERM;
};
break;
case CAUSE_W:
if((ma->vma_flags & VMA_W) == 0){
return EBADPERM;
};
break;
case CAUSE_X:
if((ma->vma_flags & VMA_X) == 0){
return EBADPERM;
};
break;
}
if ((pte = walk(pagetable, addr, 0)) == 0 || (*pte & PTE_V) == 0){
if((pa = kalloc()) == 0){
return ENOMEM;
}
//memset(pa, 0, PGSIZE);
if (mappages(pagetable, PGROUNDDOWN(addr), PGSIZE, (uint64)pa, PTE_R| PTE_W | PTE_X | PTE_U ) == -1){
int flags = PTE_U;
flags |= (ma->vma_flags & VMA_R) != 0 ? PTE_R : 0;
flags |= (ma->vma_flags & VMA_W) != 0 ? PTE_W : 0;
flags |= (ma->vma_flags & VMA_X) != 0 ? PTE_X : 0;
if (mappages(pagetable, PGROUNDDOWN(addr), PGSIZE, (uint64)pa, flags ) == -1){
kfree(pa);
return EMAPFAILED;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment