Blame SOURCES/CVE-2021-22555.patch

f48d8f
From b8c2b76bf8026457489948693638df321c680e7b Mon Sep 17 00:00:00 2001
f48d8f
From: Joel Savitz <jsavitz@redhat.com>
f48d8f
Date: Fri, 23 Jul 2021 11:26:01 -0400
f48d8f
Subject: [PATCH] netfilter: x_tables: kpatch fixes for CVE-2021-22555
f48d8f
f48d8f
Kernels:
f48d8f
4.18.0-305.el8
f48d8f
4.18.0-305.3.1.el8_4
f48d8f
4.18.0-305.7.1.el8_4
f48d8f
4.18.0-305.10.2.el8_4
f48d8f
f48d8f
Changes since last build:
f48d8f
arches: x86_64 ppc64le
f48d8f
arp_tables.o: changed function: translate_compat_table
f48d8f
ip6_tables.o: changed function: translate_compat_table
f48d8f
ip_tables.o: changed function: translate_compat_table
f48d8f
x_tables.o: changed function: xt_compat_match_from_user
f48d8f
x_tables.o: changed function: xt_compat_target_from_user
f48d8f
---------------------------
f48d8f
f48d8f
Kernels:
f48d8f
4.18.0-305.el8
f48d8f
4.18.0-305.3.1.el8_4
f48d8f
4.18.0-305.7.1.el8_4
f48d8f
4.18.0-305.10.2.el8_4
f48d8f
f48d8f
Modifications: none
f48d8f
f48d8f
Z-MR: https://gitlab.com/redhat/rhel/src/kernel/rhel-8/-/merge_requests/951
f48d8f
f48d8f
KT0: https://beaker.engineering.redhat.com/jobs/5611476 (PASS for x86_64 and queued for ppc64le)
f48d8f
for scratch Build: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=38312105
f48d8f
f48d8f
commit a6f41b0d134d0ca62a46da0204f02018d69f19dd
f48d8f
Author: Florian Westphal <fwestpha@redhat.com>
f48d8f
Date:   Thu Apr 15 17:12:32 2021 +0200
f48d8f
f48d8f
    netfilter: x_tables: fix compat match/target pad out-of-bound write
f48d8f
f48d8f
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1980500
f48d8f
    Y-Commit: 67b5dd48280ef85610333da24be367188d0542cb
f48d8f
    O-Bugzilla: 1980501
f48d8f
    CVE: CVE-2021-22555
f48d8f
f48d8f
    Upstream Status: commit b29c457a65114
f48d8f
f48d8f
    commit b29c457a6511435960115c0f548c4360d5f4801d
f48d8f
    Author: Florian Westphal <fw@strlen.de>
f48d8f
    Date:   Wed Apr 7 21:38:57 2021 +0200
f48d8f
f48d8f
        netfilter: x_tables: fix compat match/target pad out-of-bound write
f48d8f
f48d8f
        xt_compat_match/target_from_user doesn't check that zeroing the area
f48d8f
        to start of next rule won't write past end of allocated ruleset blob.
f48d8f
f48d8f
        Remove this code and zero the entire blob beforehand.
f48d8f
f48d8f
        Reported-by: syzbot+cfc0247ac173f597aaaa@syzkaller.appspotmail.com
f48d8f
        Reported-by: Andy Nguyen <theflow@google.com>
f48d8f
        Fixes: 9fa492cdc160c ("[NETFILTER]: x_tables: simplify compat API")
f48d8f
        Signed-off-by: Florian Westphal <fw@strlen.de>
f48d8f
        Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
f48d8f
f48d8f
    Signed-off-by: Florian Westphal <fwestpha@redhat.com>
f48d8f
    Signed-off-by: Jan Stancek <jstancek@redhat.com>
f48d8f
f48d8f
Signed-off-by: Joel Savitz <jsavitz@redhat.com>
f48d8f
Acked-by: Artem Savkov <asavkov@redhat.com>
f48d8f
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
f48d8f
---
f48d8f
 net/ipv4/netfilter/arp_tables.c |  2 ++
f48d8f
 net/ipv4/netfilter/ip_tables.c  |  2 ++
f48d8f
 net/ipv6/netfilter/ip6_tables.c |  2 ++
f48d8f
 net/netfilter/x_tables.c        | 10 ++--------
f48d8f
 4 files changed, 8 insertions(+), 8 deletions(-)
