git: 9d95539ffed2 - stable/13 - kstack: Add KASAN state transitions

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Mon, 01 Nov 2021 14:33:00 UTC
The branch stable/13 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=9d95539ffed299a8457c7c718a1fe039d6f595bd

commit 9d95539ffed299a8457c7c718a1fe039d6f595bd
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2021-04-13 21:39:55 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2021-11-01 14:03:02 +0000

    kstack: Add KASAN state transitions
    
    We allocate kernel stacks using a UMA cache zone.  Cache zones have
    KASAN disabled by default, but in this case it makes sense to enable it.
    
    Reviewed by:    andrew
    
    (cherry picked from commit 244f3ec642ed99a371c97b946b93b877d8be1756)
---
 sys/vm/vm_glue.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/vm/vm_glue.c b/sys/vm/vm_glue.c
index be741fd40199..7cfb08246f9e 100644
--- a/sys/vm/vm_glue.c
+++ b/sys/vm/vm_glue.c
@@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/asan.h>
 #include <sys/domainset.h>
 #include <sys/limits.h>
 #include <sys/lock.h>
@@ -86,7 +87,6 @@ __FBSDID("$FreeBSD$");
 #include <sys/vmem.h>
 #include <sys/sx.h>
 #include <sys/sysctl.h>
-#include <sys/eventhandler.h>
 #include <sys/kernel.h>
 #include <sys/ktr.h>
 #include <sys/unistd.h>
@@ -351,6 +351,7 @@ vm_thread_stack_dispose(vm_offset_t ks, int pages)
 		vm_page_free(m);
 	}
 	VM_OBJECT_WUNLOCK(kstack_object);
+	kasan_mark((void *)ks, ptoa(pages), ptoa(pages), 0);
 	kva_free(ks - (KSTACK_GUARD_PAGES * PAGE_SIZE),
 	    (pages + KSTACK_GUARD_PAGES) * PAGE_SIZE);
 }
@@ -385,6 +386,7 @@ vm_thread_new(struct thread *td, int pages)
 		return (0);
 	td->td_kstack = ks;
 	td->td_kstack_pages = pages;
+	kasan_mark((void *)ks, ptoa(pages), ptoa(pages), 0);
 	return (1);
 }
 
@@ -401,6 +403,7 @@ vm_thread_dispose(struct thread *td)
 	ks = td->td_kstack;
 	td->td_kstack = 0;
 	td->td_kstack_pages = 0;
+	kasan_mark((void *)ks, 0, ptoa(pages), KASAN_KSTACK_FREED);
 	if (pages == kstack_pages)
 		uma_zfree(kstack_cache, (void *)ks);
 	else