Blame SOURCES/CVE-2021-22555.patch

541d6a
From: Joel Savitz <jsavitz@redhat.com>
541d6a
Subject: [KPATCH 7.9] netfilter: x_tables: kpatch fixes for CVE-2021-22555
541d6a
Date: Wed, 28 Jul 2021 12:03:15 -0400
541d6a
541d6a
Kernels:
541d6a
3.10.0-1160.el7
541d6a
3.10.0-1160.2.1.el7
541d6a
3.10.0-1160.2.2.el7
541d6a
3.10.0-1160.6.1.el7
541d6a
3.10.0-1160.11.1.el7
541d6a
3.10.0-1160.15.2.el7
541d6a
3.10.0-1160.21.1.el7
541d6a
3.10.0-1160.24.1.el7
541d6a
3.10.0-1160.25.1.el7
541d6a
3.10.0-1160.31.1.el7
541d6a
3.10.0-1160.36.2.el7
541d6a
541d6a
Changes since last build:
541d6a
arches: x86_64 ppc64le
541d6a
arp_tables.o: changed function: translate_compat_table
541d6a
ip6_tables.o: changed function: translate_compat_table
541d6a
ip_tables.o: changed function: translate_compat_table
541d6a
x_tables.o: changed function: xt_compat_match_from_user
541d6a
x_tables.o: changed function: xt_compat_target_from_user
541d6a
---------------------------
541d6a
541d6a
Kernels:
541d6a
3.10.0-1160.el7
541d6a
3.10.0-1160.2.1.el7
541d6a
3.10.0-1160.2.2.el7
541d6a
3.10.0-1160.6.1.el7
541d6a
3.10.0-1160.11.1.el7
541d6a
3.10.0-1160.15.2.el7
541d6a
3.10.0-1160.21.1.el7
541d6a
3.10.0-1160.24.1.el7
541d6a
3.10.0-1160.25.1.el7
541d6a
3.10.0-1160.31.1.el7
541d6a
3.10.0-1160.36.2.el7
541d6a
541d6a
Modifications: none
541d6a
541d6a
Z-MR: https://gitlab.com/redhat/rhel/src/kernel/rhel-7/-/merge_requests/201
541d6a
KT0 test PASS: https://beaker.engineering.redhat.com/jobs/5642298
541d6a
for scratch build: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=38448253
541d6a
541d6a
commit 06215319786b979bed0f5eb3138de0506db9d39f
541d6a
Author: Florian Westphal <fwestpha@redhat.com>
541d6a
Date:   Fri Jul 9 11:42:55 2021 +0200
541d6a
541d6a
    netfilter: x_tables: fix compat match/target pad out-of-bound write
541d6a
541d6a
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1980489
541d6a
    Upstream Status: commit b29c457a65114
541d6a
    CVE: CVE-2021-22555
541d6a
541d6a
    commit b29c457a6511435960115c0f548c4360d5f4801d
541d6a
    Author: Florian Westphal <fw@strlen.de>
541d6a
    Date:   Wed Apr 7 21:38:57 2021 +0200
541d6a
541d6a
        netfilter: x_tables: fix compat match/target pad out-of-bound write
541d6a
541d6a
        xt_compat_match/target_from_user doesn't check that zeroing the area
541d6a
        to start of next rule won't write past end of allocated ruleset blob.
541d6a
541d6a
        Remove this code and zero the entire blob beforehand.
541d6a
541d6a
        Reported-by: syzbot+cfc0247ac173f597aaaa@syzkaller.appspotmail.com
541d6a
        Reported-by: Andy Nguyen <theflow@google.com>
541d6a
        Fixes: 9fa492cdc160c ("[NETFILTER]: x_tables: simplify compat API")
541d6a
        Signed-off-by: Florian Westphal <fw@strlen.de>
541d6a
        Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
541d6a
541d6a
    Signed-off-by: Florian Westphal <fwestpha@redhat.com>
541d6a
541d6a
Signed-off-by: Joel Savitz <jsavitz@redhat.com>
541d6a
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
541d6a
Acked-by: Artem Savkov <asavkov@redhat.com>
541d6a
Acked-by: Yannick Cote <ycote@redhat.com>
541d6a
---
541d6a
 net/ipv4/netfilter/arp_tables.c |  2 ++
541d6a
 net/ipv4/netfilter/ip_tables.c  |  2 ++
541d6a
 net/ipv6/netfilter/ip6_tables.c |  2 ++
541d6a
 net/netfilter/x_tables.c        | 10 ++--------
541d6a
 4 files changed, 8 insertions(+), 8 deletions(-)