f48d8f
f48d8f
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
f48d8f
index ca20efe775ee4..d2ebbeaa9870b 100644
f48d8f
--- a/net/ipv4/netfilter/arp_tables.c
f48d8f
+++ b/net/ipv4/netfilter/arp_tables.c
f48d8f
@@ -1195,6 +1195,8 @@ static int translate_compat_table(struct net *net,
f48d8f
 	if (!newinfo)
f48d8f
 		goto out_unlock;
f48d8f
 
f48d8f
+	memset(newinfo->entries, 0, size);
f48d8f
+
f48d8f
 	newinfo->number = compatr->num_entries;
f48d8f
 	for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
f48d8f
 		newinfo->hook_entry[i] = compatr->hook_entry[i];
f48d8f
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
f48d8f
index 4cdfb76b9aa8c..8d1545c3bf7b1 100644
f48d8f
--- a/net/ipv4/netfilter/ip_tables.c
f48d8f
+++ b/net/ipv4/netfilter/ip_tables.c
f48d8f
@@ -1433,6 +1433,8 @@ translate_compat_table(struct net *net,
f48d8f
 	if (!newinfo)
f48d8f
 		goto out_unlock;
f48d8f
 
f48d8f
+	memset(newinfo->entries, 0, size);
f48d8f
+
f48d8f
 	newinfo->number = compatr->num_entries;
f48d8f
 	for (i = 0; i < NF_INET_NUMHOOKS; i++) {
f48d8f
 		newinfo->hook_entry[i] = compatr->hook_entry[i];
f48d8f
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
f48d8f
index f7f25eb536d5b..b9d05ea5b9f0f 100644
f48d8f
--- a/net/ipv6/netfilter/ip6_tables.c
f48d8f
+++ b/net/ipv6/netfilter/ip6_tables.c
f48d8f
@@ -1448,6 +1448,8 @@ translate_compat_table(struct net *net,
f48d8f
 	if (!newinfo)
f48d8f
 		goto out_unlock;
f48d8f
 
f48d8f
+	memset(newinfo->entries, 0, size);
f48d8f
+
f48d8f
 	newinfo->number = compatr->num_entries;
f48d8f
 	for (i = 0; i < NF_INET_NUMHOOKS; i++) {
f48d8f
 		newinfo->hook_entry[i] = compatr->hook_entry[i];
f48d8f
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
f48d8f
index eb66934f36ec2..e258429213cab 100644
f48d8f
--- a/net/netfilter/x_tables.c
f48d8f
+++ b/net/netfilter/x_tables.c
f48d8f
@@ -736,7 +736,7 @@ void xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr,
f48d8f
 {
f48d8f
 	const struct xt_match *match = m->u.kernel.match;
f48d8f
 	struct compat_xt_entry_match *cm = (struct compat_xt_entry_match *)m;
f48d8f
-	int pad, off = xt_compat_match_offset(match);
f48d8f
+	int off = xt_compat_match_offset(match);
f48d8f
 	u_int16_t msize = cm->u.user.match_size;
f48d8f
 	char name[sizeof(m->u.user.name)];
f48d8f
 
f48d8f
@@ -746,9 +746,6 @@ void xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr,
f48d8f
 		match->compat_from_user(m->data, cm->data);
f48d8f
 	else
f48d8f
 		memcpy(m->data, cm->data, msize - sizeof(*cm));
f48d8f
-	pad = XT_ALIGN(match->matchsize) - match->matchsize;
f48d8f
-	if (pad > 0)
f48d8f
-		memset(m->data + match->matchsize, 0, pad);
f48d8f
 
f48d8f
 	msize += off;
f48d8f
 	m->u.user.match_size = msize;
f48d8f
@@ -1119,7 +1116,7 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr,
f48d8f
 {
f48d8f
 	const struct xt_target *target = t->u.kernel.target;
f48d8f
 	struct compat_xt_entry_target *ct = (struct compat_xt_entry_target *)t;
f48d8f
-	int pad, off = xt_compat_target_offset(target);
f48d8f
+	int off = xt_compat_target_offset(target);
f48d8f
 	u_int16_t tsize = ct->u.user.target_size;
f48d8f
 	char name[sizeof(t->u.user.name)];
f48d8f
 
f48d8f
@@ -1129,9 +1126,6 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr,
f48d8f
 		target->compat_from_user(t->data, ct->data);
f48d8f
 	else
f48d8f
 		memcpy(t->data, ct->data, tsize - sizeof(*ct));
f48d8f
-	pad = XT_ALIGN(target->targetsize) - target->targetsize;
f48d8f
-	if (pad > 0)
f48d8f
-		memset(t->data + target->targetsize, 0, pad);
f48d8f
 
f48d8f
 	tsize += off;
f48d8f
 	t->u.user.target_size = tsize;
f48d8f
-- 
f48d8f
2.26.3
f48d8f