Blame SOURCES/CVE-2022-1966.patch

94e9ce
From bdeb7f1c4651240043b0b8a2a5432fc9760cfadf Mon Sep 17 00:00:00 2001
94e9ce
From: Joe Lawrence <joe.lawrence@redhat.com>
94e9ce
Date: Wed, 15 Jun 2022 16:10:31 -0400
94e9ce
Subject: [KPATCH CVE-2022-1966] kpatch fixes for CVE-2022-1966
94e9ce
94e9ce
Kernels:
94e9ce
3.10.0-1160.36.2.el7
94e9ce
3.10.0-1160.41.1.el7
94e9ce
3.10.0-1160.42.2.el7
94e9ce
3.10.0-1160.45.1.el7
94e9ce
3.10.0-1160.49.1.el7
94e9ce
3.10.0-1160.53.1.el7
94e9ce
3.10.0-1160.59.1.el7
94e9ce
3.10.0-1160.62.1.el7
94e9ce
3.10.0-1160.66.1.el7
94e9ce
94e9ce
Changes since last build:
94e9ce
arches: x86_64 ppc64le
94e9ce
nf_tables_api.o: changed function: nft_expr_init
94e9ce
nft_dynset.o: changed function: nft_dynset_init
94e9ce
---------------------------
94e9ce
94e9ce
Kpatch-MR: https://gitlab.com/redhat/prdsc/rhel/src/kpatch/rhel-7/-/merge_requests/42
94e9ce
Approved-by: Yannick Cote (@ycote1)
94e9ce
Modifications: none
94e9ce
94e9ce
commit c511e60bebd0546f8ec47a3c1691ab01d262b8e4
94e9ce
Author: Phil Sutter <psutter@redhat.com>
94e9ce
Date:   Fri Jun 3 16:54:42 2022 +0200
94e9ce
94e9ce
    netfilter: nf_tables: fix memory leak if expr init fails
94e9ce
94e9ce
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2093000
94e9ce
    Upstream Status: commit 6cafaf4764a32
94e9ce
94e9ce
    commit 6cafaf4764a32597c2195aa5411b87728e1fde8a
94e9ce
    Author: Liping Zhang <liping.zhang@spreadtrum.com>
94e9ce
    Date:   Mon Jun 20 21:11:45 2016 +0800
94e9ce
94e9ce
        netfilter: nf_tables: fix memory leak if expr init fails
94e9ce
94e9ce
        If expr init fails then we need to free it.
94e9ce
94e9ce
        So when the user add a nft rule as follows:
94e9ce
94e9ce
          # nft add rule filter input tcp dport 22 flow table ssh \
94e9ce
            { ip saddr limit rate 0/second }
94e9ce
94e9ce
        memory leak will happen.
94e9ce
94e9ce
        Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
94e9ce
        Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
94e9ce
94e9ce
    Signed-off-by: Phil Sutter <psutter@redhat.com>
94e9ce
94e9ce
commit 4a4cc18bcf8f43c93dbf39cb52308dfaea4ec346
94e9ce
Author: Phil Sutter <psutter@redhat.com>
94e9ce
Date:   Fri Jun 3 16:54:43 2022 +0200
94e9ce
94e9ce
    netfilter: nf_tables: disallow non-stateful expression in sets earlier
94e9ce
94e9ce
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2093000
94e9ce
    Upstream Status: net.git commit 520778042ccca
94e9ce
    CVE: CVE-2022-1966
94e9ce
    Conflicts:
94e9ce
     * RHEL7 does not have nft_set_elem_expr_alloc(), remove
94e9ce
       NFT_EXPR_STATEFUL check from nft_dynset_init() instead
94e9ce
     * Context change in nft_expr_init() as RHEL7 does not have .release_ops
94e9ce
     * Adjusted new NFT_EXPR_STATEFUL check as upstream renamed 'info' into
94e9ce
       'expr_info'
94e9ce
94e9ce
    commit 520778042ccca019f3ffa136dd0ca565c486cedd
94e9ce
    Author: Pablo Neira Ayuso <pablo@netfilter.org>
94e9ce
    Date:   Wed May 25 10:36:38 2022 +0200
94e9ce
94e9ce
        netfilter: nf_tables: disallow non-stateful expression in sets earlier
