Skip to content

Conversation

@sktt
Copy link
Contributor

@sktt sktt commented Aug 27, 2023

Based on #284. Request for comments on this.

In particular the GDT bit that had to be reworked a bit. Also, whether and how we should give the option to use sysenter instead of syscall.

@sktt sktt requested a review from a team as a code owner August 27, 2023 22:31
@wipawel wipawel added feature New feature or request bugfix This fixes a bug Severity: high Very important bug - fix ASAP Priority: 4 Nice-to-have feature labels Aug 28, 2023
Copy link
Contributor

@minipli-oss minipli-oss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for doing this cleanup! The comments in segment.h are especially helpful, I think!

Can you please rebase your branch, as some of the depending commits got merged?

@sktt sktt force-pushed the sysenter branch 4 times, most recently from ca0212e to 9dbf6c3 Compare August 28, 2023 13:27
@sktt sktt force-pushed the sysenter branch 7 times, most recently from b60cec7 to 9f8e9c2 Compare August 29, 2023 09:45
@sktt sktt force-pushed the sysenter branch 2 times, most recently from 9bb61f9 to 2305a69 Compare August 30, 2023 10:47
sktt and others added 3 commits August 30, 2023 12:49
This allows us to use syscall from inline asm without clobbering all
callee-clobbered registers. Saving/restoring all registers also prevents
"leaking" kernel register values into userland.

Signed-off-by: Johannes Wikner <johannes.wikner@gmail.com>
The GDT entries needed to be re-organized to support sysexit. While
doing so, better document why they exist in the first place, and their
particular order.

Rename __KERN_{CS,DS}16 -> __RMODE_{CS,DS}16 to clearly indicate that
these entries only exist in the real mode GDT.

Omit entries that are unused in i386 or unused for a particular gdt.

Signed-off-by: Johannes Wikner <johannes.wikner@gmail.com>
user_cs should point to USER_CS32 so that correct %cs and %ss are set
upon sysret and sysretq.

This fixes a subtle bug which where branches using %cs (e.g., intra-mode
iret) would crash after a syscall.

Signed-off-by: Johannes Wikner <johannes.wikner@gmail.com>
sktt and others added 3 commits August 30, 2023 12:56
Introduces the necessary MSRs, and sets them to handle sysenter and
sysexits. Add macro to choose approriate instruction depending on build.

When adding compatibility mode support, we need to use either sysexit or
sysexitq depending on what usermode is executing. Same for sysret and
sysretq.

Signed-off-by: Johannes Wikner <johannes.wikner@gmail.com>
To give usermode the option to choose sysenter instead of syscall, we
expose syscall_mode(enum syscall_mode), which is by default using
syscall.

Signed-off-by: Johannes Wikner <johannes.wikner@gmail.com>
From usermode's perspective it works the same as syscall.

Signed-off-by: Johannes Wikner <johannes.wikner@gmail.com>
Signed-off-by: Pawel Wieczorkiewicz <wipawel@grsecurity.net>
Copy link
Contributor

@minipli-oss minipli-oss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, Johannes!

@wipawel wipawel merged commit 7c3c942 into KernelTestFramework:mainline Aug 30, 2023
@sktt sktt changed the title Sysenter Restructure GDT. Add sysenter support Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This fixes a bug feature New feature or request Priority: 4 Nice-to-have feature Severity: high Very important bug - fix ASAP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants