Commit 8f1f7eeb authored by David S. Miller's avatar David S. Miller

Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf

Pablo Neira Ayuso says:

====================
Netfilter fixes for net

The following patchset contains a rather large update with Netfilter
fixes, specifically targeted to incorrect RCU usage in several spots and
the userspace conntrack helper infrastructure (nfnetlink_cthelper),
more specifically they are:

1) expect_class_max is incorrect set via cthelper, as in kernel semantics
   mandate that this represents the array of expectation classes minus 1.
   Patch from Liping Zhang.

2) Expectation policy updates via cthelper are currently broken for several
   reasons: This code allows illegal changes in the policy such as changing
   the number of expeciation classes, it is leaking the updated policy and
   such update occurs with no RCU protection at all. Fix this by adding a
   new nfnl_cthelper_update_policy() that describes what is really legal on
   the update path.

3) Fix several memory leaks in cthelper, from Jeffy Chen.

4) synchronize_rcu() is missing in the removal path of several modules,
   this may lead to races since CPU may still be running on code that has
   just gone. Also from Liping Zhang.

5) Don't use the helper hashtable from cthelper, it is not safe to walk
   over those bits without the helper mutex. Fix this by introducing a
   new independent list for userspace helpers. From Liping Zhang.

6) nf_ct_extend_unregister() needs synchronize_rcu() to make sure no
   packets are walking on any conntrack extension that is gone after
   module removal, again from Liping.

7) nf_nat_snmp may crash if we fail to unregister the helper due to
   accidental leftover code, from Gao Feng.

