Blame SOURCES/CVE-2021-22555.patch

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