Re: [patch 01/10] x86/fpu/signal: Clarify exception handling in restore_fpregs_from_user()

From: Thomas Gleixner
Date: Mon Aug 30 2021 - 18:12:34 EST


On Mon, Aug 30 2021 at 15:00, Linus Torvalds wrote:
> On Mon, Aug 30, 2021 at 2:33 PM Al Viro <viro@xxxxxxxxxxxxxxxxxx> wrote:
>>
>> There's a place where we care about #PF vs. #MC (see upthread)...
>
> Interestingly (or perhaps not), that case is a problem case in general
> for "fault_in_pages_readable()".
>
> That function will only access data every PAGE_SIZE bytes, but if we
> have other exceptions that can happen at a cacheline granularity, the
> whole "retry after faulting pages in" may fail.
>
> So that kind of
>
> - try to copy from user space
>
> - if that fails, do fault_in_pages_readable() and retry
>
> loop can loop forever.
>
> restore_fpregs_from_user() is odd and special in trying to deal with
> it by looking at the error code. I'm n ot convinced it's the right
> thing to do, since it just means that all the other places we do this
> can be problematic.

It's not only about #MC. *RSTOR can also trigger #GP in case that the
user buffer contains garbage and we clearly don't want to loop forever
on that either.

Thanks,

tglx