From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796263675; b=TL64T3oc9WDxymY5FyztE29sPccFPhP2hrthSG88e4PIWp8SCh6G1SGZbgCpXhE+nuBb DBtpStojOEL9kzyFIaG4AyBn3zawpHirC5xCSorWlyhVdoRH3Pse5R662iWE+fDLXMLa8 6pTQ5G8GIzbnMqlySnyPcGy4Z95ibafsbYZvLIwu9y0CTanqoxAfKDsd6WYRSu6sq4XQa EIH8Qner/xhxameaaZo+kLV+5RJqzeTRWWydzE085VuC3DlH3rSwGodGuWGBZFcTlgSUx 1bn5itLCf43pVALKCMt91oPXt8Ll2b69pzZ37ljxsyECFNrNmzKR4KauirjTwNRELeg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796263675; 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:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=0IEWdqpi7iJ/opemLt0tqH7v//3wrpWUTqWyICITBTI=; b=sn5ynpJA0/RzAtosANZWyzNjsTbJdcThPXbQDJN5bUsJjAY9yb7zoL+tNMnNzf8Jl9Pe Kw68pt74dlLHNMuhVMyBLoXrtbUiUEY+g9TXGZIWQKzwl8Rlw7AJ4kH88e0tB6QTQUMol iVwMti95239ZnwVQx/Em9/vwL/FRchSxWC1ovCjtIfwZwmDSJcnqB8mUZ2GsOrq0ZBKzY 8tHGwaoNCeugKir9kG3y5/Fu3eOV5yS9S4qw2mP0zdT8N1aV7erx40T3mudgzhJRzZufX nekfqzQd6Fu/GH0fdi3XqbO2EEq6YVxVLTjfkHB7CUD2SQWn5M4N573k3xD62B+NOPg== 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=cWwW4cfS; arc=none smtp.remote-ip=209.85.214.182 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 70D60606A32D for ; Thu, 3 Dec 2026 02:07:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 70D60606A32D 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=cWwW4cfS Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2f02ee04378so106953515ad.1 for ; Wed, 02 Dec 2026 18:07:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796263675; x=1796868475; darn=vger.kernel.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=0IEWdqpi7iJ/opemLt0tqH7v//3wrpWUTqWyICITBTI=; b=cWwW4cfS+hYHqXBLj0Xg0bTo0Y8p/+NhxmaIHntar9Z6uH0Rnn0K0R0n1jlndLHwXd mpvygGQiDNXMxQnT/32KXLA8uQ85RjXdXkoKB5oxUN2x7+h6ot+28ubgEnpKUYhb9GfS Xr8r++wJZKzDWTHaerkA3k5Azzu8pVy4lYqFH7tgiKoMlyQwdJcYhNq/RP2hMxts+Pfp VUfbBHrnMNxr10n0gnPShVtgnGIwqTJWGYHTRhVIHSnVu0KqAAhE5YZjy4iQPTtbSMRz Qq6klAEWEDZTJvZfzSaj+9v7nX9ldiguEGfFfToXpcc38TveGUiPTBkVWraNZTbk6vkL 4mVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796263675; x=1796868475; 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=0IEWdqpi7iJ/opemLt0tqH7v//3wrpWUTqWyICITBTI=; b=EL0YrgZzY855YFvBOo+Ahz/s2PQVhCFWL45NAGWmguT/utQXev0U3fMD21GZdlVB6Q AFjbl2XqtC9Hd0E4AoYoB2HZND5VooH8lONNrmv4iroJMS2MP11aTZ+3Y3OmjbdkMgtF g3wMrJEjTu5c/OGq1+WWdaZoLwvNYqn3oq25td5jhdXDMcIOgumQEkALspE7HqV3RR5R BxWUpT2+ctlsmdzgqqZikl2a60zLHUszB8tofq16U7hjKzykq2XTOqVCBByFnSbYATSj 7fKiaIEnY1SUAH1VWRJY8Ll1DNWs9Kc4cvnXFxF7794Eu/SzSMvi6X0acGgm4KA0cgcS blcA== X-Forwarded-Encrypted: i=1; AL+hErG0QoJ0oSAf4xpfHqhs4fv4WEIC7At0oqhFJcBkPo0Pt4qptGaHSw6+dsJDLCh6zvfy106MYikfg+JXb2I=@vger.kernel.org X-Gm-Message-State: APuU4Z/kG42N0WHUf/tLqhB60YGoim3VZOg5L+Tf57dZdYNktpbWHTA2 F1KWv4R1ya0frlYitS+yd0NNhqb/pWTQ92r46ypLmYd61C94NmxG8Wgc X-Gm-Gg: AZFdTZdyTS36Pk6Qs3P2GsOKmHxRJSw0eBokVYgzMFcUJhTUwUQDR7DJN9ImRQ0ar22 B6dqn8lI6yBLURWQajcqrIyJgsBbeBw50PQguIix+DJHnxwWOR1Due+vFuyAf6yEBYpX9rQLqGR i9Uhm9rfwAdRcKGnYs6HiK954+WPPLvYiAl+UWrPl+wwIf2mr+3D3mNv7QV2L5WGk51EaVHmgcb bVplVofCFg+UUPljr1TWPTkdNDppvVvZMt+jVcltZEXnwZylURPZaE4wi1YLPCNo+hsZOM5n4sH BlvECEvn0gVcAMV1HWuU7SlHWFOWf4fvOpLqEERHHQpMVmvzZwY6Gvk8ZA9PyYD3/73d/uW0lok PcJZ1615Q3lHW4PxHBnLY4A4PE1sxS5PlDTG8tqGPwNPkkxT8MicimQoCB2eaGXG0vAl28NqhnJ YDUdhpiG0wMooxDg8snMS3y6cqBKgn8yT2vXHX5hlDPUqux6jGbtDR8LPdzg0afS+lVT4lOjYWH tWmRZ+7ebui2tYC6R+LuAvWH0wf+EWCzpaZw2b4v44JhDIaGnhP/WTYLgTjfRDkB3fZue3CbwcR EeDqaARO1UqE/lefyjYGphZwM+AjjePP7N2nCLnflQCdbEBaV0Jo1JD4mxshtiJIUqeFN9h3af9 pqbawsrcps9Sq/AquOJ0dujmbJoEdeTS6F1aM1CzMPLASTgxNF/TjfFrmAmASy5m0NRkA8r1hUK oOtA== X-Received: by 2002:a17:902:f652:b0:2e2:d77b:e587 with SMTP id d9443c01a7336-2f03f1cee76mr480491145ad.18.1796263674629; Wed, 02 Dec 2026 18:07:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 18:07:54 -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 Cc: stable@vger.kernel.org Subject: [PATCH v2 3/8] crypto: cesa - hash the last full SRAM chunk before the padding Date: Wed, 2 Dec 2026 18:07:28 -0800 Message-ID: <20261203020733.260995-4-rosenp@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203020733.260995-1-rosenp@gmail.com> References: <20261203020733.260995-1-rosenp@gmail.com> 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 When a hash is longer than the engine's total length field (0xffff), mv_cesa_ahash_dma_last_req() pads it by hand. The padding is placed in SRAM right behind the outstanding data and the two are hashed by one operation, or, if only part of the padding fits, in two. If the outstanding data fills the SRAM payload exactly, none of the padding fits behind it. That case adds no operation for the outstanding data at all and transfers the padding to the start of the SRAM data area, overwriting the last payload-sized chunk of the message before it was hashed. Every message longer than 0xffff bytes whose last chunk ends exactly at the payload size (1920 bytes with the default 2 KiB SRAM), for example any one-shot digest of a multiple of 1920 bytes, gets a wrong digest. Hash the outstanding data with its own operation first, as was done before the padding handling was rearranged. Verified on an Armada 385 (WRT3200ACM) against the software hashes, with random lengths up to 140000 bytes: about 10 of 40000 SHA1, SHA256, HMAC-SHA1 and HMAC-SHA256 digests were wrong before, all of them of that shape, and none of 60000 after. Fixes: ab270e7055e0 ("crypto: marvell/cesa - rearrange handling for sw padded hashes") Cc: stable@vger.kernel.org Signed-off-by: Rosen Penev --- drivers/crypto/marvell/cesa/hash.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/crypto/marvell/cesa/hash.c b/drivers/crypto/marvell/cesa/hash.c index d2fe96d865bd..9fd3d5c32312 100644 --- a/drivers/crypto/marvell/cesa/hash.c +++ b/drivers/crypto/marvell/cesa/hash.c @@ -607,6 +607,16 @@ mv_cesa_ahash_dma_last_req(struct mv_cesa_tdma_chain *chain, return op; padoff += len; + } else if (frag_len) { + /* + * The outstanding data fills the SRAM payload, so none of the + * padding fits behind it. Hash that data on its own before the + * padding transfer below overwrites it. + */ + op = mv_cesa_dma_add_frag(chain, &creq->op_tmpl, frag_len, + flags); + if (IS_ERR(op)) + return op; } ret = mv_cesa_dma_add_data_transfer(chain, -- 2.56.1