Blame SOURCES/0109-tc-m_xt-Fix-for-potential-string-buffer-overflows.patch

99be8f
From 8ac8129d710b8a084ce213791874330aa30ec70e Mon Sep 17 00:00:00 2001
99be8f
From: Andrea Claudi <aclaudi@redhat.com>
99be8f
Date: Mon, 29 Apr 2019 20:08:08 +0200
99be8f
Subject: [PATCH] tc/m_xt: Fix for potential string buffer overflows
99be8f
99be8f
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1465646
99be8f
Upstream Status: iproute2.git commit 56270e54661e8
99be8f
99be8f
commit 56270e54661e8ca51d4b3661b9f9bb12a0a40d95
99be8f
Author: Phil Sutter <phil@nwl.cc>
99be8f
Date:   Thu Aug 24 11:51:49 2017 +0200
99be8f
99be8f
    tc/m_xt: Fix for potential string buffer overflows
99be8f
99be8f
    - Use strncpy() when writing to target->t->u.user.name and make sure the
99be8f
      final byte remains untouched (xtables_calloc() set it to zero).
99be8f
    - 'tname' length sanitization was completely wrong: If it's length
99be8f
      exceeded the 16 bytes available in 'k', passing a length value of 16
99be8f
      to strncpy() would overwrite the previously NULL'ed 'k[15]'. Also, the
99be8f
      sanitization has to happen if 'tname' is exactly 16 bytes long as
99be8f
      well.
99be8f
99be8f
    Signed-off-by: Phil Sutter <phil@nwl.cc>
99be8f
---
99be8f
 tc/m_xt.c | 7 ++++---
99be8f
 1 file changed, 4 insertions(+), 3 deletions(-)
99be8f
99be8f
diff --git a/tc/m_xt.c b/tc/m_xt.c
99be8f
index ad52d239caf61..9218b14594403 100644
99be8f
--- a/tc/m_xt.c
99be8f
+++ b/tc/m_xt.c
99be8f
@@ -95,7 +95,8 @@ build_st(struct xtables_target *target, struct xt_entry_target *t)
99be8f
 	if (t == NULL) {
99be8f
 		target->t = xtables_calloc(1, size);
99be8f
 		target->t->u.target_size = size;
99be8f
-		strcpy(target->t->u.user.name, target->name);
99be8f
+		strncpy(target->t->u.user.name, target->name,
99be8f
+			sizeof(target->t->u.user.name) - 1);
99be8f
 		target->t->u.user.revision = target->revision;
99be8f
 
99be8f
 		if (target->init != NULL)
99be8f
@@ -277,8 +278,8 @@ static int parse_ipt(struct action_util *a, int *argc_p,
99be8f
 	}
99be8f
 	fprintf(stdout, " index %d\n", index);
99be8f
 
99be8f
-	if (strlen(tname) > 16) {
99be8f
-		size = 16;
99be8f
+	if (strlen(tname) >= 16) {
99be8f
+		size = 15;
99be8f
 		k[15] = 0;
99be8f
 	} else {
99be8f
 		size = 1 + strlen(tname);
99be8f
-- 
99be8f
2.20.1
99be8f