Skip to content

Commit 1b54f4f

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf
Pablo Neira Ayuso says: ==================== Netfilter fixes for net The following patchset contains Netfilter fixes for net: 1) Fix gcc-10 compilation warning in nf_conntrack, from Arnd Bergmann. 2) Add NF_FLOW_HW_PENDING to avoid races between stats and deletion commands, from Paul Blakey. 3) Remove WQ_MEM_RECLAIM from the offload workqueue, from Roi Dayan. 4) Infinite loop when removing nf_conntrack module, from Florian Westphal. 5) Set NF_FLOW_TEARDOWN bit on expiration to avoid races when refreshing the timeout from the software path. 6) Missing nft_set_elem_expired() check in the rbtree, from Phil Sutter. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents c9e2053 + 340eaff commit 1b54f4f

6 files changed

Lines changed: 40 additions & 9 deletions

File tree

‎include/net/netfilter/nf_conntrack.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct nf_conn {
8787
struct hlist_node nat_bysource;
8888
#endif
8989
/* all members below initialized via memset */
90-
u8 __nfct_init_offset[0];
90+
struct { } __nfct_init_offset;
9191

9292
/* If we were expected by an expectation, this will be it */
9393
struct nf_conn *master;

‎include/net/netfilter/nf_flow_table.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ enum nf_flow_flags {
127127
NF_FLOW_HW_DYING,
128128
NF_FLOW_HW_DEAD,
129129
NF_FLOW_HW_REFRESH,
130+
NF_FLOW_HW_PENDING,
130131
};
131132

132133
enum flow_offload_type {

‎net/netfilter/nf_conntrack_core.c‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,9 +1519,9 @@ __nf_conntrack_alloc(struct net *net,
15191519
ct->status = 0;
15201520
ct->timeout = 0;
15211521
write_pnet(&ct->ct_net, net);
1522-
memset(&ct->__nfct_init_offset[0], 0,
1522+
memset(&ct->__nfct_init_offset, 0,
15231523
offsetof(struct nf_conn, proto) -
1524-
offsetof(struct nf_conn, __nfct_init_offset[0]));
1524+
offsetof(struct nf_conn, __nfct_init_offset));
15251525

15261526
nf_ct_zone_add(ct, zone);
15271527

@@ -2139,8 +2139,19 @@ get_next_corpse(int (*iter)(struct nf_conn *i, void *data),
21392139
nf_conntrack_lock(lockp);
21402140
if (*bucket < nf_conntrack_htable_size) {
21412141
hlist_nulls_for_each_entry(h, n, &nf_conntrack_hash[*bucket], hnnode) {
2142-
if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
2142+
if (NF_CT_DIRECTION(h) != IP_CT_DIR_REPLY)
21432143
continue;
2144+
/* All nf_conn objects are added to hash table twice, one
2145+
* for original direction tuple, once for the reply tuple.
2146+
*
2147+
* Exception: In the IPS_NAT_CLASH case, only the reply
2148+
* tuple is added (the original tuple already existed for
2149+
* a different object).
2150+
*
2151+
* We only need to call the iterator once for each
2152+
* conntrack, so we just use the 'reply' direction
2153+
* tuple while iterating.
2154+
*/
21442155
ct = nf_ct_tuplehash_to_ctrack(h);
21452156
if (iter(ct, data))
21462157
goto found;

‎net/netfilter/nf_flow_table_core.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static void flow_offload_del(struct nf_flowtable *flow_table,
284284

285285
if (nf_flow_has_expired(flow))
286286
flow_offload_fixup_ct(flow->ct);
287-
else if (test_bit(NF_FLOW_TEARDOWN, &flow->flags))
287+
else
288288
flow_offload_fixup_ct_timeout(flow->ct);
289289

290290
flow_offload_free(flow);
@@ -361,8 +361,10 @@ static void nf_flow_offload_gc_step(struct flow_offload *flow, void *data)
361361
{
362362
struct nf_flowtable *flow_table = data;
363363

364-
if (nf_flow_has_expired(flow) || nf_ct_is_dying(flow->ct) ||
365-
test_bit(NF_FLOW_TEARDOWN, &flow->flags)) {
364+
if (nf_flow_has_expired(flow) || nf_ct_is_dying(flow->ct))
365+
set_bit(NF_FLOW_TEARDOWN, &flow->flags);
366+
367+
if (test_bit(NF_FLOW_TEARDOWN, &flow->flags)) {
366368
if (test_bit(NF_FLOW_HW, &flow->flags)) {
367369
if (!test_bit(NF_FLOW_HW_DYING, &flow->flags))
368370
nf_flow_offload_del(flow_table, flow);

‎net/netfilter/nf_flow_table_offload.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ static void flow_offload_work_handler(struct work_struct *work)
817817
WARN_ON_ONCE(1);
818818
}
819819

820+
clear_bit(NF_FLOW_HW_PENDING, &offload->flow->flags);
820821
kfree(offload);
821822
}
822823

@@ -831,9 +832,14 @@ nf_flow_offload_work_alloc(struct nf_flowtable *flowtable,
831832
{
832833
struct flow_offload_work *offload;
833834

835+
if (test_and_set_bit(NF_FLOW_HW_PENDING, &flow->flags))
836+
return NULL;
837+
834838
offload = kmalloc(sizeof(struct flow_offload_work), GFP_ATOMIC);
835-
if (!offload)
839+
if (!offload) {
840+
clear_bit(NF_FLOW_HW_PENDING, &flow->flags);
836841
return NULL;
842+
}
837843

838844
offload->cmd = cmd;
839845
offload->flow = flow;
@@ -1056,7 +1062,7 @@ static struct flow_indr_block_entry block_ing_entry = {
10561062
int nf_flow_table_offload_init(void)
10571063
{
10581064
nf_flow_offload_wq = alloc_workqueue("nf_flow_table_offload",
1059-
WQ_UNBOUND | WQ_MEM_RECLAIM, 0);
1065+
WQ_UNBOUND, 0);
10601066
if (!nf_flow_offload_wq)
10611067
return -ENOMEM;
10621068

‎net/netfilter/nft_set_rbtree.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ static bool __nft_rbtree_lookup(const struct net *net, const struct nft_set *set
7979
parent = rcu_dereference_raw(parent->rb_left);
8080
continue;
8181
}
82+
83+
if (nft_set_elem_expired(&rbe->ext))
84+
return false;
85+
8286
if (nft_rbtree_interval_end(rbe)) {
8387
if (nft_set_is_anonymous(set))
8488
return false;
@@ -94,6 +98,7 @@ static bool __nft_rbtree_lookup(const struct net *net, const struct nft_set *set
9498

9599
if (set->flags & NFT_SET_INTERVAL && interval != NULL &&
96100
nft_set_elem_active(&interval->ext, genmask) &&
101+
!nft_set_elem_expired(&interval->ext) &&
97102
nft_rbtree_interval_start(interval)) {
98103
*ext = &interval->ext;
99104
return true;
@@ -154,6 +159,9 @@ static bool __nft_rbtree_get(const struct net *net, const struct nft_set *set,
154159
continue;
155160
}
156161

162+
if (nft_set_elem_expired(&rbe->ext))
163+
return false;
164+
157165
if (!nft_set_ext_exists(&rbe->ext, NFT_SET_EXT_FLAGS) ||
158166
(*nft_set_ext_flags(&rbe->ext) & NFT_SET_ELEM_INTERVAL_END) ==
159167
(flags & NFT_SET_ELEM_INTERVAL_END)) {
@@ -170,6 +178,7 @@ static bool __nft_rbtree_get(const struct net *net, const struct nft_set *set,
170178

171179
if (set->flags & NFT_SET_INTERVAL && interval != NULL &&
172180
nft_set_elem_active(&interval->ext, genmask) &&
181+
!nft_set_elem_expired(&interval->ext) &&
173182
((!nft_rbtree_interval_end(interval) &&
174183
!(flags & NFT_SET_ELEM_INTERVAL_END)) ||
175184
(nft_rbtree_interval_end(interval) &&
@@ -418,6 +427,8 @@ static void nft_rbtree_walk(const struct nft_ctx *ctx,
418427

419428
if (iter->count < iter->skip)
420429
goto cont;
430+
if (nft_set_elem_expired(&rbe->ext))
431+
goto cont;
421432
if (!nft_set_elem_active(&rbe->ext, iter->genmask))
422433
goto cont;
423434

0 commit comments

Comments
 (0)