diff mbox series

crypto: ccree: don't attempt 0 len DMA mappings

Message ID 20220217192726.612328-1-gilad@benyossef.com
State Accepted
Commit 1fb37b5692c915edcc2448a6b37255738c7c77e0
Headers show
Series crypto: ccree: don't attempt 0 len DMA mappings | expand

Commit Message

Gilad Ben-Yossef Feb. 17, 2022, 7:27 p.m. UTC
Refuse to try mapping zero bytes as this may cause a fault
on some configurations / platforms and it seems the prev.
attempt is not enough and we need to be more explicit.

Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
Reported-by: Corentin Labbe <clabbe.montjoie@gmail.com>
Fixes: ce0fc6db38de ("crypto: ccree - protect against empty or NULL
scatterlists")
---
 drivers/crypto/ccree/cc_buffer_mgr.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Herbert Xu Feb. 23, 2022, 3:32 a.m. UTC | #1
On Thu, Feb 17, 2022 at 09:27:26PM +0200, Gilad Ben-Yossef wrote:
> Refuse to try mapping zero bytes as this may cause a fault
> on some configurations / platforms and it seems the prev.
> attempt is not enough and we need to be more explicit.
> 
> Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
> Reported-by: Corentin Labbe <clabbe.montjoie@gmail.com>
> Fixes: ce0fc6db38de ("crypto: ccree - protect against empty or NULL
> scatterlists")
> ---
>  drivers/crypto/ccree/cc_buffer_mgr.c | 7 +++++++
>  1 file changed, 7 insertions(+)

Patch applied.  Thanks.
diff mbox series

Patch

diff --git a/drivers/crypto/ccree/cc_buffer_mgr.c b/drivers/crypto/ccree/cc_buffer_mgr.c
index a5e041d9d2cf..11e0278c8631 100644
--- a/drivers/crypto/ccree/cc_buffer_mgr.c
+++ b/drivers/crypto/ccree/cc_buffer_mgr.c
@@ -258,6 +258,13 @@  static int cc_map_sg(struct device *dev, struct scatterlist *sg,
 {
 	int ret = 0;
 
+	if (!nbytes) {
+		*mapped_nents = 0;
+		*lbytes = 0;
+		*nents = 0;
+		return 0;
+	}
+
 	*nents = cc_get_sgl_nents(dev, sg, nbytes, lbytes);
 	if (*nents > max_sg_nents) {
 		*nents = 0;