From 0a078bf71d41c66168b4740bee12d8f1a7d94f80 Mon Sep 17 00:00:00 2001
From: Joe Lawrence <joe.lawrence@redhat.com>
Date: Thu, 10 Aug 2023 15:09:04 -0400
Subject: [KPATCH 7.9] kpatch fixes for CVE-2023-32233
Content-type: text/plain
Kernels:
3.10.0-1160.95.1.el7
Changes since last build:
[x86_64]:
cls_u32.o: changed function: u32_set_parms.isra.21
nf_tables_api.o: changed function: nf_tables_delsetelem
nf_tables_api.o: changed function: nf_tables_newsetelem
nf_tables_api.o: changed function: nf_tables_set_lookup
nf_tables_api.o: changed function: nf_tables_set_lookup_byid
nf_tables_api.o: changed function: nft_validate_register_store
nft_byteorder.o: changed function: nft_byteorder_eval
nft_dynset.o: changed function: nft_dynset_init
nft_lookup.o: changed function: nft_lookup_init
[ppc64le]:
cls_u32.o: changed function: u32_set_parms.isra.21
nf_tables_api.o: changed function: nf_tables_bind_check_setelem
nf_tables_api.o: changed function: nf_tables_delset
nf_tables_api.o: changed function: nf_tables_delsetelem
nf_tables_api.o: changed function: nf_tables_dump_set
nf_tables_api.o: changed function: nf_tables_getset
nf_tables_api.o: changed function: nf_tables_getsetelem
nf_tables_api.o: changed function: nf_tables_newset
nf_tables_api.o: changed function: nf_tables_newsetelem
nf_tables_api.o: changed function: nf_tables_set_lookup
nf_tables_api.o: changed function: nf_tables_set_lookup_byid
nf_tables_api.o: changed function: nft_add_set_elem
nf_tables_api.o: changed function: nft_validate_register_store
nft_byteorder.o: changed function: nft_byteorder_eval
nft_dynset.o: changed function: nft_dynset_init
nft_lookup.o: changed function: nft_lookup_init
---------------------------
Modifications:
- For ppc64le, add -fno-optimize-sibling-calls attribute for
nf_tables_api.c :: nf_tables_getsetelem()
commit cde71785485c5f12520ed90f93e3e2f78270a7b7
Author: Florian Westphal <fwestpha@redhat.com>
Date: Thu Jul 13 16:10:39 2023 +0200
netfilter: nf_tables: do not allow SET_ID to refer to another table
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2196159
Upstream Status: commit 470ee20e069a6
Conflicts:
net/netfilter/nf_tables_api.c
We lack commit 6ab3443e9e796 ("netfilter: nf_tables: pass ctx to nf_tables_expr_destroy()"),
which added the "nft_table" pointer to struct nft_set.
We can't easily pick this one up becaue it makes the kabi checker trip over
the nft_set layout change, and RH_KABI_EXTEND can't be used at the structures
end because nft_set last member is a VLA.
Fortunately we can work around it by changing
"set->table" to "trans->ctx.table", we only need this check in the transaction phase.
commit 470ee20e069a6d05ae549f7d0ef2bdbcee6a81b2
Author: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Date: Tue Aug 9 14:01:46 2022 -0300
netfilter: nf_tables: do not allow SET_ID to refer to another table
When doing lookups for sets on the same batch by using its ID, a set from a
different table can be used.
Then, when the table is removed, a reference to the set may be kept after
the set is freed, leading to a potential use-after-free.
When looking for sets by ID, use the table that was used for the lookup by
name, and only return sets belonging to that same table.
This fixes CVE-2022-2586, also reported as ZDI-CAN-17470.
Reported-by: Team Orca of Sea Security (@seasecresponse)
Fixes: 958bee14d071 ("netfilter: nf_tables: use new transaction infrastructure to handle sets")
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fwestpha@redhat.com>
commit 6a38a385344448ab2f4e68e833fcf9a7e3d62128
Author: Florian Westphal <fwestpha@redhat.com>
Date: Thu Jul 13 16:11:38 2023 +0200
netfilter: nf_tables: skip deactivated anonymous sets during lookups
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2196159
Upstream Status: RHEL7 only
CVE: CVE-2023-32233
The fix for the above CVE was incomplete in *RHEL7*.
its not enough to check if the set is scheduled for removal when
an element is supposed to be deleted, this check needs to be done
for all other element operations too, e.g. when an element is
supposed to be *added* to a set.
Move the check to the two functions that do the set lookup.
sets that are scheduled for removal/pending in the transaction
are no longer found if they have the "removed" bit set.
Fixes: ffb7eb4b21c69 ("netfilter: nf_tables: deactivate anonymous set from preparation phase")
Reported-by: Phil Sutter <psutter@redhat.com>
Signed-off-by: Florian Westphal <fwestpha@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
---
include/net/netfilter/nf_tables.h | 1 +
net/netfilter/nf_tables_api.c | 19 ++++++++++++-------
net/netfilter/nft_dynset.c | 1 +
net/netfilter/nft_lookup.c | 1 +
4 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index c0fadaa475e8..f763ef31bee7 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -396,6 +396,7 @@ static inline struct nft_set *nft_set_container_of(const void *priv)
struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
const struct nlattr *nla);
struct nft_set *nf_tables_set_lookup_byid(const struct net *net,
+ const struct nft_table *table,
const struct nlattr *nla);
static inline unsigned long nft_set_gc_interval(const struct nft_set *set)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index e5c639ae2e76..273130af8386 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -2431,22 +2431,28 @@ struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
return ERR_PTR(-EINVAL);
list_for_each_entry(set, &table->sets, list) {
- if (!nla_strcmp(nla, set->name))
+ if (!nla_strcmp(nla, set->name) && !set->removed)
return set;
}
return ERR_PTR(-ENOENT);
}
struct nft_set *nf_tables_set_lookup_byid(const struct net *net,
+ const struct nft_table *table,
const struct nlattr *nla)
{
struct nft_trans *trans;
u32 id = ntohl(nla_get_be32(nla));
list_for_each_entry(trans, &net->nft.commit_list, list) {
- if (trans->msg_type == NFT_MSG_NEWSET &&
- id == nft_trans_set_id(trans))
- return nft_trans_set(trans);
+ if (trans->msg_type == NFT_MSG_NEWSET) {
+ struct nft_set *set = nft_trans_set(trans);
+
+ if (id == nft_trans_set_id(trans) &&
+ trans->ctx.table == table &&
+ !set->removed)
+ return set;
+ }
}
return ERR_PTR(-ENOENT);
}
@@ -3295,6 +3301,7 @@ nla_put_failure:
return -ENOSPC;
}
+__attribute__((optimize("-fno-optimize-sibling-calls")))
static int nf_tables_getsetelem(struct sock *nlsk, struct sk_buff *skb,
const struct nlmsghdr *nlh,
const struct nlattr * const nla[])
@@ -3640,6 +3647,7 @@ static int nf_tables_newsetelem(struct net *net, struct sock *nlsk,
if (IS_ERR(set)) {
if (nla[NFTA_SET_ELEM_LIST_SET_ID]) {
set = nf_tables_set_lookup_byid(net,
+ ctx.table,
nla[NFTA_SET_ELEM_LIST_SET_ID]);
}
if (IS_ERR(set))
@@ -3762,9 +3770,6 @@ static int nf_tables_delsetelem(struct net *net, struct sock *nlsk,
if (!list_empty(&set->bindings) && set->flags & NFT_SET_CONSTANT)
return -EBUSY;
- if (set->removed)
- return -ENOENT;
-
if (nla[NFTA_SET_ELEM_LIST_ELEMENTS] == NULL) {
struct nft_set_dump_args args = {
.iter = {
diff --git a/net/netfilter/nft_dynset.c b/net/netfilter/nft_dynset.c
index 9c11a024d96d..c50dd3221fa5 100644
--- a/net/netfilter/nft_dynset.c
+++ b/net/netfilter/nft_dynset.c
@@ -119,6 +119,7 @@ static int nft_dynset_init(const struct nft_ctx *ctx,
if (IS_ERR(set)) {
if (tb[NFTA_DYNSET_SET_ID])
set = nf_tables_set_lookup_byid(ctx->net,
+ ctx->table,
tb[NFTA_DYNSET_SET_ID]);
if (IS_ERR(set))
return PTR_ERR(set);
diff --git a/net/netfilter/nft_lookup.c b/net/netfilter/nft_lookup.c
index f57f7b8f2400..7a3c09fd50ef 100644
--- a/net/netfilter/nft_lookup.c
+++ b/net/netfilter/nft_lookup.c
@@ -74,6 +74,7 @@ static int nft_lookup_init(const struct nft_ctx *ctx,
if (IS_ERR(set)) {
if (tb[NFTA_LOOKUP_SET_ID]) {
set = nf_tables_set_lookup_byid(ctx->net,
+ ctx->table,
tb[NFTA_LOOKUP_SET_ID]);
}
if (IS_ERR(set))
--
2.41.0