Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Antoine Tenart <antoine.tenart@free-electrons.com>
To: herbert@gondor.apana.org.au, davem@davemloft.net
Cc: Antoine Tenart <antoine.tenart@free-electrons.com>,
	thomas.petazzoni@free-electrons.com,
	gregory.clement@free-electrons.com,
	miquel.raynal@free-electrons.com, oferh@marvell.com,
	igall@marvell.com, nadavh@marvell.com,
	linux-crypto@vger.kernel.org
Subject: [PATCH v2 3/4] crypto: inside-secure - only update the result buffer when provided
Date: Tue, 28 Nov 2017 16:42:35 +0100	[thread overview]
Message-ID: <20171128154236.19192-4-antoine.tenart@free-electrons.com> (raw)
In-Reply-To: <20171128154236.19192-1-antoine.tenart@free-electrons.com>

The patch fixes the ahash support by only updating the result buffer
when provided. Otherwise the driver could crash with NULL pointer
exceptions, because the ahash caller isn't required to supply a result
buffer on all calls.

Fixes: 1b44c5a60c13 ("crypto: inside-secure - add SafeXcel EIP197 crypto engine driver")
Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
---
 drivers/crypto/inside-secure/safexcel_hash.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/inside-secure/safexcel_hash.c b/drivers/crypto/inside-secure/safexcel_hash.c
index 6135c9f5742c..424f4c5d4d25 100644
--- a/drivers/crypto/inside-secure/safexcel_hash.c
+++ b/drivers/crypto/inside-secure/safexcel_hash.c
@@ -150,7 +150,12 @@ static int safexcel_handle_req_result(struct safexcel_crypto_priv *priv, int rin
 
 	if (sreq->finish)
 		result_sz = crypto_ahash_digestsize(ahash);
-	memcpy(sreq->state, areq->result, result_sz);
+
+	/* The called isn't required to supply a result buffer. Updated it only
+	 * when provided.
+	 */
+	if (areq->result)
+		memcpy(sreq->state, areq->result, result_sz);
 
 	dma_unmap_sg(priv->dev, areq->src,
 		     sg_nents_for_len(areq->src, areq->nbytes), DMA_TO_DEVICE);
-- 
2.14.3

  parent reply	other threads:[~2017-11-28 15:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-28 15:42 [PATCH v2 0/4] crypto: inside-secure - set of fixes Antoine Tenart
2017-11-28 15:42 ` [PATCH v2 1/4] crypto: inside-secure - per request invalidation Antoine Tenart
2017-11-28 15:42 ` [PATCH v2 2/4] crypto: inside-secure - free requests even if their handling failed Antoine Tenart
2017-11-28 15:42 ` Antoine Tenart [this message]
2017-11-30  9:19   ` [PATCH v2 3/4] crypto: inside-secure - only update the result buffer when provided Kamil Konieczny
2017-11-30  9:29     ` Antoine Tenart
2017-11-30 11:52       ` Kamil Konieczny
2017-11-30 12:41         ` Antoine Tenart
2017-11-30 14:10           ` Kamil Konieczny
2017-11-30 14:30             ` Antoine Tenart
2017-12-01  0:31     ` Herbert Xu
2017-12-01  8:11       ` Antoine Tenart
2017-12-01 10:18         ` Kamil Konieczny
2017-12-01 10:24           ` Antoine Tenart
2017-12-01 10:43             ` Kamil Konieczny
2017-12-01 10:55               ` Antoine Tenart
2017-12-01 10:36           ` Herbert Xu
2017-12-01 11:24             ` Kamil Konieczny
2017-12-01 10:35         ` Herbert Xu
2017-12-01 10:52           ` Antoine Tenart
2017-11-28 15:42 ` [PATCH v2 4/4] crypto: inside-secure - fix request allocations in invalidation path Antoine Tenart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171128154236.19192-4-antoine.tenart@free-electrons.com \
    --to=antoine.tenart@free-electrons.com \
    --cc=davem@davemloft.net \
    --cc=gregory.clement@free-electrons.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=igall@marvell.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=miquel.raynal@free-electrons.com \
    --cc=nadavh@marvell.com \
    --cc=oferh@marvell.com \
    --cc=thomas.petazzoni@free-electrons.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox