* [PATCH nf v3 0/2] Fix invoking expectfn unloaded
@ 2017-03-21 6:06 fgao
2017-03-21 6:06 ` [PATCH nf v3 1/2] netfilter: helper: Rename struct nf_ct_helper_expectfn to nf_ct_nat_helper fgao
2017-03-21 6:06 ` [PATCH nf v3 2/2] netfilter: helper: Fix possible panic caused by invoking expectfn unloaded fgao
0 siblings, 2 replies; 5+ messages in thread
From: fgao @ 2017-03-21 6:06 UTC (permalink / raw)
To: pablo, netfilter-devel, gfree_wind; +Cc: Gao Feng
From: Gao Feng <fgao@ikuai8.com>
It is possible that invoke one expectfn whose module is already unloaded.
These two patches are used to fix it.
Gao Feng (2):
netfilter: helper: Rename struct nf_ct_helper_expectfn to
nf_ct_nat_helper
netfilter: helper: Fix possible panic caused by invoking expectfn
unloaded
include/net/netfilter/nf_conntrack_expect.h | 2 +
include/net/netfilter/nf_conntrack_helper.h | 15 ++---
net/ipv4/netfilter/nf_nat_h323.c | 14 +++--
net/netfilter/nf_conntrack_broadcast.c | 1 +
net/netfilter/nf_conntrack_expect.c | 1 +
net/netfilter/nf_conntrack_helper.c | 95 +++++++++++++++++------------
net/netfilter/nf_conntrack_netlink.c | 21 ++++---
net/netfilter/nf_nat_core.c | 7 ++-
net/netfilter/nf_nat_sip.c | 7 ++-
9 files changed, 95 insertions(+), 68 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH nf v3 1/2] netfilter: helper: Rename struct nf_ct_helper_expectfn to nf_ct_nat_helper
2017-03-21 6:06 [PATCH nf v3 0/2] Fix invoking expectfn unloaded fgao
@ 2017-03-21 6:06 ` fgao
2017-03-21 6:06 ` [PATCH nf v3 2/2] netfilter: helper: Fix possible panic caused by invoking expectfn unloaded fgao
1 sibling, 0 replies; 5+ messages in thread
From: fgao @ 2017-03-21 6:06 UTC (permalink / raw)
To: pablo, netfilter-devel, gfree_wind; +Cc: Gao Feng
From: Gao Feng <fgao@ikuai8.com>
Rename struct nf_ct_helper_expectfn to nf_ct_nat_helper, and rename
other functions or variables which refer to it.
The new name is better than the old one.
Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
v3: Rename the nf_ct_helper_expectfn, func, and member, per Pablo,
v2: Use the module as the identifier when flush expect
v1: initial version
include/net/netfilter/nf_conntrack_helper.h | 14 ++++++-------
net/ipv4/netfilter/nf_nat_h323.c | 12 +++++------
net/netfilter/nf_conntrack_helper.c | 32 ++++++++++++++---------------
net/netfilter/nf_conntrack_netlink.c | 16 +++++++--------
net/netfilter/nf_nat_core.c | 6 +++---
net/netfilter/nf_nat_sip.c | 6 +++---
6 files changed, 43 insertions(+), 43 deletions(-)
diff --git a/include/net/netfilter/nf_conntrack_helper.h b/include/net/netfilter/nf_conntrack_helper.h
index 1eaac1f..d14fe493 100644
--- a/include/net/netfilter/nf_conntrack_helper.h
+++ b/include/net/netfilter/nf_conntrack_helper.h
@@ -111,7 +111,7 @@ int nf_conntrack_broadcast_help(struct sk_buff *skb, unsigned int protoff,
enum ip_conntrack_info ctinfo,
unsigned int timeout);
-struct nf_ct_helper_expectfn {
+struct nf_ct_nat_helper {
struct list_head head;
const char *name;
void (*expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp);
@@ -121,12 +121,12 @@ struct nf_ct_helper_expectfn {
void nf_ct_helper_log(struct sk_buff *skb, const struct nf_conn *ct,
const char *fmt, ...);
-void nf_ct_helper_expectfn_register(struct nf_ct_helper_expectfn *n);
-void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n);
-struct nf_ct_helper_expectfn *
-nf_ct_helper_expectfn_find_by_name(const char *name);
-struct nf_ct_helper_expectfn *
-nf_ct_helper_expectfn_find_by_symbol(const void *symbol);
+void nf_ct_nat_helper_register(struct nf_ct_nat_helper *n);
+void nf_ct_nat_helper_unregister(struct nf_ct_nat_helper *n);
+struct nf_ct_nat_helper *
+nf_ct_nat_helper_find_by_name(const char *name);
+struct nf_ct_nat_helper *
+nf_ct_nat_helper_find_by_symbol(const void *symbol);
extern struct hlist_head *nf_ct_helper_hash;
extern unsigned int nf_ct_helper_hsize;
diff --git a/net/ipv4/netfilter/nf_nat_h323.c b/net/ipv4/netfilter/nf_nat_h323.c
index 574f7eb..346e764 100644
--- a/net/ipv4/netfilter/nf_nat_h323.c
+++ b/net/ipv4/netfilter/nf_nat_h323.c
@@ -567,12 +567,12 @@ static int nat_callforwarding(struct sk_buff *skb, struct nf_conn *ct,
return 0;
}
-static struct nf_ct_helper_expectfn q931_nat = {
+static struct nf_ct_nat_helper q931_nat = {
.name = "Q.931",
.expectfn = ip_nat_q931_expect,
};
-static struct nf_ct_helper_expectfn callforwarding_nat = {
+static struct nf_ct_nat_helper callforwarding_nat = {
.name = "callforwarding",
.expectfn = ip_nat_callforwarding_expect,
};
@@ -599,8 +599,8 @@ static int __init init(void)
RCU_INIT_POINTER(nat_h245_hook, nat_h245);
RCU_INIT_POINTER(nat_callforwarding_hook, nat_callforwarding);
RCU_INIT_POINTER(nat_q931_hook, nat_q931);
- nf_ct_helper_expectfn_register(&q931_nat);
- nf_ct_helper_expectfn_register(&callforwarding_nat);
+ nf_ct_nat_helper_register(&q931_nat);
+ nf_ct_nat_helper_register(&callforwarding_nat);
return 0;
}
@@ -616,8 +616,8 @@ static void __exit fini(void)
RCU_INIT_POINTER(nat_h245_hook, NULL);
RCU_INIT_POINTER(nat_callforwarding_hook, NULL);
RCU_INIT_POINTER(nat_q931_hook, NULL);
- nf_ct_helper_expectfn_unregister(&q931_nat);
- nf_ct_helper_expectfn_unregister(&callforwarding_nat);
+ nf_ct_nat_helper_unregister(&q931_nat);
+ nf_ct_nat_helper_unregister(&callforwarding_nat);
synchronize_rcu();
}
diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
index 6dc44d9..0eaa01e 100644
--- a/net/netfilter/nf_conntrack_helper.c
+++ b/net/netfilter/nf_conntrack_helper.c
@@ -293,32 +293,32 @@ void nf_ct_helper_destroy(struct nf_conn *ct)
}
}
-static LIST_HEAD(nf_ct_helper_expectfn_list);
+static LIST_HEAD(nf_ct_nat_helper_list);
-void nf_ct_helper_expectfn_register(struct nf_ct_helper_expectfn *n)
+void nf_ct_nat_helper_register(struct nf_ct_nat_helper *n)
{
spin_lock_bh(&nf_conntrack_expect_lock);
- list_add_rcu(&n->head, &nf_ct_helper_expectfn_list);
+ list_add_rcu(&n->head, &nf_ct_nat_helper_list);
spin_unlock_bh(&nf_conntrack_expect_lock);
}
-EXPORT_SYMBOL_GPL(nf_ct_helper_expectfn_register);
+EXPORT_SYMBOL_GPL(nf_ct_nat_helper_register);
-void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n)
+void nf_ct_nat_helper_unregister(struct nf_ct_nat_helper *n)
{
spin_lock_bh(&nf_conntrack_expect_lock);
list_del_rcu(&n->head);
spin_unlock_bh(&nf_conntrack_expect_lock);
}
-EXPORT_SYMBOL_GPL(nf_ct_helper_expectfn_unregister);
+EXPORT_SYMBOL_GPL(nf_ct_nat_helper_unregister);
-struct nf_ct_helper_expectfn *
-nf_ct_helper_expectfn_find_by_name(const char *name)
+struct nf_ct_nat_helper *
+nf_ct_nat_helper_find_by_name(const char *name)
{
- struct nf_ct_helper_expectfn *cur;
+ struct nf_ct_nat_helper *cur;
bool found = false;
rcu_read_lock();
- list_for_each_entry_rcu(cur, &nf_ct_helper_expectfn_list, head) {
+ list_for_each_entry_rcu(cur, &nf_ct_nat_helper_list, head) {
if (!strcmp(cur->name, name)) {
found = true;
break;
@@ -327,16 +327,16 @@ struct nf_ct_helper_expectfn *
rcu_read_unlock();
return found ? cur : NULL;
}
-EXPORT_SYMBOL_GPL(nf_ct_helper_expectfn_find_by_name);
+EXPORT_SYMBOL_GPL(nf_ct_nat_helper_find_by_name);
-struct nf_ct_helper_expectfn *
-nf_ct_helper_expectfn_find_by_symbol(const void *symbol)
+struct nf_ct_nat_helper *
+nf_ct_nat_helper_find_by_symbol(const void *symbol)
{
- struct nf_ct_helper_expectfn *cur;
+ struct nf_ct_nat_helper *cur;
bool found = false;
rcu_read_lock();
- list_for_each_entry_rcu(cur, &nf_ct_helper_expectfn_list, head) {
+ list_for_each_entry_rcu(cur, &nf_ct_nat_helper_list, head) {
if (cur->expectfn == symbol) {
found = true;
break;
@@ -345,7 +345,7 @@ struct nf_ct_helper_expectfn *
rcu_read_unlock();
return found ? cur : NULL;
}
-EXPORT_SYMBOL_GPL(nf_ct_helper_expectfn_find_by_symbol);
+EXPORT_SYMBOL_GPL(nf_ct_nat_helper_find_by_symbol);
__printf(3, 4)
void nf_ct_helper_log(struct sk_buff *skb, const struct nf_conn *ct,
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 6806b5e..66817a5 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -2508,7 +2508,7 @@ static int ctnetlink_exp_dump_mask(struct sk_buff *skb,
struct nlattr *nest_parms;
struct nf_conntrack_tuple nat_tuple = {};
#endif
- struct nf_ct_helper_expectfn *expfn;
+ struct nf_ct_nat_helper *nat_helper;
if (timeout < 0)
timeout = 0;
@@ -2557,9 +2557,9 @@ static int ctnetlink_exp_dump_mask(struct sk_buff *skb,
nla_put_string(skb, CTA_EXPECT_HELP_NAME, helper->name))
goto nla_put_failure;
}
- expfn = nf_ct_helper_expectfn_find_by_symbol(exp->expectfn);
- if (expfn != NULL &&
- nla_put_string(skb, CTA_EXPECT_FN, expfn->name))
+ nat_helper = nf_ct_nat_helper_find_by_symbol(exp->expectfn);
+ if (!nat_helper &&
+ nla_put_string(skb, CTA_EXPECT_FN, nat_helper->name))
goto nla_put_failure;
return 0;
@@ -3070,14 +3070,14 @@ static int ctnetlink_del_expect(struct net *net, struct sock *ctnl,
}
if (cda[CTA_EXPECT_FN]) {
const char *name = nla_data(cda[CTA_EXPECT_FN]);
- struct nf_ct_helper_expectfn *expfn;
+ struct nf_ct_nat_helper *nat_helper;
- expfn = nf_ct_helper_expectfn_find_by_name(name);
- if (expfn == NULL) {
+ nat_helper = nf_ct_nat_helper_find_by_name(name);
+ if (!nat_helper) {
err = -EINVAL;
goto err_out;
}
- exp->expectfn = expfn->expectfn;
+ exp->expectfn = nat_helper->expectfn;
} else
exp->expectfn = NULL;
diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
index 94b14c5..eae9bec 100644
--- a/net/netfilter/nf_nat_core.c
+++ b/net/netfilter/nf_nat_core.c
@@ -848,7 +848,7 @@ static void __net_exit nf_nat_net_exit(struct net *net)
.exit = nf_nat_net_exit,
};
-static struct nf_ct_helper_expectfn follow_master_nat = {
+static struct nf_ct_nat_helper follow_master_nat = {
.name = "nat-follow-master",
.expectfn = nf_nat_follow_master,
};
@@ -872,7 +872,7 @@ static int __init nf_nat_init(void)
if (ret < 0)
goto cleanup_extend;
- nf_ct_helper_expectfn_register(&follow_master_nat);
+ nf_ct_nat_helper_register(&follow_master_nat);
/* Initialize fake conntrack so that NAT will skip it */
nf_ct_untracked_status_or(IPS_NAT_DONE_MASK);
@@ -898,7 +898,7 @@ static void __exit nf_nat_cleanup(void)
unregister_pernet_subsys(&nf_nat_net_ops);
nf_ct_extend_unregister(&nat_extend);
- nf_ct_helper_expectfn_unregister(&follow_master_nat);
+ nf_ct_nat_helper_unregister(&follow_master_nat);
RCU_INIT_POINTER(nfnetlink_parse_nat_setup_hook, NULL);
#ifdef CONFIG_XFRM
RCU_INIT_POINTER(nf_nat_decode_session_hook, NULL);
diff --git a/net/netfilter/nf_nat_sip.c b/net/netfilter/nf_nat_sip.c
index 791fac4..d27c5a2 100644
--- a/net/netfilter/nf_nat_sip.c
+++ b/net/netfilter/nf_nat_sip.c
@@ -618,7 +618,7 @@ static unsigned int nf_nat_sdp_media(struct sk_buff *skb, unsigned int protoff,
return NF_DROP;
}
-static struct nf_ct_helper_expectfn sip_nat = {
+static struct nf_ct_nat_helper sip_nat = {
.name = "sip",
.expectfn = nf_nat_sip_expected,
};
@@ -627,7 +627,7 @@ static void __exit nf_nat_sip_fini(void)
{
RCU_INIT_POINTER(nf_nat_sip_hooks, NULL);
- nf_ct_helper_expectfn_unregister(&sip_nat);
+ nf_ct_nat_helper_unregister(&sip_nat);
synchronize_rcu();
}
@@ -645,7 +645,7 @@ static int __init nf_nat_sip_init(void)
{
BUG_ON(nf_nat_sip_hooks != NULL);
RCU_INIT_POINTER(nf_nat_sip_hooks, &sip_hooks);
- nf_ct_helper_expectfn_register(&sip_nat);
+ nf_ct_nat_helper_register(&sip_nat);
return 0;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH nf v3 2/2] netfilter: helper: Fix possible panic caused by invoking expectfn unloaded
2017-03-21 6:06 [PATCH nf v3 0/2] Fix invoking expectfn unloaded fgao
2017-03-21 6:06 ` [PATCH nf v3 1/2] netfilter: helper: Rename struct nf_ct_helper_expectfn to nf_ct_nat_helper fgao
@ 2017-03-21 6:06 ` fgao
2017-03-21 14:13 ` Pablo Neira Ayuso
1 sibling, 1 reply; 5+ messages in thread
From: fgao @ 2017-03-21 6:06 UTC (permalink / raw)
To: pablo, netfilter-devel, gfree_wind; +Cc: Gao Feng
From: Gao Feng <fgao@ikuai8.com>
Because the conntrack NAT module could be rmmod anytime, so we should
really leave things in clean state if such thing happens and make sure
we don't leave any packet running over code that will be gone after
the removal.
We only removed the expectations when unregister conntrack helper before.
Actually it is necessary too when remove the nat helper.
Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
v3: Rename the nf_ct_helper_expectfn, func, and member, per Pablo,
v2: Use the module as the identifier when flush expect
v1: initial version
include/net/netfilter/nf_conntrack_expect.h | 2 +
include/net/netfilter/nf_conntrack_helper.h | 1 +
net/ipv4/netfilter/nf_nat_h323.c | 2 +
net/netfilter/nf_conntrack_broadcast.c | 1 +
net/netfilter/nf_conntrack_expect.c | 1 +
net/netfilter/nf_conntrack_helper.c | 63 ++++++++++++++++++-----------
net/netfilter/nf_conntrack_netlink.c | 5 ++-
net/netfilter/nf_nat_core.c | 1 +
net/netfilter/nf_nat_sip.c | 1 +
9 files changed, 52 insertions(+), 25 deletions(-)
diff --git a/include/net/netfilter/nf_conntrack_expect.h b/include/net/netfilter/nf_conntrack_expect.h
index 5ed33ea..f2bc64e 100644
--- a/include/net/netfilter/nf_conntrack_expect.h
+++ b/include/net/netfilter/nf_conntrack_expect.h
@@ -26,6 +26,8 @@ struct nf_conntrack_expect {
/* Function to call after setup and insertion */
void (*expectfn)(struct nf_conn *new,
struct nf_conntrack_expect *this);
+ /* The module which expectfn belongs to */
+ struct module *nat_module;
/* Helper to assign to new connection */
struct nf_conntrack_helper *helper;
diff --git a/include/net/netfilter/nf_conntrack_helper.h b/include/net/netfilter/nf_conntrack_helper.h
index d14fe493..dd1a687 100644
--- a/include/net/netfilter/nf_conntrack_helper.h
+++ b/include/net/netfilter/nf_conntrack_helper.h
@@ -113,6 +113,7 @@ int nf_conntrack_broadcast_help(struct sk_buff *skb, unsigned int protoff,
struct nf_ct_nat_helper {
struct list_head head;
+ struct module *me;
const char *name;
void (*expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp);
};
diff --git a/net/ipv4/netfilter/nf_nat_h323.c b/net/ipv4/netfilter/nf_nat_h323.c
index 346e764..4c8eef6 100644
--- a/net/ipv4/netfilter/nf_nat_h323.c
+++ b/net/ipv4/netfilter/nf_nat_h323.c
@@ -569,11 +569,13 @@ static int nat_callforwarding(struct sk_buff *skb, struct nf_conn *ct,
static struct nf_ct_nat_helper q931_nat = {
.name = "Q.931",
+ .me = THIS_MODULE,
.expectfn = ip_nat_q931_expect,
};
static struct nf_ct_nat_helper callforwarding_nat = {
.name = "callforwarding",
+ .me = THIS_MODULE,
.expectfn = ip_nat_callforwarding_expect,
};
diff --git a/net/netfilter/nf_conntrack_broadcast.c b/net/netfilter/nf_conntrack_broadcast.c
index 4e99cca..ca54735 100644
--- a/net/netfilter/nf_conntrack_broadcast.c
+++ b/net/netfilter/nf_conntrack_broadcast.c
@@ -66,6 +66,7 @@ int nf_conntrack_broadcast_help(struct sk_buff *skb,
exp->mask.src.u.udp.port = htons(0xFFFF);
exp->expectfn = NULL;
+ exp->nat_module = NULL;
exp->flags = NF_CT_EXPECT_PERMANENT;
exp->class = NF_CT_EXPECT_CLASS_DEFAULT;
exp->helper = NULL;
diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c
index 4b2e1fb..b6d081a 100644
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -296,6 +296,7 @@ void nf_ct_expect_init(struct nf_conntrack_expect *exp, unsigned int class,
exp->flags = 0;
exp->class = class;
exp->expectfn = NULL;
+ exp->nat_module = NULL;
exp->helper = NULL;
exp->tuple.src.l3num = family;
exp->tuple.dst.protonum = proto;
diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
index 0eaa01e..c25c9be 100644
--- a/net/netfilter/nf_conntrack_helper.c
+++ b/net/netfilter/nf_conntrack_helper.c
@@ -130,6 +130,42 @@ static unsigned int helper_hash(const struct nf_conntrack_tuple *tuple)
return NULL;
}
+static void
+nf_ct_flush_expect(const struct module *me)
+{
+ struct nf_conntrack_expect *exp;
+ const struct hlist_node *next;
+ u32 i;
+
+ if (!me)
+ return;
+
+ /* Make sure no one is still using the module unless
+ * its a connection in the hash.
+ */
+ synchronize_rcu();
+
+ /* Get rid of expectations */
+ spin_lock_bh(&nf_conntrack_expect_lock);
+ for (i = 0; i < nf_ct_expect_hsize; i++) {
+ hlist_for_each_entry_safe(exp, next,
+ &nf_ct_expect_hash[i], hnode) {
+ struct nf_conn_help *master_help = nfct_help(exp->master);
+
+ if ((master_help->helper && master_help->helper->me == me) ||
+ (exp->helper && exp->helper->me == me) ||
+ exp->nat_module == me) {
+ /* This expect belongs to the dying module */
+ if (del_timer(&exp->timeout)) {
+ nf_ct_unlink_expect(exp);
+ nf_ct_expect_put(exp);
+ }
+ }
+ }
+ }
+ spin_unlock_bh(&nf_conntrack_expect_lock);
+}
+
struct nf_conntrack_helper *
__nf_conntrack_helper_find(const char *name, u16 l3num, u8 protonum)
{
@@ -308,6 +344,8 @@ void nf_ct_nat_helper_unregister(struct nf_ct_nat_helper *n)
spin_lock_bh(&nf_conntrack_expect_lock);
list_del_rcu(&n->head);
spin_unlock_bh(&nf_conntrack_expect_lock);
+
+ nf_ct_flush_expect(n->me);
}
EXPORT_SYMBOL_GPL(nf_ct_nat_helper_unregister);
@@ -421,8 +459,6 @@ static void __nf_conntrack_helper_unregister(struct nf_conntrack_helper *me,
void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me)
{
struct nf_conntrack_tuple_hash *h;
- struct nf_conntrack_expect *exp;
- const struct hlist_node *next;
const struct hlist_nulls_node *nn;
unsigned int last_hsize;
spinlock_t *lock;
@@ -434,28 +470,7 @@ void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me)
nf_ct_helper_count--;
mutex_unlock(&nf_ct_helper_mutex);
- /* Make sure every nothing is still using the helper unless its a
- * connection in the hash.
- */
- synchronize_rcu();
-
- /* Get rid of expectations */
- spin_lock_bh(&nf_conntrack_expect_lock);
- for (i = 0; i < nf_ct_expect_hsize; i++) {
- hlist_for_each_entry_safe(exp, next,
- &nf_ct_expect_hash[i], hnode) {
- struct nf_conn_help *help = nfct_help(exp->master);
- if ((rcu_dereference_protected(
- help->helper,
- lockdep_is_held(&nf_conntrack_expect_lock)
- ) == me || exp->helper == me) &&
- del_timer(&exp->timeout)) {
- nf_ct_unlink_expect(exp);
- nf_ct_expect_put(exp);
- }
- }
- }
- spin_unlock_bh(&nf_conntrack_expect_lock);
+ nf_ct_flush_expect(me->me);
rtnl_lock();
for_each_net(net)
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 66817a5..50628aa 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -3078,8 +3078,11 @@ static int ctnetlink_del_expect(struct net *net, struct sock *ctnl,
goto err_out;
}
exp->expectfn = nat_helper->expectfn;
- } else
+ exp->nat_module = nat_helper->me;
+ } else {
exp->expectfn = NULL;
+ exp->nat_module = NULL;
+ }
exp->class = class;
exp->master = ct;
diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
index eae9bec..f337208 100644
--- a/net/netfilter/nf_nat_core.c
+++ b/net/netfilter/nf_nat_core.c
@@ -850,6 +850,7 @@ static void __net_exit nf_nat_net_exit(struct net *net)
static struct nf_ct_nat_helper follow_master_nat = {
.name = "nat-follow-master",
+ .me = THIS_MODULE,
.expectfn = nf_nat_follow_master,
};
diff --git a/net/netfilter/nf_nat_sip.c b/net/netfilter/nf_nat_sip.c
index d27c5a2..4095a45 100644
--- a/net/netfilter/nf_nat_sip.c
+++ b/net/netfilter/nf_nat_sip.c
@@ -620,6 +620,7 @@ static unsigned int nf_nat_sdp_media(struct sk_buff *skb, unsigned int protoff,
static struct nf_ct_nat_helper sip_nat = {
.name = "sip",
+ .me = THIS_MODULE,
.expectfn = nf_nat_sip_expected,
};
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH nf v3 2/2] netfilter: helper: Fix possible panic caused by invoking expectfn unloaded
2017-03-21 6:06 ` [PATCH nf v3 2/2] netfilter: helper: Fix possible panic caused by invoking expectfn unloaded fgao
@ 2017-03-21 14:13 ` Pablo Neira Ayuso
2017-03-21 14:20 ` Gao Feng
0 siblings, 1 reply; 5+ messages in thread
From: Pablo Neira Ayuso @ 2017-03-21 14:13 UTC (permalink / raw)
To: fgao; +Cc: netfilter-devel, gfree_wind
On Tue, Mar 21, 2017 at 02:06:26PM +0800, fgao@ikuai8.com wrote:
> From: Gao Feng <fgao@ikuai8.com>
>
> Because the conntrack NAT module could be rmmod anytime, so we should
> really leave things in clean state if such thing happens and make sure
> we don't leave any packet running over code that will be gone after
> the removal.
>
> We only removed the expectations when unregister conntrack helper before.
> Actually it is necessary too when remove the nat helper.
We still need something like this, right?
diff --git a/net/netfilter/nf_nat_sip.c b/net/netfilter/nf_nat_sip.c
index 791fac4fd745..38f1ed5219e4 100644
--- a/net/netfilter/nf_nat_sip.c
+++ b/net/netfilter/nf_nat_sip.c
@@ -377,6 +377,7 @@ static unsigned int nf_nat_sip_expect(struct
sk_buff *skb, unsigned int protoff,
exp->saved_proto.udp.port = exp->tuple.dst.u.udp.port;
exp->dir = !dir;
exp->expectfn = nf_nat_sip_expected;
+ exp->nat_module = THIS_MODULE;
for (; port != 0; port++) {
int ret;
So if the user invokes:
rmmod nf_nat_sip
we can get rid of this expectation from nf_ct_flush_expect().
^ permalink raw reply related [flat|nested] 5+ messages in thread
* RE: [PATCH nf v3 2/2] netfilter: helper: Fix possible panic caused by invoking expectfn unloaded
2017-03-21 14:13 ` Pablo Neira Ayuso
@ 2017-03-21 14:20 ` Gao Feng
0 siblings, 0 replies; 5+ messages in thread
From: Gao Feng @ 2017-03-21 14:20 UTC (permalink / raw)
To: 'Pablo Neira Ayuso', fgao; +Cc: netfilter-devel, gfree_wind
Hi Pablo,
> -----Original Message-----
> From: netfilter-devel-owner@vger.kernel.org
> [mailto:netfilter-devel-owner@vger.kernel.org] On Behalf Of Pablo Neira
Ayuso
> Sent: Tuesday, March 21, 2017 10:13 PM
> To: fgao@ikuai8.com
> Cc: netfilter-devel@vger.kernel.org; gfree_wind@126.com
> Subject: Re: [PATCH nf v3 2/2] netfilter: helper: Fix possible panic
caused by
> invoking expectfn unloaded
>
> On Tue, Mar 21, 2017 at 02:06:26PM +0800, fgao@ikuai8.com wrote:
> > From: Gao Feng <fgao@ikuai8.com>
> >
> > Because the conntrack NAT module could be rmmod anytime, so we should
> > really leave things in clean state if such thing happens and make sure
> > we don't leave any packet running over code that will be gone after
> > the removal.
> >
> > We only removed the expectations when unregister conntrack helper
before.
> > Actually it is necessary too when remove the nat helper.
>
> We still need something like this, right?
Yes, we need to remove expect when remove helper and nat_helper.
>
> diff --git a/net/netfilter/nf_nat_sip.c b/net/netfilter/nf_nat_sip.c index
> 791fac4fd745..38f1ed5219e4 100644
> --- a/net/netfilter/nf_nat_sip.c
> +++ b/net/netfilter/nf_nat_sip.c
> @@ -377,6 +377,7 @@ static unsigned int nf_nat_sip_expect(struct sk_buff
> *skb, unsigned int protoff,
> exp->saved_proto.udp.port = exp->tuple.dst.u.udp.port;
> exp->dir = !dir;
> exp->expectfn = nf_nat_sip_expected;
> + exp->nat_module = THIS_MODULE;
>
> for (; port != 0; port++) {
> int ret;
>
> So if the user invokes:
>
> rmmod nf_nat_sip
>
> we can get rid of this expectation from nf_ct_flush_expect().
Oh, I missed the data path, only covered the ctlink codes.
I would update the patch again.
Best Regards
Feng
> --
> To unsubscribe from this list: send the line "unsubscribe netfilter-devel"
in the
> body of a message to majordomo@vger.kernel.org More majordomo info at
> http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-03-21 14:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-21 6:06 [PATCH nf v3 0/2] Fix invoking expectfn unloaded fgao
2017-03-21 6:06 ` [PATCH nf v3 1/2] netfilter: helper: Rename struct nf_ct_helper_expectfn to nf_ct_nat_helper fgao
2017-03-21 6:06 ` [PATCH nf v3 2/2] netfilter: helper: Fix possible panic caused by invoking expectfn unloaded fgao
2017-03-21 14:13 ` Pablo Neira Ayuso
2017-03-21 14:20 ` Gao Feng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).