Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8064958ybi; Thu, 6 Jun 2019 06:12:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjaFG7kS4KtsJqadBcDBvo/5DdQ4SgMuLf5qf9d4jlOStiZWeO54ts/3iqJjMEqc0664LF X-Received: by 2002:a17:902:b691:: with SMTP id c17mr27883829pls.107.1559826724961; Thu, 06 Jun 2019 06:12:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559826724; cv=none; d=google.com; s=arc-20160816; b=u7KlAS6reSOp3thhQ/cfFGbdxi4BWbPahNroUEcPI0DHagEYXB+sb6bSeJGDCW/hL6 PSb3QnLjFC53MdvVol0oDchcdZM7hVZl6BDRf6E7I33O0AvkwM9bRdDKZ3JaxBh9Oco+ C8n7EzMe3mUgZ+BFgCZ+iv/aQEvCoFEnw19lNXP+5aL+OfULqiK/FafP+ptsoMAuc1pn 7O/+dwV+FCIgU91nUfTGHp7JTWMIDvbvcg9j5GexlHKK3PdcMS6KbBDghR5lfKbo2gS5 wpupGJgkdGTc97XvDUrqcZlbGFvdbgf036ym34qITcEYTk4Go2Wq6x8ryir42MwnyH4i BHyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=MdznkmYUy0nzk2/YWJI8CLZrmjDsDQfLcBIhZ6qUSCo=; b=asCNYTqWhEFbEMO6h0hV3D2KbcRNUeVP71O1c9IZI6hzNsGsHjC3N+iECCN45OO6Hi mtT6XvXhagNltAXBY+4stlI/DyMLTfVqE017xCeEO3iYJCW6602rtVPFMH7ntWg1oAly fZVS5ZzkVZaOXsXPsKPE4seAK49q6YXH+hmLLLMqoa14evMF5H3Z/i9T2J4bP/S6QZZ+ NFvnYpoQB5H/5LELydOVRQROC7xI/x2PQz4SjWcaM09RroYUSf77I+XElPWbkjvnQGev oM6wA6LUPnL+sfirC1pAcEDggRssw4FgaCqYFAp233uRY763tZiyvHDeb1k0dZRzq/rH FVrg== 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 u25si1864629pfh.45.2019.06.06.06.11.46; Thu, 06 Jun 2019 06:12:04 -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; 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 S1727256AbfFFNJP (ORCPT + 99 others); Thu, 6 Jun 2019 09:09:15 -0400 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:50524 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726014AbfFFNJP (ORCPT ); Thu, 6 Jun 2019 09:09:15 -0400 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id B5F4B8027B; Thu, 6 Jun 2019 15:09:03 +0200 (CEST) Date: Thu, 6 Jun 2019 15:09:13 +0200 From: Pavel Machek To: pavel@ucw.cz Cc: linux-kernel@vger.kernel.org, "Peter Zijlstra (Intel)" , Borislav Petkov , Josh Poimboeuf , Linus Torvalds , Thomas Gleixner , Ingo Molnar , Sasha Levin Subject: Re: [PATCH 4.19 208/276] x86/ia32: Fix ia32_restore_sigcontext() AC leak Message-ID: <20190606130913.GD27432@amd> References: <20190530030523.133519668@linuxfoundation.org> <20190530030538.134917754@linuxfoundation.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ZARJHfwaSJQLOEUz" Content-Disposition: inline In-Reply-To: <20190530030538.134917754@linuxfoundation.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --ZARJHfwaSJQLOEUz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! (stable removed from cc). > [ Upstream commit 67a0514afdbb8b2fc70b771b8c77661a9cb9d3a9 ] >=20 > Objtool spotted that we call native_load_gs_index() with AC set. > Re-arrange the code to avoid that. Does this introduce undefined behaviour? >=20 > @@ -72,6 +71,7 @@ static int ia32_restore_sigcontext(struct pt_regs *regs, > struct sigcontext_32 __user *sc) > { > unsigned int tmpflags, err =3D 0; > + u16 gs, fs, es, ds; > void __user *buf; > u32 tmp; > =20 > @@ -79,16 +79,10 @@ static int ia32_restore_sigcontext(struct pt_regs *re= gs, > current->restart_block.fn =3D do_no_restart_syscall; > =20 > 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 =3D GET_SEG(gs); es is unitialized at this point, and we can trap. > + fs =3D GET_SEG(fs); > + ds =3D GET_SEG(ds); > + es =3D GET_SEG(es); > =20 > 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 *r= egs, > buf =3D compat_ptr(tmp); > } get_user_catch(err); > =20 > + /* > + * 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); > + But now we use uninitialized value in es... > err |=3D fpu__restore_sig(buf, 1); > =20 > force_iret(); Best regards, Pavel --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --ZARJHfwaSJQLOEUz Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlz5EHkACgkQMOfwapXb+vIfLACffEPp+lXO+Qx/xdsCtIi7lPTd R8sAoKLfCon9uCspCieqbuE8LudvueJF =FYiM -----END PGP SIGNATURE----- --ZARJHfwaSJQLOEUz--