Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: linux-crypto@vger.kernel.org, Herbert Xu <herbert@gondor.apana.org.au>
Cc: Srujana Challa <schalla@marvell.com>,
	Bharat Bhushan <bbhushan2@marvell.com>,
	"David S. Miller" <davem@davemloft.net>,
	Rosen Penev <rosenp@gmail.com>,
	Arnaud Ebalard <arno@natisbad.org>,
	Boris Brezillon <bbrezillon@kernel.org>,
	Russell King <rmk+kernel@arm.linux.org.uk>,
	Romain Perier <romain.perier@free-electrons.com>
Subject: [PATCH 0/8] crypto: cesa - fixes for the Marvell CESA driver
Date: Fri, 27 Nov 2026 20:40:42 -0800	[thread overview]
Message-ID: <20261128044050.722617-1-rosenp@gmail.com> (raw)

These fix bugs in the Marvell CESA driver, found while reviewing and
testing it on an Armada 385 (Linksys WRT3200ACM).

Patch 1 clears the IRQ affinity hint before devm frees the IRQs. Since
commit 8dc981ba2fad the hint is left set, and __free_irq() warns about
it on removal or when probe fails after the first engine's IRQ.

Patch 2 suppresses the bind attributes. Transforms only hold a reference
on the module, so unbinding the device through sysfs freed its state
under transforms that were still in use, and corrupted the reference
counts of the static algorithms for a later rebind.

Patches 3 and 4 fix hashes that the driver pads by hand: messages whose
total length does not fit the engine's 16-bit length field, and, for
HMAC, also any final operation with no data left (any update()/final()
over a block-aligned length, or an empty message). Patch 3 stops the
padding from overwriting the last SRAM-sized chunk of a message before
it is hashed. Patch 4 makes the padding count the HMAC ipad block and
finishes the HMAC outer hash in software, which the engine does not do
for such messages.

Patches 5 to 8 fix the path used by engines without TDMA (Orion). CBC
requests longer than the SRAM payload restarted from the request IV at
every step, and hashes were wrong whenever they took more than one
step: the hand-made padding landed in the wrong place, updates could
step an empty operation, and hashes of 64 KiB or more were never padded.

The hash algorithms are still disabled by commit e845d2399a00
("crypto: marvell/cesa - Disable hash algorithms"). The concurrent
failures that led to it come from a DMA pool double free, which commit
23073a888ba1 ("crypto: marvell/cesa - Fix DMA cache leaks on hash setup
errors") fixed as a side effect: reverting just its req->cache = NULL
brings back wrong digests within milliseconds under parallel load,
followed by a lockup. With that commit and this series, I will send a
patch to re-enable them separately, along with a few cleanups.

Testing was done on the WRT3200ACM with the driver from this series
built as an out-of-tree module for its OpenWrt 6.12 kernel. The kernel's
crypto self-tests are disabled there, so a test module compared every
result against the software implementations: up to 8 threads, random
lengths up to 140000 bytes, scatterlist splits, in-place and separate
buffers, update/final/finup/export/import sequences and random HMAC
keys. The non-TDMA path was tested by disabling TDMA in a test build.
Before the series, about 0.5% of HMACs were wrong single threaded, and
about 1 in 4000 hashes with lengths up to 140000 bytes; without TDMA,
77% of CBC results and most hashes over 1920 bytes were wrong, and a 4
thread run hung. With the series, about 750000 requests over both paths
gave no wrong result. With patch 2 the bind attributes are gone and the
module cannot be unloaded while a transform exists; unload/reload cycles
gave no warnings.

An AI coding assistant (Claude Code, Claude Opus 5.5) was used to review
the driver, find the bugs, write the fixes and the test module, run the
tests on the WRT3200ACM, and draft the commit messages and this cover
letter.

Rosen Penev (8):
  crypto: cesa - clear the IRQ affinity hint before freeing the IRQ
  crypto: cesa - do not allow unbinding the device
  crypto: cesa - hash the last full SRAM chunk before the padding
  crypto: cesa - finish the HMAC outer hash when padding by hand
  crypto: cesa - keep the chained IV on the non-TDMA cipher path
  crypto: cesa - put the non-TDMA hash padding behind the data
  crypto: cesa - do not step empty hash operations on the non-TDMA path
  crypto: cesa - finish long hashes on the non-TDMA path

 drivers/crypto/marvell/Kconfig       |   3 +
 drivers/crypto/marvell/cesa/cesa.c   |  19 ++-
 drivers/crypto/marvell/cesa/cesa.h   |  12 ++
 drivers/crypto/marvell/cesa/cipher.c |   8 +-
 drivers/crypto/marvell/cesa/hash.c   | 168 ++++++++++++++++++++++++---
 5 files changed, 190 insertions(+), 20 deletions(-)


base-commit: 9fb9278d13dca54ce7ecd3254c7df8839e59f03d
-- 
2.56.1


             reply	other threads:[~2026-11-28  4:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  4:40 Rosen Penev [this message]
2026-11-28  4:40 ` [PATCH 1/8] crypto: cesa - clear the IRQ affinity hint before freeing the IRQ Rosen Penev
2026-11-28  4:40 ` [PATCH 2/8] crypto: cesa - do not allow unbinding the device Rosen Penev
2026-11-28  4:40 ` [PATCH 3/8] crypto: cesa - hash the last full SRAM chunk before the padding Rosen Penev
2026-11-28  4:40 ` [PATCH 4/8] crypto: cesa - finish the HMAC outer hash when padding by hand Rosen Penev
2026-11-28  4:52   ` sashiko-bot
2026-11-28  4:40 ` [PATCH 5/8] crypto: cesa - keep the chained IV on the non-TDMA cipher path Rosen Penev
2026-11-28  4:40 ` [PATCH 6/8] crypto: cesa - put the non-TDMA hash padding behind the data Rosen Penev
2026-11-28  4:40 ` [PATCH 7/8] crypto: cesa - do not step empty hash operations on the non-TDMA path Rosen Penev
2026-11-28  4:40 ` [PATCH 8/8] crypto: cesa - finish long hashes " Rosen Penev
2026-11-28  4:52   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261128044050.722617-1-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=arno@natisbad.org \
    --cc=bbhushan2@marvell.com \
    --cc=bbrezillon@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=romain.perier@free-electrons.com \
    --cc=schalla@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox