1
- From efc0be2279a82664ed2d87ad51573e39222b8c1c Mon Sep 17 00:00:00 2001
1
+ From 12c9638cef18730910ab8afc0cf8dc999ba6c7d9 Mon Sep 17 00:00:00 2001
2
2
From: "G. Varga, Gabor" <Gabor.G.Varga@arm.com>
3
- Date: Wed, 9 Jul 2025 14:21:03 +0200
3
+ Date: Tue, 29 Jul 2025 14:17:06 +0200
4
4
Subject: [PATCH] Refining signature buffer size
5
5
6
6
When using t_cose with the PSA Crypto adaptor layer,
@@ -13,29 +13,29 @@ inside the PSA Crypto service and can exceed internal limits like
13
13
CRYPTO_IOVEC_BUFFER_SIZE.
14
14
15
15
This patch addresses the issue by computing the expected signature size
16
- using t_cose_crypto_sig_size() and passing the smaller of the two sizes
17
- to psa_sign_hash(). If the signature size query fails, the original
18
- buffer size is used as a fallback to maintain compatibility.
16
+ using t_cose_crypto_sig_size() and validating it against the actual size
17
+ of the provided buffer. If the expected size exceeds the available
18
+ buffer length, the function returns T_COSE_ERR_SIG_BUFFER_SIZE,
19
+ preventing a potentially unsafe call into psa_sign_hash().
19
20
20
21
Signed-off-by: G. Varga, Gabor <Gabor.G.Varga@arm.com>
21
- Change-Id: I97ab1633b6acf6de25bdbf4cf76c3666568c53c1
22
+ Change-Id: If70d36e930decb05a2bd45c2b31edf74a5cbea9f
22
23
---
23
- crypto_adapters/t_cose_psa_crypto.c | 13 + +++++++++++-
24
- 1 file changed, 12 insertions(+), 1 deletion(-)
24
+ crypto_adapters/t_cose_psa_crypto.c | 12 +++++++++++-
25
+ 1 file changed, 11 insertions(+), 1 deletion(-)
25
26
26
27
diff --git a/crypto_adapters/t_cose_psa_crypto.c b/crypto_adapters/t_cose_psa_crypto.c
27
- index 2095002..018c52b 100644
28
+ index 2095002..0d32cba 100644
28
29
--- a/crypto_adapters/t_cose_psa_crypto.c
29
30
+++ b/crypto_adapters/t_cose_psa_crypto.c
30
- @@ -239,6 +239,17 @@ t_cose_crypto_sign(int32_t cose_algorithm_id,
31
+ @@ -239,6 +239,16 @@ t_cose_crypto_sign(int32_t cose_algorithm_id,
31
32
32
33
signing_key_psa = (psa_key_handle_t)signing_key.key.handle;
33
34
34
35
+ /* Determine signature size and validate against buffer size */
35
36
+ return_value = t_cose_crypto_sig_size(cose_algorithm_id, signing_key, &signature_len);
36
37
+ if (return_value != T_COSE_SUCCESS) {
37
- + /* Fallback: use entire buffer */
38
- + signature_len = signature_buffer.len;
38
+ + goto Done;
39
39
+ } else if (signature_len > signature_buffer.len) {
40
40
+ /* Determined size too large for provided buffer */
41
41
+ return_value = T_COSE_ERR_SIG_BUFFER_SIZE;
@@ -45,7 +45,7 @@ index 2095002..018c52b 100644
45
45
/* It is assumed that this call is checking the signature_buffer
46
46
* length and won't write off the end of it.
47
47
*/
48
- @@ -248,7 +259 ,7 @@ t_cose_crypto_sign(int32_t cose_algorithm_id,
48
+ @@ -248,7 +258 ,7 @@ t_cose_crypto_sign(int32_t cose_algorithm_id,
49
49
hash_to_sign.ptr,
50
50
hash_to_sign.len,
51
51
signature_buffer.ptr, /* Sig buf */
0 commit comments