mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 3/3] crypto: ccp - protect RSA implementation from too large input data
@ 2018-02-24 16:03 Maciej S. Szmigiero
  2018-03-01  0:35 ` Gary R Hook
  0 siblings, 1 reply; 2+ messages in thread
From: Maciej S. Szmigiero @ 2018-02-24 16:03 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller
  Cc: David Howells, Tom Lendacky, Gary Hook, keyrings, linux-crypto,
	linux-kernel

CCP RSA implementation uses a hardware input buffer which size depends only
on the current RSA key length. Key modulus and a message to be processed
is then copied to this buffer based on their own lengths.

Since the price for providing too long input data is a buffer overflow and
there already has been a case when this has happened let's better reject
such oversized input data and log an error message in this case so we know
what is going on.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
---
 drivers/crypto/ccp/ccp-ops.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
index 406b95329b3d..517aeee30abf 100644
--- a/drivers/crypto/ccp/ccp-ops.c
+++ b/drivers/crypto/ccp/ccp-ops.c
@@ -1770,10 +1770,6 @@ static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
 	if (!rsa->exp || !rsa->mod || !rsa->src || !rsa->dst)
 		return -EINVAL;
 
-	memset(&op, 0, sizeof(op));
-	op.cmd_q = cmd_q;
-	op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
-
 	/* The RSA modulus must precede the message being acted upon, so
 	 * it must be copied to a DMA area where the message and the
 	 * modulus can be concatenated.  Therefore the input buffer
@@ -1785,6 +1781,26 @@ static int ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
 	o_len = 32 * ((rsa->key_size + 255) / 256);
 	i_len = o_len * 2;
 
+	if (rsa->mod_len > o_len) {
+		dev_err(cmd_q->ccp->dev,
+			"RSA modulus of %u bytes too large for key size of %u bits\n",
+			(unsigned int)rsa->mod_len,
+			(unsigned int)rsa->key_size);
+		return -EINVAL;
+	}
+
+	if (rsa->src_len > o_len) {
+		dev_err(cmd_q->ccp->dev,
+			"RSA data of %u bytes too large for key size of %u bits\n",
+			(unsigned int)rsa->src_len,
+			(unsigned int)rsa->key_size);
+		return -EINVAL;
+	}
+
+	memset(&op, 0, sizeof(op));
+	op.cmd_q = cmd_q;
+	op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
+
 	sb_count = 0;
 	if (cmd_q->ccp->vdata->version < CCP_VERSION(5, 0)) {
 		/* sb_count is the number of storage block slots required

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-03-01  0:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-24 16:03 [PATCH 3/3] crypto: ccp - protect RSA implementation from too large input data Maciej S. Szmigiero
2018-03-01  0:35 ` Gary R Hook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®