From 69c9009e60ab1e9ab11c4e8d0ab11a4f0c2c6d8e Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 7 May 2024 00:14:29 -0400 Subject: kernel: vm_fault: Ref vmobj before usage Signed-off-by: Ian Moffett --- sys/vm/vm_fault.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'sys') diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c index 219db91..45def7f 100644 --- a/sys/vm/vm_fault.c +++ b/sys/vm/vm_fault.c @@ -101,6 +101,7 @@ vm_fault(vaddr_t va, vm_prot_t access_type) struct vm_mapping *mapping; struct vm_object *vmobj; + int s = 0; size_t granule = vm_get_page_size(); vaddr_t va_base = va & ~(granule - 1); @@ -115,11 +116,17 @@ vm_fault(vaddr_t va, vm_prot_t access_type) /* Invalid access type */ return -1; + vm_object_ref(vmobj); + /* Can we perform demand paging? */ if (vmobj->demand) { - if (vm_demand_page(mapping, va_base, access_type) != 0) - return -1; + s = vm_demand_page(mapping, va_base, access_type); + if (s != 0) + goto done; } - return 0; +done: + /* Drop the vmobj ref */ + vm_object_unref(vmobj); + return s; } -- cgit v1.2.3