Skip to content

RFC x86/vsyscall: Tighten vsyscall emulation checks for a #PF fixup

Sohil Mehta lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest2 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2x86/vsyscall: Avoid vsyscall emulation when X86_PF_INSTR is not setarch/x86/entry/vsyscall/vsyscall_64.c+3 -20 replies
2/2x86/vsyscall: Avoid vsyscall emulation for some unexpected fault typesarch/x86/entry/vsyscall/vsyscall_64.c arch/x86/mm/fault.c+3 -50 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/2] x86/vsyscall: Tighten vsyscall emulation checks for a #PF fixup

This series is a result of the suggestions made by Peter Anvin at
https://lore.kernel.org/lkml/[email protected]/.

The vsyscall emulation code already has a bunch of checks to make sure only valid page faults get emulated. This series improves those checks mainly from the defensive point of view.

The patches are based on the LASS-vsyscall series under review at
https://lore.kernel.org/lkml/[email protected]/

Patch 1 seems like a straightforward change that is unlikely to cause any issues.

Patch 2 adds a few more PF error codes to the emulation reject-list. But, it is debatable whether they are absolutely necessary.

X86_PF_RSVD: Reserved bits being set in do_user_addr_fault() already generates an OOPS before vsyscall emulation attempted. No need to check for it again.

X86_PF_PK: PKRU never rejects instruction fetches so it is highly unlikely the vsyscall emulation code will be reached with this bit set.

X86_PF_SHSTK: I am not sure if we can have a vsyscall page access that results in X86_PF_SHSTK set but doesn't have X86_PF_WRITE with it. If we cannot, the current checks in emulate_vsyscall_pf() will already reject emulation.

I have included X86_PF_PK and X86_PF_SHSTK in patch 2 because I am not a 100% sure about the reasoning. Additionally, I don't see any harm in including them. Also, should we also add X86_PF_SGX and X86_PF_RMP by the same logic? Any insight here would be appreciated.

The patches pass the vsyscall selftest. But, they should be considered untested as I don't know how to generate these PF error codes in the vsyscall context.

Sohil Mehta (2):
x86/vsyscall: Avoid vsyscall emulation when X86_PF_INSTR is not set x86/vsyscall: Avoid vsyscall emulation for some unexpected fault types

 arch/x86/entry/vsyscall/vsyscall_64.c | 10 ++++++----
 arch/x86/mm/fault.c                   |  3 ---
 2 files changed, 6 insertions(+), 7 deletions(-)
Signature · 1 line
2.43.0