Re: System Call trashing registers

From: Thomas Gleixner
Date: Fri Sep 01 2023 - 13:04:10 EST


On Fri, Sep 01 2023 at 23:24, Ammar Faizi wrote:
> On 8/24/23 11:15 PM, Joshua Hudson wrote:
>> 2) syscall is documented to trash rcx and r11.
>>
>> What I don't understand is why this hasn't ever led to a security
>> issue due to leaking values from kernel space (in the trashed
>> registers) back to userspace.
>
> That behavior is architectural. It's the 'syscall' instruction that
> clobbers %rcx and %r11. Not the kernel.
>
> The kernel's syscall entry point even saves %rcx and %r11, but at that
> point they've already been overwritten by the syscall instruction
> itself with the original %rip and %rflags values. So they contain
> userspace values. No internal kernel data is leaked in %rcx and %r11.

Correct.

It does not matter which entry method you use. The kernel always saves
all registers and restores them. syscall, sysenter, int80 behave the
same way. The implicit clobber by the syscall instruction is done in
hardware and the kernel can't do anything about it.

I can't reproduce this either and the code tells me that any attempt to
reproduce is futile.

Thanks,

tglx