From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8702460A262D for ; Wed, 2 Dec 2026 10:11:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=kfop0huG; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=sTuoufRd DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=mqhEMX+dTfta9ngQrXrSBqoot3UHRPpRJe13vqfjLpc=; b=kfop0huGaUB5U+Y5+xTy5Sgxgm +BEkNBqea7JtV7+bCC/N6PSXh0eNi8S3y5mP/4Jke2V8ovm+S0IDxfg9NP6inE/8SK3/64WvOABd2 nIHO2RPq1vIpe5obuFU8fLc8lmLgsWwB23A4KKyrNtuA0vk1w44GLbAe4SgnjNHCtA9hppfzSqafR Cx6ur5QC8KYl/ak1xrj+amOCmZgwdgGxKhRLauJccxhf0BvKfh59grMCYchjuuGSntAa1t0JijpOv nV+Bg1MFfwA5XIPNuZYEqtZwXU2vh5Yg6XKYWrHDMevbnTLDx7te16EysnE5UQIoGqeteR6neQRKa t9OtKTnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYhIi-0000000B4gg-1zNP; Wed, 02 Dec 2026 10:11:00 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYhIe-0000000B4YP-3yzq for linux-amlogic@lists.infradead.org; Wed, 02 Dec 2026 10:10:59 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4bb6adaf0f1so107638215e9.0 for ; Wed, 02 Dec 2026 02:10:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796206255; x=1796811055; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=P/zm0au68m57Hq6vfLAu7YErRpN2OWQzOgDKVXe4cXU=; b=sTuoufRd+SM0PGqffbmarEaSXGUezrpBtIO+bv6H2pvPEs61LKwPMzBHUFV0Fnldmh 9B9VhLVds7iU5jcItEFQwqDAlfn+nLv5qp/LzjFegVOhl2h0lNzESKEQtlCMVb5p+hXP J475x4bQTImqWMzfTpsCliD2noEnidGSwJcgaigGsltqNZJv09GXsWupGp6l8+aanWLW i3NQz1xoYbWq0yDoa5cB6fmAzfBxbdFbl0nH8y1wmChaHxwiJmGr9YmpF1S18Mb9YUTM /X93s/Z4bwVfuTZT95qcHUjj+VjAaqSOS05dZTxaw+UNvRHDYUCXzikyJhFs84RpVtVa o8jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796206255; x=1796811055; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=P/zm0au68m57Hq6vfLAu7YErRpN2OWQzOgDKVXe4cXU=; b=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Nqa+bsm9RGm2wWaZ2LDfRLJ6wP5bH8xGPQ 6J6woSbsBV+BEDl7No1QTf38Amprd+9Xhui1a99jrjfv/F/WlShHr3FHZM83A4DY3JTxFu7NaFn ELuMsCsrTvGcgePfFjdyyMOBKfUSp9M5iij6fWG2X0VttA== X-Received: by 2002:a05:600c:19d0:b0:4bb:65ed:b55c with SMTP id 5b1f17b1804b1-4bb88824b18mr785452965e9.33.1796206255092; Wed, 02 Dec 2026 02:10:55 -0800 (PST) Received: from localhost.localdomain ([79.117.198.103]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb88402ce9sm899268965e9.0.2026.12.02.02.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 02:10:53 -0800 (PST) From: Jose Nieto To: Corentin Labbe , Herbert Xu , "David S . Miller" Cc: linux-crypto@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Rob Herring , Krzysztof Kozlowski , Conor Dooley Subject: [PATCH v15 27/35] crypto: amlogic: fix setup descriptor lengths and CBC IV reload Date: Wed, 2 Dec 2026 11:10:28 +0100 Message-ID: <20261202101036.116145-7-jnieto.alaber@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261202101036.116145-1-jnieto.alaber@gmail.com> References: <20261202100714.115460-1-jnieto.alaber@gmail.com> <20261202101036.116145-1-jnieto.alaber@gmail.com> X-Archived-By: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261202_021057_172496_A603C30A X-CRM114-Status: GOOD ( 17.06 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-amlogic" X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The key/IV setup descriptors were misprogrammed after the descriptor refactoring: - meson_setup_keyiv_descs() always emitted setup_desc_cnt descriptors and set each length to the full key/IV length, so on the three-descriptor platforms (GXL, AXG) the later descriptors read past the DMA-mapped buffer. Emit only as many descriptors as needed to cover the key/IV (one per 16 bytes, capped at setup_desc_cnt) and set each length accordingly. For ECB this yields one or two descriptors instead of three, avoiding the out-of-bounds DMA read. - The CBC IV has to be reloaded into the key/IV buffer on every hardware kick: a request can span several descriptor batches and the IV is updated (chaining) after each one. Keep the CBC IV copy and DMA sync in meson_setup_keyiv_descs(), which runs once per batch, and drop the now redundant copy done before the loop in meson_cipher(). Signed-off-by: Jose Nieto --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 13 ++++++++----- drivers/crypto/amlogic/amlogic-gxl-hasher.c | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index c11ccbaf920d..53fd339ea7d7 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -154,6 +154,7 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) struct meson_dev *mc = op->mc; unsigned int ivsize = crypto_skcipher_ivsize(tfm); unsigned int blockmode = algt->blockmode; + unsigned int desc_cnt; int i; if (ctx->tloffset) @@ -165,14 +166,18 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) ctx->keyiv.len, DMA_TO_DEVICE); } - for (i = 0; i < mc->pdata->setup_desc_cnt; i++) { + desc_cnt = min(mc->pdata->setup_desc_cnt, + DIV_ROUND_UP(ctx->keyiv.len, 16)); + + for (i = 0; i < desc_cnt; i++) { struct meson_desc *desc = &mc->chanlist[rctx->flow].tl[ctx->tloffset]; int offset = i * 16; desc->t_src = cpu_to_le32(ctx->keyiv.addr + offset); desc->t_dst = cpu_to_le32(offset); - desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | ctx->keyiv.len); + desc->t_status = cpu_to_le32(DESC_OWN | DESC_MODE_KEY | + ctx->keyiv.len / desc_cnt); ctx->tloffset++; } @@ -328,10 +333,8 @@ static int meson_cipher(struct skcipher_request *areq) if (ctx.keyiv.len == AES_KEYSIZE_192) ctx.keyiv.len = AES_MAX_KEY_SIZE; - if (algt->blockmode == DESC_OPMODE_CBC) { - memcpy(op->keyiv + AES_MAX_KEY_SIZE, areq->iv, ivsize); + if (algt->blockmode == DESC_OPMODE_CBC) ctx.keyiv.len = AES_MAX_KEY_SIZE + ivsize; - } ctx.keyiv.addr = dma_map_single(mc->dev, op->keyiv, ctx.keyiv.len, DMA_TO_DEVICE); diff --git a/drivers/crypto/amlogic/amlogic-gxl-hasher.c b/drivers/crypto/amlogic/amlogic-gxl-hasher.c index 978cdcd8a4f9..710dd413bd51 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-hasher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-hasher.c @@ -253,7 +253,8 @@ static void meson_setup_state_descs(struct hasher_ctx *ctx) desc = &mc->chanlist[rctx->flow].tl[ctx->tloffset]; desc->t_src = cpu_to_le32(ctx->state_addr + offset); desc->t_dst = cpu_to_le32(offset); - desc->t_status = cpu_to_le32(MESON_SHA_BUFFER_SIZE | + desc->t_status = cpu_to_le32(MESON_SHA_BUFFER_SIZE / + mc->pdata->setup_desc_cnt | DESC_MODE_KEY | DESC_OWN); ctx->tloffset++; -- 2.47.3 _______________________________________________ linux-amlogic mailing list linux-amlogic@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-amlogic