Patch "dma-direct: don't over-decrypt memory" has been added to the 5.18-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    dma-direct: don't over-decrypt memory

to the 5.18-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     dma-direct-don-t-over-decrypt-memory.patch
and it can be found in the queue-5.18 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 9c9f86a0512322af381e2180f5a81a1ec4ea9127
Author: Robin Murphy <robin.murphy@xxxxxxx>
Date:   Fri May 20 18:10:13 2022 +0100

    dma-direct: don't over-decrypt memory
    
    [ Upstream commit 4a37f3dd9a83186cb88d44808ab35b78375082c9 ]
    
    The original x86 sev_alloc() only called set_memory_decrypted() on
    memory returned by alloc_pages_node(), so the page order calculation
    fell out of that logic. However, the common dma-direct code has several
    potential allocators, not all of which are guaranteed to round up the
    underlying allocation to a power-of-two size, so carrying over that
    calculation for the encryption/decryption size was a mistake. Fix it by
    rounding to a *number* of pages, rather than an order.
    
    Until recently there was an even worse interaction with DMA_DIRECT_REMAP
    where we could have ended up decrypting part of the next adjacent
    vmalloc area, only averted by no architecture actually supporting both
    configs at once. Don't ask how I found that one out...
    
    Fixes: c10f07aa27da ("dma/direct: Handle force decryption for DMA coherent buffers in common code")
    Signed-off-by: Robin Murphy <robin.murphy@xxxxxxx>
    Signed-off-by: Christoph Hellwig <hch@xxxxxx>
    Acked-by: David Rientjes <rientjes@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 3e7f4aab740e..e978f36e6be8 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -79,7 +79,7 @@ static int dma_set_decrypted(struct device *dev, void *vaddr, size_t size)
 {
 	if (!force_dma_unencrypted(dev))
 		return 0;
-	return set_memory_decrypted((unsigned long)vaddr, 1 << get_order(size));
+	return set_memory_decrypted((unsigned long)vaddr, PFN_UP(size));
 }
 
 static int dma_set_encrypted(struct device *dev, void *vaddr, size_t size)
@@ -88,7 +88,7 @@ static int dma_set_encrypted(struct device *dev, void *vaddr, size_t size)
 
 	if (!force_dma_unencrypted(dev))
 		return 0;
-	ret = set_memory_encrypted((unsigned long)vaddr, 1 << get_order(size));
+	ret = set_memory_encrypted((unsigned long)vaddr, PFN_UP(size));
 	if (ret)
 		pr_warn_ratelimited("leaking DMA memory that can't be re-encrypted\n");
 	return ret;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux