Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp762976pxb; Thu, 19 Nov 2020 13:12:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJyuw76JXg2o2T8pQBxLLCAaEaOxFuEVthGa0BEEq0Ds9nZvbfh/z1zh8538ZGR5Ee4J1me2 X-Received: by 2002:a50:cd09:: with SMTP id z9mr33237477edi.152.1605820354335; Thu, 19 Nov 2020 13:12:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605820354; cv=none; d=google.com; s=arc-20160816; b=VqPir2sCCGMxmfCqeWmMhl2HMp9cuQ9FS6k5Rer++26AG1qUqEECsqQ9pGZFEGq+o8 8U/+6kriqhxWqCSgQWlQcS0aWjjJvOK0dW/RQDwpHO2rt2B4cAM8oUPZ/Ig/4YHhqPNJ fXjf/gQWV25N7zEmGjiIp5D9uGAf9WUd6M+25Kb18msMLfI3+CM/IgG2na0gQ6eGVmQ5 ZUblogT1Kz68Pe36No4UnDGeVKt3yN6LUxQgXFENuX+TCBXfpchmfVOHxQxUNYmAs//u 7DREL4NyBb9eIukBRA8a/WjTinyRM3pbm8mJgTgPMm8ZjBdUfa4egmzjNM5GxhXKk4ce AqRg== 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:dkim-signature; bh=jw+078vvvUlWNn7t0/H1Rw5virF2GcIVQ8n8bu6313Y=; b=nQl8Lwl7BaiL9kgzEkZq2sY2qbjIfsEjA6/VCrf0AspO1PlCh6ldCErD6hDW2Lggmh C7gnhdvp/asLnqMx3FZweqWLIB5c6haVGaA0VEEOj/H3BtdRsJbiu82qMGoOGfAGTynu gIi1O0Tq1XrgyQvhWrbqoHsc+g9a295FjlOVV6ZHx6otQHWubsyIAjN2O9Wa8nXXPJiq 8TC9LELIaMb+3eyWl6NFCVo3B86QFOLYFwoAZhwdU5iWV8u9A8ihwo3vaiApHMpLPFd9 vU00YY4D+Pi+SD1jIzj6O3ppu83VInrvHcHDCSYcTq51YTm8djb1EV8Zn4lfrHTNcKg4 4Wpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eX9gKLP4; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t5si557673edq.590.2020.11.19.13.12.11; Thu, 19 Nov 2020 13:12:34 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=eX9gKLP4; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726837AbgKSVJS (ORCPT + 99 others); Thu, 19 Nov 2020 16:09:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:41692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726096AbgKSVJS (ORCPT ); Thu, 19 Nov 2020 16:09:18 -0500 Received: from dhcp-10-100-145-180.wdc.com (unknown [199.255.45.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E20E822255; Thu, 19 Nov 2020 21:09:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605820157; bh=wobWbrfe+CcBfAqh6g1sHmyepcpP3tuS6adaYB2sqNk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eX9gKLP40Y036drTN5kXwWv7ntyy0/4K4wht1FrMjOGTY7+WYClrYAi61GWWeUcda QHt7JNCDAr6UlQTfIXDfl21Z7SKYuakRPErWkTMlfS4eCZ50RmSNgrKPC6qDUs+005 hO0pO+OriwUpiDtdlBoYNC2MLiaz7UCAEab/zPRg= Date: Thu, 19 Nov 2020 13:09:14 -0800 From: Keith Busch To: Tom Roeder Cc: Jens Axboe , Christoph Hellwig , Sagi Grimberg , Peter Gonda , Marios Pomonis , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] nvme: Cache DMA descriptors to prevent corruption. Message-ID: <20201119210914.GB2855047@dhcp-10-100-145-180.wdc.com> References: <20201119185919.2742954-1-tmroeder@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201119185919.2742954-1-tmroeder@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 19, 2020 at 10:59:19AM -0800, Tom Roeder wrote: > This patch changes the NVMe PCI implementation to cache host_mem_descs > in non-DMA memory instead of depending on descriptors stored in DMA > memory. This change is needed under the malicious-hypervisor threat > model assumed by the AMD SEV and Intel TDX architectures, which encrypt > guest memory to make it unreadable. Some versions of these architectures > also make it cryptographically hard to modify guest memory without > detection. > > On these architectures, Linux generally leaves DMA memory unencrypted so > that devices can still communicate directly with the kernel: DMA memory > remains readable to and modifiable by devices. This means that this > memory is also accessible to a hypervisor. > > However, this means that a malicious hypervisor could modify the addr or > size fields of descriptors and cause the NVMe driver to call > dma_free_attrs on arbitrary addresses or on the right addresses but with > the wrong size. To prevent this attack, this commit changes the code to > cache those descriptors in non-DMA memory and to use the cached values > when freeing the memory they describe. If the hypervisor does that, then the device may use the wrong addresses, too. I guess you can't do anything about that from the driver, though. > + /* Cache the host_mem_descs in non-DMA memory so a malicious hypervisor > + * can't change them. > + */ > + struct nvme_host_mem_buf_desc *host_mem_descs_cache; > void **host_mem_desc_bufs; This is never seen by an nvme device, so no need for an nvme specific type here. You can use arch native types.