From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6161F3D9037; Wed, 8 Apr 2026 18:28:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775672907; cv=none; b=pZ7bU+VdALHrc+/IC4dRRkbcChSy4oV4aLmIcgNhNJTUnk7ysSQZ2ckxO7YsLxap9d4kDko7tFxKi2fKMwF0ch2403e99QJ3j3nw/IVwR+ESgroEQqrFnHZIESLNC03/qXTrRke/cCCPknl2ZMlnkaGSYZRsRP4QUFbr9/QQ5TE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775672907; c=relaxed/simple; bh=yzNmmhvVbyWjOargIUY+/BMjcN9KLtABjIxokZNFSLQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dpaZBHLUPf5tHY5AXZJS6rCs8vH9FdjwcJfr/lJVgTvJMwh0X4T0BRe9epz9KECGdbcy/vvcB3NwQo+8Rzc5CeNQ4HzO9fGzFLDPqZvZzSe6n7V3QoB4KKbwa9ib3GLJan3nhWJ1gpJsH/yxY7VwU/Lf7SSek18EYZZ+xYG1EHI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=WbLUIJot; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="WbLUIJot" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0F94C4AF09; Wed, 8 Apr 2026 18:28:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1775672907; bh=yzNmmhvVbyWjOargIUY+/BMjcN9KLtABjIxokZNFSLQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WbLUIJotn+3NNPPCnX32z1g4/T4q1hUGijf9lhdeOR9EzxIAIs7Z3y4o1GwQrt3vm fSu89Hgrg2YiC96BS0vKgz+NzetoYosTIQbMOWOebMLNQqL6ymxZy6akAk+wp7A+wH +bHRvS2VOtHCMKyBHJAkNI9UCFF6LdC00FDn2rKY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Horia=20Geant=C4=83?= , Herbert Xu , Sasha Levin Subject: [PATCH 6.18 026/277] crypto: caam - fix overflow on long hmac keys Date: Wed, 8 Apr 2026 20:00:11 +0200 Message-ID: <20260408175934.829380804@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408175933.836769063@linuxfoundation.org> References: <20260408175933.836769063@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Horia Geantă [ Upstream commit 80688afb9c35b3934ce2d6be9973758915e2e0ef ] When a key longer than block size is supplied, it is copied and then hashed into the real key. The memory allocated for the copy needs to be rounded to DMA cache alignment, as otherwise the hashed key may corrupt neighbouring memory. The copying is performed using kmemdup, however this leads to an overflow: reading more bytes (aligned_len - keylen) from the keylen source buffer. Fix this by replacing kmemdup with kmalloc, followed by memcpy. Fixes: 199354d7fb6e ("crypto: caam - Remove GFP_DMA and add DMA alignment padding") Signed-off-by: Horia Geantă Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/caam/caamalg_qi2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c index c6117c23eb25b..07665494c8758 100644 --- a/drivers/crypto/caam/caamalg_qi2.c +++ b/drivers/crypto/caam/caamalg_qi2.c @@ -3326,9 +3326,10 @@ static int ahash_setkey(struct crypto_ahash *ahash, const u8 *key, if (aligned_len < keylen) return -EOVERFLOW; - hashed_key = kmemdup(key, aligned_len, GFP_KERNEL); + hashed_key = kmalloc(aligned_len, GFP_KERNEL); if (!hashed_key) return -ENOMEM; + memcpy(hashed_key, key, keylen); ret = hash_digest_key(ctx, &keylen, hashed_key, digestsize); if (ret) goto bad_free_key; -- 2.53.0