x86/entry: Harden return-to-user
authorPeter Zijlstra <peterz@infradead.org>
Mon, 20 Nov 2023 14:33:46 +0000 (15:33 +0100)
committerIngo Molnar <mingo@kernel.org>
Tue, 21 Nov 2023 12:57:31 +0000 (13:57 +0100)
commit1e4d3001f59fb7a9917cb746544b65e616b5f809
tree6d04c0058f5f125f755e883acbd8558e7f8773ee
parentc516213726fb572700cce4a5909aa8d82b77192a
x86/entry: Harden return-to-user

Make the CONFIG_DEBUG_ENTRY=y check that validates CS is a user segment
unconditional and move it nearer to IRET.

  PRE:
       140,026,608      cycles:k                                                      ( +-  0.01% )
       236,696,176      instructions:k            #    1.69  insn per cycle           ( +-  0.00% )

  POST:
       139,957,681      cycles:k                                                      ( +-  0.01% )
       236,681,819      instructions:k            #    1.69  insn per cycle           ( +-  0.00% )

(this is with --repeat 100 and the run-to-run variance is bigger than
the difference shown)

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20231120143626.753200755@infradead.org
arch/x86/entry/entry_64.S