Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6015512ybc; Wed, 27 Nov 2019 13:26:32 -0800 (PST) X-Google-Smtp-Source: APXvYqx0hkNKO5EhP7ZyegqJD4UZNkSwVGrAGYooDKYLEngjgCXpGjU+RwwSjQqscOQR1XPSgQal X-Received: by 2002:aa7:cf19:: with SMTP id a25mr28037829edy.237.1574889992357; Wed, 27 Nov 2019 13:26:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574889992; cv=none; d=google.com; s=arc-20160816; b=SQDfEf2VIjgudyiBV4DZHrE8+1DZo4aIe+5bexOlJHJEhG1os9ZeGbX7P26HmVzadO +cdRA/l++LiAkw4vMHo1VfyRsgKcjjvFlZE6AQ6VmF+UD8boUg6jhjblTpIbG+fXVL0i BIgrmt6uLkl6WcDIcurzNXtVuWAKEl6C7iqw14oXigq3PR/MIclo9PpiQk+DTJGBZA7O u2XR4au/i0tME0z6mQZNot09UV0RtqeQsbyCU9LuXgzOmXs7CT6X/z8zI1H2TjhcZ/c1 f866IubiEdA9eosLWtighGPxGC3RQz529qDvMUQWjoCzB9U9vnx7OK4SJ41Zf+65oqtZ t0Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZuDz6HoSjeDX0FxQXUZBgGFRRI9RrlfxW3GgSPjMBd4=; b=HBd/bqryQEA/IsTWJHb2m+w4o2amSuAAOBOFX0XhCwTKsJCtq8apvZAcEkdIblKLhg e5VT+mJ5potYftxh24/KF/t4ZnVWRBWMc2ZNiftPDkImSi7kPIsBJgPNoNcDt5fH7NBe Ik8bcLtrXVo52UsLnQuNo4jHwKuzp+hNl7oeA3cfup9Kw1Km7Pq8hN6Pg0wF7rQsVfga PebZCO9ZhN79CnSKBKYPfB9yi9i7R+WHWgY5sNAUDmuoUaFJ4m9NgTWPQGPCzLfDHN5W WNkoH6AszRVEEPGsTObrkLp9O5xbznJEHkEdyhLL4/xZFfvCkBign/qT6uuRk5D0QelZ DVgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xXWDDGOa; 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 m4si9987528eja.96.2019.11.27.13.26.08; Wed, 27 Nov 2019 13:26:32 -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; dkim=pass header.i=@kernel.org header.s=default header.b=xXWDDGOa; 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 S1730059AbfK0VVl (ORCPT + 99 others); Wed, 27 Nov 2019 16:21:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:32834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731750AbfK0VGw (ORCPT ); Wed, 27 Nov 2019 16:06:52 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AD5462086A; Wed, 27 Nov 2019 21:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888812; bh=nfS1Bvz/Gc6ID7OsOKV+BI/hrTRDWNcVHNNvsdEfMWI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xXWDDGOaVN6OqHSF3xjcsmZmpHp/I6syUppfUuAS05+mkoIcbJDeLKeoEsBzLPxEA QFQ1a4+Z+UWUWvnzFEW7e0buhy5vnMNLJ73eOJj/DYj3igovFVokxE1jfVoJu13vlu zdjjSrq9HLqpN4KKMH0I4RVjF+ubBq2096CVyn2E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Linus Torvalds , Ingo Molnar , Borislav Petkov Subject: [PATCH 4.19 277/306] x86/entry/32: Fix FIXUP_ESPFIX_STACK with user CR3 Date: Wed, 27 Nov 2019 21:32:07 +0100 Message-Id: <20191127203135.043436214@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Lutomirski commit 4a13b0e3e10996b9aa0b45a764ecfe49f6fcd360 upstream. UNWIND_ESPFIX_STACK needs to read the GDT, and the GDT mapping that can be accessed via %fs is not mapped in the user pagetables. Use SGDT to find the cpu_entry_area mapping and read the espfix offset from that instead. Reported-and-tested-by: Borislav Petkov Signed-off-by: Andy Lutomirski Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Linus Torvalds Cc: Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/entry/entry_32.S | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) --- a/arch/x86/entry/entry_32.S +++ b/arch/x86/entry/entry_32.S @@ -315,7 +315,8 @@ .macro CHECK_AND_APPLY_ESPFIX #ifdef CONFIG_X86_ESPFIX32 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8) +#define GDT_ESPFIX_OFFSET (GDT_ENTRY_ESPFIX_SS * 8) +#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + GDT_ESPFIX_OFFSET ALTERNATIVE "jmp .Lend_\@", "", X86_BUG_ESPFIX @@ -1056,12 +1057,26 @@ ENDPROC(entry_INT80_32) * We can't call C functions using the ESPFIX stack. This code reads * the high word of the segment base from the GDT and swiches to the * normal stack and adjusts ESP with the matching offset. + * + * We might be on user CR3 here, so percpu data is not mapped and we can't + * access the GDT through the percpu segment. Instead, use SGDT to find + * the cpu_entry_area alias of the GDT. */ #ifdef CONFIG_X86_ESPFIX32 /* fixup the stack */ - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */ - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */ + pushl %ecx + subl $2*4, %esp + sgdt (%esp) + movl 2(%esp), %ecx /* GDT address */ + /* + * Careful: ECX is a linear pointer, so we need to force base + * zero. %cs is the only known-linear segment we have right now. + */ + mov %cs:GDT_ESPFIX_OFFSET + 4(%ecx), %al /* bits 16..23 */ + mov %cs:GDT_ESPFIX_OFFSET + 7(%ecx), %ah /* bits 24..31 */ shl $16, %eax + addl $2*4, %esp + popl %ecx addl %esp, %eax /* the adjusted stack pointer */ pushl $__KERNEL_DS pushl %eax