diff --git a/arch/lkl/include/asm/thread_info.h b/arch/lkl/include/asm/thread_info.h index ae6df8f77f5e2e..1b23d96c741a39 100644 --- a/arch/lkl/include/asm/thread_info.h +++ b/arch/lkl/include/asm/thread_info.h @@ -8,6 +8,23 @@ #include #include +#define __HAVE_ARCH_OBJECT_IS_ON_STACK +static inline int arch_object_is_on_stack(const void *obj) +{ + unsigned long addr = (unsigned long)obj; + unsigned long stack_size; + unsigned long stack; + + if (!lkl_ops || !lkl_ops->thread_stack) + return 0; + + stack = (unsigned long)lkl_ops->thread_stack(&stack_size); + if (!stack) + return 0; + + return addr >= stack && addr - stack < stack_size; +} + struct thread_info { struct task_struct *task; unsigned long flags; diff --git a/include/linux/sched/task_stack.h b/include/linux/sched/task_stack.h index 6c2fef89a4fdb5..ab25a50affe0a8 100644 --- a/include/linux/sched/task_stack.h +++ b/include/linux/sched/task_stack.h @@ -88,10 +88,17 @@ void exit_task_stack_account(struct task_struct *tsk); static inline int object_is_on_stack(const void *obj) { +#ifndef __HAVE_ARCH_OBJECT_IS_ON_STACK void *stack = task_stack_page(current); +#endif obj = kasan_reset_tag(obj); + +#ifdef __HAVE_ARCH_OBJECT_IS_ON_STACK + return arch_object_is_on_stack(obj); +#else return (obj >= stack) && (obj < (stack + THREAD_SIZE)); +#endif } extern void thread_stack_cache_init(void);