Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp463969imp; Thu, 21 Feb 2019 05:08:00 -0800 (PST) X-Google-Smtp-Source: AHgI3IYemQBPFYHnlmbzjr/De+cOMUZitzVjoXzf0vI8sPX/YqzebrMr1A9TjPSZSuljvAOgWfSf X-Received: by 2002:a17:902:8692:: with SMTP id g18mr14056705plo.149.1550754480610; Thu, 21 Feb 2019 05:08:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550754480; cv=none; d=google.com; s=arc-20160816; b=tgxipyLzYuED5xHUK306VHHg2VO7g2m4NsPKJQbpgeVWvTzI6IE1hUdfR5/CrnbUvR 2a4Ovwvy06cpL9rfCAhKEVpjLOcWree0Czp5/jdoZ1svq/MnnHDWafkrvPkEMNccPePk S82GYC/fSo+Ec+ygp2Fpf9KOKMH+0Nzn+T0se+WsS6NQugX8Cj/hTALK8Eaej8xBavO5 Qz0jwB3+H+xZ+NK2xs6FAY6YZn9bjU/qjmWBc5aeJM8bXjBEnmmfSYYMZB6Pfk4dDg0I IuapdsDPXDRtkMdqI/eM6acJDpSh7fFn8HoIjuYErKNRZ/uexm5+dY4LhIEXMjNFtwfc KJ7g== 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=/NBIibnGClx646X2AZqSW2D0Pa151ZtXVDPZLznorP4=; b=VmrUtAx/SX5DHRn9cPAeunYkPFEFqTKM63/b8UMQjOKkhCXEkSRT2zfY9/ijE/Ehkn 9ZQypBdZ7miB6jRAkTrFHAItmTehspRHp7FzdMYiR4LT2xdaz0nntV+QJszCH6y02Tsr L8D0st+Fxd7Baqg/tQ7TBsR7qV4Uc4MFWgPcycwOtnjztomOcFhYIOOLSB64W+JKoRqQ 6W5Ooh0OICwkL9rC6NUC+LtYEeVw2I2ULrVgtcgyLDRnBiO7iJ6NFFl7wlFxS2OKKNQJ 2KJfdapMzoUDwmiJ01jXxYHAmOxcnTf/4qa2TzTZIO9Dtvx6Gf0RuwFhP1zXjR4Ybmm8 fnIQ== 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 130si21295665pfy.262.2019.02.21.05.07.44; Thu, 21 Feb 2019 05:08:00 -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 S1727696AbfBUNGw (ORCPT + 99 others); Thu, 21 Feb 2019 08:06:52 -0500 Received: from mother.openwall.net ([195.42.179.200]:47404 "HELO mother.openwall.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1725831AbfBUNGw (ORCPT ); Thu, 21 Feb 2019 08:06:52 -0500 Received: (qmail 32250 invoked from network); 21 Feb 2019 13:06:49 -0000 Received: from localhost (HELO pvt.openwall.com) (127.0.0.1) by localhost with SMTP; 21 Feb 2019 13:06:49 -0000 Received: by pvt.openwall.com (Postfix, from userid 503) id 5E5A8AA7D0; Thu, 21 Feb 2019 14:06:45 +0100 (CET) Date: Thu, 21 Feb 2019 14:06:45 +0100 From: Solar Designer To: Kees Cook Cc: Thomas Gleixner , Jann Horn , Dominik Brodowski , LKML , Kernel Hardening , X86 ML Subject: Re: [PATCH v2] x86/asm: Pin sensitive CR4 bits Message-ID: <20190221130645.GA8281@openwall.com> References: <20190220180934.GA46255@beast> <20190220184859.GA6429@openwall.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 01:20:58PM -0800, Kees Cook wrote: > On Wed, Feb 20, 2019 at 10:49 AM Solar Designer wrote: > > > > On Wed, Feb 20, 2019 at 10:09:34AM -0800, Kees Cook wrote: > > > + 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. > > It will not land upstream with a BUG() or panic(). Linus has > explicitly stated that none of this work can do that until it has > "baked" in the kernel for a couple years. OK. > In his defense, anyone sufficiently paranoid can already raise the > priority of a WARN() into a panic via sysctl kernel.panic_on_warn (and > kernel.panic_on_oops). I think there are too many uses of WARN() for anyone sane to enable that in production, whereas it'd have made sense to enable it for the few security-related uses. > > 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. > > Isn't cr4 CPU-local though? Good point. I don't know. If CR4 is per hardware thread, then the race would require an interrupt and would be much harder to win. > Couldn't we turn off interrupts to stop the race? This won't help. An attack would skip the code that disables interrupts and land right on the MOV instruction. Alexander