aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/proc.h
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2020-12-01 17:04:46 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2020-12-01 17:04:46 +0000
commit5941edfcdc17ed51b65125c25d3fac632bf4cd81 (patch)
tree00430933ed016cdd2ebc8b353c8ae55c32a24a01 /sys/sys/proc.h
parentc49747eaf241cb79632dca7308f97fd518d90ec5 (diff)
downloadsrc-5941edfcdc17ed51b65125c25d3fac632bf4cd81.tar.gz
src-5941edfcdc17ed51b65125c25d3fac632bf4cd81.zip
Add a kstack_contains() helper function.
This is useful for stack unwinders which need to avoid out-of-bounds reads of a kernel stack which can trigger kernel faults. Reviewed by: kib, markj Obtained from: CheriBSD Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D27356
Notes
Notes: svn path=/head/; revision=368240
Diffstat (limited to 'sys/sys/proc.h')
-rw-r--r--sys/sys/proc.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 23bac23b5188..0d92dfb7578d 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1198,6 +1198,13 @@ curthread_pflags2_restore(int save)
curthread->td_pflags2 &= save;
}
+static __inline bool
+kstack_contains(struct thread *td, vm_offset_t va, size_t len)
+{
+ return (va >= td->td_kstack && va + len >= va &&
+ va + len <= td->td_kstack + td->td_kstack_pages * PAGE_SIZE);
+}
+
static __inline __pure2 struct td_sched *
td_get_sched(struct thread *td)
{