94e9ce
94e9ce
        Since 3e135cd499bf ("netfilter: nft_dynset: dynamic stateful expression
94e9ce
        instantiation"), it is possible to attach stateful expressions to set
94e9ce
        elements.
94e9ce
94e9ce
        cd5125d8f518 ("netfilter: nf_tables: split set destruction in deactivate
94e9ce
        and destroy phase") introduces conditional destruction on the object to
94e9ce
        accomodate transaction semantics.
94e9ce
94e9ce
        nft_expr_init() calls expr->ops->init() first, then check for
94e9ce
        NFT_STATEFUL_EXPR, this stills allows to initialize a non-stateful
94e9ce
        lookup expressions which points to a set, which might lead to UAF since
94e9ce
        the set is not properly detached from the set->binding for this case.
94e9ce
        Anyway, this combination is non-sense from nf_tables perspective.
94e9ce
94e9ce
        This patch fixes this problem by checking for NFT_STATEFUL_EXPR before
94e9ce
        expr->ops->init() is called.
94e9ce
94e9ce
        The reporter provides a KASAN splat and a poc reproducer (similar to
94e9ce
        those autogenerated by syzbot to report use-after-free errors). It is
94e9ce
        unknown to me if they are using syzbot or if they use similar automated
94e9ce
        tool to locate the bug that they are reporting.
94e9ce
94e9ce
        For the record, this is the KASAN splat.
94e9ce
94e9ce
        [   85.431824] ==================================================================
94e9ce
        [   85.432901] BUG: KASAN: use-after-free in nf_tables_bind_set+0x81b/0xa20
94e9ce
        [   85.433825] Write of size 8 at addr ffff8880286f0e98 by task poc/776
94e9ce
        [   85.434756]
94e9ce
        [   85.434999] CPU: 1 PID: 776 Comm: poc Tainted: G        W         5.18.0+ #2
94e9ce
        [   85.436023] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014
94e9ce
94e9ce
        Fixes: 0b2d8a7b638b ("netfilter: nf_tables: add helper functions for expression handling")
94e9ce
        Reported-and-tested-by: Aaron Adams <edg-e@nccgroup.com>
94e9ce
        Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
94e9ce
94e9ce
    Signed-off-by: Phil Sutter <psutter@redhat.com>
94e9ce
94e9ce
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
94e9ce
---
94e9ce
 net/netfilter/nf_tables_api.c | 16 +++++++++++-----
94e9ce
 net/netfilter/nft_dynset.c    |  4 ----
94e9ce
 2 files changed, 11 insertions(+), 9 deletions(-)
94e9ce
94e9ce
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
94e9ce
index 0f46d90715a3..44738b987690 100644
94e9ce
--- a/net/netfilter/nf_tables_api.c
94e9ce
+++ b/net/netfilter/nf_tables_api.c
94e9ce
@@ -1739,21 +1739,27 @@ struct nft_expr *nft_expr_init(const struct nft_ctx *ctx,
94e9ce
 
94e9ce
 	err = nf_tables_expr_parse(ctx, nla, &info;;
94e9ce
 	if (err < 0)
94e9ce
-		goto err1;
94e9ce
+		goto err_expr_parse;
94e9ce
+
94e9ce
+	err = -EOPNOTSUPP;
94e9ce
+	if (!(info.ops->type->flags & NFT_EXPR_STATEFUL))
94e9ce
+		goto err_expr_stateful;
94e9ce
 
94e9ce
 	err = -ENOMEM;
94e9ce
 	expr = kzalloc(info.ops->size, GFP_KERNEL);
94e9ce
 	if (expr == NULL)
94e9ce
-		goto err2;
94e9ce
+		goto err_expr_stateful;
94e9ce
 
94e9ce
 	err = nf_tables_newexpr(ctx, &info, expr);
94e9ce
 	if (err < 0)
94e9ce
-		goto err2;
94e9ce
+		goto err_expr_new;
94e9ce
 
94e9ce
 	return expr;
94e9ce
-err2:
94e9ce
+err_expr_new:
94e9ce
+	kfree(expr);
94e9ce
+err_expr_stateful:
94e9ce
 	module_put(info.ops->type->owner);
94e9ce
-err1:
94e9ce
+err_expr_parse:
94e9ce
 	return ERR_PTR(err);
94e9ce
 }
94e9ce
 
94e9ce
diff --git a/net/netfilter/nft_dynset.c b/net/netfilter/nft_dynset.c
94e9ce
index 3f9f8e82716e..0cf187230050 100644
94e9ce
--- a/net/netfilter/nft_dynset.c
94e9ce
+++ b/net/netfilter/nft_dynset.c
94e9ce
@@ -174,10 +174,6 @@ static int nft_dynset_init(const struct nft_ctx *ctx,
94e9ce
 		priv->expr = nft_expr_init(ctx, tb[NFTA_DYNSET_EXPR]);
94e9ce
 		if (IS_ERR(priv->expr))
94e9ce
 			return PTR_ERR(priv->expr);
94e9ce
-
94e9ce
-		err = -EOPNOTSUPP;
94e9ce
-		if (!(priv->expr->ops->type->flags & NFT_EXPR_STATEFUL))
94e9ce
-			goto err1;
94e9ce
 	} else if (set->flags & NFT_SET_EVAL)
94e9ce
 		return -EINVAL;
94e9ce
 
94e9ce
-- 
94e9ce
2.34.3
94e9ce
94e9ce