Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp158425rwi; Sun, 30 Oct 2022 22:31:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7bBJgqoWWZPPv7jfZMu8n5JkH9EMjTJ4OyDA52aL0pkJL1TPjJQ6JFqBGVoaciq0KXoEBW X-Received: by 2002:a17:902:8542:b0:186:75ee:baac with SMTP id d2-20020a170902854200b0018675eebaacmr12420782plo.35.1667194291521; Sun, 30 Oct 2022 22:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667194291; cv=none; d=google.com; s=arc-20160816; b=oJDbs0vDv2+q6kU0TAA2Mfrc1vZq6zSmJixZTA9P372kf3XdEgcIEWPt819GRx6dfz NxhVBJ9vrNauUlokPAtixZ7h1dqeRBHMtMMmAjgxFhSTbsrYhcTFHMGMse4MSnA+QIqX lxP6T8jum03sYPpxGFAlyD/0YexhpZSn/ThDomnMgx+r7BrbNt+Q8dKuE8LSHeL+L5uH BC4iUmGAF9unMNCLiQLVFsgayc4btANn/VesC2JBjnyf+PZWbI/t7xFsRxkKF39Nm5Y6 Kuy92jKtsflorqCnGzSs0+oAFeSxTjO0I6i8wiIY0GuLhV9U6+o8YG0zCO1go7sIlaqQ ivjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=oF7QaoNaC3BVriizpHFYP5Gr1KWbQCkEuGc7WVWpAsA=; b=xwr4wOtKK/6Qk9267ZNsSd4xuxujdyh6EPv42scwuR6/Ok70iCrluf/t1jcivfdSr+ z1dINQebgClPSCpYHZxkygca9hSKF5MABSGKjlcFHRPMiZnC+4lNHVBgrJPg9dol0BpH mnGGrYGckyNpYV/PSl8QMVcqflUVlTxb28LFfVwEkm/6ZgxHKhUqNQvX0A091LGJss/8 YXc3e9XvOIJbtxh0eL3lJMhYHmXWKaE62tTAXUXdRzQY0RJ2Dlj9dBzTk1PGphkfgPvR rvuG1yPxCe909e7OcV3aBoCV6mEJMRF6c4LQ/sW46e4rY7sRjxks1OE3R71FxxbLVWQS l2+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov.name header.s=fm2 header.b=KDb0W4sZ; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=gEh2oOg9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iw7-20020a170903044700b001868431ecdbsi6723335plb.20.2022.10.30.22.31.18; Sun, 30 Oct 2022 22:31:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov.name header.s=fm2 header.b=KDb0W4sZ; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=gEh2oOg9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbiJaEdu (ORCPT + 99 others); Mon, 31 Oct 2022 00:33:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbiJaEds (ORCPT ); Mon, 31 Oct 2022 00:33:48 -0400 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19E1A9582; Sun, 30 Oct 2022 21:33:48 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 4D64E320034E; Mon, 31 Oct 2022 00:33:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 31 Oct 2022 00:33:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1667190825; x=1667277225; bh=oF 7QaoNaC3BVriizpHFYP5Gr1KWbQCkEuGc7WVWpAsA=; b=KDb0W4sZCCoB8m55Gk v9SGYht6oOISermCdc6VbqMg8trtmknUfk11vKDbcy20c8brEtLt3QJbbYMoIokU NjRLDx5vHNILi5CzBkThjDY1SMFoBk2Wbfij4pQLOtrJj4Yg+ZFmM5pxYMVbcQBe 4c2rB7nYVhI0zEsMW0UqJesRRwOml0lWNqlRyX56LG2CVuhc9yEMtLpxl+O7KNZ2 tlDmvdEjoW3ymRfWwHVzqmNMtsDF1IiAeFjE5ahVwX3Y7Y5sUZ7haZYl7KVNeAb3 ojGV2/ixqycbe30Zf95Z0zeiqs2NbrYrqrGE5/ahi1921m1h+0ubnbnPzJosQr2u g+pg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1667190825; x=1667277225; bh=oF7QaoNaC3BVriizpHFYP5Gr1KWb QCkEuGc7WVWpAsA=; b=gEh2oOg9drka0PzqY41OsrXaF6tFaGES2SujwbngDd2g YWagHESxcRuMMQcm+oqcVXRAb4s+Z2BUKaNsGg3fzl0ZPSbuwOTtYR3bJAX9pFZQ fxsEhwhufuLZ4xDK3bn2PFbx0Hw5Fxd9l2nEM3KlMgKOCkWwVq2Tm2LFz7u9U2p2 VAWCN3m3i9FV4uZRJh5OZiZVZJCP0kRh/MCIo0j2t1EUQn0N7GYxb1WRW1VEUaHt Yy80dgrgbmLpp7oRHZlzmmzOGgKZlZXdTiXf72w1Ae1T2SJg0wWmZHabeYSgoB8P VXH01m8v6IB2gT+4se7DpgdCnrbsYgxxRt5wIhFIwA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedruddugdejudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehttddttddttddvnecuhfhrohhmpedfmfhirhhi lhhlucetrdcuufhhuhhtvghmohhvfdcuoehkihhrihhllhesshhhuhhtvghmohhvrdhnrg hmvgeqnecuggftrfgrthhtvghrnhephfeigefhtdefhedtfedthefghedutddvueehtedt tdehjeeukeejgeeuiedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepkhhirhhilhhlsehshhhuthgvmhhovhdrnhgrmhgv X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 31 Oct 2022 00:33:44 -0400 (EDT) Received: by box.shutemov.name (Postfix, from userid 1000) id 8EA2E109579; Mon, 31 Oct 2022 07:33:42 +0300 (+03) Date: Mon, 31 Oct 2022 07:33:42 +0300 From: "Kirill A. Shutemov" To: Guorui Yu Cc: kirill.shutemov@linux.intel.com, ak@linux.intel.com, bp@alien8.de, dan.j.williams@intel.com, dave.hansen@intel.com, david@redhat.com, elena.reshetova@intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org, luto@kernel.org, mingo@redhat.com, peterz@infradead.org, sathyanarayanan.kuppuswamy@linux.intel.com, seanjc@google.com, stable@vger.kernel.org, tglx@linutronix.de, thomas.lendacky@amd.com, x86@kernel.org Subject: Re: [PATCH 2/2] x86/tdx: Do not allow #VE due to EPT violation on the private memory Message-ID: <20221031043342.di5wtvi2x4mfbkko@box.shutemov.name> References: <20221028141220.29217-3-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 31, 2022 at 12:07:45PM +0800, Guorui Yu wrote: > The core of this vulnerability is not directly related to the > ATTR_SEPT_VE_DISABLE, but the MMIO processing logic in #VE. > > We have encountered similar problems on SEV-ES, here are their fixes on > Kernel [1] and OVMF[2]. > > Instead of enforcing the ATTR_SEPT_VE_DISABLE in TDX guest kernel, I think > the fix should also include necessary check on the MMIO path of the #VE > routine. Missing SEPT_VE_DISABLE exposes to more security problems than confused handle_mmio(). Rogue #VE that is rightly timed can be used to escalate privileges and more. Just adding check there would solve only some potential attacks. > static int handle_mmio(struct pt_regs *regs, struct ve_info *ve) > { > unsigned long *reg, val, vaddr; > char buffer[MAX_INSN_SIZE]; > struct insn insn = {}; > enum mmio_type mmio; > int size, extend_size; > u8 extend_val = 0; > > // Some addtional security check about ve->gpa should be introduced here. > > /* Only in-kernel MMIO is supported */ > if (WARN_ON_ONCE(user_mode(regs))) > return -EFAULT; > > // ... > } > > If we don't fix the problem at the point where we found, but rely on > complicated composite logic and long comments in the kernel, I'm confident > we'll fall back into the same pit in the near future :). The plan is to add the check there along with relaxing SEPT_VE_DISABLE for debug TD. It is required to debug guest kernel effectively. Otherwise access to unaccepted memory would terminate TD with zero info on why. But it is not the urgent fix. It can be submitted separately. -- Kiryl Shutsemau / Kirill A. Shutemov