From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
To: Joshua Hudson <joshudson@gmail.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: x86-ml <x86@kernel.org>
Subject: Re: System Call trashing registers
Date: Fri, 1 Sep 2023 23:24:11 +0700 [thread overview]
Message-ID: <dbce949f-d8b5-fb88-af63-21a82e431aa3@gnuweeb.org> (raw)
In-Reply-To: <CA+jjjYQWeqDY3EFQWmVzV2pXyhfRaHm6s-XWYSXfe1CxvkeuEQ@mail.gmail.com>
On 8/24/23 11:15 PM, Joshua Hudson wrote:
> 1) A lot of my old 32-bit programs don't work on x64 linux anymore
> because int 80h now trashes ecx and edx. This hasn't been a serious
> problem for me.
Do you have a reproducer? It doesn't trash ecx and edx on my machine.
Linux 6.5.0-rc5-af-home-2023-08-08-gf01d31303231
```
#include <stdio.h>
static void do_int80(void)
{
int ecx = 0x11111;
int edx = 0x22222;
int eax = 158; // sched_yield
__asm__ volatile (
"int $0x80"
: "+a"(eax), "+c"(ecx), "+d"(edx)
:
: "memory"
);
printf("ecx = %#x\n", ecx);
printf("edx = %#x\n", edx);
}
int main(void)
{
int i;
for (i = 0; i < 3; i++)
do_int80();
return 0;
}
```
ammarfaizi2@integral2:/tmp$ gcc -Wall -Wextra -Os z.c -o z
ammarfaizi2@integral2:/tmp$ ./z
ecx = 0x11111
edx = 0x22222
ecx = 0x11111
edx = 0x22222
ecx = 0x11111
edx = 0x22222
> 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.
--
Ammar Faizi
next prev parent reply other threads:[~2023-09-01 16:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-24 16:15 Joshua Hudson
2023-08-28 15:06 ` Pavel Machek
2023-08-28 16:41 ` Joshua Hudson
2023-08-28 17:06 ` David Laight
2023-08-28 17:11 ` Joshua Hudson
2023-09-01 16:24 ` Ammar Faizi [this message]
2023-09-01 17:03 ` Thomas Gleixner
2023-09-01 17:38 ` Joshua Hudson
2023-09-01 18:49 ` Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dbce949f-d8b5-fb88-af63-21a82e431aa3@gnuweeb.org \
--to=ammarfaizi2@gnuweeb.org \
--cc=joshudson@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®