Skip to content

Commit e466af7

Browse files
Eric Dumazetummakynes
authored andcommitted
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: d7591f0 ("netfilter: x_tables: introduce and use xt_copy_counters_from_user") Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Willem de Bruijn <willemb@google.com> Acked-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 5f9bfe0 commit e466af7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/netfilter/x_tables.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ void *xt_copy_counters_from_user(const void __user *user, unsigned int len,
892892
if (copy_from_user(&compat_tmp, user, sizeof(compat_tmp)) != 0)
893893
return ERR_PTR(-EFAULT);
894894

895-
strlcpy(info->name, compat_tmp.name, sizeof(info->name));
895+
memcpy(info->name, compat_tmp.name, sizeof(info->name) - 1);
896896
info->num_counters = compat_tmp.num_counters;
897897
user += sizeof(compat_tmp);
898898
} else
@@ -905,9 +905,9 @@ void *xt_copy_counters_from_user(const void __user *user, unsigned int len,
905905
if (copy_from_user(info, user, sizeof(*info)) != 0)
906906
return ERR_PTR(-EFAULT);
907907

908-
info->name[sizeof(info->name) - 1] = '\0';
909908
user += sizeof(*info);
910909
}
910+
info->name[sizeof(info->name) - 1] = '\0';
911911

912912
size = sizeof(struct xt_counters);
913913
size *= info->num_counters;

0 commit comments

Comments
 (0)