# Re: \[PATCH v26 23/30\] x86/cet/shstk: Handle thread shadow stack

- From: Yu, Yu-cheng \<hidden\>
- Date: 2021-05-11 18:35:14 
- List: linux-api
- Page: https://ratatoskr.run/linux-api/2021/05/1372421
- Thread: https://ratatoskr.run/linux-doc/2021/04/6352121/t.md

```text
On 5/10/2021 7:15 AM, Borislav Petkov wrote:
> On Tue, Apr 27, 2021 at 01:43:08PM -0700, Yu-cheng Yu wrote:
>> @@ -181,6 +184,12 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg,
>>   	if (clone_flags & CLONE_SETTLS)
>>   		ret = set_new_tls(p, tls);
>>   
>> +#ifdef CONFIG_X86_64
>
> IS_ENABLED
>
>> +	/* Allocate a new shadow stack for pthread */
>> +	if (!ret)
>> +		ret = shstk_setup_thread(p, clone_flags, stack_size);
>> +#endif
>> +
>
> And why is this addition here...
>
>>   	if (!ret && unlikely(test_tsk_thread_flag(current, TIF_IO_BITMAP)))
>>   		io_bitmap_share(p);
>
> ... instead of here?
>
> <---
>

io_bitmap_share() does refcount_inc(&current->thread.io_bitmap->refcnt), and the function won't fail.  However, shadow stack allocation can fail.  So, maybe leave io_bitmap_share() at the end?

Thanks,
Yu-cheng
```
