mit-pdos / xv6-riscv

Xv6 for RISC-V
Other
6.6k stars 2.38k forks source link

[fix] mappages: potential memory leak #118

Open yztz opened 2 years ago

yztz commented 2 years ago

In mappages, if size > 1 PAGESIZE or va not page-aligned(i.e. need to map more than one page), it will lead to a memory leak with a midway kalloc failure. When mappages returns -1, it will try to call uvmfree->freewalk to free the page-table pages and may lead to a panic because of an mapped page. In the unmodified version, maapages always successes or is only called with 1 PAGESIZE, so this problem doesn't rise.