541d6a
541d6a
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
541d6a
index 602d92697038..66ad3b4e194c 100644
541d6a
--- a/net/ipv4/netfilter/arp_tables.c
541d6a
+++ b/net/ipv4/netfilter/arp_tables.c
541d6a
@@ -1364,6 +1364,8 @@ static int translate_compat_table(struct xt_table_info **pinfo,
541d6a
 	if (!newinfo)
541d6a
 		goto out_unlock;
541d6a
 
541d6a
+	memset(newinfo->entries, 0, size);
541d6a
+
541d6a
 	newinfo->number = compatr->num_entries;
541d6a
 	for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
541d6a
 		newinfo->hook_entry[i] = info->hook_entry[i];
541d6a
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
541d6a
index 3559f7ffa430..d9de653be67e 100644
541d6a
--- a/net/ipv4/netfilter/ip_tables.c
541d6a
+++ b/net/ipv4/netfilter/ip_tables.c
541d6a
@@ -1622,6 +1622,8 @@ translate_compat_table(struct net *net,
541d6a
 	if (!newinfo)
541d6a
 		goto out_unlock;
541d6a
 
541d6a
+	memset(newinfo->entries, 0, size);
541d6a
+
541d6a
 	newinfo->number = compatr->num_entries;
541d6a
 	for (i = 0; i < NF_INET_NUMHOOKS; i++) {
541d6a
 		newinfo->hook_entry[i] = compatr->hook_entry[i];
541d6a
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
541d6a
index 1772a1797e79..d112bfc86aac 100644
541d6a
--- a/net/ipv6/netfilter/ip6_tables.c
541d6a
+++ b/net/ipv6/netfilter/ip6_tables.c
541d6a
@@ -1626,6 +1626,8 @@ translate_compat_table(struct net *net,
541d6a
 	if (!newinfo)
541d6a
 		goto out_unlock;
541d6a
 
541d6a
+	memset(newinfo->entries, 0, size);
541d6a
+
541d6a
 	newinfo->number = compatr->num_entries;
541d6a
 	for (i = 0; i < NF_INET_NUMHOOKS; i++) {
541d6a
 		newinfo->hook_entry[i] = compatr->hook_entry[i];
541d6a
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
541d6a
index 76e40ff48b10..affd08ce7df8 100644
541d6a
--- a/net/netfilter/x_tables.c
541d6a
+++ b/net/netfilter/x_tables.c
541d6a
@@ -564,7 +564,7 @@ void xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr,
541d6a
 {
541d6a
 	const struct xt_match *match = m->u.kernel.match;
541d6a
 	struct compat_xt_entry_match *cm = (struct compat_xt_entry_match *)m;
541d6a
-	int pad, off = xt_compat_match_offset(match);
541d6a
+	int off = xt_compat_match_offset(match);
541d6a
 	u_int16_t msize = cm->u.user.match_size;
541d6a
 	char name[sizeof(m->u.user.name)];
541d6a
 
541d6a
@@ -574,9 +574,6 @@ void xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr,
541d6a
 		match->compat_from_user(m->data, cm->data);
541d6a
 	else
541d6a
 		memcpy(m->data, cm->data, msize - sizeof(*cm));
541d6a
-	pad = XT_ALIGN(match->matchsize) - match->matchsize;
541d6a
-	if (pad > 0)
541d6a
-		memset(m->data + match->matchsize, 0, pad);
541d6a
 
541d6a
 	msize += off;
541d6a
 	m->u.user.match_size = msize;
541d6a
@@ -913,7 +910,7 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr,
541d6a
 {
541d6a
 	const struct xt_target *target = t->u.kernel.target;
541d6a
 	struct compat_xt_entry_target *ct = (struct compat_xt_entry_target *)t;
541d6a
-	int pad, off = xt_compat_target_offset(target);
541d6a
+	int off = xt_compat_target_offset(target);
541d6a
 	u_int16_t tsize = ct->u.user.target_size;
541d6a
 	char name[sizeof(t->u.user.name)];
541d6a
 
541d6a
@@ -923,9 +920,6 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr,
541d6a
 		target->compat_from_user(t->data, ct->data);
541d6a
 	else
541d6a
 		memcpy(t->data, ct->data, tsize - sizeof(*ct));
541d6a
-	pad = XT_ALIGN(target->targetsize) - target->targetsize;
541d6a
-	if (pad > 0)
541d6a
-		memset(t->data + target->targetsize, 0, pad);
541d6a
 
541d6a
 	tsize += off;
541d6a
 	t->u.user.target_size = tsize;
541d6a
-- 
541d6a
2.27.0
541d6a
541d6a