Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp892995imp; Wed, 20 Feb 2019 10:56:27 -0800 (PST) X-Google-Smtp-Source: AHgI3IaPdmjoWtHbkRCCvhvgFGBmKRLsHqhlAclqiDI+im1fDKjySN0NEndcx0AWznKxFRsMSftD X-Received: by 2002:a63:5964:: with SMTP id j36mr30459741pgm.210.1550688987324; Wed, 20 Feb 2019 10:56:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550688987; cv=none; d=google.com; s=arc-20160816; b=PHB/DRFzuISTx+7W4M7FmLo7iRbOpe13syhOtA5ALH0RsMsdNX4RC9xVPd60P6jRbI 5bwSSJ3OkHYgSrQ522Utz5ah/7E/FUzRyMNDGilBU6chKXIqYpkKnMIsqa5kDGnyL+iy GEFgcEdM47++obId917aSKXNajEcV1fdgssfGPWjlfm1kSTWCH5HZlQG25Ii63Ghd+qQ RAaPbySNd7fCvjCKKSvh9h7JYcqFtzx9ysNtfK+Irfo26kyF/CQMF2ItNHpp6RM7DgcV 1kQjWUe9W95xX9oxuddsWb3AUys/Gwg/UqhQT4x41ONhsDdYI+BmOWPbbX95P2BaHLqG o5/A== 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=dkNRIiGVQ+8TCT+jw/o5f5gtXnkZ2e8lseRq4OCqPOM=; b=ZWxeuRxzo2QSjEZBCB6cKOubkOPao3VAQaGXRC5DXMAyB0bpOLlCISJ/DtXxHiSW9l UOtl3Tm86njLb9KL+0jcs2s5DBJP5TXoDk7uk+Y1kaY7I7aBm8CaUrQkCgqMg2RmF7DK oOh9vWIuidJTn4jL/YMydTnTjSwQw7jVJtczSMw/x485R9EFn2eUk+RYDPREXdcuEPAR mSGraE72IvUMyWjwyAIhfIb5Bszo6OMdWDm91vi7cRUZG2dwA28KL26Lg/glFWMnZyuH uAUY+2Ig0yY/dShwFSSoCzB4nKI1qbGSVyfDEvDbVmoZNrvEoUOUPKN/SKwv3KipQcgd eq3g== 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 b9si21478292plb.350.2019.02.20.10.56.11; Wed, 20 Feb 2019 10:56:27 -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; 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 S1726380AbfBTSzu (ORCPT + 99 others); Wed, 20 Feb 2019 13:55:50 -0500 Received: from mother.openwall.net ([195.42.179.200]:52511 "HELO mother.openwall.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1725798AbfBTSzu (ORCPT ); Wed, 20 Feb 2019 13:55:50 -0500 X-Greylist: delayed 401 seconds by postgrey-1.27 at vger.kernel.org; Wed, 20 Feb 2019 13:55:50 EST Received: (qmail 30382 invoked from network); 20 Feb 2019 18:49:08 -0000 Received: from localhost (HELO pvt.openwall.com) (127.0.0.1) by localhost with SMTP; 20 Feb 2019 18:49:08 -0000 Received: by pvt.openwall.com (Postfix, from userid 503) id 067D8AA7D0; Wed, 20 Feb 2019 19:48:59 +0100 (CET) Date: Wed, 20 Feb 2019 19:48:59 +0100 From: Solar Designer To: Kees Cook Cc: Thomas Gleixner , Jann Horn , Dominik Brodowski , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, x86@kernel.org Subject: Re: [PATCH v2] x86/asm: Pin sensitive CR4 bits Message-ID: <20190220184859.GA6429@openwall.com> References: <20190220180934.GA46255@beast> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190220180934.GA46255@beast> User-Agent: Mutt/1.4.2.3i Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 20, 2019 at 10:09:34AM -0800, Kees Cook wrote: > +extern volatile unsigned long cr4_pin; > + > static inline void native_write_cr4(unsigned long val) > { > +again: > + val |= cr4_pin; > asm volatile("mov %0,%%cr4": : "r" (val), "m" (__force_order)); > + /* > + * If the MOV above was used directly as a ROP gadget we can > + * notice the lack of pinned bits in "val" and start the function > + * from the beginning to gain the cr4_pin bits for sure. > + */ > + if (WARN_ONCE((val & cr4_pin) != cr4_pin, "cr4 bypass attempt?!\n")) > + goto again; > } I think "goto again" is too mild a response given that it occurs after a successful write of a non-pinned value to CR4. I think it'd allow some exploits to eventually win the race: make their desired use of whatever functionality SMEP, etc. would have prevented - which may be just a few instructions they need to run - before the CR4 value is reverted after "goto again". I think it's one of those cases where a kernel panic would be more appropriate. Also, WARN_ONCE possibly introduces a delay sufficient to realistically win this race on the first try. If we choose to warn, we should do it after having reverted the CR4 value, not before. Alexander