From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796263672; b=BjnhW1Z4AWSRWrx5nPwI/vQQVnvNkyEUKi4yy42rlOiPvd3bxXsVQ6MLIJy2xeuOIBMh Z83OCwGOw+EU1mzLCXHI+J+bIUss96URHXXLKV8AzL/9P15oJ5HvFzHMrHWyOvEejJ9JV XMjDgb+yhjiJuq012haVxEzFqBjf6oZW2xQrfRXCRvD8LdquLKvGaMMxaoFl5sJHkIzSO MQCj+hdSYUn6WZLzmepBAcUrLhZ7TVXG2wpBmSwcLeFdKfSo414gsZF9sNIeELGRuzM8b DQcV4ebLkw4OTWH9oGbgjNqQo1jNZaozdJ3Y7k6yT4ayZn37S2LZChuPrEtqRtAwxZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796263672; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=8MV9C1MsD49qblhVKnJHg3qeYJ+/1277bj6NsNpmwO0=; b=icAfcRsBNZMzhta4H6P0F/HCH91m8b3YSQ66MJwm1D8GSRKuqwHdnCSx72SDTze3bKGm jB55fHOI8p2+OQxVfDgXthnogVBoxTlJH0l9C7teBzOxnvS9QaWTyBOtcD1uc1B/MZxXi Dpbra3iGxuTftxc1ntUhgad1kuuy3vd04pSHOLkkoajCl0rdtuSmsTMhxGhodfG37NYJq F6HDuX6ZAU2OGP71ME8mhp3kMJPADcmS4nNdjkuVTqiaQqXyS55+Shvs9UzbrflY117H0 nE9B+HlWsFtXYC6oTBQU4lXWNkho292HtSWCYKBMhYExPhIMB114uYuzLxkljO8prEw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=e5e91AZh; arc=none smtp.remote-ip=209.85.214.178 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9372606A322 for ; Thu, 3 Dec 2026 02:07:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C9372606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=e5e91AZh Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2f07a960666so107937065ad.1 for ; Wed, 02 Dec 2026 18:07:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796263671; x=1796868471; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=8MV9C1MsD49qblhVKnJHg3qeYJ+/1277bj6NsNpmwO0=; b=e5e91AZhBr1aJnHPdD+YaGuGy2EhPnDsQsj5lMHK3JCEq0dSrxx5f8Z6Qe3wx6f6bq mk2j/DdgIinb12587ylfkGwD5cxlFegIQDnWexejhjLxkm1NnzTWJE7ARhkIBMJJWeBR 84c6SZLn0gqv4WDSunhbitIQzdyl5GGhIdUnBK7VJ0bi8GOYlc1UI9BgOHT6I998pKCV MCGvW8BI98DlHRN/MJTBh/+OglruDlj2JPOSOxRjwUbLN59r8XB2N1mnOBS/2s9X7E0m m2RMPUdFHH9TDaYCrMLLzT15e9HmSF+dJxgIMcoud7Aayt+nUC/3bCNnEO57t8FO1LA6 NQfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796263671; x=1796868471; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=8MV9C1MsD49qblhVKnJHg3qeYJ+/1277bj6NsNpmwO0=; b=Cg4OHzEoKBHFWSOdB5F+DTJF5T7ca5Rm0V9HUUhtzqVQytX1n/RpP3KOq+L6MN2idA 7N7QqXNg82n0GXIivujpxWInCjj73VNgiA0kiHLC3NY3uLHWqg7gonnESbhZ6M1H4zLY 1yCjuGZq3RuoAuTE54U0bRDgoi4VYwz77XkQ8Go0FF8+Pk0dG0M/HK3ufgtjUq7tXLsx 0cPkfACwqpz+mB1XDhFvUiX65dDB/HzrsdxkSZD+6oZGdFDEewELF6kMqZf10t6TXoJt 3TfPoCpf+nol1vqIqLm9pW3CqCZ8c7dCBP0Ca9ngL4QMULjamodAAN6c3zmOkrdI1R9y Ijtg== X-Forwarded-Encrypted: i=1; AL+hErHeq/Y1FL2McmnmbtdhcFPHt/KZHjrDGW0RD8mbOHLHmQYa0L/Yb2rhkyMsdIbUBUAxlZtzyqYkz9fsQVo=@vger.kernel.org X-Gm-Message-State: APuU4Z/JRu2oie+GKCl9QdYPMyXCsQVMc+vMQPdQjs0gA7IIqmUKNhd+ 6pmjFZ3WroeMGOTk4IwAfen3wjAcMBLYHN4EJh8rQzgQzdLGNjFG+CsI X-Gm-Gg: AZFdTZeGxklb4fR0OStmUAoUhKdO4VWKva+1EWXe09xQJU7wze8Wn0pxfZj+OtYTNAI yTjGtTXlIaY5E5RFeKPwa/d1TGn6uhxfUTUHdDiTOuw8oCmjEEq9xHXrLbbVqM0xkjyAuTLDeNf uclcBoNI2bokaKOiGgfme78DnpJYshXTK7tb2tEippo4/yVveL+V384DDkN4WRtYJ7bG7bOvZpu Lyr0MDEV3vQ2/iodpG0Qqx/a5Wv4dv9BIeNjcfyRSJ1gKpJ/SmateeJmd/UVVoheAi+rVdhjnfu UGmnR34rxFuOJKb6sZm4gWdlKhmN05vV7lKOd2C/hfDre2LIJcqRoZ5FK9/ykghIUjsUgs0wrMg l5ROKtMywrmR1H/nuaHsMKn97t8fv7igh4eWxIoNSsvURUKISoXKbwZw9Q42MUO01kd8rtJJRy4 Mt1KoNUWiS57bvfIT1xAbtCP96ZVYa2FZx5PhSJBZe6polIPGzqo3V5R5Z9cSCs0CPGr8cHPQOb XEkJ1ucfWdLk6mm3+ayjYsiU2MH4/3SADI+XsX0l0K+5XFFBTEwyoRY32DRkoR1MfOlWrOIN5Kz 6hMdrgT6xYKIAzz3/7WEdoKCsZHwk11sGBL1CrsvBj2T2tCGXo71LHdHg//fzEJc6EcOvBFR2VE alOLY0QF0k0Wp6vwVjegwyDOD6qsLJ0waZyNdYv62Z6O7hNkcfk2iuTk/gidSCst/e5r390pque ULTw== X-Received: by 2002:a17:902:f787:b0:2ed:379:158d with SMTP id d9443c01a7336-2f03f0fcd73mr435508615ad.9.1796263670781; Wed, 02 Dec 2026 18:07:50 -0800 (PST) Received: from ryzen.lan ([2601:644:8000:37f::e34]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f0b58fce71sm157752485ad.45.2026.12.02.18.07.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 18:07:50 -0800 (PST) From: Rosen Penev To: Srujana Challa , Bharat Bhushan , Herbert Xu , "David S. Miller" , Rosen Penev , Boris Brezillon , Arnaud Ebalard , Russell King , Romain Perier , linux-crypto@vger.kernel.org Subject: [PATCH v2 0/8] crypto: cesa - fixes for the Marvell CESA driver Date: Wed, 2 Dec 2026 18:07:25 -0800 Message-ID: <20261203020733.260995-1-rosenp@gmail.com> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Changes in v2: - Patch 4: Fixes: the initial driver commit f63601fd616a instead of db509a45339f; the hand-made padding and the IVDIG readback for HMAC predate TDMA. - Patch 8: build the hand-made padding in a buffer of its own (CESA_HASH_MAX_PADDING_SIZE). Long hashes now reach that path with any remainder, and for a remainder of 56..63 the padding is up to 72 bytes, which overflowed the 64-byte request cache. - Cover letter: results under a 6.18 kernel with the full self-tests. 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. The full series was also run on the same board under an OpenWrt 6.18 kernel with CONFIG_CRYPTO_SELFTESTS_FULL: all twelve algorithms pass, HMAC-MD5 included. An AF_ALG test comparing each mv-* driver against the software one (random lengths up to 140000, update splits, export/import through accept(), random HMAC keys, chained CBC, in place) gave no wrong result in about 1.07 million requests at 1 and 8 threads. 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 | 14 +++ drivers/crypto/marvell/cesa/cipher.c | 8 +- drivers/crypto/marvell/cesa/hash.c | 176 ++++++++++++++++++++++++--- 5 files changed, 197 insertions(+), 23 deletions(-) -- 2.56.1