diff mbox series

[3/5] crypto: hisilicon/sec - fix the max length of AAD for the CCM mode

Message ID 1627701996-4589-4-git-send-email-yekai13@huawei.com (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show
Series crypto: hisilicon - some misc bugfix for SEC engine | expand

Commit Message

yekai (A) July 31, 2021, 3:26 a.m. UTC
Fix the maximum length of AAD for the CCM mode due to the hardware limited

Signed-off-by: Kai Ye <yekai13@huawei.com>
---
 drivers/crypto/hisilicon/sec2/sec_crypto.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Herbert Xu Aug. 6, 2021, 8:32 a.m. UTC | #1
On Sat, Jul 31, 2021 at 11:26:34AM +0800, Kai Ye wrote:
>
> @@ -2218,6 +2219,10 @@ static int sec_aead_spec_check(struct sec_ctx *ctx, struct sec_req *sreq)
>  	}
>  
>  	if (c_mode == SEC_CMODE_CCM) {
> +		if (unlikely(req->assoclen > SEC_MAX_CCM_AAD_LEN)) {
> +			dev_err(dev, "CCM input aad parameter is too long!\n");
> +			return -EINVAL;
> +		}

You shouldn't be printing messages on a code path that can be
triggered by userspace without rate limit.

Thanks,
diff mbox series

Patch

diff --git a/drivers/crypto/hisilicon/sec2/sec_crypto.c b/drivers/crypto/hisilicon/sec2/sec_crypto.c
index b3ac1bd..010bde9 100644
--- a/drivers/crypto/hisilicon/sec2/sec_crypto.c
+++ b/drivers/crypto/hisilicon/sec2/sec_crypto.c
@@ -63,6 +63,7 @@ 
 #define SEC_AUTH_CIPHER		0x1
 #define SEC_MAX_MAC_LEN		64
 #define SEC_MAX_AAD_LEN		65535
+#define SEC_MAX_CCM_AAD_LEN	65279
 #define SEC_TOTAL_MAC_SZ	(SEC_MAX_MAC_LEN * QM_Q_DEPTH)
 
 #define SEC_PBUF_SZ			512
@@ -2218,6 +2219,10 @@  static int sec_aead_spec_check(struct sec_ctx *ctx, struct sec_req *sreq)
 	}
 
 	if (c_mode == SEC_CMODE_CCM) {
+		if (unlikely(req->assoclen > SEC_MAX_CCM_AAD_LEN)) {
+			dev_err(dev, "CCM input aad parameter is too long!\n");
+			return -EINVAL;
+		}
 		ret = aead_iv_demension_check(req);
 		if (ret) {
 			dev_err(dev, "aead input iv param error!\n");