Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6011748ybc; Wed, 27 Nov 2019 13:21:57 -0800 (PST) X-Google-Smtp-Source: APXvYqxtR0daShcDvaE2VDPRjivZwXnUF0wghRMv0I1JpbQmyo2yoW4V7KUVBhXsqicaD0E8RIK5 X-Received: by 2002:a50:e619:: with SMTP id y25mr34715016edm.204.1574889717522; Wed, 27 Nov 2019 13:21:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574889717; cv=none; d=google.com; s=arc-20160816; b=mJDuFn2M1w7NmM6n1ofamru42qJ5W7DzyYlviFaxCbQG3jZ2kRG8CXxzjE7DcCUGB3 Sjj1weDjiqJ4QalLjvx/aOAZv1JTr+ztim0X6sCPvT9YLR6HNeo2h20+mOm0Bo/54o7Z tp8daPrLVvKuikHbD1YZ+sG8CTqgfR1UXaJ8gwXCNhRdsfL5CmvLD5McmZXZjjZq7MXy ge7NbznwXAjPCSGBOGIzODY/H6uRVrzeJUOVtwknz4a+QqwNARKjHbz8hoqS0l6wbZRm f4FH1vxabjXKsG7P/Jh0RHAHZiMPCF2f12g/kVRtv0aWMacW77Fh7Doe0OT1lT8sptFe Gj3A== 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=Wvmthg1ltrwKxUNwYSKg2VfrafFOOCjetcr31+Wpgus=; b=NSakcx+RewDwe6y4aMqrIRxMOqT6r4P4PJs/KmpJkhSOZ4bPey4dNkfKCiTDnaZGjH DEGAhwrTEPRFZn5Y1zHWZhKXYavkeHW+1D7pSFMENGaOgwMAF6ofLCzJU8rNJS/iljd5 0vM0oIwqrMgnZ6kv/JHwLYaNY0t5W9omY/arhcl2DflOOcMUmmcBdISSYkBeRB6dy+MW cRjtB6ae4M5B9/2sADq3pU1iG3P8rOdSv8EwitEZwvtmcvInS21hZw2M9P+VgClIyl8l 1o2m5mVgft4IacJmteTEjYY42pfro25s9ld7oPmFrcEEEKMqfgjTmZGrA4V/AsGacoko LMYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2ZHFC26Z; 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 q30si12002224edb.372.2019.11.27.13.21.34; Wed, 27 Nov 2019 13:21:57 -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=2ZHFC26Z; 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 S2387480AbfK0VT1 (ORCPT + 99 others); Wed, 27 Nov 2019 16:19:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:37792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732373AbfK0VKc (ORCPT ); Wed, 27 Nov 2019 16:10:32 -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 8A7BF2086A; Wed, 27 Nov 2019 21:10:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574889032; bh=Xm1l4jck4nbnQDoioOAsUALDtTZS1OsKdbYJlQLPRdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2ZHFC26ZGUngLnz1+WzYiXSGNwLAjY8iPy5bBa2RbIJV77+0iNz26hmzVwLNvbRnB mJHMri1vhuXzxnwQZz6QDRJTpmAg8TZN8br/rUHNLCmjs3eunpKCEixy7wHu6ZFS7t 29iw6OyfXpYwAsdWZmhrSLZrUrGZANQnsCQ+338Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Lutomirski , "Peter Zijlstra (Intel)" , stable@kernel.org Subject: [PATCH 5.3 58/95] x86/entry/32: Use %ss segment where required Date: Wed, 27 Nov 2019 21:32:15 +0100 Message-Id: <20191127202924.538538946@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127202845.651587549@linuxfoundation.org> References: <20191127202845.651587549@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 4c4fd55d3d59a41ddfa6ecba7e76928921759f43 upstream. When re-building the IRET frame we use %eax as an destination %esp, make sure to then also match the segment for when there is a nonzero SS base (ESPFIX). [peterz: Changelog and minor edits] Fixes: 3c88c692c287 ("x86/stackframe/32: Provide consistent pt_regs") Signed-off-by: Andy Lutomirski Signed-off-by: Peter Zijlstra (Intel) Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- arch/x86/entry/entry_32.S | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) --- a/arch/x86/entry/entry_32.S +++ b/arch/x86/entry/entry_32.S @@ -210,6 +210,8 @@ /* * The high bits of the CS dword (__csh) are used for CS_FROM_*. * Clear them in case hardware didn't do this for us. + * + * Be careful: we may have nonzero SS base due to ESPFIX. */ andl $0x0000ffff, 3*4(%esp) @@ -263,6 +265,13 @@ .endm .macro IRET_FRAME + /* + * We're called with %ds, %es, %fs, and %gs from the interrupted + * frame, so we shouldn't use them. Also, we may be in ESPFIX + * mode and therefore have a nonzero SS base and an offset ESP, + * so any attempt to access the stack needs to use SS. (except for + * accesses through %esp, which automatically use SS.) + */ testl $CS_FROM_KERNEL, 1*4(%esp) jz .Lfinished_frame_\@ @@ -276,20 +285,20 @@ movl 5*4(%esp), %eax # (modified) regs->sp movl 4*4(%esp), %ecx # flags - movl %ecx, -4(%eax) + movl %ecx, %ss:-1*4(%eax) movl 3*4(%esp), %ecx # cs andl $0x0000ffff, %ecx - movl %ecx, -8(%eax) + movl %ecx, %ss:-2*4(%eax) movl 2*4(%esp), %ecx # ip - movl %ecx, -12(%eax) + movl %ecx, %ss:-3*4(%eax) movl 1*4(%esp), %ecx # eax - movl %ecx, -16(%eax) + movl %ecx, %ss:-4*4(%eax) popl %ecx - lea -16(%eax), %esp + lea -4*4(%eax), %esp popl %eax .Lfinished_frame_\@: .endm