From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796246023; b=0a0G1xiT4qSFlFhOzKHNxCJffzWvOi0aIKfcjlN0jk2saX+P17J7sxnAZnpFZUIPVf7O +YiH0P0+jVl34EH3cMNrpqV6lKyOOopOojI8v5TNDBBFRB+T+DcCatlSHiN1yN6vXKEM1 iKbZYZyuOYKfiqClLvrX/aB6OP9qX+Ye+6LZwW/p4SRkAO0PyGsoGylydqPcwXkaSSs0J FIBQetAD/omK2E+mvgW23RCF6KC4ln+sgMwbWBE2WHN40ADzUQ6n1K8ij5/xr+JShUEEN /b5P/AJDb8AxWabWp4ZiRvAeFWAbEayX9j6i7LdJBGIZcPEGMq4YGeSa1v+iBthBVkw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796246023; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-TM-AS-GCONF: X-Proofpoint-ORIG-GUID:X-Proofpoint-Spam-Details-Enc: X-Proofpoint-GUID:X-Proofpoint-Spam-Info:X-Authority-Analysis: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=Ya9jKUIXeowWsO1hYr0apVSy5GXQrV6BfkALg49/+LU=; b=hjqC51JTWwO7cmqZmYFFQmvnOa4D/7P+6Re2uKFcmD1Nzrn66n1xOeNZmUrKq6XMmR2x 6FWghdmAwE7K836NEscTu/AhJ2BJI5MPYVP2ygAJlGpYdY/Y6Id7763uJ8ziRUF8MqVaX bGuQEGb+Wgyg/oPagGalSxQagkakZZ1g8y9mYgI+8AQYNXPjpkZ0JjKDEKNO8v3PYx1Mh 2O0FSsDejt6XAH1B94kEEpItleQnNRPt4oo9D0hbob/KSNUY+fSGE1Mi5hhppqoV5w0EF TMKdxp/PrPvZkU5PoQzG6POEZ7A7d6MDTq4hFTP0qdlQTBtr2eo2BdPItz13oQ/jHhQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=V4F+sfAz; arc=none smtp.remote-ip=148.163.156.1 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8876F606A322; Wed, 2 Dec 2026 21:13:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8876F606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=V4F+sfAz Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B2J4dju3878305; Wed, 2 Dec 2026 21:13:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=Ya9jKU IXeowWsO1hYr0apVSy5GXQrV6BfkALg49/+LU=; b=V4F+sfAzJmbsXJaqTMFpvq 6zlStgj5SFCYJvcnUElpLT8pJy7taO1JvJsHm5jxoWK8fFZdMXdxO7/Zy0u0240i NcgfM3mp2Z0KWvZVQiHJtMF9VoAeRZktt8AeJNDgUoZDiHjvNjY/j7D+01PzhtIu 3NtoTvdtNgcjZnbTZqbdTpiSunjC0gom7LlnTHmHhlu0Qahl1v620UD+HkKTIScJ t63pKwquUjyNz/RmYjIR2No1+FyYUWkfjVFy5u72yiWXu/KM87pcPttaCodAaiqy 5vmVy1loD1e2xgBlwFUVcGaXfspCOXO/NVSpfHPTbsv/KXAXgHzNQahSOcqGVG9A == Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7pmtby9k-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 02 Dec 2026 21:13:22 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B2J4Lqn479582; Wed, 2 Dec 2026 21:13:22 GMT Received: from smtprelay07.dal12v.mail.ibm.com ([172.16.1.9]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4ja2uv56ce-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Dec 2026 21:13:22 +0000 (GMT) Received: from smtpav04.wdc07v.mail.ibm.com (smtpav04.wdc07v.mail.ibm.com [10.39.53.231]) by smtprelay07.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B2LDLOe29098530 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 2 Dec 2026 21:13:21 GMT Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 06A5358050; Wed, 2 Dec 2026 21:13:21 +0000 (GMT) Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4B0DA58045; Wed, 2 Dec 2026 21:13:20 +0000 (GMT) Received: from [9.47.158.153] (unknown [9.47.158.153]) by smtpav04.wdc07v.mail.ibm.com (Postfix) with ESMTP; Wed, 2 Dec 2026 21:13:20 +0000 (GMT) Message-ID: <66003f46-9f45-46c2-9f5b-2bdda2ee533b@linux.ibm.com> Date: Wed, 2 Dec 2026 16:13:19 -0500 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] crypto: ecdsa - Reject non-DER X9.62 signatures To: florian.bauckholt@cispa.de, Lukas Wunner , Ignat Korchagin , Herbert Xu , "David S. Miller" Cc: linux-crypto@vger.kernel.org, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org References: <20261201-ecdsa-x962-der-v2-1-00ba1a98a530@cispa.de> Content-Language: en-US From: Stefan Berger In-Reply-To: <20261201-ecdsa-x962-der-v2-1-00ba1a98a530@cispa.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: FG7ia3HBg3NlJkzq6ow8wYVkJbXoU2Kw X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAyMDA4NCBTYWx0ZWRfX6E3XVOx3gg48 F3u6SkvA08hM7j4gb1VhijLjpCx8ipsbbEmSpCv3PtlFee6JdSYuS+zylZ3UUtrDNdJVIWSVhvD OlAIQW4hDOnpI6TVOBl3hhQmOsOKevie2ZqvaVJzBo28mLEBmKCYwO3qW9v2pi/qCYzN+5UHV1J oPj5N8ctOXPEzsxGWaOD3iJJ5C+suR+U1iy7jpazHLRLWXR/jLWnsG3LsMOpJfHyGkNdUr4xaKf 4TyZMphdwGfBTnsUYx+816XK5zxbo4T9ghGRcOw2E1fsqc0r6G9bxRcKR8RhIORL2yhbeXUJq7D lJRTVRU5q2fUkq+Mr2BI/Znx6PaWO3uW/UOrT3RolTZuI+4a2yg5Ny+wfSZDVj0knRJn9eKdT10 +w7WJkiRVKfqCU/rjI2Gy88BhSHzniboSm4z+jH/bBvoY4flQWGw9MSCQQAZJvoZDbHQqfGJDr0 YfuyY57K0afsmSZ55Ew== X-Proofpoint-GUID: FG7ia3HBg3NlJkzq6ow8wYVkJbXoU2Kw X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAyMDA4NCBTYWx0ZWRfX8JM7zLQ/YA/L v9Pgu8WXSkGUgQaFbM4rer+lR+lUx+XDCVmrp0aitEovsPZjhl31kzoxFmG4niXcEBZkCYLrpiF vCZyE1ryKUogFFfDwWIjmw8t9fQDs5c= X-Authority-Analysis: v=2.4 cv=U9cHnuru c=1 sm=1 tr=0 ts=6b1089f3 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=YEb2fhS1726XOHPAqp4A:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-02_05,2026-12-02_07,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 priorityscore=1501 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612020084 On 12/1/26 6:21 AM, Florian Bauckholt via B4 Relay wrote: > From: Florian Bauckholt > > The x962(ecdsa-nist-*) template decodes Ecdsa-Sig-Value with the > generic BER decoder, and ecdsa_get_signature_rs() only strips one > leading zero byte without looking at the INTEGER's sign or encoding. > As a result the following encodings of a valid signature are accepted > as well: > > - a SEQUENCE tag without the constructed bit (0x10 instead of 0x30), > as the decoder ignores that bit when matching a constructed tag > - non-minimal length encodings of the SEQUENCE, r or s (long form > where the short form fits, or padded with zero bytes) > - indefinite length for the SEQUENCE > - data following the SEQUENCE (the decoder does not check that the > whole buffer was consumed) > - r or s with the most significant bit set but without the leading > zero byte, i.e. a negative INTEGER read as positive > - r or s with a superfluous leading zero byte > > RFC 3279 section 2.2.3 and SEC 1 section C.5 require Ecdsa-Sig-Value to > be DER-encoded, so all of these are invalid and should be rejected. > > This is a potential but unlikely behaviour change for users of the x962 > template (X.509 certificates, module and IMA signatures, > KEYCTL_PKEY_VERIFY): signatures that are valid ECDSA signatures but are > not DER-encoded used to verify and are now rejected with -EINVAL. The > p1363 template is not affected. > > Rejecting trailing data relies on KEYCTL_PKEY_VERIFY passing the > caller's signature length. Between commit cb481e59ea6c ("KEYS: fix > overflow in keyctl_pkey_params_get_2()") and commit 94cd21592349 ("KEYS: > Fix asym key overflow in keyctl_pkey_verify()") it passed max_sig_size > instead, so trees containing the former need the latter before this > patch, or every signature shorter than the maximum is rejected. > > Add a test vector for each of these encodings, taken or derived from > Wycheproof's secp256r1/SHA-256 test vectors. > > Found by differential testing against other ECDSA implementations. > > Fixes: 4e6602916bc6 ("crypto: ecdsa - Add support for ECDSA signature verification") > Signed-off-by: Florian Bauckholt Tested-by: Stefan Berger