Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp601326ybg; Fri, 12 Jun 2020 09:36:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymoAie8cGkU3xHP5AzhuZ9bk+lrtQKNuu5vM3besvK5dcj90rs6kZ7Z2YvZLLuSmcVtwgM X-Received: by 2002:aa7:cd4b:: with SMTP id v11mr12988705edw.356.1591979793456; Fri, 12 Jun 2020 09:36:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591979793; cv=none; d=google.com; s=arc-20160816; b=tJ0Fkfam9WXt4zjx+E/VQfWZ6nwic3DSl72a8sxqUT1iyqQpNQFjTDusUT4+JyoING Yz7kP6UrgKEXcoRtq+JnTPNJ+jVhWCCsUnKoiztqJh2UNdRk2s4b/X7My6TtTi4hF6+Z XOfLd/1bDv9jD+eQAe7QAEnNMVb90hjblMnPB9Euz9J49gcypLkv+jP1w31Up+IEeeRF r84F9RfbVPi2LZUYHKTQ6ybfSK+9ot1RYyU4TphrD3oDGfC8b5SwinSAAJ/ZRKKwHSge 6ydmCXako2WUsLawSZZF+C6AN51zDapxdfBbigmUFnv7SCYI7jgEn27kywVXXh0w+zLG tXVw== 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:ironport-sdr:ironport-sdr; bh=EDgmpclgEOha/PTOwErfYdfusf/DU9NrZcH1ffishjc=; b=Va9FpOi5nPu+JvO1KNcKJt1DJHy5MJqE3IhUkO00F5PhsSGZHgtalPDOv8gdsOSInC ZJfZte60+akYyI1bQWNCruffBllZRUKTXk+iyBY0UOesVpeqY52HtmXk1qDo5Va0MCq6 sNFey3cmtUp0v0LRy0EXKQYJvNb0iX59j43fvfKiKLaDKP7ZB0ePYpaE+LHUYjUdpa4A e7HOCEPln/mNxkTmx2duKRrUjKcl0i1PK55XxPrhEiCfMJYrt5/ZpIQD7MVj41Mf4Y3r bEgUlgNRYqINNJJ3mY3IfdvFTf5yO4pEWhWEK7JGQlSIGsTFF5VXGZLBlZBHX2F+SHOZ Q2qg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lj6si4096613ejb.108.2020.06.12.09.36.11; Fri, 12 Jun 2020 09:36:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726371AbgFLQeI (ORCPT + 99 others); Fri, 12 Jun 2020 12:34:08 -0400 Received: from mga09.intel.com ([134.134.136.24]:23746 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726112AbgFLQeH (ORCPT ); Fri, 12 Jun 2020 12:34:07 -0400 IronPort-SDR: 0ErhRB5FSTBLN11toJmxxYyah6LasDNZUlIrghLfkxA53DOeK0r2ltiBKt4gBjN/dqPBQ4TGiM iyJJlcRyLWNw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2020 09:34:06 -0700 IronPort-SDR: bQgeC4VBmyhs2p4OQebZkZzkLy8HM9QNhBMV7DebR+LLkZkC+Gxi6fncD00UZqmM1tl1CwOfUr CQAnefalwQ0Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,504,1583222400"; d="scan'208";a="307347223" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.152]) by fmsmga002.fm.intel.com with ESMTP; 12 Jun 2020 09:34:06 -0700 Date: Fri, 12 Jun 2020 09:34:06 -0700 From: Sean Christopherson To: Borislav Petkov Cc: x86-ml , Linus Torvalds , lkml Subject: Re: [RFC PATCH] x86/msr: Filter MSR writes Message-ID: <20200612163406.GA1026@linux.intel.com> References: <20200612105026.GA22660@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200612105026.GA22660@zn.tnic> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 12, 2020 at 12:50:26PM +0200, Borislav Petkov wrote: > @@ -95,11 +114,18 @@ static ssize_t msr_write(struct file *file, const char __user *buf, > err = wrmsr_safe_on_cpu(cpu, reg, data[0], data[1]); > if (err) > break; > + > tmp += 2; > bytes += 8; > } > > - return bytes ? bytes : err; > + if (bytes) { > + add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK); The kernel should be tainted if the WRMSR is attempted, regardless of whether it succeeds, and it should happen before the WRMSR. E.g. pointing MSR_IA32_DS_AREA at a bad address will likely cause an OOPS on the #PF that would occur the next time the CPU attempts to access the area, which could happen before wrmsr_safe_on_cpu() even returns. In general, there's no telling what microcode magic is buried behind WRMSR, i.e. a fault on WRMSR is not a good indicator that the CPU is still in a sane state. It might also make sense to do pr_err/warn_ratelimited() before the WRMSR, e.g. to help triage MSR writes that cause insta-death or lead to known bad behavior down the line. > + > + return bytes; > + } > + > + return err; > } > > static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg) > @@ -242,6 +268,8 @@ static void __exit msr_exit(void) > } > module_exit(msr_exit) > > +module_param(allow_writes, bool, 0400); This can be 0600, or maybe 0644, i.e. allow the user to enable/disable writes after the module has been loaded. > + > MODULE_AUTHOR("H. Peter Anvin "); > MODULE_DESCRIPTION("x86 generic MSR driver"); > MODULE_LICENSE("GPL");