PF_USER_WORKERs and shadow stack
I know nothing about the shadow stacks, perhaps I missed something obvious.
But it seems that if a features_enabled(ARCH_SHSTK_SHSTK) thread creates a PF_USER_WORKER thread, shstk_alloc_thread_stack() will allocate the shadow stack for no reason.
Don't we need something like the "patch" below? PF_USER_WORKERs never return to userspace. Note also that update_fpu_shstk() won't be called in this case.
Oleg.
arch/x86/kernel/process.c +9 -3
@@ -209,9 +209,15 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)* is disabled, new_ssp will remain 0, and fpu_clone() will know not to * update it. */ - new_ssp =shstk_alloc_thread_stack (p, clone_flags, args->stack_size); -if (IS_ERR_VALUE (new_ssp)) -return PTR_ERR ((void *)new_ssp); +if (args->fn) { + new_ssp =0 ; +// clear p->thread -> shstk/features, +// reset_thread_features() won't work + }else { + new_ssp =shstk_alloc_thread_stack (p, clone_flags, args->stack_size); +if (IS_ERR_VALUE (new_ssp)) +return PTR_ERR ((void *)new_ssp); + }fpu_clone (p, clone_flags, args->fn, new_ssp);
Quoted 3 lines · Oleg Nesterov
But it seems that if a
features_enabled(ARCH_SHSTK_SHSTK)thread creates aPF_USER_WORKERthread,shstk_alloc_thread_stack()will allocate the shadow stack for no reason.
Is this costing us anything other than some CPU cycles and 160 bytes of memory for a VMA?
Quoted 8 lines · Dave Hansen
Quoted 3 lines · Oleg Nesterov
But it seems that if a
features_enabled(ARCH_SHSTK_SHSTK)thread creates aPF_USER_WORKERthread,shstk_alloc_thread_stack()will allocate the shadow stack for no reason.Is this costing us anything other than some CPU cycles and 160 bytes of memory for a VMA?
Well, I guess no, but I do have another reason for "something-like-this" cleanup. I am working on other changes which should eliminate x86_task_fpu(PF_USER_WORKER). Hopefully I'll send the patches tomorrow. To remind, see
https://lore.kernel.org/all/[email protected]/
So I'd like to ensure that ssp_active() can't return T in ssp_get().
And... Dave, I understand that it is very easy to criticize someone else's code ;) But - if I am right - the current logic doesn't look clean to me. Regardless.
Oleg.
Quoted 11 lines · Oleg Nesterov
Quoted 6 lines · Dave Hansen
Quoted 3 lines · Oleg Nesterov
But it seems that if a
features_enabled(ARCH_SHSTK_SHSTK)thread creates aPF_USER_WORKERthread,shstk_alloc_thread_stack()will allocate the shadow stack for no reason.Is this costing us anything other than some CPU cycles and 160 bytes of memory for a VMA?
Well, I guess no, but I do have another reason for "something-like-this" cleanup. I am working on other changes which should eliminate
x86_task_fpu(PF_USER_WORKER). Hopefully I'll send the patches tomorrow. To remind, see
https://lore.kernel.org/all/[email protected]/
Yep, I assumed the efforts were connected.
Quoted 4 lines
So I'd like to ensure that
ssp_active()can't return T inssp_get().And... Dave, I understand that it is very easy to criticize someone else's code 😉 But - if I am right - the current logic doesn't look clean to me. Regardless.
Hey, I'm all for having "clean" code. But if we're going to add complexity (aka. code) to the kernel, we should know what it's getting us other than "cleanliness".
BTW, how many PF_USER_WORKER threads _are_ there out there? I wouldn't have thought that they were prevalent enough to justify much of an effort here.
Quoted 8 lines · Dave Hansen
Quoted 4 lines · Oleg Nesterov
So I'd like to ensure that
ssp_active()can't return T inssp_get().And... Dave, I understand that it is very easy to criticize someone else's code 😉 But - if I am right - the current logic doesn't look clean to me. Regardless.
Quoted 7 lines
Hey, I'm all for having "clean" code. But if we're going to add complexity (aka. code) to the kernel, we should know what it's getting us other than "cleanliness".
BTW, how many
PF_USER_WORKERthreads _are_ there out there? I wouldn't have thought that they were prevalent enough to justify much of an effort here.
Agreed. I'll send the patches I have in a minute. To me they don't add too much complexity and imo they cleanup the changed code.
But! I understand that cleanups are always subjective, so please review and share your opinion.
Oleg.
Quoted 11 lines · Oleg Nesterov
Quoted 8 lines · Dave Hansen
Quoted 3 lines · Oleg Nesterov
But it seems that if a
features_enabled(ARCH_SHSTK_SHSTK)thread creates aPF_USER_WORKERthread,shstk_alloc_thread_stack()will allocate the shadow stack for no reason.Is this costing us anything other than some CPU cycles and 160 bytes of memory for a VMA?
Quoted 6 lines
Well, I guess no, but I do have another reason for "something-like-this" cleanup. I am working on other changes which should eliminate
x86_task_fpu(PF_USER_WORKER). Hopefully I'll send the patches tomorrow. To remind, see
https://lore.kernel.org/all/[email protected]/So I'd like to ensure that
ssp_active()can't return T inssp_get().
Sorry for noise, in case I wasn't clear...
I meant, can't return T if target->flags & PF_USER_WORKER
Oleg.
Quoted 4 lines
And... Dave, I understand that it is very easy to criticize someone else's code ;) But - if I am right - the current logic doesn't look clean to me. Regardless.
Oleg.