dma-direct: check return value when encrypting or decrypting memory
authorDavid Rientjes <rientjes@google.com>
Thu, 11 Jun 2020 19:20:30 +0000 (12:20 -0700)
committerChristoph Hellwig <hch@lst.de>
Wed, 17 Jun 2020 07:29:38 +0000 (09:29 +0200)
commit56fccf21d1961a06e2a0c96ce446ebf036651062
treec47f6ddb7b3afd5e0ffefafad4af257cb200b486
parent96a539fa3bb71f443ae08e57b9f63d6e5bb2207c
dma-direct: check return value when encrypting or decrypting memory

__change_page_attr() can fail which will cause set_memory_encrypted() and
set_memory_decrypted() to return non-zero.

If the device requires unencrypted DMA memory and decryption fails, simply
free the memory and fail.

If attempting to re-encrypt in the failure path and that encryption fails,
there is no alternative other than to leak the memory.

Fixes: c10f07aa27da ("dma/direct: Handle force decryption for DMA coherent buffers in common code")
Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
kernel/dma/direct.c