From 7c59ec14e654533616d8033e610a909498907f0a Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Thu, 3 Jan 2019 16:26:52 +0000 Subject: [PATCH] Fix a use-after-free in the riscv pmap_release() implementation. Don't bother zeroing the top-level page before freeing it. Previously, the page was freed before being zeroed. Reviewed by: jhb, kib MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D18720 --- sys/riscv/riscv/pmap.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c index 8db8772c4f47..9604fbf00b9c 100644 --- a/sys/riscv/riscv/pmap.c +++ b/sys/riscv/riscv/pmap.c @@ -1297,17 +1297,13 @@ pmap_release(pmap_t pmap) ("pmap_release: pmap resident count %ld != 0", pmap->pm_stats.resident_count)); - m = PHYS_TO_VM_PAGE(DMAP_TO_PHYS((vm_offset_t)pmap->pm_l1)); - vm_page_unwire_noq(m); - vm_page_free_zero(m); - - /* Remove pmap from the allpmaps list */ mtx_lock(&allpmaps_lock); LIST_REMOVE(pmap, pm_list); mtx_unlock(&allpmaps_lock); - /* Remove kernel pagetables */ - bzero(pmap->pm_l1, PAGE_SIZE); + m = PHYS_TO_VM_PAGE(DMAP_TO_PHYS((vm_offset_t)pmap->pm_l1)); + vm_page_unwire_noq(m); + vm_page_free(m); } #if 0