Skip to content

Commit 8d5ea35

Browse files
committed
x86/entry: Consolidate check_user_regs()
The user register sanity check is sprinkled all over the place. Move it into enter_from_user_mode(). Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b35ad84 commit 8d5ea35

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

arch/x86/entry/common.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ static noinstr void check_user_regs(struct pt_regs *regs)
8282
* 2) Invoke context tracking if enabled to reactivate RCU
8383
* 3) Trace interrupts off state
8484
*/
85-
static noinstr void enter_from_user_mode(void)
85+
static noinstr void enter_from_user_mode(struct pt_regs *regs)
8686
{
8787
enum ctx_state state = ct_state();
8888

89+
check_user_regs(regs);
8990
lockdep_hardirqs_off(CALLER_ADDR0);
9091
user_exit_irqoff();
9192

@@ -95,8 +96,9 @@ static noinstr void enter_from_user_mode(void)
9596
instrumentation_end();
9697
}
9798
#else
98-
static __always_inline void enter_from_user_mode(void)
99+
static __always_inline void enter_from_user_mode(struct pt_regs *regs)
99100
{
101+
check_user_regs(regs);
100102
lockdep_hardirqs_off(CALLER_ADDR0);
101103
instrumentation_begin();
102104
trace_hardirqs_off_finish();
@@ -369,9 +371,7 @@ __visible noinstr void do_syscall_64(unsigned long nr, struct pt_regs *regs)
369371
{
370372
struct thread_info *ti;
371373

372-
check_user_regs(regs);
373-
374-
enter_from_user_mode();
374+
enter_from_user_mode(regs);
375375
instrumentation_begin();
376376

377377
local_irq_enable();
@@ -434,9 +434,7 @@ static void do_syscall_32_irqs_on(struct pt_regs *regs)
434434
/* Handles int $0x80 */
435435
__visible noinstr void do_int80_syscall_32(struct pt_regs *regs)
436436
{
437-
check_user_regs(regs);
438-
439-
enter_from_user_mode();
437+
enter_from_user_mode(regs);
440438
instrumentation_begin();
441439

442440
local_irq_enable();
@@ -487,16 +485,14 @@ __visible noinstr long do_fast_syscall_32(struct pt_regs *regs)
487485
vdso_image_32.sym_int80_landing_pad;
488486
bool success;
489487

490-
check_user_regs(regs);
491-
492488
/*
493489
* SYSENTER loses EIP, and even SYSCALL32 needs us to skip forward
494490
* so that 'regs->ip -= 2' lands back on an int $0x80 instruction.
495491
* Fix it up.
496492
*/
497493
regs->ip = landing_pad;
498494

499-
enter_from_user_mode();
495+
enter_from_user_mode(regs);
500496
instrumentation_begin();
501497

502498
local_irq_enable();
@@ -599,8 +595,7 @@ idtentry_state_t noinstr idtentry_enter(struct pt_regs *regs)
599595
};
600596

601597
if (user_mode(regs)) {
602-
check_user_regs(regs);
603-
enter_from_user_mode();
598+
enter_from_user_mode(regs);
604599
return ret;
605600
}
606601

@@ -733,8 +728,7 @@ void noinstr idtentry_exit(struct pt_regs *regs, idtentry_state_t state)
733728
*/
734729
void noinstr idtentry_enter_user(struct pt_regs *regs)
735730
{
736-
check_user_regs(regs);
737-
enter_from_user_mode();
731+
enter_from_user_mode(regs);
738732
}
739733

740734
/**

0 commit comments

Comments
 (0)