Skip to contentSkip to conversation

tipc: input validation

PATCH Applied Andrea Claudi 2 participants 5 messages May 1, 2021 – May 9, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover tipc: input validation

This series fixes two buffer overflow on tipc due to missing input leght validation on key and algname params.

Andrea Claudi (2):
tipc: bail out if algname is abnormally long
tipc: bail out if key is abnormally long

 tipc/misc.c | 3 +++
 tipc/node.c | 9 +++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)
Signature · 1 line
2.30.2
#4 lore raw

PATCH 2/2 tipc: bail out if key is abnormally long

tipc segfaults when called with an abnormally long key:

$ tipc node set key 0123456789abcdef0123456789abcdef0123456789abcdef
*** buffer overflow detected ***: terminated

Fix this returning an error if key length is longer than TIPC_AEAD_KEYLEN_MAX.

Fixes 24bee3bf9752 ("tipc: add new commands to set TIPC AEAD key")
---
 tipc/misc.c | 3 +++
 1 file changed, 3 insertions(+)
tipc/misc.c +3 -0
index 1daf3072..909975d8 100644
@@ -113,6 +113,9 @@ int str2key(char *str, struct tipc_aead_key *key)
 	    }
 	}
 
+	if (len > TIPC_AEAD_KEYLEN_MAX)
+		return -1;
+
 	/* Obtain key: */
 	if (!ishex) {
 		key->keylen = len;
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/2 tipc: bail out if algname is abnormally long

In reply to Andrea Claudi

tipc segfaults when called with an abnormally long algname:

$ tipc node set key 0x1234 algname supercalifragilistichespiralidososupercalifragilistichespiralidoso
*** buffer overflow detected ***: terminated

Fix this returning an error if provided algname is longer than TIPC_AEAD_ALG_NAME.

Fixes 24bee3bf9752 ("tipc: add new commands to set TIPC AEAD key")
---
 tipc/node.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tipc/node.c +7 -2
index ae75bfff..bf592a07 100644
@@ -236,10 +236,15 @@ get_ops:
 
 	/* Get algorithm name, default: "gcm(aes)" */
 	opt_algname = get_opt(opts, "algname");
-	if (!opt_algname)
+	if (!opt_algname) {
 		strcpy(input.key.alg_name, "gcm(aes)");
-	else
+	} else {
+		if (strlen(opt_algname->val) > TIPC_AEAD_ALG_NAME) {
+			fprintf(stderr, "error, invalid algname\n");
+			return -EINVAL;
+		}
 		strcpy(input.key.alg_name, opt_algname->val);
+	}
 
 	/* Get node identity */
 	opt_nodeid = get_opt(opts, "nodeid");
Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH iproute2 1/2] tipc: bail out if algname is abnormally long

[ cc author of Fixes commit ]

Quoted 37 lines · Andrea Claudi

tipc segfaults when called with an abnormally long algname:

$ tipc node set key 0x1234 algname supercalifragilistichespiralidososupercalifragilistichespiralidoso
*** buffer overflow detected ***: terminated

Fix this returning an error if provided algname is longer than TIPC_AEAD_ALG_NAME.

Fixes 24bee3bf9752 ("tipc: add new commands to set TIPC AEAD key")
---
 tipc/node.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tipc/node.c +7 -2
index ae75bfff..bf592a07 100644
@@ -236,10 +236,15 @@ get_ops:
 
 	/* Get algorithm name, default: "gcm(aes)" */
 	opt_algname = get_opt(opts, "algname");
-	if (!opt_algname)
+	if (!opt_algname) {
 		strcpy(input.key.alg_name, "gcm(aes)");
-	else
+	} else {
+		if (strlen(opt_algname->val) > TIPC_AEAD_ALG_NAME) {
+			fprintf(stderr, "error, invalid algname\n");
+			return -EINVAL;
+		}
 		strcpy(input.key.alg_name, opt_algname->val);
+	}
 
 	/* Get node identity */
 	opt_nodeid = get_opt(opts, "nodeid");
Applied
#3 lore raw

Re: [PATCH iproute2 1/2] tipc: bail out if algname is abnormally long

In reply to Andrea Claudi
Quoted 5 lines · Andrea Claudi

tipc segfaults when called with an abnormally long algname:

$ tipc node set key 0x1234 algname supercalifragilistichespiralidososupercalifragilistichespiralidoso
*** buffer overflow detected ***: terminated
Quoted 9 lines

Fix this returning an error if provided algname is longer than TIPC_AEAD_ALG_NAME.

Fixes 24bee3bf9752 ("tipc: add new commands to set TIPC AEAD key")
---
 tipc/node.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

applied both, thanks.