Skip to contentSkip to conversation

crypto: ccp - Fix handling of RSA exponent on a v5 device

PATCH Superseded Gary R Hook 3 participants 7 messages Nov 1, 2016 – Nov 17, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: ccp - Fix handling of RSA exponent on a v5 device

The exponent size in the ccp_op structure is in bits. A v5 CCP requires the exponent size to be in bytes, so convert the size from bits to bytes when populating the descriptor.

The current code references the exponent in memory, but these fields have not been set since the exponent is actually store in the LSB. Populate the descriptor with the LSB location (address).

---
 drivers/crypto/ccp/ccp-dev-v5.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/crypto/ccp/ccp-dev-v5.c +5 -5
index ff7816a..e2ce819 100644
@@ -403,7 +403,7 @@ static int ccp5_perform_rsa(struct ccp_op *op)
 	CCP5_CMD_PROT(&desc) = 0;
 
 	function.raw = 0;
-	CCP_RSA_SIZE(&function) = op->u.rsa.mod_size;
+	CCP_RSA_SIZE(&function) = op->u.rsa.mod_size >> 3;
 	CCP5_CMD_FUNCTION(&desc) = function.raw;
 
 	CCP5_CMD_LEN(&desc) = op->u.rsa.input_len;
@@ -418,10 +418,10 @@ static int ccp5_perform_rsa(struct ccp_op *op)
 	CCP5_CMD_DST_HI(&desc) = ccp_addr_hi(&op->dst.u.dma);
 	CCP5_CMD_DST_MEM(&desc) = CCP_MEMTYPE_SYSTEM;
 
-	/* Key (Exponent) is in external memory */
-	CCP5_CMD_KEY_LO(&desc) = ccp_addr_lo(&op->exp.u.dma);
-	CCP5_CMD_KEY_HI(&desc) = ccp_addr_hi(&op->exp.u.dma);
-	CCP5_CMD_KEY_MEM(&desc) = CCP_MEMTYPE_SYSTEM;
+	/* Exponent is in LSB memory */
+	CCP5_CMD_KEY_LO(&desc) = op->sb_key * LSB_ITEM_SIZE;
+	CCP5_CMD_KEY_HI(&desc) = 0;
+	CCP5_CMD_KEY_MEM(&desc) = CCP_MEMTYPE_SB;
 
 	return ccp5_do_cmd(&desc, op->cmd_q);
 }
maintainer
#1 lore raw
Quoted 10 lines · Gary R Hook

The exponent size in the ccp_op structure is in bits. A v5 CCP requires the exponent size to be in bytes, so convert the size from bits to bytes when populating the descriptor.

The current code references the exponent in memory, but these fields have not been set since the exponent is actually store in the LSB. Populate the descriptor with the LSB location (address).

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#2 lore raw
Quoted 5 lines · Herbert Xu
Quoted 4 lines · Gary R Hook

The exponent size in the ccp_op structure is in bits. A v5 CCP requires the exponent size to be in bytes, so convert the size from bits to bytes when populating the descriptor.

Quoted 9 lines
Quoted 6 lines

The current code references the exponent in memory, but these fields have not been set since the exponent is actually store in the LSB. Populate the descriptor with the LSB location (address).

Patch applied. Thanks.

Thanks, Herbert.

Is there a possibility of getting this pushed to 4.9, being it's a bug fix?

Signature · 3 lines
This is my day job. Follow me at:
IG/Twitter/Facebook: @grhookphoto
IG/Twitter/Facebook: @grhphotographer
maintainer
#3 lore raw
Quoted 13 lines · Gary R Hook
Quoted 12 lines · Herbert Xu
Quoted 10 lines · Gary R Hook

The exponent size in the ccp_op structure is in bits. A v5 CCP requires the exponent size to be in bytes, so convert the size from bits to bytes when populating the descriptor.

The current code references the exponent in memory, but these fields have not been set since the exponent is actually store in the LSB. Populate the descriptor with the LSB location (address).

Quoted 7 lines
Quoted 2 lines

Patch applied. Thanks.

Thanks, Herbert.

Is there a possibility of getting this pushed to 4.9, being it's a bug fix?

I thought ccp doesn't support RSA yet or is there another entry path into this code?

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#4 lore raw
Quoted 17 lines · Herbert Xu
Quoted 16 lines · Gary R Hook
Quoted 14 lines · Herbert Xu
Quoted 10 lines · Gary R Hook

The exponent size in the ccp_op structure is in bits. A v5 CCP requires the exponent size to be in bytes, so convert the size from bits to bytes when populating the descriptor.

The current code references the exponent in memory, but these fields have not been set since the exponent is actually store in the LSB. Populate the descriptor with the LSB location (address).

Patch applied. Thanks.

Quoted 7 lines
Quoted 4 lines

Thanks, Herbert.

Is there a possibility of getting this pushed to 4.9, being it's a bug fix?

I thought ccp doesn't support RSA yet or is there another entry path into this code?

The kernel crypto layer does not yet support RSA, true. However, we designed the ccp.ko layer to be available to anyone that wants to use it. The underlying module currently has differing behavior/results between the v3 and v5 implementations of the RSA command function. This patch fixes the borked v5 code.

Signature · 3 lines
This is my day job. Follow me at:
IG/Twitter/Facebook: @grhookphoto
IG/Twitter/Facebook: @grhphotographer
#6 lore raw
In reply to Herbert Xu
Quoted 10 lines · Herbert Xu
Quoted 6 lines · Gary R Hook

The kernel crypto layer does not yet support RSA, true. However, we designed the ccp.ko layer to be available to anyone that wants to use it. The underlying module currently has differing behavior/results between the v3 and v5 implementations of the RSA command function. This patch fixes the borked v5 code.

Do you mean that an out-of-tree module could enter the buggy code path?

I mean that anything that can call ccp_run_cmd() (in ccp.ko) can run into a problem, yes. Is this likely? We don't know, as we don't know if anyone actually uses this layer. But it _is_ possible to find the problem.

Signature · 3 lines
This is my day job. Follow me at:
IG/Twitter/Facebook: @grhookphoto
IG/Twitter/Facebook: @grhphotographer
maintainer
#5 lore raw
In reply to Gary R Hook
Quoted 6 lines · Gary R Hook

The kernel crypto layer does not yet support RSA, true. However, we designed the ccp.ko layer to be available to anyone that wants to use it. The underlying module currently has differing behavior/results between the v3 and v5 implementations of the RSA command function. This patch fixes the borked v5 code.

Do you mean that an out-of-tree module could enter the buggy code path?

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt