From nobody Thu Dec 18 18:01:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41B5BC072A2 for ; Mon, 20 Nov 2023 03:13:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231838AbjKTDNO convert rfc822-to-8bit (ORCPT ); Sun, 19 Nov 2023 22:13:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjKTDNN (ORCPT ); Sun, 19 Nov 2023 22:13:13 -0500 Received: from ex01.ufhost.com (ex01.ufhost.com [61.152.239.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9D71129; Sun, 19 Nov 2023 19:13:04 -0800 (PST) Received: from EXMBX166.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX166", Issuer "EXMBX166" (not verified)) by ex01.ufhost.com (Postfix) with ESMTP id E977B24E24C; Mon, 20 Nov 2023 11:12:50 +0800 (CST) Received: from EXMBX168.cuchost.com (172.16.6.78) by EXMBX166.cuchost.com (172.16.6.76) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 20 Nov 2023 11:12:50 +0800 Received: from ubuntu.localdomain (161.142.156.101) by EXMBX168.cuchost.com (172.16.6.78) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 20 Nov 2023 11:12:46 +0800 From: Jia Jie Ho To: Herbert Xu , "David S . Miller" CC: , Subject: [PATCH v2] crypto: starfive - Pad adata with zeroes Date: Mon, 20 Nov 2023 11:12:42 +0800 Message-ID: <20231120031242.25100-1-jiajie.ho@starfivetech.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [161.142.156.101] X-ClientProxiedBy: EXCAS064.cuchost.com (172.16.6.24) To EXMBX168.cuchost.com (172.16.6.78) X-YovoleRuleAgent: yovoleflag Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Aad requires padding with zeroes up to 15 bytes in some cases. This patch increases the allocated buffer size for aad and prevents the driver accessing uninitialized memory region. v1->v2: Specify reason for alloc size change in descriptions. Signed-off-by: Jia Jie Ho --- drivers/crypto/starfive/jh7110-aes.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/starfive/jh7110-aes.c b/drivers/crypto/starfive= /jh7110-aes.c index 9378e6682f0e..e0fe599f8192 100644 --- a/drivers/crypto/starfive/jh7110-aes.c +++ b/drivers/crypto/starfive/jh7110-aes.c @@ -500,7 +500,7 @@ static int starfive_aes_prepare_req(struct skcipher_req= uest *req, scatterwalk_start(&cryp->out_walk, rctx->out_sg); =20 if (cryp->assoclen) { - rctx->adata =3D kzalloc(ALIGN(cryp->assoclen, AES_BLOCK_SIZE), GFP_KERNE= L); + rctx->adata =3D kzalloc(cryp->assoclen + AES_BLOCK_SIZE, GFP_KERNEL); if (!rctx->adata) return dev_err_probe(cryp->dev, -ENOMEM, "Failed to alloc memory for adata"); @@ -569,7 +569,7 @@ static int starfive_aes_aead_do_one_req(struct crypto_e= ngine *engine, void *areq struct starfive_cryp_ctx *ctx =3D crypto_aead_ctx(crypto_aead_reqtfm(req)); struct starfive_cryp_dev *cryp =3D ctx->cryp; - struct starfive_cryp_request_ctx *rctx =3D ctx->rctx; + struct starfive_cryp_request_ctx *rctx; u32 block[AES_BLOCK_32]; u32 stat; int err; @@ -579,6 +579,8 @@ static int starfive_aes_aead_do_one_req(struct crypto_e= ngine *engine, void *areq if (err) return err; =20 + rctx =3D ctx->rctx; + if (!cryp->assoclen) goto write_text; =20 --=20 2.34.1