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)
committerSasha Levin <sashal@kernel.org>
Tue, 30 Jun 2020 19:36:03 +0000 (15:36 -0400)
commit91c7b0407ca6a62c095d265f76926b67bf66c026
treed1c8b6ee7fb2c85cba4111ae331f47a3f94fda72
parentaf00c3908ccc9d5036e79ae068f76a10f650210a
dma-direct: check return value when encrypting or decrypting memory

[ Upstream commit 56fccf21d1961a06e2a0c96ce446ebf036651062 ]

__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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/dma/direct.c