Re: [PATCH 3/3] x86/sigreturn: Reject system segements

From: H. Peter Anvin
Date: Sun Dec 17 2023 - 16:08:28 EST


On December 13, 2023 10:54:00 AM PST, Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxx> wrote:
>On Wed, 13 Dec 2023 at 08:34, Brian Gerst <brgerst@xxxxxxxxx> wrote:
>>
>> @@ -98,7 +98,11 @@ static bool ia32_restore_sigcontext(struct pt_regs *regs,
>>
>> /* Get CS/SS and force CPL3 */
>> regs->cs = sc.cs | 0x03;
>> + if (!valid_user_selector(regs->cs))
>> + return false;
>> regs->ss = sc.ss | 0x03;
>> + if (!valid_user_selector(regs->ss))
>> + return false;
>
>Side note: the SS/CS checks could be stricter than the usual selector tests.
>
>In particular, normal segments can be Null segments. But CS/SS must not be.
>
>Also, since you're now checking the validity, maybe we shouldn't do
>the "force cpl3" any more, and just make it an error to try to load a
>non-cpl3 segment at sigreturn..
>
>That forcing was literally just because we weren't checking it for sanity...
>
> Linus

Not to mention that changing a null descriptor to 3 is wrong.