From patchwork Wed Jul 22 22:00:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 11679231 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B14966C1 for ; Wed, 22 Jul 2020 22:11:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9716A22B43 for ; Wed, 22 Jul 2020 22:11:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Xz2mcYoU"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0/WVH3J0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733132AbgGVWLd (ORCPT ); Wed, 22 Jul 2020 18:11:33 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:52524 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733043AbgGVWLc (ORCPT ); Wed, 22 Jul 2020 18:11:32 -0400 Message-Id: <20200722220519.943016204@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1595455889; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=wfrNNyf0k+yoW4cOmX0AJIgfRphuvLoCo0Pz618iLsM=; b=Xz2mcYoUeYbJNNZIUOB1eiWQee3inAqH3lDgZhE2FElxDFjiIM17JIXw1O1IIp2uxEcHLL SJh4Wke9/ubJcki48DcbEhVuEi30dtzT41xOga1Vns1Awr35GAhI5V4CrBiROZCbtXvdeT FjIvWI2T9jLAhvrYE952AizT5/jdX9ToF/cfIgHQtjkY+OG2otPGV0s8FZSjNY0cPodmHu yZMqInqp8nzI4FK44oDfRMW349nWTEgCK43PgA60mDq6u1kd5nfMNoYsAtGh3/Tb9C5OC8 SRfUS/GhtsUm6Ut5tfOr1NwrL+Wz+D4o8LJWtovyvu52YAib2XKvdVSKJSKvew== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1595455890; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=wfrNNyf0k+yoW4cOmX0AJIgfRphuvLoCo0Pz618iLsM=; b=0/WVH3J0pffARIVH6hk71lVyU59nWYuBpO5nU967HFVZ9bSaBBuH2xcwOJXInA2YOvB5Zz GP8C3Psg5IarlxAQ== Date: Thu, 23 Jul 2020 00:00:00 +0200 From: Thomas Gleixner To: LKML Cc: x86@kernel.org, linux-arch@vger.kernel.org, Will Deacon , Arnd Bergmann , Mark Rutland , Kees Cook , Keno Fischer , Paolo Bonzini , kvm@vger.kernel.org, Gabriel Krisman Bertazi , Sean Christopherson Subject: [patch V5 06/15] x86/entry: Consolidate check_user_regs() References: <20200722215954.464281930@linutronix.de> MIME-Version: 1.0 Content-transfer-encoding: 8-bit Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Thomas Gleixner The user register sanity check is sprinkled all over the place. Move it into enter_from_user_mode(). Signed-off-by: Thomas Gleixner Reviewed-by: Kees Cook --- arch/x86/entry/common.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -82,10 +82,11 @@ static noinstr void check_user_regs(stru * 2) Invoke context tracking if enabled to reactivate RCU * 3) Trace interrupts off state */ -static noinstr void enter_from_user_mode(void) +static noinstr void enter_from_user_mode(struct pt_regs *regs) { enum ctx_state state = ct_state(); + check_user_regs(regs); lockdep_hardirqs_off(CALLER_ADDR0); user_exit_irqoff(); @@ -95,8 +96,9 @@ static noinstr void enter_from_user_mode instrumentation_end(); } #else -static __always_inline void enter_from_user_mode(void) +static __always_inline void enter_from_user_mode(struct pt_regs *regs) { + check_user_regs(regs); lockdep_hardirqs_off(CALLER_ADDR0); instrumentation_begin(); trace_hardirqs_off_finish(); @@ -369,9 +371,7 @@ static void __syscall_return_slowpath(st { struct thread_info *ti; - check_user_regs(regs); - - enter_from_user_mode(); + enter_from_user_mode(regs); instrumentation_begin(); local_irq_enable(); @@ -434,9 +434,7 @@ static void do_syscall_32_irqs_on(struct /* Handles int $0x80 */ __visible noinstr void do_int80_syscall_32(struct pt_regs *regs) { - check_user_regs(regs); - - enter_from_user_mode(); + enter_from_user_mode(regs); instrumentation_begin(); local_irq_enable(); @@ -487,8 +485,6 @@ static bool __do_fast_syscall_32(struct vdso_image_32.sym_int80_landing_pad; bool success; - check_user_regs(regs); - /* * SYSENTER loses EIP, and even SYSCALL32 needs us to skip forward * so that 'regs->ip -= 2' lands back on an int $0x80 instruction. @@ -496,7 +492,7 @@ static bool __do_fast_syscall_32(struct */ regs->ip = landing_pad; - enter_from_user_mode(); + enter_from_user_mode(regs); instrumentation_begin(); local_irq_enable(); @@ -599,8 +595,7 @@ idtentry_state_t noinstr idtentry_enter( }; if (user_mode(regs)) { - check_user_regs(regs); - enter_from_user_mode(); + enter_from_user_mode(regs); return ret; } @@ -733,8 +728,7 @@ void noinstr idtentry_exit(struct pt_reg */ void noinstr idtentry_enter_user(struct pt_regs *regs) { - check_user_regs(regs); - enter_from_user_mode(); + enter_from_user_mode(regs); } /**