diff options
author | Mark Johnston <markj@FreeBSD.org> | 2024-04-22 15:43:17 +0000 |
---|---|---|
committer | Mark Johnston <markj@FreeBSD.org> | 2024-04-22 15:46:59 +0000 |
commit | 800da341bc4a35f4b4d82d104b130825d9a42ffa (patch) | |
tree | 882a8212c5521ba5e908be6106a407c0e8265d48 /sys/sys | |
parent | dd03eafacba962c9dcec929c3ed9d63e7c43da3a (diff) | |
download | src-800da341bc4a35f4b4d82d104b130825d9a42ffa.tar.gz src-800da341bc4a35f4b4d82d104b130825d9a42ffa.zip |
thread: Simplify sanitizer integration with thread creation
fork() may allocate a new thread in one of two ways: from UMA, or cached
in a freed proc that was just allocated from UMA. In either case, KASAN
and KMSAN need to initialize some state; in particular they need to
initialize the shadow mapping of the new thread's stack.
This is done differently between KASAN and KMSAN, which is confusing.
This patch improves things a bit:
- Add a new thread_recycle() function, which moves all kernel stack
handling out of kern_fork.c, since it doesn't really belong there.
- Then, thread_alloc_stack() has only one local caller, so just inline
it.
- Avoid redundant shadow stack initialization: thread_alloc()
initializes the KMSAN shadow stack (via kmsan_thread_alloc()) even
through vm_thread_new() already did that.
- Add kasan_thread_alloc(), for consistency with kmsan_thread_alloc().
No functional change intended.
Reviewed by: khng
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D44891
Diffstat (limited to 'sys/sys')
-rw-r--r-- | sys/sys/asan.h | 4 | ||||
-rw-r--r-- | sys/sys/proc.h | 2 |
2 files changed, 5 insertions, 1 deletions
diff --git a/sys/sys/asan.h b/sys/sys/asan.h index a3becdef5f57..6a01d0531725 100644 --- a/sys/sys/asan.h +++ b/sys/sys/asan.h @@ -53,14 +53,18 @@ #define KASAN_KSTACK_FREED 0xFE #define KASAN_EXEC_ARGS_FREED 0xFF +struct thread; + void kasan_init(void); void kasan_init_early(vm_offset_t, size_t); void kasan_shadow_map(vm_offset_t, size_t); void kasan_mark(const void *, size_t, size_t, uint8_t); +void kasan_thread_alloc(struct thread *); #else /* KASAN */ #define kasan_init() #define kasan_shadow_map(a, s) #define kasan_mark(p, s, l, c) +#define kasan_thread_alloc(t) #endif /* !KASAN */ #endif /* !_SYS_ASAN_H_ */ diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 33b836f4150e..1b542d1374b4 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1262,7 +1262,6 @@ void cpu_thread_free(struct thread *); void cpu_thread_swapin(struct thread *); void cpu_thread_swapout(struct thread *); struct thread *thread_alloc(int pages); -int thread_alloc_stack(struct thread *, int pages); int thread_check_susp(struct thread *td, bool sleep); void thread_cow_get_proc(struct thread *newtd, struct proc *p); void thread_cow_get(struct thread *newtd, struct thread *td); @@ -1275,6 +1274,7 @@ void thread_exit(void) __dead2; void thread_free(struct thread *td); void thread_link(struct thread *td, struct proc *p); void thread_reap_barrier(void); +int thread_recycle(struct thread *, int pages); int thread_single(struct proc *p, int how); void thread_single_end(struct proc *p, int how); void thread_stash(struct thread *td); |