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 5C29232FA3D; Fri, 9 Jan 2026 11:52:02 +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=1767959522; cv=none; b=Y0stiLyG8OrF96Kjc03YfCCKP+RlwyMOaVVGTMtE4smZXAK+JeuA00TKN/X6hnJzHjbOBE/zaLlDJDQ4vP1y0V3G6AmVPmNm4VufUImcU2HxqWVQ/xj3n2uhlhvtwaWIntpOqdK32LCH88x8AfuFpF5KFIsGy864FYqxlIwuYmE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767959522; c=relaxed/simple; bh=WXMSbNZuGORSTBrGCDXur9BsilYJFOGL7FkTxjp8+YY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=svGD7grpw/1iQitF7h1yWv9Xe3rqQBKBmbSsjurrYCjN8hZUdkhVZrpXa03c/GQCBzsp27mTWFoORyAYrw5gPwAJZHRC27tPdsNygTc+s3S8El3S+apipzyAqJEiwLtjf2YF8efBnZrfvSvb65sYbdsTJBF+C5Zqog7dn4xf3gs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=g7K7PGf3; 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="g7K7PGf3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBB8BC4CEF1; Fri, 9 Jan 2026 11:52:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1767959522; bh=WXMSbNZuGORSTBrGCDXur9BsilYJFOGL7FkTxjp8+YY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g7K7PGf3LtaKmj+TaOYWM4u+mwbCmQFGIhagirK0XgYD8lKVul7xjk6WD1hde2lmc yOjXAmKQlhjJYl7z7ByZf7xyhJMIUuNsTM9mia+MOYqUToOUsD7LXpYgsXBJInOAh3 kW8WQaAWFw9v6UDzm5FC5her3/F8jDA9u2vVtDmo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Thorsten Blum , Lukas Wunner , Herbert Xu , Sasha Levin Subject: [PATCH 6.6 082/737] crypto: asymmetric_keys - prevent overflow in asymmetric_key_generate_id Date: Fri, 9 Jan 2026 12:33:41 +0100 Message-ID: <20260109112137.081229279@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260109112133.973195406@linuxfoundation.org> References: <20260109112133.973195406@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-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thorsten Blum [ Upstream commit df0845cf447ae1556c3440b8b155de0926cbaa56 ] Use check_add_overflow() to guard against potential integer overflows when adding the binary blob lengths and the size of an asymmetric_key_id structure and return ERR_PTR(-EOVERFLOW) accordingly. This prevents a possible buffer overflow when copying data from potentially malicious X.509 certificate fields that can be arbitrarily large, such as ASN.1 INTEGER serial numbers, issuer names, etc. Fixes: 7901c1a8effb ("KEYS: Implement binary asymmetric key ID handling") Signed-off-by: Thorsten Blum Reviewed-by: Lukas Wunner Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- crypto/asymmetric_keys/asymmetric_type.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crypto/asymmetric_keys/asymmetric_type.c b/crypto/asymmetric_keys/asymmetric_type.c index 43af5fa510c09..7859b0692b42b 100644 --- a/crypto/asymmetric_keys/asymmetric_type.c +++ b/crypto/asymmetric_keys/asymmetric_type.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -151,12 +152,17 @@ struct asymmetric_key_id *asymmetric_key_generate_id(const void *val_1, size_t len_2) { struct asymmetric_key_id *kid; - - kid = kmalloc(sizeof(struct asymmetric_key_id) + len_1 + len_2, - GFP_KERNEL); + size_t kid_sz; + size_t len; + + if (check_add_overflow(len_1, len_2, &len)) + return ERR_PTR(-EOVERFLOW); + if (check_add_overflow(sizeof(struct asymmetric_key_id), len, &kid_sz)) + return ERR_PTR(-EOVERFLOW); + kid = kmalloc(kid_sz, GFP_KERNEL); if (!kid) return ERR_PTR(-ENOMEM); - kid->len = len_1 + len_2; + kid->len = len; memcpy(kid->data, val_1, len_1); memcpy(kid->data + len_1, val_2, len_2); return kid; -- 2.51.0