From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from 6.mo583.mail-out.ovh.net (6.mo583.mail-out.ovh.net [178.32.119.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F19863F4859 for ; Fri, 16 Oct 2026 09:03:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.32.119.138 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792141445; cv=none; b=EEZ1r3HGj9WwaAU1GTWG3lyuvwrfGFuFNVnjbGc8Finl656OFCsspAw+3f/cSWpm6+i2y7X7yo74dxaN5UnRBusSj2HbPpP2QkAGufnbewfQSpS3Fazfo81B6BD0x+nZr9Ew8wGm5+RebkZLV/av2pn8R3Fq+9pOkRM+6fdMW1M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792141445; c=relaxed/simple; bh=Q0ET48T5kgmvhDWW6V1583s0V4siUNHdEUiqObL6GsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mYk6Zl7BvufIbuP3fI8VA8YzshJrBWdoXJx1AOpC4gLE3Ib1beP72d9tWB5b7t2UW2gRonbKmS9F/AjvN9Qy5JNaOkUrV0tLedYjJn5VKA7wynLe3xW+Ad1SXtRuuDCP/ZYp401Mu7rDOh5UC4y/lnarYxpd3AAhLK9hJezbVeA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cynove.com; spf=pass smtp.mailfrom=cynove.com; dkim=pass (2048-bit key) header.d=cynove.com header.i=@cynove.com header.b=RViDwafa; arc=none smtp.client-ip=178.32.119.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cynove.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cynove.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cynove.com header.i=@cynove.com header.b="RViDwafa" Received: from director3.ghost.mail-out.ovh.net (unknown [10.110.0.14]) by mo583.mail-out.ovh.net (Postfix) with ESMTP id 4j5fBH6kS2z60dM for ; Fri, 16 Oct 2026 09:03:51 +0000 (UTC) Received: from ghost-submission-7ccd8bbbb6-4kjr4 (unknown [10.111.174.188]) by director3.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 46763C0D11; Fri, 16 Oct 2026 09:03:51 +0000 (UTC) Received: from cynove.com ([37.59.142.97]) by ghost-submission-7ccd8bbbb6-4kjr4 with ESMTPSA id fClPE3Xo0WpZ/AEAmtFogg:T2 (envelope-from ); Fri, 16 Oct 2026 09:03:51 +0000 Authentication-Results:garm.ovh; auth=pass (GARM-97G002356f9ba6-d7b5-4ce0-a9a4-835329139dfb, 49BC7871EA8B080B249AF49F55FA702C3B4DE52D) smtp.auth=Stephane.Debusne@cynove.com X-OVh-ClientIp:176.150.47.247 From: Stephane Debusne To: herbert@gondor.apana.org.au, lukas@wunner.de Cc: ignat@cloudflare.com, davem@davemloft.net, horia.geanta@nxp.com, pankaj.gupta@nxp.com, gaurav.jain@nxp.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Stephane Debusne , stable@vger.kernel.org Subject: [PATCH 1/2] crypto: akcipher - use a separate buffer in the sync helpers Date: Fri, 16 Oct 2026 11:03:32 +0200 Message-ID: <20261016090333.2247764-2-stephane.debusne@cynove.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261016090333.2247764-1-stephane.debusne@cynove.com> References: <20261016090333.2247764-1-stephane.debusne@cynove.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit x-ovh-tracer-id: 16750857340520291099 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: dmFkZTGD4nW62LQB9KssNcZQuK5k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og7tIpf5yAd SMmy7MqZSX+oBoxaolDqW35KtGKlokxnBOwA3xQiGHyNA== crypto_akcipher_sync_prep() places the data buffer right after the request context, in the same allocation, and passes it to the driver in place (src == dst). On non-coherent DMA, the start of this buffer may share a cache line with the end of the request context. A DMA-based driver such as the CAAM (caampkc) writes req_ctx->edesc and req_ctx->akcipher_op_done after dma_map_sg() of the destination, which dirties that line. On arm64, dma_unmap_sg(DMA_FROM_DEVICE) cleans and invalidates partial lines (dc civac), so the stale CPU copy is written back over the result written by the device. crypto_akcipher_sync_encrypt() and crypto_akcipher_sync_decrypt() are used by rsassa_pkcs1_sign() and by software_key_eds_op() (keyctl pkey_encrypt and pkey_decrypt), so RSA signing and encryption through rsa-caam are affected. On i.MX8M Mini (CAAM era 9, rsa-caam, 6.18), the buffer starts at offset 40 of a 64-byte line shared with the end of the request context, and crypto_akcipher_sync_encrypt() returns a result whose first 24 bytes still hold the input in 199 of 200 calls. Allocate the data buffer separately, so that it is DMA-safe like any kmalloc() buffer. Fixes: addde1f2c966 ("crypto: akcipher - Add sync interface without SG lists") Cc: stable@vger.kernel.org Signed-off-by: Stephane Debusne --- crypto/akcipher.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/crypto/akcipher.c b/crypto/akcipher.c index 630bb1973..2381ed43b 100644 --- a/crypto/akcipher.c +++ b/crypto/akcipher.c @@ -170,23 +170,29 @@ static int crypto_akcipher_sync_prep(struct crypto_akcipher_sync_data *data) struct akcipher_request *req; struct scatterlist *sg; unsigned int mlen; - unsigned int len; u8 *buf; mlen = max(data->slen, data->dlen); - len = sizeof(*req) + reqsize + mlen; - if (len < mlen) - return -EOVERFLOW; - - req = kzalloc(len, GFP_KERNEL); + req = kzalloc(sizeof(*req) + reqsize, GFP_KERNEL); if (!req) return -ENOMEM; + /* + * The data buffer is mapped for DMA by hardware drivers. Keep it in + * its own allocation: placed right after the request context, it + * may share a cache line with fields the driver writes while the + * buffer is mapped, which corrupts the result on non-coherent DMA. + */ + buf = kzalloc(mlen, GFP_KERNEL); + if (!buf) { + kfree(req); + return -ENOMEM; + } + data->req = req; akcipher_request_set_tfm(req, data->tfm); - buf = (u8 *)(req + 1) + reqsize; data->buf = buf; memcpy(buf, data->src, data->slen); @@ -207,6 +213,7 @@ static int crypto_akcipher_sync_post(struct crypto_akcipher_sync_data *data, err = crypto_wait_req(err, &data->cwait); memcpy(data->dst, data->buf, data->dlen); data->dlen = data->req->dst_len; + kfree_sensitive(data->buf); kfree_sensitive(data->req); return err; } -- 2.43.0