Skip to content

Commit eeff826

Browse files
committed
netfilter: nftables: update table flags from the commit phase
jira VUlN-597 subsystem-sync netfilter:nf_tables 4.18.0-511 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 1f63a37 commit eeff826

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;
@@ -8227,11 +8231,10 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
82278231
switch (trans->msg_type) {
82288232
case NFT_MSG_NEWTABLE:
82298233
if (nft_trans_table_update(trans)) {
8230-
if (!nft_trans_table_enable(trans)) {
8231-
nf_tables_table_disable(net,
8232-
trans->ctx.table);
8233-
trans->ctx.table->flags |= NFT_TABLE_F_DORMANT;
8234-
}
8234+
if (nft_trans_table_state(trans) == NFT_TABLE_STATE_DORMANT)
8235+
nf_tables_table_disable(net, trans->ctx.table);
8236+
8237+
trans->ctx.table->flags = nft_trans_table_flags(trans);
82358238
} else {
82368239
nft_clear(net, trans->ctx.table);
82378240
}
@@ -8453,11 +8456,9 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action)
84538456
switch (trans->msg_type) {
84548457
case NFT_MSG_NEWTABLE:
84558458
if (nft_trans_table_update(trans)) {
8456-
if (nft_trans_table_enable(trans)) {
8457-
nf_tables_table_disable(net,
8458-
trans->ctx.table);
8459-
trans->ctx.table->flags |= NFT_TABLE_F_DORMANT;
8460-
}
8459+
if (nft_trans_table_state(trans) == NFT_TABLE_STATE_WAKEUP)
8460+
nf_tables_table_disable(net, trans->ctx.table);
8461+
84618462
nft_trans_destroy(trans);
84628463
} else {
84638464
list_del_rcu(&trans->ctx.table->list);

0 commit comments

Comments
 (0)