netfilter: nf_flow_table: do not use deleted CT's flow offload
Subsystems (2)
PATCH 4/4 netfilter: nf_flow_table: do not use deleted CT's flow offload
flow offload of CT can be deleted by the masquerade module. then, flow offload should be deleted too. but GC and data-path of flow offload do not check CT's status. hence they will be removed only by the timeout.
GC and data-path routine will check ct_general.use value. If that value is 1, it means that CT is removed from the list. So, GC will delete this and data-path do not use this.
--- net/netfilter/nf_flow_table_core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/netfilter/nf_flow_table_core.c +9 -1
@@ -232,6 +232,7 @@ flow_offload_lookup(struct nf_flowtable *flow_table, {struct flow_offload_tuple_rhash *tuplehash;struct flow_offload *flow; +struct flow_offload_entry *e;int dir; tuplehash = rhashtable_lookup(&flow_table->rhashtable, tuple,
@@ -244,6 +245,10 @@ flow_offload_lookup(struct nf_flowtable *flow_table,if (flow->flags & (FLOW_OFFLOAD_DYING |FLOW_OFFLOAD_TEARDOWN ))return NULL ; + e = container_of(flow, struct flow_offload_entry, flow); +if (unlikely (atomic_read (&e->ct->ct_general.use) ==1 )) +return NULL ; +return tuplehash; }EXPORT_SYMBOL_GPL (flow_offload_lookup);
@@ -290,9 +295,12 @@ static inline bool nf_flow_has_expired(const struct flow_offload *flow)static void nf_flow_offload_gc_step (struct flow_offload *flow,void *data) {struct nf_flowtable *flow_table = data; +struct flow_offload_entry *e; + e = container_of(flow, struct flow_offload_entry, flow);if (nf_flow_has_expired (flow) || - (flow->flags & (FLOW_OFFLOAD_DYING |FLOW_OFFLOAD_TEARDOWN ))) + (flow->flags & (FLOW_OFFLOAD_DYING |FLOW_OFFLOAD_TEARDOWN )) || + (atomic_read (&e->ct->ct_general.use) ==1 ))flow_offload_del (flow_table, flow); }
Signature · 1 line
2.17.1
Pablo Neira Ayuso
maintainerQuoted 26 lines · Taehee Yoo
flow offload of CT can be deleted by the masquerade module. then, flow offload should be deleted too. but GC and data-path of flow offload do not check CT's status. hence they will be removed only by the timeout.
GC and data-path routine will check ct_general.use value. If that value is 1, it means that CT is removed from the list. So, GC will delete this and data-path do not use this.
Signed-off-by Taehee Yoo <[email protected]>--- net/netfilter/nf_flow_table_core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)net/netfilter/nf_flow_table_core.c +1
-0@@ -232,6 +232,7 @@ flow_offload_lookup(struct nf_flowtable *flow_table, {struct flow_offload_tuple_rhash *tuplehash;struct flow_offload *flow; +struct flow_offload_entry *e;int dir; tuplehash = rhashtable_lookup(&flow_table->rhashtable, tuple,
net/netfilter/nf_flow_table_core.c flow_offload_lookup(struct nf_flowtable *flow_table, · line 249
Quoted 5 lines
net/netfilter/nf_flow_table_core.c +2
-0@@ -244,6 +245,10 @@ flow_offload_lookup(struct nf_flowtable *flow_table,if (flow->flags & (FLOW_OFFLOAD_DYING |FLOW_OFFLOAD_TEARDOWN ))return NULL ; + e = container_of(flow, struct flow_offload_entry, flow); +if (unlikely (atomic_read (&e->ct->ct_general.use) ==1 ))
Could we use the IPS_DYING_BIT instead?
Quoted 1 line · Pablo Neira Ayuso
Hi Pablo,
Thank you for the review!
Quoted 30 lines · Taehee Yoo
Quoted 29 lines
flow offload of CT can be deleted by the masquerade module. then, flow offload should be deleted too. but GC and data-path of flow offload do not check CT's status. hence they will be removed only by the timeout.
GC and data-path routine will check ct_general.use value. If that value is 1, it means that CT is removed from the list. So, GC will delete this and data-path do not use this.
Signed-off-by Taehee Yoo <[email protected]>--- net/netfilter/nf_flow_table_core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)net/netfilter/nf_flow_table_core.c +1
-0@@ -232,6 +232,7 @@ flow_offload_lookup(struct nf_flowtable *flow_table, {struct flow_offload_tuple_rhash *tuplehash;struct flow_offload *flow; +struct flow_offload_entry *e;int dir; tuplehash = rhashtable_lookup(&flow_table->rhashtable, tuple,@@ -244,6 +245,10 @@ flow_offload_lookup(struct nf_flowtable *flow_table,if (flow->flags & (FLOW_OFFLOAD_DYING |FLOW_OFFLOAD_TEARDOWN ))return NULL ;
Quoted 4 lines
net/netfilter/nf_flow_table_core.c flow_offload_lookup(struct nf_flowtable *flow_table, · line 249
Quoted 2 lines
net/netfilter/nf_flow_table_core.c +2
-0+ e = container_of(flow, struct flow_offload_entry, flow); +if (unlikely (atomic_read (&e->ct->ct_general.use) ==1 ))Could we use the
IPS_DYING_BITinstead?
Oh, it looks better.
I will test and send v2 patch!
Thanks!