Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp899121pxb; Thu, 19 Nov 2020 17:12:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwI4yWT1oEZEWpBGR1S3uMMROy/KrnA9/cA/xWkk6B4qWBeacDGfVx+nJ2WcRtr1BGaE7fS X-Received: by 2002:a50:ccdb:: with SMTP id b27mr11072307edj.253.1605834754849; Thu, 19 Nov 2020 17:12:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605834754; cv=none; d=google.com; s=arc-20160816; b=d+uy8YJQhBoI8Wgh3l95Z7hKbrf+VidfEgT+U4DIaWnbQtOUkHqZhj7rzckT8TwYg0 M4yONnyk/vRbyX/dnRaHlENw3s9zAH5BRNBc1tbXQp8sU1Ed80xFMa/zGR5b/GA0/FYj yUyisudiiX2FtikbUkPN7AqIH9ZL19w+TrZkysWg0dT8Syfmq2J8tGs1E9r6Ps7adc7y a1wsxrcS6iFiZnnF+XFXW+eD94oOsKQ0JVeeM2aN4a0IE1Zy3pU0UEOpzFQ40sqM4ErW /mZnwDNNaU/LjqT0T0Bmqw862DSl5Y6aC8vL4NwaSo6fxHbnoQA1OFt9BWj5JMQUBkqD 3m1A== 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=4K9iPhC4qNk/Rh7UFJxvkVuXYE1ScmXCx5XNoAoo/BE=; b=AV36MEpCf6aQS/q9lTtVU4FQSugLED9DXV63napjMYVUAdS+0jz7C0o9d4l+Q6/buE 7DvqhQuEbE28qFRYkmKDl/oiUPVRVu9vZRFhoK7ihXc/nvXiTRT95S0q/JPJ6qtfPbuI FfV7CtdGtjao3twPUy7IZ/S++n3KSZWRftLbF33oIchCJFSr289NucDrV88xVCZzEB5U KniM8FTnswwDvusxHHwGmcmMbUF87PKbSZRlutqSLH36j3FYp/jH/vW+RIDYV4IYB/8H xw696r61R8cs2Iob+mj3uzjTkgPbwX4akNwFHxPUr6VIEXI4IMM27lger+YU3RZmIga7 afOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=E3GJkkDU; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ga28si744185ejc.566.2020.11.19.17.12.11; Thu, 19 Nov 2020 17: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=@google.com header.s=20161025 header.b=E3GJkkDU; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726420AbgKTBJq (ORCPT + 99 others); Thu, 19 Nov 2020 20:09:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726260AbgKTBJq (ORCPT ); Thu, 19 Nov 2020 20:09:46 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87661C0613CF for ; Thu, 19 Nov 2020 17:09:46 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id v5so2204468pff.10 for ; Thu, 19 Nov 2020 17:09:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=4K9iPhC4qNk/Rh7UFJxvkVuXYE1ScmXCx5XNoAoo/BE=; b=E3GJkkDUqRZcXOyddzcINghpgvYz14dVycTO5GBG/X8xKxQGkdk61gAfgNosA+BnrD DhtJQ6e8tMom+YYPIqk23Jw5SqIoZz7vdbzFyFT8RisdczKdIb4GfLoPhR+AbER0ZlHS IR3i5nest+Wdeh8ILGUPy6OlF2IeMsx79P/E+cMqDxO1spMZbJf+lVvHyvtmPwWPLYem UgMxICwkAvDt0epg4fjoojKXIZq9f8fvoXbIyX/KS6gopdru9Do6qv5y6i8XApp9KoU7 5FeGwEbL6MZF4XVusM+xWmuIeUtjsRjEPYWl4HVr4KjjXKMLM1B0Qxcu9HsMurpfBDfv nLAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=4K9iPhC4qNk/Rh7UFJxvkVuXYE1ScmXCx5XNoAoo/BE=; b=NCPoyZ2+bVlHGIDdNW4Z67ziMiDo1IyGkx8UXBj+UtoGTwp6NluRDUCqLkg9LRQ6PQ dvqK4B5A9v1ZMjhlTBLOAubGVI65OsG4IuxyKSM8YgFFWh+eVjtSCGvP25LO43CwKVCW +yzlN4t6P7gGW1gJSiHPsOW6Su3i6Ds4uhQ0mCKffoYhnm3uYQl16pe2cDPtgHL5CK4v Q/b7T1LHdlRfe9K2lU93XcXgm4yfv+vpVI/nOVcwXMD42oqfxOvSf/dVp/6FwYMC7AzV B4QIdMHZwd65JKTjNcqcjVsbJpS8UTBziTvSMM7cWUkWDLY8tEJRTY+3HAPhcSLDN3t6 tP3Q== X-Gm-Message-State: AOAM532oYzSvvmgYyu43Py+IuKC/9eqFU/v72pcmywbreK4Wzu2JB7LA jHDGEx5su2Cu80e80mDVV+XfcIORVhjguQ== X-Received: by 2002:a17:90a:4802:: with SMTP id a2mr7781069pjh.22.1605834585766; Thu, 19 Nov 2020 17:09:45 -0800 (PST) Received: from google.com ([2620:0:1008:11:7220:84ff:fe09:dc21]) by smtp.gmail.com with ESMTPSA id c193sm1206226pfb.78.2020.11.19.17.09.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 17:09:44 -0800 (PST) Date: Thu, 19 Nov 2020 17:09:40 -0800 From: Tom Roeder To: Keith Busch 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: <20201120010940.GA2943603@google.com> References: <20201119185919.2742954-1-tmroeder@google.com> <20201119210914.GB2855047@dhcp-10-100-145-180.wdc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20201119210914.GB2855047@dhcp-10-100-145-180.wdc.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 19, 2020 at 01:09:14PM -0800, Keith Busch wrote: >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. I agree; I don't think there's anything the driver can do about that. > >> + /* 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. Thanks! I'll change the type to a new struct that has the addr and size fields as native integers and send out a v2 for this patch that makes that change and cleans up a couple of minor style issues in my code.