From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_PASS, USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0997C43381 for ; Mon, 25 Feb 2019 16:10:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A00D2183F for ; Mon, 25 Feb 2019 16:10:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="FWfpBe+T" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727990AbfBYQKK (ORCPT ); Mon, 25 Feb 2019 11:10:10 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:48880 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727661AbfBYQKK (ORCPT ); Mon, 25 Feb 2019 11:10:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Tawx4lmsRRjp0D5cm+weto7GNiuytBsLWsZM3fB2Kpw=; b=FWfpBe+To1EtfKO4mNvXlIR/f JVc9aH7T2dFU7hCcblhwKmWg0wScNswEMpiO2xGMB/FLYX1WGoQmp1Om6ir5BBSUWOIJg5wM5e7jt 0QKLO+pklGq/TtFAt75eHXit8F8UBJeMIatpe5uKAVIhJSKhPp2t1m0yZ2AVQZb0s5ep9aWh+tTSR 6QnyygFu4fTGGOZcpabM9yh/i7w3viXo4WvjAvuuphVAF8Y5gVGCd5JNRNm9DXG5uk5KNQCd1GDkn srgoDxr1De6UCSITIfcOaMYe8/5tWTpfNAa8pGDGCj0nbAtS8yyvJbtlnZkQIYGAGgYdXcVbF5Kh9 kDrHoD/fw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gyIpR-000235-6F; Mon, 25 Feb 2019 16:10:05 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 99A842026BE6C; Mon, 25 Feb 2019 17:10:03 +0100 (CET) Date: Mon, 25 Feb 2019 17:10:03 +0100 From: Peter Zijlstra To: Andy Lutomirski Cc: Linus Torvalds , Thomas Gleixner , "H. Peter Anvin" , Julien Thierry , Will Deacon , Ingo Molnar , Catalin Marinas , James Morse , valentin.schneider@arm.com, Brian Gerst , Josh Poimboeuf , Andrew Lutomirski , Borislav Petkov , Denys Vlasenko , LKML Subject: Re: [PATCH 2/6] x86/ia32: Fix ia32_restore_sigcontext AC leak Message-ID: <20190225161003.GL32477@hirez.programming.kicks-ass.net> References: <20190225124330.613028745@infradead.org> <20190225125231.936952143@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 25, 2019 at 07:41:50AM -0800, Andy Lutomirski wrote: > This is so tangled. > > How about changing RELOAD_SEG to replace unsigned int pre = > GET_SEG(seg); with unsigned int pre = (seg); to make it less magic. > Then do: > > unsigned int gs = GET_SEG(gs); > > ... > > RELOAD_SEG(gs); > > And now the code actually does what it looks like it does. Is this what you mean? --- diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c index 321fe5f5d0e9..e04eeeddcc35 100644 --- a/arch/x86/ia32/ia32_signal.c +++ b/arch/x86/ia32/ia32_signal.c @@ -53,17 +53,16 @@ #define GET_SEG(seg) ({ \ unsigned short tmp; \ get_user_ex(tmp, &sc->seg); \ - tmp; \ + tmp | 3; \ }) #define COPY_SEG_CPL3(seg) do { \ - regs->seg = GET_SEG(seg) | 3; \ + regs->seg = GET_SEG(seg); \ } while (0) #define RELOAD_SEG(seg) { \ - unsigned int pre = GET_SEG(seg); \ + unsigned int pre = (seg); \ 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();