Received: by 10.223.185.116 with SMTP id b49csp1014990wrg; Wed, 21 Feb 2018 10:35:34 -0800 (PST) X-Google-Smtp-Source: AH8x226kYryLXZNCApHx5lMdwvWt0qnYY7G7naO+FVFTAdZ14OnG+8jADX01SWjq7Unk0TfBC/aZ X-Received: by 2002:a17:902:aa8e:: with SMTP id d14-v6mr3844404plr.94.1519238134547; Wed, 21 Feb 2018 10:35:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519238134; cv=none; d=google.com; s=arc-20160816; b=Kk85DW483bi6SsQjQ0dhLsocJbnq0F0aLhiJljlP2N1mioIzG2NlyhUJeVsmuPEE4f xfrs5AWxyZuNu8YiarB6iQBesv64kAk/RX58UK3/9hrq18loH+Jm377qPO/QtR2S7U7j MSrrDkCTAWAP/dDoRiWPopgZyQYhzbTxXWi0egd/8hXHKwwVH0JrMxixGqnikcc/qQ/y E+rNtZGGOn2n2XY6okHTvNgR+610//bPJTE0bfhcBCo+p45Zo1f5JpnyOSgXG29rWsNU EguL1gwR+O8tC6dzzEBx6EQ0r/6O/SMA4VfJeDqZlTNKm5IJzE496RPZxMDsn0q71AzC jH/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Ls+fHU1RjOL44wG5Hyo5pHYJIh2MSxOEOL4Mgf4ObPU=; b=QiIRUrDSr+nqW7eV7gXx7MbEN5901CGHOnwvGzEhowavAmkc1VQoxLzJlTFbNdGqOk BFhf7pHGfNYtY0+uRPrb9nqrdLqcD3SE+aY3lbOgu6J6ljoUIj2LqfiZJqf8BcM/zFQA H9BcCQKPehFM+BS3rZnAnQqQIrTJCiMgVfzrHtlvPnrcE47gBgG/0Fe/pXJhCpbpTvvP pHw9wLshrGoJGNdX7PRum7xamJF5FZINAtiLqyZnQ0cXWLclrYeUNDrzNPaFPBKQvHvT PzPJXRzCT4eKiIltaml06+vB6AdvPQzHVXzChASTQD+NwDd7jqv2tw6TqqbxjfbD0Mwu 1n3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m62si1159336pfm.41.2018.02.21.10.35.20; Wed, 21 Feb 2018 10:35:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965466AbeBUNJh (ORCPT + 99 others); Wed, 21 Feb 2018 08:09:37 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:43064 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965450AbeBUNJf (ORCPT ); Wed, 21 Feb 2018 08:09:35 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7C8C611F3; Wed, 21 Feb 2018 13:09:34 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Lutomirski , Thomas Gleixner , Arjan van de Ven , Borislav Petkov , Dan Williams , Dave Hansen , David Woodhouse , Linus Torvalds , Peter Zijlstra , Ingo Molnar Subject: [PATCH 4.15 087/163] x86/entry/64: Fix CR3 restore in paranoid_exit() Date: Wed, 21 Feb 2018 13:48:36 +0100 Message-Id: <20180221124535.195847594@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124529.931834518@linuxfoundation.org> References: <20180221124529.931834518@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ingo Molnar commit e48657573481a5dff7cfdc3d57005c80aa816500 upstream. Josh Poimboeuf noticed the following bug: "The paranoid exit code only restores the saved CR3 when it switches back to the user GS. However, even in the kernel GS case, it's possible that it needs to restore a user CR3, if for example, the paranoid exception occurred in the syscall exit path between SWITCH_TO_USER_CR3_STACK and SWAPGS." Josh also confirmed via targeted testing that it's possible to hit this bug. Fix the bug by also restoring CR3 in the paranoid_exit_no_swapgs branch. The reason we haven't seen this bug reported by users yet is probably because "paranoid" entry points are limited to the following cases: idtentry double_fault do_double_fault has_error_code=1 paranoid=2 idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK idtentry int3 do_int3 has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK idtentry machine_check do_mce has_error_code=0 paranoid=1 Amongst those entry points only machine_check is one that will interrupt an IRQS-off critical section asynchronously - and machine check events are rare. The other main asynchronous entries are NMI entries, which can be very high-freq with perf profiling, but they are special: they don't use the 'idtentry' macro but are open coded and restore user CR3 unconditionally so don't have this bug. Reported-and-tested-by: Josh Poimboeuf Reviewed-by: Andy Lutomirski Acked-by: Thomas Gleixner Cc: Arjan van de Ven Cc: Borislav Petkov Cc: Dan Williams Cc: Dave Hansen Cc: David Woodhouse Cc: Greg Kroah-Hartman Cc: Linus Torvalds Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20180214073910.boevmg65upbk3vqb@gmail.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/entry/entry_64.S | 1 + 1 file changed, 1 insertion(+) --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -1168,6 +1168,7 @@ ENTRY(paranoid_exit) jmp .Lparanoid_exit_restore .Lparanoid_exit_no_swapgs: TRACE_IRQS_IRETQ_DEBUG + RESTORE_CR3 scratch_reg=%rbx save_reg=%r14 .Lparanoid_exit_restore: jmp restore_regs_and_return_to_kernel END(paranoid_exit)