Skip to content

Commit 8ba38a7

Browse files
kirylhansendc
authored andcommitted
x86/vsyscall: Do not require X86_PF_INSTR to emulate vsyscall
emulate_vsyscall() expects to see X86_PF_INSTR in PFEC on a vsyscall page fault, but the CPU does not report X86_PF_INSTR if neither X86_FEATURE_NX nor X86_FEATURE_SMEP are enabled. X86_FEATURE_NX should be enabled on nearly all 64-bit CPUs, except for early P4 processors that did not support this feature. Instead of explicitly checking for X86_PF_INSTR, compare the fault address to RIP. On machines with X86_FEATURE_NX enabled, issue a warning if RIP is equal to fault address but X86_PF_INSTR is absent. [ dhansen: flesh out code comments ] Originally-by: Dave Hansen <dave.hansen@intel.com> Reported-by: Andrew Cooper <andrew.cooper3@citrix.com> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com> Link: https://lore.kernel.org/all/bd81a98b-f8d4-4304-ac55-d4151a1a77ab@intel.com Link: https://lore.kernel.org/all/20250624145918.2720487-1-kirill.shutemov%40linux.intel.com
1 parent 8f5ae30 commit 8ba38a7

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

arch/x86/entry/vsyscall/vsyscall_64.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ bool emulate_vsyscall(unsigned long error_code,
124124
if ((error_code & (X86_PF_WRITE | X86_PF_USER)) != X86_PF_USER)
125125
return false;
126126

127-
if (!(error_code & X86_PF_INSTR)) {
127+
/*
128+
* Assume that faults at regs->ip are because of an
129+
* instruction fetch. Return early and avoid
130+
* emulation for faults during data accesses:
131+
*/
132+
if (address != regs->ip) {
128133
/* Failed vsyscall read */
129134
if (vsyscall_mode == EMULATE)
130135
return false;
@@ -136,13 +141,19 @@ bool emulate_vsyscall(unsigned long error_code,
136141
return false;
137142
}
138143

144+
/*
145+
* X86_PF_INSTR is only set when NX is supported. When
146+
* available, use it to double-check that the emulation code
147+
* is only being used for instruction fetches:
148+
*/
149+
if (cpu_feature_enabled(X86_FEATURE_NX))
150+
WARN_ON_ONCE(!(error_code & X86_PF_INSTR));
151+
139152
/*
140153
* No point in checking CS -- the only way to get here is a user mode
141154
* trap to a high address, which means that we're in 64-bit user code.
142155
*/
143156

144-
WARN_ON_ONCE(address != regs->ip);
145-
146157
if (vsyscall_mode == NONE) {
147158
warn_bad_vsyscall(KERN_INFO, regs,
148159
"vsyscall attempted with vsyscall=none");

0 commit comments

Comments
 (0)