Skip to content

Commit 3bc63fb

Browse files
Phil Suttergregkh
authored andcommitted
netfilter: nf_tables: Reintroduce shortened deletion notifications
[ Upstream commit a1050dd ] Restore commit 28339b2 ("netfilter: nf_tables: do not send complete notification of deletions") and fix it: - Avoid upfront modification of 'event' variable so the conditionals become effective. - Always include NFTA_OBJ_TYPE attribute in object notifications, user space requires it for proper deserialisation. - Catch DESTROY events, too. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Stable-dep-of: b2f742c ("netfilter: nf_tables: restart set lookup on base_seq change") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 39f40f1 commit 3bc63fb

1 file changed

Lines changed: 50 additions & 17 deletions

File tree

net/netfilter/nf_tables_api.c

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,9 +1153,9 @@ static int nf_tables_fill_table_info(struct sk_buff *skb, struct net *net,
11531153
{
11541154
struct nlmsghdr *nlh;
11551155

1156-
event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
1157-
nlh = nfnl_msg_put(skb, portid, seq, event, flags, family,
1158-
NFNETLINK_V0, nft_base_seq(net));
1156+
nlh = nfnl_msg_put(skb, portid, seq,
1157+
nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event),
1158+
flags, family, NFNETLINK_V0, nft_base_seq(net));
11591159
if (!nlh)
11601160
goto nla_put_failure;
11611161

@@ -1165,6 +1165,12 @@ static int nf_tables_fill_table_info(struct sk_buff *skb, struct net *net,
11651165
NFTA_TABLE_PAD))
11661166
goto nla_put_failure;
11671167

1168+
if (event == NFT_MSG_DELTABLE ||
1169+
event == NFT_MSG_DESTROYTABLE) {
1170+
nlmsg_end(skb, nlh);
1171+
return 0;
1172+
}
1173+
11681174
if (nla_put_be32(skb, NFTA_TABLE_FLAGS,
11691175
htonl(table->flags & NFT_TABLE_F_MASK)))
11701176
goto nla_put_failure;
@@ -2022,9 +2028,9 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net,
20222028
{
20232029
struct nlmsghdr *nlh;
20242030

2025-
event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
2026-
nlh = nfnl_msg_put(skb, portid, seq, event, flags, family,
2027-
NFNETLINK_V0, nft_base_seq(net));
2031+
nlh = nfnl_msg_put(skb, portid, seq,
2032+
nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event),
2033+
flags, family, NFNETLINK_V0, nft_base_seq(net));
20282034
if (!nlh)
20292035
goto nla_put_failure;
20302036

@@ -2034,6 +2040,13 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net,
20342040
NFTA_CHAIN_PAD))
20352041
goto nla_put_failure;
20362042

2043+
if (!hook_list &&
2044+
(event == NFT_MSG_DELCHAIN ||
2045+
event == NFT_MSG_DESTROYCHAIN)) {
2046+
nlmsg_end(skb, nlh);
2047+
return 0;
2048+
}
2049+
20372050
if (nft_is_base_chain(chain)) {
20382051
const struct nft_base_chain *basechain = nft_base_chain(chain);
20392052
struct nft_stats __percpu *stats;
@@ -4871,9 +4884,10 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
48714884
u32 seq = ctx->seq;
48724885
int i;
48734886

4874-
event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
4875-
nlh = nfnl_msg_put(skb, portid, seq, event, flags, ctx->family,
4876-
NFNETLINK_V0, nft_base_seq(ctx->net));
4887+
nlh = nfnl_msg_put(skb, portid, seq,
4888+
nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event),
4889+
flags, ctx->family, NFNETLINK_V0,
4890+
nft_base_seq(ctx->net));
48774891
if (!nlh)
48784892
goto nla_put_failure;
48794893

@@ -4885,6 +4899,12 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
48854899
NFTA_SET_PAD))
48864900
goto nla_put_failure;
48874901

4902+
if (event == NFT_MSG_DELSET ||
4903+
event == NFT_MSG_DESTROYSET) {
4904+
nlmsg_end(skb, nlh);
4905+
return 0;
4906+
}
4907+
48884908
if (set->flags != 0)
48894909
if (nla_put_be32(skb, NFTA_SET_FLAGS, htonl(set->flags)))
48904910
goto nla_put_failure;
@@ -8359,20 +8379,26 @@ static int nf_tables_fill_obj_info(struct sk_buff *skb, struct net *net,
83598379
{
83608380
struct nlmsghdr *nlh;
83618381

8362-
event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
8363-
nlh = nfnl_msg_put(skb, portid, seq, event, flags, family,
8364-
NFNETLINK_V0, nft_base_seq(net));
8382+
nlh = nfnl_msg_put(skb, portid, seq,
8383+
nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event),
8384+
flags, family, NFNETLINK_V0, nft_base_seq(net));
83658385
if (!nlh)
83668386
goto nla_put_failure;
83678387

83688388
if (nla_put_string(skb, NFTA_OBJ_TABLE, table->name) ||
83698389
nla_put_string(skb, NFTA_OBJ_NAME, obj->key.name) ||
8390+
nla_put_be32(skb, NFTA_OBJ_TYPE, htonl(obj->ops->type->type)) ||
83708391
nla_put_be64(skb, NFTA_OBJ_HANDLE, cpu_to_be64(obj->handle),
83718392
NFTA_OBJ_PAD))
83728393
goto nla_put_failure;
83738394

8374-
if (nla_put_be32(skb, NFTA_OBJ_TYPE, htonl(obj->ops->type->type)) ||
8375-
nla_put_be32(skb, NFTA_OBJ_USE, htonl(obj->use)) ||
8395+
if (event == NFT_MSG_DELOBJ ||
8396+
event == NFT_MSG_DESTROYOBJ) {
8397+
nlmsg_end(skb, nlh);
8398+
return 0;
8399+
}
8400+
8401+
if (nla_put_be32(skb, NFTA_OBJ_USE, htonl(obj->use)) ||
83768402
nft_object_dump(skb, NFTA_OBJ_DATA, obj, reset))
83778403
goto nla_put_failure;
83788404

@@ -9413,9 +9439,9 @@ static int nf_tables_fill_flowtable_info(struct sk_buff *skb, struct net *net,
94139439
struct nft_hook *hook;
94149440
struct nlmsghdr *nlh;
94159441

9416-
event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
9417-
nlh = nfnl_msg_put(skb, portid, seq, event, flags, family,
9418-
NFNETLINK_V0, nft_base_seq(net));
9442+
nlh = nfnl_msg_put(skb, portid, seq,
9443+
nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event),
9444+
flags, family, NFNETLINK_V0, nft_base_seq(net));
94199445
if (!nlh)
94209446
goto nla_put_failure;
94219447

@@ -9425,6 +9451,13 @@ static int nf_tables_fill_flowtable_info(struct sk_buff *skb, struct net *net,
94259451
NFTA_FLOWTABLE_PAD))
94269452
goto nla_put_failure;
94279453

9454+
if (!hook_list &&
9455+
(event == NFT_MSG_DELFLOWTABLE ||
9456+
event == NFT_MSG_DESTROYFLOWTABLE)) {
9457+
nlmsg_end(skb, nlh);
9458+
return 0;
9459+
}
9460+
94289461
if (nla_put_be32(skb, NFTA_FLOWTABLE_USE, htonl(flowtable->use)) ||
94299462
nla_put_be32(skb, NFTA_FLOWTABLE_FLAGS, htonl(flowtable->data.flags)))
94309463
goto nla_put_failure;

0 commit comments

Comments
 (0)