From 5941edfcdc17ed51b65125c25d3fac632bf4cd81 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Tue, 1 Dec 2020 17:04:46 +0000 Subject: 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 --- sys/sys/proc.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'sys/sys/proc.h') 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) { -- cgit v1.2.3