8) Fix leak in nfnetlink_queue with secctx support, from Liping Zhang.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 358e78b5 77c1c03c
...@@ -1260,16 +1260,6 @@ static const struct nf_conntrack_expect_policy snmp_exp_policy = { ...@@ -1260,16 +1260,6 @@ static const struct nf_conntrack_expect_policy snmp_exp_policy = {
.timeout = 180, .timeout = 180,
}; };
static struct nf_conntrack_helper snmp_helper __read_mostly = {
.me = THIS_MODULE,
.help = help,
.expect_policy = &snmp_exp_policy,
.name = "snmp",
.tuple.src.l3num = AF_INET,
.tuple.src.u.udp.port = cpu_to_be16(SNMP_PORT),
.tuple.dst.protonum = IPPROTO_UDP,
};
static struct nf_conntrack_helper snmp_trap_helper __read_mostly = { static struct nf_conntrack_helper snmp_trap_helper __read_mostly = {
.me = THIS_MODULE, .me = THIS_MODULE,
.help = help, .help = help,
...@@ -1288,22 +1278,16 @@ static struct nf_conntrack_helper snmp_trap_helper __read_mostly = { ...@@ -1288,22 +1278,16 @@ static struct nf_conntrack_helper snmp_trap_helper __read_mostly = {
static int __init nf_nat_snmp_basic_init(void) static int __init nf_nat_snmp_basic_init(void)
{ {
int ret = 0;
BUG_ON(nf_nat_snmp_hook != NULL); BUG_ON(nf_nat_snmp_hook != NULL);
RCU_INIT_POINTER(nf_nat_snmp_hook, help); RCU_INIT_POINTER(nf_nat_snmp_hook, help);
ret = nf_conntrack_helper_register(&snmp_trap_helper); return nf_conntrack_helper_register(&snmp_trap_helper);
if (ret < 0) {
nf_conntrack_helper_unregister(&snmp_helper);
return ret;
}
return ret;
} }
static void __exit nf_nat_snmp_basic_fini(void) static void __exit nf_nat_snmp_basic_fini(void)
{ {
RCU_INIT_POINTER(nf_nat_snmp_hook, NULL); RCU_INIT_POINTER(nf_nat_snmp_hook, NULL);
synchronize_rcu();
nf_conntrack_helper_unregister(&snmp_trap_helper); nf_conntrack_helper_unregister(&snmp_trap_helper);
} }
......
...@@ -290,6 +290,7 @@ void nf_conntrack_unregister_notifier(struct net *net, ...@@ -290,6 +290,7 @@ void nf_conntrack_unregister_notifier(struct net *net,
BUG_ON(notify != new); BUG_ON(notify != new);
RCU_INIT_POINTER(net->ct.nf_conntrack_event_cb, NULL); RCU_INIT_POINTER(net->ct.nf_conntrack_event_cb, NULL);
mutex_unlock(&nf_ct_ecache_mutex); mutex_unlock(&nf_ct_ecache_mutex);
/* synchronize_rcu() is called from ctnetlink_exit. */
} }
EXPORT_SYMBOL_GPL(nf_conntrack_unregister_notifier); EXPORT_SYMBOL_GPL(nf_conntrack_unregister_notifier);
...@@ -326,6 +327,7 @@ void nf_ct_expect_unregister_notifier(struct net *net, ...@@ -326,6 +327,7 @@ void nf_ct_expect_unregister_notifier(struct net *net,
BUG_ON(notify != new); BUG_ON(notify != new);
RCU_INIT_POINTER(net->ct.nf_expect_event_cb, NULL); RCU_INIT_POINTER(net->ct.nf_expect_event_cb, NULL);
mutex_unlock(&nf_ct_ecache_mutex); mutex_unlock(&nf_ct_ecache_mutex);
/* synchronize_rcu() is called from ctnetlink_exit. */
} }
EXPORT_SYMBOL_GPL(nf_ct_expect_unregister_notifier); EXPORT_SYMBOL_GPL(nf_ct_expect_unregister_notifier);
......
...@@ -53,7 +53,11 @@ nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, ...@@ -53,7 +53,11 @@ nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id,
rcu_read_lock(); rcu_read_lock();
t = rcu_dereference(nf_ct_ext_types[id]); t = rcu_dereference(nf_ct_ext_types[id]);
BUG_ON(t == NULL); if (!t) {
rcu_read_unlock();
return NULL;
}
off = ALIGN(sizeof(struct nf_ct_ext), t->align); off = ALIGN(sizeof(struct nf_ct_ext), t->align);
len = off + t->len + var_alloc_len; len = off + t->len + var_alloc_len;
alloc_size = t->alloc_size + var_alloc_len; alloc_size = t->alloc_size + var_alloc_len;
...@@ -88,7 +92,10 @@ void *__nf_ct_ext_add_length(struct nf_conn *ct, enum nf_ct_ext_id id, ...@@ -88,7 +92,10 @@ void *__nf_ct_ext_add_length(struct nf_conn *ct, enum nf_ct_ext_id id,
rcu_read_lock(); rcu_read_lock();
t = rcu_dereference(nf_ct_ext_types[id]); t = rcu_dereference(nf_ct_ext_types[id]);
BUG_ON(t == NULL); if (!t) {
rcu_read_unlock();
return NULL;
}
newoff = ALIGN(old->len, t->align); newoff = ALIGN(old->len, t->align);
newlen = newoff + t->len + var_alloc_len; newlen = newoff + t->len + var_alloc_len;
...@@ -175,6 +182,6 @@ void nf_ct_extend_unregister(struct nf_ct_ext_type *type) ...@@ -175,6 +182,6 @@ void nf_ct_extend_unregister(struct nf_ct_ext_type *type)
RCU_INIT_POINTER(nf_ct_ext_types[type->id], NULL); RCU_INIT_POINTER(nf_ct_ext_types[type->id], NULL);
update_alloc_size(type); update_alloc_size(type);
mutex_unlock(&nf_ct_ext_type_mutex); mutex_unlock(&nf_ct_ext_type_mutex);
rcu_barrier(); /* Wait for completion of call_rcu()'s */ synchronize_rcu();
} }
EXPORT_SYMBOL_GPL(nf_ct_extend_unregister); EXPORT_SYMBOL_GPL(nf_ct_extend_unregister);
...@@ -3442,6 +3442,7 @@ static void __exit ctnetlink_exit(void) ...@@ -3442,6 +3442,7 @@ static void __exit ctnetlink_exit(void)
#ifdef CONFIG_NETFILTER_NETLINK_GLUE_CT #ifdef CONFIG_NETFILTER_NETLINK_GLUE_CT
RCU_INIT_POINTER(nfnl_ct_hook, NULL); RCU_INIT_POINTER(nfnl_ct_hook, NULL);
#endif #endif
synchronize_rcu();
} }
module_init(ctnetlink_init); module_init(ctnetlink_init);
......
...@@ -903,6 +903,8 @@ static void __exit nf_nat_cleanup(void) ...@@ -903,6 +903,8 @@ static void __exit nf_nat_cleanup(void)
#ifdef CONFIG_XFRM #ifdef CONFIG_XFRM
RCU_INIT_POINTER(nf_nat_decode_session_hook, NULL); RCU_INIT_POINTER(nf_nat_decode_session_hook, NULL);
#endif #endif
synchronize_rcu();
for (i = 0; i < NFPROTO_NUMPROTO; i++) for (i = 0; i < NFPROTO_NUMPROTO; i++)
kfree(nf_nat_l4protos[i]); kfree(nf_nat_l4protos[i]);
......
...@@ -32,6 +32,13 @@ MODULE_LICENSE("GPL"); ...@@ -32,6 +32,13 @@ MODULE_LICENSE("GPL");
MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>"); MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
MODULE_DESCRIPTION("nfnl_cthelper: User-space connection tracking helpers"); MODULE_DESCRIPTION("nfnl_cthelper: User-space connection tracking helpers");
struct nfnl_cthelper {
struct list_head list;
struct nf_conntrack_helper helper;
};
static LIST_HEAD(nfnl_cthelper_list);
static int static int
nfnl_userspace_cthelper(struct sk_buff *skb, unsigned int protoff, nfnl_userspace_cthelper(struct sk_buff *skb, unsigned int protoff,
struct nf_conn *ct, enum ip_conntrack_info ctinfo) struct nf_conn *ct, enum ip_conntrack_info ctinfo)
...@@ -161,6 +168,7 @@ nfnl_cthelper_parse_expect_policy(struct nf_conntrack_helper *helper, ...@@ -161,6 +168,7 @@ nfnl_cthelper_parse_expect_policy(struct nf_conntrack_helper *helper,
int i, ret; int i, ret;
struct nf_conntrack_expect_policy *expect_policy; struct nf_conntrack_expect_policy *expect_policy;
struct nlattr *tb[NFCTH_POLICY_SET_MAX+1]; struct nlattr *tb[NFCTH_POLICY_SET_MAX+1];
unsigned int class_max;
ret = nla_parse_nested(tb, NFCTH_POLICY_SET_MAX, attr, ret = nla_parse_nested(tb, NFCTH_POLICY_SET_MAX, attr,
nfnl_cthelper_expect_policy_set); nfnl_cthelper_expect_policy_set);
...@@ -170,19 +178,18 @@ nfnl_cthelper_parse_expect_policy(struct nf_conntrack_helper *helper, ...@@ -170,19 +178,18 @@ nfnl_cthelper_parse_expect_policy(struct nf_conntrack_helper *helper,
if (!tb[NFCTH_POLICY_SET_NUM]) if (!tb[NFCTH_POLICY_SET_NUM])
return -EINVAL; return -EINVAL;
helper->expect_class_max = class_max = ntohl(nla_get_be32(tb[NFCTH_POLICY_SET_NUM]));
ntohl(nla_get_be32(tb[NFCTH_POLICY_SET_NUM])); if (class_max == 0)
return -EINVAL;
if (helper->expect_class_max != 0 && if (class_max > NF_CT_MAX_EXPECT_CLASSES)
helper->expect_class_max > NF_CT_MAX_EXPECT_CLASSES)
return -EOVERFLOW; return -EOVERFLOW;
expect_policy = kzalloc(sizeof(struct nf_conntrack_expect_policy) * expect_policy = kzalloc(sizeof(struct nf_conntrack_expect_policy) *
helper->expect_class_max, GFP_KERNEL); class_max, GFP_KERNEL);
if (expect_policy == NULL) if (expect_policy == NULL)
return -ENOMEM; return -ENOMEM;
for (i=0; i<helper->expect_class_max; i++) { for (i = 0; i < class_max; i++) {
if (!tb[NFCTH_POLICY_SET+i]) if (!tb[NFCTH_POLICY_SET+i])
goto err; goto err;
...@@ -191,6 +198,8 @@ nfnl_cthelper_parse_expect_policy(struct nf_conntrack_helper *helper, ...@@ -191,6 +198,8 @@ nfnl_cthelper_parse_expect_policy(struct nf_conntrack_helper *helper,
if (ret < 0) if (ret < 0)
goto err; goto err;
} }
helper->expect_class_max = class_max - 1;
helper->expect_policy = expect_policy; helper->expect_policy = expect_policy;
return 0; return 0;
err: err:
...@@ -203,18 +212,20 @@ nfnl_cthelper_create(const struct nlattr * const tb[], ...@@ -203,18 +212,20 @@ nfnl_cthelper_create(const struct nlattr * const tb[],
struct nf_conntrack_tuple *tuple) struct nf_conntrack_tuple *tuple)
{ {
struct nf_conntrack_helper *helper; struct nf_conntrack_helper *helper;
struct nfnl_cthelper *nfcth;
int ret; int ret;
if (!tb[NFCTH_TUPLE] || !tb[NFCTH_POLICY] || !tb[NFCTH_PRIV_DATA_LEN]) if (!tb[NFCTH_TUPLE] || !tb[NFCTH_POLICY] || !tb[NFCTH_PRIV_DATA_LEN])
return -EINVAL; return -EINVAL;
helper = kzalloc(sizeof(struct nf_conntrack_helper), GFP_KERNEL); nfcth = kzalloc(sizeof(*nfcth), GFP_KERNEL);
if (helper == NULL) if (nfcth == NULL)
return -ENOMEM; return -ENOMEM;
helper = &nfcth->helper;
ret = nfnl_cthelper_parse_expect_policy(helper, tb[NFCTH_POLICY]); ret = nfnl_cthelper_parse_expect_policy(helper, tb[NFCTH_POLICY]);
if (ret < 0) if (ret < 0)
goto err; goto err1;
strncpy(helper->name, nla_data(tb[NFCTH_NAME]), NF_CT_HELPER_NAME_LEN); strncpy(helper->name, nla_data(tb[NFCTH_NAME]), NF_CT_HELPER_NAME_LEN);
helper->data_len = ntohl(nla_get_be32(tb[NFCTH_PRIV_DATA_LEN])); helper->data_len = ntohl(nla_get_be32(tb[NFCTH_PRIV_DATA_LEN]));
...@@ -245,14 +256,100 @@ nfnl_cthelper_create(const struct nlattr * const tb[], ...@@ -245,14 +256,100 @@ nfnl_cthelper_create(const struct nlattr * const tb[],
ret = nf_conntrack_helper_register(helper); ret = nf_conntrack_helper_register(helper);
if (ret < 0) if (ret < 0)
goto err; goto err2;
list_add_tail(&nfcth->list, &nfnl_cthelper_list);
return 0; return 0;
err: err2:
kfree(helper); kfree(helper->expect_policy);
err1:
kfree(nfcth);
return ret; return ret;
} }
static int
nfnl_cthelper_update_policy_one(const struct nf_conntrack_expect_policy *policy,
struct nf_conntrack_expect_policy *new_policy,
const struct nlattr *attr)
{
struct nlattr *tb[NFCTH_POLICY_MAX + 1];
int err;
err = nla_parse_nested(tb, NFCTH_POLICY_MAX, attr,
nfnl_cthelper_expect_pol);
if (err < 0)
return err;
if (!tb[NFCTH_POLICY_NAME] ||
!tb[NFCTH_POLICY_EXPECT_MAX] ||
!tb[NFCTH_POLICY_EXPECT_TIMEOUT])
return -EINVAL;
if (nla_strcmp(tb[NFCTH_POLICY_NAME], policy->name))
return -EBUSY;
new_policy->max_expected =
ntohl(nla_get_be32(tb[NFCTH_POLICY_EXPECT_MAX]));
new_policy->timeout =
ntohl(nla_get_be32(tb[NFCTH_POLICY_EXPECT_TIMEOUT]));
return 0;
}
static int nfnl_cthelper_update_policy_all(struct nlattr *tb[],
struct nf_conntrack_helper *helper)
{
struct nf_conntrack_expect_policy new_policy[helper->expect_class_max + 1];
struct nf_conntrack_expect_policy *policy;
int i, err;
/* Check first that all policy attributes are well-formed, so we don't
* leave things in inconsistent state on errors.
*/
for (i = 0; i < helper->expect_class_max + 1; i++) {
if (!tb[NFCTH_POLICY_SET + i])
return -EINVAL;
err = nfnl_cthelper_update_policy_one(&helper->expect_policy[i],
&new_policy[i],
tb[NFCTH_POLICY_SET + i]);
if (err < 0)
return err;
}
/* Now we can safely update them. */
for (i = 0; i < helper->expect_class_max + 1; i++) {
policy = (struct nf_conntrack_expect_policy *)
&helper->expect_policy[i];
policy->max_expected = new_policy->max_expected;
policy->timeout = new_policy->timeout;
}
return 0;
}
static int nfnl_cthelper_update_policy(struct nf_conntrack_helper *helper,
const struct nlattr *attr)
{
struct nlattr *tb[NFCTH_POLICY_SET_MAX + 1];
unsigned int class_max;
int err;
err = nla_parse_nested(tb, NFCTH_POLICY_SET_MAX, attr,
nfnl_cthelper_expect_policy_set);
if (err < 0)
return err;
if (!tb[NFCTH_POLICY_SET_NUM])
return -EINVAL;
class_max = ntohl(nla_get_be32(tb[NFCTH_POLICY_SET_NUM]));
if (helper->expect_class_max + 1 != class_max)
return -EBUSY;
return nfnl_cthelper_update_policy_all(tb, helper);
}
static int static int
nfnl_cthelper_update(const struct nlattr * const tb[], nfnl_cthelper_update(const struct nlattr * const tb[],
struct nf_conntrack_helper *helper) struct nf_conntrack_helper *helper)
...@@ -263,8 +360,7 @@ nfnl_cthelper_update(const struct nlattr * const tb[], ...@@ -263,8 +360,7 @@ nfnl_cthelper_update(const struct nlattr * const tb[],
return -EBUSY; return -EBUSY;
if (tb[NFCTH_POLICY]) { if (tb[NFCTH_POLICY]) {
ret = nfnl_cthelper_parse_expect_policy(helper, ret = nfnl_cthelper_update_policy(helper, tb[NFCTH_POLICY]);
tb[NFCTH_POLICY]);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
...@@ -293,7 +389,8 @@ static int nfnl_cthelper_new(struct net *net, struct sock *nfnl, ...@@ -293,7 +389,8 @@ static int nfnl_cthelper_new(struct net *net, struct sock *nfnl,
const char *helper_name; const char *helper_name;
struct nf_conntrack_helper *cur, *helper = NULL; struct nf_conntrack_helper *cur, *helper = NULL;
struct nf_conntrack_tuple tuple; struct nf_conntrack_tuple tuple;
int ret = 0, i; struct nfnl_cthelper *nlcth;
int ret = 0;
if (!tb[NFCTH_NAME] || !tb[NFCTH_TUPLE]) if (!tb[NFCTH_NAME] || !tb[NFCTH_TUPLE])
return -EINVAL; return -EINVAL;
...@@ -304,31 +401,22 @@ static int nfnl_cthelper_new(struct net *net, struct sock *nfnl, ...@@ -304,31 +401,22 @@ static int nfnl_cthelper_new(struct net *net, struct sock *nfnl,
if (ret < 0) if (ret < 0)
return ret; return ret;
rcu_read_lock(); list_for_each_entry(nlcth, &nfnl_cthelper_list, list) {
for (i = 0; i < nf_ct_helper_hsize && !helper; i++) { cur = &nlcth->helper;
hlist_for_each_entry_rcu(cur, &nf_ct_helper_hash[i], hnode) {
/* skip non-userspace conntrack helpers. */ if (strncmp(cur->name, helper_name, NF_CT_HELPER_NAME_LEN))
if (!(cur->flags & NF_CT_HELPER_F_USERSPACE)) continue;
continue;
if (strncmp(cur->name, helper_name, if ((tuple.src.l3num != cur->tuple.src.l3num ||
NF_CT_HELPER_NAME_LEN) != 0) tuple.dst.protonum != cur->tuple.dst.protonum))
continue; continue;
if ((tuple.src.l3num != cur->tuple.src.l3num || if (nlh->nlmsg_flags & NLM_F_EXCL)
tuple.dst.protonum != cur->tuple.dst.protonum)) return -EEXIST;
continue;
if (nlh->nlmsg_flags & NLM_F_EXCL) { helper = cur;
ret = -EEXIST; break;
goto err;
}
helper = cur;
break;
}
} }
rcu_read_unlock();
if (helper == NULL) if (helper == NULL)
ret = nfnl_cthelper_create(tb, &tuple); ret = nfnl_cthelper_create(tb, &tuple);
...@@ -336,9 +424,6 @@ static int nfnl_cthelper_new(struct net *net, struct sock *nfnl, ...@@ -336,9 +424,6 @@ static int nfnl_cthelper_new(struct net *net, struct sock *nfnl,
ret = nfnl_cthelper_update(tb, helper); ret = nfnl_cthelper_update(tb, helper);
return ret; return ret;
err:
rcu_read_unlock();
return ret;
} }
static int static int
...@@ -377,10 +462,10 @@ nfnl_cthelper_dump_policy(struct sk_buff *skb, ...@@ -377,10 +462,10 @@ nfnl_cthelper_dump_policy(struct sk_buff *skb,
goto nla_put_failure; goto nla_put_failure;
if (nla_put_be32(skb, NFCTH_POLICY_SET_NUM, if (nla_put_be32(skb, NFCTH_POLICY_SET_NUM,
htonl(helper->expect_class_max))) htonl(helper->expect_class_max + 1)))
goto nla_put_failure; goto nla_put_failure;
for (i=0; i<helper->expect_class_max; i++) { for (i = 0; i < helper->expect_class_max + 1; i++) {
nest_parms2 = nla_nest_start(skb, nest_parms2 = nla_nest_start(skb,
(NFCTH_POLICY_SET+i) | NLA_F_NESTED); (NFCTH_POLICY_SET+i) | NLA_F_NESTED);
if (nest_parms2 == NULL) if (nest_parms2 == NULL)
...@@ -502,11 +587,12 @@ static int nfnl_cthelper_get(struct net *net, struct sock *nfnl, ...@@ -502,11 +587,12 @@ static int nfnl_cthelper_get(struct net *net, struct sock *nfnl,
struct sk_buff *skb, const struct nlmsghdr *nlh, struct sk_buff *skb, const struct nlmsghdr *nlh,
const struct nlattr * const tb[]) const struct nlattr * const tb[])
{ {
int ret = -ENOENT, i; int ret = -ENOENT;
struct nf_conntrack_helper *cur; struct nf_conntrack_helper *cur;
struct sk_buff *skb2; struct sk_buff *skb2;
char *helper_name = NULL; char *helper_name = NULL;
struct nf_conntrack_tuple tuple; struct nf_conntrack_tuple tuple;
struct nfnl_cthelper *nlcth;
bool tuple_set = false; bool tuple_set = false;
if (nlh->nlmsg_flags & NLM_F_DUMP) { if (nlh->nlmsg_flags & NLM_F_DUMP) {
...@@ -527,45 +613,39 @@ static int nfnl_cthelper_get(struct net *net, struct sock *nfnl, ...@@ -527,45 +613,39 @@ static int nfnl_cthelper_get(struct net *net, struct sock *nfnl,
tuple_set = true; tuple_set = true;
} }
for (i = 0; i < nf_ct_helper_hsize; i++) { list_for_each_entry(nlcth, &nfnl_cthelper_list, list) {
hlist_for_each_entry_rcu(cur, &nf_ct_helper_hash[i], hnode) { cur = &nlcth->helper;
if (helper_name &&
strncmp(cur->name, helper_name, NF_CT_HELPER_NAME_LEN))
continue;
/* skip non-userspace conntrack helpers. */ if (tuple_set &&
if (!(cur->flags & NF_CT_HELPER_F_USERSPACE)) (tuple.src.l3num != cur->tuple.src.l3num ||
continue; tuple.dst.protonum != cur->tuple.dst.protonum))
continue;
if (helper_name && strncmp(cur->name, helper_name, skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
NF_CT_HELPER_NAME_LEN) != 0) { if (skb2 == NULL) {
continue; ret = -ENOMEM;
} break;
if (tuple_set && }
(tuple.src.l3num != cur->tuple.src.l3num ||
tuple.dst.protonum != cur->tuple.dst.protonum))
continue;
skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (skb2 == NULL) {
ret = -ENOMEM;
break;
}
ret = nfnl_cthelper_fill_info(skb2, NETLINK_CB(skb).portid, ret = nfnl_cthelper_fill_info(skb2, NETLINK_CB(skb).portid,
nlh->nlmsg_seq, nlh->nlmsg_seq,
NFNL_MSG_TYPE(nlh->nlmsg_type), NFNL_MSG_TYPE(nlh->nlmsg_type),
NFNL_MSG_CTHELPER_NEW, cur); NFNL_MSG_CTHELPER_NEW, cur);
if (ret <= 0) { if (ret <= 0) {
kfree_skb(skb2); kfree_skb(skb2);
break; break;
} }
ret = netlink_unicast(nfnl, skb2, NETLINK_CB(skb).portid, ret = netlink_unicast(nfnl, skb2, NETLINK_CB(skb).portid,
MSG_DONTWAIT); MSG_DONTWAIT);
if (ret > 0) if (ret > 0)
ret = 0; ret = 0;
/* this avoids a loop in nfnetlink. */ /* this avoids a loop in nfnetlink. */
return ret == -EAGAIN ? -ENOBUFS : ret; return ret == -EAGAIN ? -ENOBUFS : ret;
}
} }
return ret; return ret;
} }
...@@ -576,10 +656,10 @@ static int nfnl_cthelper_del(struct net *net, struct sock *nfnl, ...@@ -576,10 +656,10 @@ static int nfnl_cthelper_del(struct net *net, struct sock *nfnl,
{ {
char *helper_name = NULL; char *helper_name = NULL;
struct nf_conntrack_helper *cur; struct nf_conntrack_helper *cur;
struct hlist_node *tmp;
struct nf_conntrack_tuple tuple; struct nf_conntrack_tuple tuple;
bool tuple_set = false, found = false; bool tuple_set = false, found = false;
int i, j = 0, ret; struct nfnl_cthelper *nlcth, *n;
int j = 0, ret;
if (tb[NFCTH_NAME]) if (tb[NFCTH_NAME])
helper_name = nla_data(tb[NFCTH_NAME]); helper_name = nla_data(tb[NFCTH_NAME]);
...@@ -592,28 +672,27 @@ static int nfnl_cthelper_del(struct net *net, struct sock *nfnl, ...@@ -592,28 +672,27 @@ static int nfnl_cthelper_del(struct net *net, struct sock *nfnl,
tuple_set = true; tuple_set = true;
} }
for (i = 0; i < nf_ct_helper_hsize; i++) { list_for_each_entry_safe(nlcth, n, &nfnl_cthelper_list, list) {
hlist_for_each_entry_safe(cur, tmp, &nf_ct_helper_hash[i], cur = &nlcth->helper;
hnode) { j++;
/* skip non-userspace conntrack helpers. */
if (!(cur->flags & NF_CT_HELPER_F_USERSPACE))
continue;
j++; if (helper_name &&
strncmp(cur->name, helper_name, NF_CT_HELPER_NAME_LEN))
continue;
if (helper_name && strncmp(cur->name, helper_name, if (tuple_set &&
NF_CT_HELPER_NAME_LEN) != 0) { (tuple.src.l3num != cur->tuple.src.l3num ||
continue; tuple.dst.protonum != cur->tuple.dst.protonum))
} continue;
if (tuple_set &&
(tuple.src.l3num != cur->tuple.src.l3num ||
tuple.dst.protonum != cur->tuple.dst.protonum))
continue;
found = true; found = true;
nf_conntrack_helper_unregister(cur); nf_conntrack_helper_unregister(cur);
} kfree(cur->expect_policy);
list_del(&nlcth->list);
kfree(nlcth);
} }
/* Make sure we return success if we flush and there is no helpers */ /* Make sure we return success if we flush and there is no helpers */
return (found || j == 0) ? 0 : -ENOENT; return (found || j == 0) ? 0 : -ENOENT;
} }
...@@ -662,20 +741,16 @@ static int __init nfnl_cthelper_init(void) ...@@ -662,20 +741,16 @@ static int __init nfnl_cthelper_init(void)
static void __exit nfnl_cthelper_exit(void) static void __exit nfnl_cthelper_exit(void)
{ {
struct nf_conntrack_helper *cur; struct nf_conntrack_helper *cur;
struct hlist_node *tmp; struct nfnl_cthelper *nlcth, *n;
int i;
nfnetlink_subsys_unregister(&nfnl_cthelper_subsys); nfnetlink_subsys_unregister(&nfnl_cthelper_subsys);
for (i=0; i<nf_ct_helper_hsize; i++) { list_for_each_entry_safe(nlcth, n, &nfnl_cthelper_list, list) {
hlist_for_each_entry_safe(cur, tmp, &nf_ct_helper_hash[i], cur = &nlcth->helper;
hnode) {
/* skip non-userspace conntrack helpers. */
if (!(cur->flags & NF_CT_HELPER_F_USERSPACE))
continue;
nf_conntrack_helper_unregister(cur); nf_conntrack_helper_unregister(cur);
} kfree(cur->expect_policy);
kfree(nlcth);
} }
} }
......
...@@ -646,8 +646,8 @@ static void __exit cttimeout_exit(void) ...@@ -646,8 +646,8 @@ static void __exit cttimeout_exit(void)
#ifdef CONFIG_NF_CONNTRACK_TIMEOUT #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
RCU_INIT_POINTER(nf_ct_timeout_find_get_hook, NULL); RCU_INIT_POINTER(nf_ct_timeout_find_get_hook, NULL);
RCU_INIT_POINTER(nf_ct_timeout_put_hook, NULL); RCU_INIT_POINTER(nf_ct_timeout_put_hook, NULL);
synchronize_rcu();
#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
rcu_barrier();
} }
module_init(cttimeout_init); module_init(cttimeout_init);
......
...@@ -443,7 +443,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, ...@@ -443,7 +443,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
skb = alloc_skb(size, GFP_ATOMIC); skb = alloc_skb(size, GFP_ATOMIC);
if (!skb) { if (!skb) {
skb_tx_error(entskb); skb_tx_error(entskb);
return NULL; goto nlmsg_failure;
} }
nlh = nlmsg_put(skb, 0, 0, nlh = nlmsg_put(skb, 0, 0,
...@@ -452,7 +452,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, ...@@ -452,7 +452,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
if (!nlh) { if (!nlh) {
skb_tx_error(entskb); skb_tx_error(entskb);
kfree_skb(skb); kfree_skb(skb);
return NULL; goto nlmsg_failure;
} }
nfmsg = nlmsg_data(nlh); nfmsg = nlmsg_data(nlh);
nfmsg->nfgen_family = entry->state.pf; nfmsg->nfgen_family = entry->state.pf;
...@@ -598,12 +598,17 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, ...@@ -598,12 +598,17 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
} }
nlh->nlmsg_len = skb->len; nlh->nlmsg_len = skb->len;
if (seclen)
security_release_secctx(secdata, seclen);
return skb; return skb;
nla_put_failure: nla_put_failure:
skb_tx_error(entskb); skb_tx_error(entskb);
kfree_skb(skb); kfree_skb(skb);
net_err_ratelimited("nf_queue: error creating packet message\n"); net_err_ratelimited("nf_queue: error creating packet message\n");
nlmsg_failure:
if (seclen)
security_release_secctx(secdata, seclen);
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment