Blame SOURCES/libxt_string-Fix-array-out-of-bounds-check.patch

9a3fa7
From 5790cacab5a3fd7bde26056fa0f8b4650bd21bb7 Mon Sep 17 00:00:00 2001
9a3fa7
From: Phil Sutter <psutter@redhat.com>
9a3fa7
Date: Fri, 15 Mar 2019 17:50:10 +0100
9a3fa7
Subject: [PATCH] libxt_string: Fix array out of bounds check
9a3fa7
9a3fa7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1525980
9a3fa7
Upstream Status: iptables commit 6fc7762f6f785
9a3fa7
9a3fa7
commit 6fc7762f6f78526e3cb0c189ac2778a6be4c00b5
9a3fa7
Author: Phil Sutter <phil@nwl.cc>
9a3fa7
Date:   Mon Sep 17 13:38:33 2018 +0200
9a3fa7
9a3fa7
    libxt_string: Fix array out of bounds check
9a3fa7
9a3fa7
    Commit 56d7ab42f3782 ("libxt_string: Avoid potential array out of bounds
9a3fa7
    access") tried to fix parse_hex_string() for overlong strings but the
9a3fa7
    change still allowed for 'sindex' to become XT_STRING_MAX_PATTERN_SIZE
9a3fa7
    which leads to access of first byte after info->pattern. This is not
9a3fa7
    really a problem because it merely overwrites info->patlen before
9a3fa7
    calling xtables_error() later, but covscan still detects it so it's
9a3fa7
    still worth fixing.
9a3fa7
9a3fa7
    The crucial bit here is that 'sindex' has to be incremented at end of
9a3fa7
    the last iteration since its value is used for info->patlen. Hence just
9a3fa7
    move the overflow check to the beginning of the loop.
9a3fa7
9a3fa7
    Fixes: 56d7ab42f3782 ("libxt_string: Avoid potential array out of bounds access")
9a3fa7
    Signed-off-by: Phil Sutter <phil@nwl.cc>
9a3fa7
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9a3fa7
9a3fa7
Signed-off-by: Phil Sutter <psutter@redhat.com>
9a3fa7
---
9a3fa7
 extensions/libxt_string.c | 6 ++++--
9a3fa7
 1 file changed, 4 insertions(+), 2 deletions(-)
9a3fa7
9a3fa7
diff --git a/extensions/libxt_string.c b/extensions/libxt_string.c
9a3fa7
index d298c6a7081e7..7c6366cbbf1b3 100644
9a3fa7
--- a/extensions/libxt_string.c
9a3fa7
+++ b/extensions/libxt_string.c
9a3fa7
@@ -103,6 +103,9 @@ parse_hex_string(const char *s, struct xt_string_info *info)
9a3fa7
 	}
9a3fa7
 
9a3fa7
 	while (i < slen) {
9a3fa7
+		if (sindex >= XT_STRING_MAX_PATTERN_SIZE)
9a3fa7
+			xtables_error(PARAMETER_PROBLEM,
9a3fa7
+				      "STRING too long \"%s\"", s);
9a3fa7
 		if (s[i] == '\\' && !hex_f) {
9a3fa7
 			literal_f = 1;
9a3fa7
 		} else if (s[i] == '\\') {
9a3fa7
@@ -159,8 +162,7 @@ parse_hex_string(const char *s, struct xt_string_info *info)
9a3fa7
 			info->pattern[sindex] = s[i];
9a3fa7
 			i++;
9a3fa7
 		}
9a3fa7
-		if (++sindex > XT_STRING_MAX_PATTERN_SIZE)
9a3fa7
-			xtables_error(PARAMETER_PROBLEM, "STRING too long \"%s\"", s);
9a3fa7
+		sindex++;
9a3fa7
 	}
9a3fa7
 	info->patlen = sindex;
9a3fa7
 }
9a3fa7
-- 
9a3fa7
2.21.0
9a3fa7