lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 7 Jul 2022 07:58:40 +0200
From:   Christoph Hellwig <hch@....de>
To:     "Andrea Parri (Microsoft)" <parri.andrea@...il.com>
Cc:     Christoph Hellwig <hch@....de>,
        Marek Szyprowski <m.szyprowski@...sung.com>,
        Robin Murphy <robin.murphy@....com>,
        KY Srinivasan <kys@...rosoft.com>,
        Haiyang Zhang <haiyangz@...rosoft.com>,
        Stephen Hemminger <sthemmin@...rosoft.com>,
        Wei Liu <wei.liu@...nel.org>, Dexuan Cui <decui@...rosoft.com>,
        Michael Kelley <mikelley@...rosoft.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        Peter Anvin <hpa@...or.com>, linux-kernel@...r.kernel.org,
        iommu@...ts.linux-foundation.org, iommu@...ts.linux.dev,
        linux-hyperv@...r.kernel.org, x86@...nel.org
Subject: Re: [RFC PATCH 2/2] dma-direct: Fix dma_direct_{alloc,free}() for
 Hyperv-V IVMs

On Wed, Jul 06, 2022 at 09:50:27PM +0200, Andrea Parri (Microsoft) wrote:
> @@ -305,6 +306,21 @@ void *dma_direct_alloc(struct device *dev, size_t size,
>  		ret = page_address(page);
>  		if (dma_set_decrypted(dev, ret, size))
>  			goto out_free_pages;
> +#ifdef CONFIG_HAS_IOMEM
> +		/*
> +		 * Remap the pages in the unencrypted physical address space
> +		 * when dma_unencrypted_base is set (e.g., for Hyper-V AMD
> +		 * SEV-SNP isolated guests).
> +		 */
> +		if (dma_unencrypted_base) {
> +			phys_addr_t ret_pa = virt_to_phys(ret);
> +
> +			ret_pa += dma_unencrypted_base;
> +			ret = memremap(ret_pa, size, MEMREMAP_WB);
> +			if (!ret)
> +				goto out_encrypt_pages;
> +		}
> +#endif


So:

this needs to move into dma_set_decrypted, otherwise we don't handle
the dma_alloc_pages case (never mind that this is pretty unreadable).

Which then again largely duplicates the code in swiotlb.  So I think
what we need here is a low-level helper that does the
set_memory_decrypted and memremap.  I'm not quite sure where it
should go, but maybe some of the people involved with memory
encryption might have good ideas.  unencrypted_base should go with
it and then both swiotlb and dma-direct can call it.

> +	/*
> +	 * If dma_unencrypted_base is set, the virtual address returned by
> +	 * dma_direct_alloc() is in the vmalloc address range.
> +	 */
> +	if (!dma_unencrypted_base && is_vmalloc_addr(cpu_addr)) {
>  		vunmap(cpu_addr);
>  	} else {
>  		if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_CLEAR_UNCACHED))
>  			arch_dma_clear_uncached(cpu_addr, size);
> +#ifdef CONFIG_HAS_IOMEM
> +		if (dma_unencrypted_base) {
> +			memunmap(cpu_addr);
> +			/* re-encrypt the pages using the original address */
> +			cpu_addr = page_address(pfn_to_page(PHYS_PFN(
> +					dma_to_phys(dev, dma_addr))));
> +		}
> +#endif
>  		if (dma_set_encrypted(dev, cpu_addr, size))

Same on the unmap side.  It might also be worth looking into reordering
the checks in some form instead o that raw dma_unencrypted_base check
before the unmap.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