Blame SOURCES/CVE-2022-32250.patch

ca659d
From 2f9874af7248b917772c8673054118267b3be415 Mon Sep 17 00:00:00 2001
ca659d
From: Julia Denham <jdenham@redhat.com>
ca659d
Date: Mon, 11 Jul 2022 08:10:32 -0400
ca659d
Subject: [KPATCH CVE-2022-32250] kpatch fixes for CVE-2022-1966
ca659d
Content-type: text/plain
ca659d
ca659d
Kernels:
ca659d
4.18.0-372.9.1.el8
ca659d
ca659d
Changes since last build:
ca659d
arches: x86_64 ppc64le
ca659d
nf_tables_api.o: changed function: nft_expr_init
ca659d
nf_tables_api.o: changed function: nft_set_elem_expr_alloc
ca659d
---------------------------
ca659d
ca659d
Kpatch-MR: https://gitlab.com/redhat/prdsc/rhel/src/kpatch/rhel-8/-/merge_requests/53
ca659d
Approved-by: Joe Lawrence (@joe.lawrence)
ca659d
Approved-by: Yannick Cote (@ycote1)
ca659d
Modifications: none
ca659d
ca659d
commit afeaad78f78f7593e89f540a87b8796e8d705d57
ca659d
Author: Phil Sutter <psutter@redhat.com>
ca659d
Date:   Thu Jun 2 20:58:22 2022 +0200
ca659d
ca659d
    netfilter: nf_tables: disallow non-stateful expression in sets earlier
ca659d
ca659d
    Bugzilla: https://bugzilla.redhat.com/2092986
ca659d
    CVE: CVE-2022-32250
ca659d
    Y-Commit: cfb0d599ec74a88a5f02455616f96946defb849e
ca659d
ca659d
    O-Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2092987
ca659d
    Upstream Status: net.git commit 520778042ccca
ca659d
    O-CVE: CVE-2022-32250
ca659d
    Conflicts: Upstream renamed info -> expr_info.
ca659d
ca659d
    commit 520778042ccca019f3ffa136dd0ca565c486cedd
ca659d
    Author: Pablo Neira Ayuso <pablo@netfilter.org>
ca659d
    Date:   Wed May 25 10:36:38 2022 +0200
ca659d
ca659d
        netfilter: nf_tables: disallow non-stateful expression in sets earlier
ca659d
ca659d
        Since 3e135cd499bf ("netfilter: nft_dynset: dynamic stateful expression
ca659d
        instantiation"), it is possible to attach stateful expressions to set
ca659d
        elements.
ca659d
ca659d
        cd5125d8f518 ("netfilter: nf_tables: split set destruction in deactivate
ca659d
        and destroy phase") introduces conditional destruction on the object to
ca659d
        accomodate transaction semantics.
ca659d
ca659d
        nft_expr_init() calls expr->ops->init() first, then check for
ca659d
        NFT_STATEFUL_EXPR, this stills allows to initialize a non-stateful
ca659d
        lookup expressions which points to a set, which might lead to UAF since
ca659d
        the set is not properly detached from the set->binding for this case.
ca659d
        Anyway, this combination is non-sense from nf_tables perspective.
ca659d
ca659d
        This patch fixes this problem by checking for NFT_STATEFUL_EXPR before
ca659d
        expr->ops->init() is called.
ca659d
ca659d
        The reporter provides a KASAN splat and a poc reproducer (similar to
ca659d
        those autogenerated by syzbot to report use-after-free errors). It is
ca659d
        unknown to me if they are using syzbot or if they use similar automated
ca659d
        tool to locate the bug that they are reporting.
ca659d
ca659d
        For the record, this is the KASAN splat.
ca659d
ca659d
        [   85.431824] ==================================================================
ca659d
        [   85.432901] BUG: KASAN: use-after-free in nf_tables_bind_set+0x81b/0xa20
ca659d
        [   85.433825] Write of size 8 at addr ffff8880286f0e98 by task poc/776
ca659d
        [   85.434756]
ca659d
        [   85.434999] CPU: 1 PID: 776 Comm: poc Tainted: G        W         5.18.0+ #2
ca659d
        [   85.436023] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014
ca659d
ca659d
        Fixes: 0b2d8a7b638b ("netfilter: nf_tables: add helper functions for expression handling")
ca659d
        Reported-and-tested-by: Aaron Adams <edg-e@nccgroup.com>
ca659d
        Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
ca659d
ca659d
    Signed-off-by: Phil Sutter <psutter@redhat.com>
ca659d
    Signed-off-by: Augusto Caringi <acaringi@redhat.com>
ca659d
ca659d
Signed-off-by: Julia Denham <jdenham@redhat.com>
ca659d
---
ca659d
 net/netfilter/nf_tables_api.c | 19 ++++++++++---------
ca659d
 1 file changed, 10 insertions(+), 9 deletions(-)
ca659d
ca659d
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
ca659d
index aa095db8d0ca..097680c5f914 100644
ca659d
--- a/net/netfilter/nf_tables_api.c
ca659d
+++ b/net/netfilter/nf_tables_api.c
ca659d
@@ -2576,27 +2576,31 @@ static struct nft_expr *nft_expr_init(const struct nft_ctx *ctx,
ca659d
 
ca659d
 	err = nf_tables_expr_parse(ctx, nla, &info;;
ca659d
 	if (err < 0)
ca659d
-		goto err1;
ca659d
+		goto err_expr_parse;
ca659d
+
ca659d
+	err = -EOPNOTSUPP;
ca659d
+	if (!(info.ops->type->flags & NFT_EXPR_STATEFUL))
ca659d
+		goto err_expr_stateful;
ca659d
 
ca659d
 	err = -ENOMEM;
ca659d
 	expr = kzalloc(info.ops->size, GFP_KERNEL);
ca659d
 	if (expr == NULL)
ca659d
-		goto err2;
ca659d
+		goto err_expr_stateful;
ca659d
 
ca659d
 	err = nf_tables_newexpr(ctx, &info, expr);
ca659d
 	if (err < 0)
ca659d
-		goto err3;
ca659d
+		goto err_expr_new;
ca659d
 
ca659d
 	return expr;
ca659d
-err3:
ca659d
+err_expr_new:
ca659d
 	kfree(expr);
ca659d
-err2:
ca659d
+err_expr_stateful:
ca659d
 	owner = info.ops->type->owner;
ca659d
 	if (info.ops->type->release_ops)
ca659d
 		info.ops->type->release_ops(info.ops);
ca659d
 
ca659d
 	module_put(owner);
ca659d
-err1:
ca659d
+err_expr_parse:
ca659d
 	return ERR_PTR(err);
ca659d
 }
ca659d
 
ca659d
@@ -4983,9 +4987,6 @@ struct nft_expr *nft_set_elem_expr_alloc(const struct nft_ctx *ctx,
ca659d
 		return expr;
ca659d
 
ca659d
 	err = -EOPNOTSUPP;
ca659d
-	if (!(expr->ops->type->flags & NFT_EXPR_STATEFUL))
ca659d
-		goto err_set_elem_expr;
ca659d
-
ca659d
 	if (expr->ops->type->flags & NFT_EXPR_GC) {
ca659d
 		if (set->flags & NFT_SET_TIMEOUT)
ca659d
 			goto err_set_elem_expr;
ca659d
-- 
ca659d
2.26.3
ca659d
ca659d