Skip to content

Commit 2a59cf6

Browse files
committed
netfilter: nftables: update table flags from the commit phase
jira VULN-597 subsystem-sync netfilter:nf_tables 4.18.0-534 commit-author Pablo Neira Ayuso <pablo@netfilter.org> commit 0ce7cf4 Do not update table flags from the preparation phase. Store the flags update into the transaction, then update the flags from the commit phase. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> (cherry picked from commit 0ce7cf4) Signed-off-by: Greg Rose <g.v.rose@ciq.com>
1 parent 35d45e9 commit 2a59cf6

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

include/net/netfilter/nf_tables.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,13 +1449,16 @@ struct nft_trans_chain {
14491449

14501450
struct nft_trans_table {
14511451
bool update;
1452-
bool enable;
1452+
u8 state;
1453+
u32 flags;
14531454
};
14541455

14551456
#define nft_trans_table_update(trans) \
14561457
(((struct nft_trans_table *)trans->data)->update)
1457-
#define nft_trans_table_enable(trans) \
1458-
(((struct nft_trans_table *)trans->data)->enable)
1458+
#define nft_trans_table_state(trans) \
1459+
(((struct nft_trans_table *)trans->data)->state)
1460+
#define nft_trans_table_flags(trans) \
1461+
(((struct nft_trans_table *)trans->data)->flags)
14591462

14601463
struct nft_trans_elem {
14611464
struct nft_set *set;

net/netfilter/nf_tables_api.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,12 @@ static void nf_tables_table_disable(struct net *net, struct nft_table *table)
945945
nft_table_disable(net, table, 0);
946946
}
947947

948+
enum {
949+
NFT_TABLE_STATE_UNCHANGED = 0,
950+
NFT_TABLE_STATE_DORMANT,
951+
NFT_TABLE_STATE_WAKEUP
952+
};
953+
948954
static int nf_tables_updtable(struct nft_ctx *ctx)
949955
{
950956
struct nft_trans *trans;
@@ -968,19 +974,17 @@ static int nf_tables_updtable(struct nft_ctx *ctx)
968974

969975
if ((flags & NFT_TABLE_F_DORMANT) &&
970976
!(ctx->table->flags & NFT_TABLE_F_DORMANT)) {
971-
nft_trans_table_enable(trans) = false;
977+
nft_trans_table_state(trans) = NFT_TABLE_STATE_DORMANT;
972978
} else if (!(flags & NFT_TABLE_F_DORMANT) &&
973979
ctx->table->flags & NFT_TABLE_F_DORMANT) {
974-
ctx->table->flags &= ~NFT_TABLE_F_DORMANT;
975980
ret = nf_tables_table_enable(ctx->net, ctx->table);
976981
if (ret >= 0)
977-
nft_trans_table_enable(trans) = true;
978-
else
979-
ctx->table->flags |= NFT_TABLE_F_DORMANT;
982+
nft_trans_table_state(trans) = NFT_TABLE_STATE_WAKEUP;
980983
}
981984
if (ret < 0)
982985
goto err;
983986

987+
nft_trans_table_flags(trans) = flags;
984988
nft_trans_table_update(trans) = true;
985989
list_add_tail(&trans->list, &ctx->net->nft.commit_list);
986990
return 0;
@@ -8226,11 +8230,10 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
82268230
switch (trans->msg_type) {
82278231
case NFT_MSG_NEWTABLE:
82288232
if (nft_trans_table_update(trans)) {
8229-
if (!nft_trans_table_enable(trans)) {
8230-
nf_tables_table_disable(net,
8231-
trans->ctx.table);
8232-
trans->ctx.table->flags |= NFT_TABLE_F_DORMANT;
8233-
}
8233+
if (nft_trans_table_state(trans) == NFT_TABLE_STATE_DORMANT)
8234+
nf_tables_table_disable(net, trans->ctx.table);
8235+
8236+
trans->ctx.table->flags = nft_trans_table_flags(trans);
82348237
} else {
82358238
nft_clear(net, trans->ctx.table);
82368239
}
@@ -8452,11 +8455,9 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action)
84528455
switch (trans->msg_type) {
84538456
case NFT_MSG_NEWTABLE:
84548457
if (nft_trans_table_update(trans)) {
8455-
if (nft_trans_table_enable(trans)) {
8456-
nf_tables_table_disable(net,
8457-
trans->ctx.table);
8458-
trans->ctx.table->flags |= NFT_TABLE_F_DORMANT;
8459-
}
8458+
if (nft_trans_table_state(trans) == NFT_TABLE_STATE_WAKEUP)
8459+
nf_tables_table_disable(net, trans->ctx.table);
8460+
84608461
nft_trans_destroy(trans);
84618462
} else {
84628463
list_del_rcu(&trans->ctx.table->list);

0 commit comments

Comments
 (0)