[Devel] [PATCH RHEL7 COMMIT] ms/netfilter: x_tables: avoid stack-out-of-bounds read in xt_copy_counters_from_user

Konstantin Khorenko khorenko at virtuozzo.com
Fri Jun 15 19:06:36 MSK 2018


The commit is pushed to "branch-rh7-3.10.0-693.21.1.vz7.50.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-693.21.1.vz7.50.11
------>
commit 449fe6ed47e1348cfe141b73f87f9e64345c4200
Author: Eric Dumazet <edumazet at google.com>
Date:   Fri Jun 15 19:06:36 2018 +0300

    ms/netfilter: x_tables: avoid stack-out-of-bounds read in xt_copy_counters_from_user
    
    syzkaller reports an out of bound read in strlcpy(), triggered
    by xt_copy_counters_from_user()
    
    Fix this by using memcpy(), then forcing a zero byte at the last position
    of the destination, as Florian did for the non COMPAT code.
    
    Fixes: d7591f0c41ce ("netfilter: x_tables: introduce and use xt_copy_counters_from_user")
    Signed-off-by: Eric Dumazet <edumazet at google.com>
    Cc: Willem de Bruijn <willemb at google.com>
    Acked-by: Florian Westphal <fw at strlen.de>
    Signed-off-by: Pablo Neira Ayuso <pablo at netfilter.org>
    (cherry picked from commit e466af75c074e76107ae1cd5a2823e9c61894ffb)
    Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 net/netfilter/x_tables.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index 38f6d7106f98..29704d861624 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -928,7 +928,7 @@ void *xt_copy_counters_from_user(const void __user *user, unsigned int len,
 		if (copy_from_user(&compat_tmp, user, sizeof(compat_tmp)) != 0)
 			return ERR_PTR(-EFAULT);
 
-		strlcpy(info->name, compat_tmp.name, sizeof(info->name));
+		memcpy(info->name, compat_tmp.name, sizeof(info->name) - 1);
 		info->num_counters = compat_tmp.num_counters;
 		user += sizeof(compat_tmp);
 	} else
@@ -941,9 +941,9 @@ void *xt_copy_counters_from_user(const void __user *user, unsigned int len,
 		if (copy_from_user(info, user, sizeof(*info)) != 0)
 			return ERR_PTR(-EFAULT);
 
-		info->name[sizeof(info->name) - 1] = '\0';
 		user += sizeof(*info);
 	}
+	info->name[sizeof(info->name) - 1] = '\0';
 
 	size = sizeof(struct xt_counters);
 	size *= info->num_counters;


More information about the Devel mailing list