tipc: Ensure NUL-termination of remote algorithm name
Subsystems (3)
PATCH 1/1 tipc: Ensure NUL-termination of remote algorithm name
In tipc_crypto_key_rcv(), the algorithm name is copied from the incoming message using memcpy with a fixed size of TIPC_AEAD_ALG_NAME (32 bytes). If the remote peer sends a name that fills all 32 bytes without a NUL terminator, the alg_name field will not be NUL-terminated. This string is later passed to crypto_alloc_aead() which expects a NUL-terminated string, potentially causing an out-of-bounds read when the crypto subsystem searches for the algorithm by name.
Fix by explicitly NUL-terminating the last byte of alg_name after the memcpy.
--- net/tipc/crypto.c | 1 + 1 file changed, 1 insertion(+)
net/tipc/crypto.c +1 -0
@@ -2325,6 +2325,7 @@ static bool tipc_crypto_key_rcv(struct tipc_crypto *rx, struct tipc_msg *hdr)/* Copy key from msg data */ skey->keylen = keylen;memcpy (skey->alg_name, data,TIPC_AEAD_ALG_NAME ); + skey->alg_name[TIPC_AEAD_ALG_NAME -1 ] ='\0' ;memcpy (skey->key, data +TIPC_AEAD_ALG_NAME +sizeof (__be32), skey->keylen);
Signature · 1 line
2.39.3 (Apple Git-145)
Tung Quang Nguyen
maintainerQuoted 9 lines
Subject: [PATCH] tipc: Ensure NUL-termination of remote algorithm name
In
tipc_crypto_key_rcv(), the algorithm name is copied from the incoming message using memcpy with a fixed size ofTIPC_AEAD_ALG_NAME(32 bytes). If the remote peer sends a name that fills all 32 bytes without a NUL terminator, thealg_namefield will not be NUL-terminated. This string is later passed tocrypto_alloc_aead()which expects a NUL-terminated string, potentially causing an out-of-bounds read when the crypto subsystem searches for the algorithm by name.
TIPC only supports one algorithm name "gcm(aes)" which is 8-byte length. So, there is no " name that fills all 32 bytes" as you mentioned.
Quoted 14 lines
Fix by explicitly NUL-terminating the last byte of
alg_nameafter the memcpy.Fixes 1ef6f7c9390f ("tipc: add automatic session key exchange")Signed-off-by Dudu Lu <[email protected]>---
net/tipc/crypto.c| 1 +1 file changed, 1 insertion(+)net/tipc/crypto.c index renamed from net/tipc/crypto.c +0
-0
d3046a39ff72..ac072356bf0c100644
net/tipc/crypto.c static bool tipc_crypto_key_rcv(struct tipc_crypto · line 2329
Quoted 5 lines
net/tipc/crypto.c +1
-0@@ -2325,6 +2325,7 @@ static bool tipc_crypto_key_rcv(struct tipc_crypto *rx, struct tipc_msg *hdr)/* Copy key from msg data */ skey->keylen = keylen;memcpy (skey->alg_name, data,TIPC_AEAD_ALG_NAME ); + skey->alg_name[TIPC_AEAD_ALG_NAME -1 ] ='\0' ;
This is not needed as explained above.
Quoted 6 lines
net/tipc/crypto.c +0
-1memcpy (skey->key, data +TIPC_AEAD_ALG_NAME +sizeof (__be32), skey->keylen); --2.39.3 (Apple Git-145)