Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp272399ybi; Wed, 29 May 2019 21:07:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4fd8iORSkhTGIpyum+NGULaEgMV6sN5Y8xP81pPxuqqLbt6xUWUGwAeLEy0WDzno6rCez X-Received: by 2002:a17:902:760f:: with SMTP id k15mr1833794pll.125.1559189229545; Wed, 29 May 2019 21:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559189229; cv=none; d=google.com; s=arc-20160816; b=nAiYJ0K+VI6S9smla+9C+ntkLoddUAsHCdSfpP8KlIM8ChJuxqEjzx0374YqvoPiVv fhYxHA2x3Tx1Y/siUOPMzG6BP+I3UoNsYH9jLxtPHarIDrAJf6ON5cyv+ofoj56SfJTO OjlSKdb1364ZawukICPsPJRJp//4sUCatOtNn/+UW8beahEp1sqb2QS7zpT3biUTDWYB yRDDZWjrCi9oC8EY+AfwXL8Cyw2+ySvUYo8rQpxOOPbI749D/m8SD02IING0ESC1GoA+ h0qRAepoZzBkJcEDZYUCOIY1MpB8yegVT2TyleCxUg8JhlWD+GZ8ngR3dH23Xts7U6KX MQng== 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=nCKco/nnKLQOABK+PsdH+1IMX+XYmGqGiny610DoSLU=; b=N8SBHAX50mVztEVPlrVUOB1MsAuTPrs1sP66G7BYzNRjObACv6jXXV+FY01fMvzWPn efX483aIaj608ijqomm+Yk4dY5ZRzCyxs7NQbWYrbgMbmNteeoK9gBiRsdLovlvNtqXs /Tx+3r/rNo2dSO0MiD40qp9ZgyudT2ot8TKlkGe+bUqTl+2dqA0tJc4ernMmLtUYd4RZ ZXUlfO0YhBVL4BGExc6otu5VBRRa6P/jZCsE3vHrgWVoco6VIZd5JbATVpvVYbz4zV/t aeVWLctP/ntJSC7Gblc/SQOpkcoRGl9Ze5jkOvfhL+GdR3wzS3Y4zSkumEOqhe/vEaau ldIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JB6ozZAO; 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 o6si1905166plk.296.2019.05.29.21.06.53; Wed, 29 May 2019 21:07:09 -0700 (PDT) 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=JB6ozZAO; 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 S1731267AbfE3EEt (ORCPT + 99 others); Thu, 30 May 2019 00:04:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:48242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731272AbfE3DRu (ORCPT ); Wed, 29 May 2019 23:17:50 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (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 97AE82472A; Thu, 30 May 2019 03:17:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186269; bh=6GuArfTvBzCsb8xZnBZRozVOoVR8LndQKkMUmS0qzpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JB6ozZAOaUb5LmfUHltjC65g9oakIIwHOZBiLuCYd1JD58o7uTEvyIqDPEkTqjlbs ZPgwhVwx7sj/u98kVAY7cUgMdk9AC1vN5t+n5BWGHKK8K0tzlB/p0BnPhUYvLpvNg5 eLst2LdzQ4ordlLyB0hVKRkLjimmW0UKVQeXXxao= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Borislav Petkov , Josh Poimboeuf , Linus Torvalds , Thomas Gleixner , Ingo Molnar , Sasha Levin Subject: [PATCH 4.19 208/276] x86/ia32: Fix ia32_restore_sigcontext() AC leak Date: Wed, 29 May 2019 20:06:06 -0700 Message-Id: <20190530030538.134917754@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@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 [ Upstream commit 67a0514afdbb8b2fc70b771b8c77661a9cb9d3a9 ] Objtool spotted that we call native_load_gs_index() with AC set. Re-arrange the code to avoid that. Signed-off-by: Peter Zijlstra (Intel) Cc: Borislav Petkov Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- arch/x86/ia32/ia32_signal.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c index 86b1341cba9ac..513ba49c204fe 100644 --- a/arch/x86/ia32/ia32_signal.c +++ b/arch/x86/ia32/ia32_signal.c @@ -61,9 +61,8 @@ } while (0) #define RELOAD_SEG(seg) { \ - unsigned int pre = GET_SEG(seg); \ + unsigned int pre = (seg) | 3; \ unsigned int cur = get_user_seg(seg); \ - pre |= 3; \ if (pre != cur) \ set_user_seg(seg, pre); \ } @@ -72,6 +71,7 @@ static int ia32_restore_sigcontext(struct pt_regs *regs, struct sigcontext_32 __user *sc) { unsigned int tmpflags, err = 0; + u16 gs, fs, es, ds; void __user *buf; u32 tmp; @@ -79,16 +79,10 @@ static int ia32_restore_sigcontext(struct pt_regs *regs, current->restart_block.fn = do_no_restart_syscall; get_user_try { - /* - * Reload fs and gs if they have changed in the signal - * handler. This does not handle long fs/gs base changes in - * the handler, but does not clobber them at least in the - * normal case. - */ - RELOAD_SEG(gs); - RELOAD_SEG(fs); - RELOAD_SEG(ds); - RELOAD_SEG(es); + gs = GET_SEG(gs); + fs = GET_SEG(fs); + ds = GET_SEG(ds); + es = GET_SEG(es); COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx); COPY(dx); COPY(cx); COPY(ip); COPY(ax); @@ -106,6 +100,17 @@ static int ia32_restore_sigcontext(struct pt_regs *regs, buf = compat_ptr(tmp); } get_user_catch(err); + /* + * Reload fs and gs if they have changed in the signal + * handler. This does not handle long fs/gs base changes in + * the handler, but does not clobber them at least in the + * normal case. + */ + RELOAD_SEG(gs); + RELOAD_SEG(fs); + RELOAD_SEG(ds); + RELOAD_SEG(es); + err |= fpu__restore_sig(buf, 1); force_iret(); -- 2.20.1