Blame SOURCES/CVE-2021-22555.patch

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