mirror of https://gitee.com/openkylin/linux.git
Merge branch 'master' of git://blackhole.kfki.hu/nf
Jozsef Kadlecsik says: ==================== Please apply the next patch against the nf tree: - Deniz Eren reported that parallel flush/dump of list:set type of sets can lead to kernel crash. The bug was due to non-RCU compatible flushing, listing in the set type, fixed by me. - Julia Lawall pointed out that IPSET_ATTR_ETHER netlink attribute length was not checked explicitly. The patch adds the missing checkings. ==================== Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
This commit is contained in:
commit
793882bfc3
|
@ -267,6 +267,8 @@ bitmap_ipmac_uadt(struct ip_set *set, struct nlattr *tb[],
|
||||||
|
|
||||||
e.id = ip_to_id(map, ip);
|
e.id = ip_to_id(map, ip);
|
||||||
if (tb[IPSET_ATTR_ETHER]) {
|
if (tb[IPSET_ATTR_ETHER]) {
|
||||||
|
if (nla_len(tb[IPSET_ATTR_ETHER]) != ETH_ALEN)
|
||||||
|
return -IPSET_ERR_PROTOCOL;
|
||||||
memcpy(e.ether, nla_data(tb[IPSET_ATTR_ETHER]), ETH_ALEN);
|
memcpy(e.ether, nla_data(tb[IPSET_ATTR_ETHER]), ETH_ALEN);
|
||||||
e.add_mac = 1;
|
e.add_mac = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -985,6 +985,9 @@ static int ip_set_destroy(struct net *net, struct sock *ctnl,
|
||||||
if (unlikely(protocol_failed(attr)))
|
if (unlikely(protocol_failed(attr)))
|
||||||
return -IPSET_ERR_PROTOCOL;
|
return -IPSET_ERR_PROTOCOL;
|
||||||
|
|
||||||
|
/* Must wait for flush to be really finished in list:set */
|
||||||
|
rcu_barrier();
|
||||||
|
|
||||||
/* Commands are serialized and references are
|
/* Commands are serialized and references are
|
||||||
* protected by the ip_set_ref_lock.
|
* protected by the ip_set_ref_lock.
|
||||||
* External systems (i.e. xt_set) must call
|
* External systems (i.e. xt_set) must call
|
||||||
|
|
|
@ -110,7 +110,8 @@ hash_mac4_uadt(struct ip_set *set, struct nlattr *tb[],
|
||||||
if (tb[IPSET_ATTR_LINENO])
|
if (tb[IPSET_ATTR_LINENO])
|
||||||
*lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);
|
*lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);
|
||||||
|
|
||||||
if (unlikely(!tb[IPSET_ATTR_ETHER]))
|
if (unlikely(!tb[IPSET_ATTR_ETHER] ||
|
||||||
|
nla_len(tb[IPSET_ATTR_ETHER]) != ETH_ALEN))
|
||||||
return -IPSET_ERR_PROTOCOL;
|
return -IPSET_ERR_PROTOCOL;
|
||||||
|
|
||||||
ret = ip_set_get_extensions(set, tb, &ext);
|
ret = ip_set_get_extensions(set, tb, &ext);
|
||||||
|
|
|
@ -30,6 +30,7 @@ MODULE_ALIAS("ip_set_list:set");
|
||||||
struct set_elem {
|
struct set_elem {
|
||||||
struct rcu_head rcu;
|
struct rcu_head rcu;
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
|
struct ip_set *set; /* Sigh, in order to cleanup reference */
|
||||||
ip_set_id_t id;
|
ip_set_id_t id;
|
||||||
} __aligned(__alignof__(u64));
|
} __aligned(__alignof__(u64));
|
||||||
|
|
||||||
|
@ -151,30 +152,29 @@ list_set_kadt(struct ip_set *set, const struct sk_buff *skb,
|
||||||
/* Userspace interfaces: we are protected by the nfnl mutex */
|
/* Userspace interfaces: we are protected by the nfnl mutex */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
__list_set_del(struct ip_set *set, struct set_elem *e)
|
__list_set_del_rcu(struct rcu_head * rcu)
|
||||||
{
|
{
|
||||||
|
struct set_elem *e = container_of(rcu, struct set_elem, rcu);
|
||||||
|
struct ip_set *set = e->set;
|
||||||
struct list_set *map = set->data;
|
struct list_set *map = set->data;
|
||||||
|
|
||||||
ip_set_put_byindex(map->net, e->id);
|
ip_set_put_byindex(map->net, e->id);
|
||||||
/* We may call it, because we don't have a to be destroyed
|
|
||||||
* extension which is used by the kernel.
|
|
||||||
*/
|
|
||||||
ip_set_ext_destroy(set, e);
|
ip_set_ext_destroy(set, e);
|
||||||
kfree_rcu(e, rcu);
|
kfree(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
list_set_del(struct ip_set *set, struct set_elem *e)
|
list_set_del(struct ip_set *set, struct set_elem *e)
|
||||||
{
|
{
|
||||||
list_del_rcu(&e->list);
|
list_del_rcu(&e->list);
|
||||||
__list_set_del(set, e);
|
call_rcu(&e->rcu, __list_set_del_rcu);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
list_set_replace(struct ip_set *set, struct set_elem *e, struct set_elem *old)
|
list_set_replace(struct set_elem *e, struct set_elem *old)
|
||||||
{
|
{
|
||||||
list_replace_rcu(&old->list, &e->list);
|
list_replace_rcu(&old->list, &e->list);
|
||||||
__list_set_del(set, old);
|
call_rcu(&old->rcu, __list_set_del_rcu);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -244,9 +244,6 @@ list_set_uadd(struct ip_set *set, void *value, const struct ip_set_ext *ext,
|
||||||
struct set_elem *e, *n, *prev, *next;
|
struct set_elem *e, *n, *prev, *next;
|
||||||
bool flag_exist = flags & IPSET_FLAG_EXIST;
|
bool flag_exist = flags & IPSET_FLAG_EXIST;
|
||||||
|
|
||||||
if (SET_WITH_TIMEOUT(set))
|
|
||||||
set_cleanup_entries(set);
|
|
||||||
|
|
||||||
/* Find where to add the new entry */
|
/* Find where to add the new entry */
|
||||||
n = prev = next = NULL;
|
n = prev = next = NULL;
|
||||||
list_for_each_entry(e, &map->members, list) {
|
list_for_each_entry(e, &map->members, list) {
|
||||||
|
@ -301,10 +298,11 @@ list_set_uadd(struct ip_set *set, void *value, const struct ip_set_ext *ext,
|
||||||
if (!e)
|
if (!e)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
e->id = d->id;
|
e->id = d->id;
|
||||||
|
e->set = set;
|
||||||
INIT_LIST_HEAD(&e->list);
|
INIT_LIST_HEAD(&e->list);
|
||||||
list_set_init_extensions(set, ext, e);
|
list_set_init_extensions(set, ext, e);
|
||||||
if (n)
|
if (n)
|
||||||
list_set_replace(set, e, n);
|
list_set_replace(e, n);
|
||||||
else if (next)
|
else if (next)
|
||||||
list_add_tail_rcu(&e->list, &next->list);
|
list_add_tail_rcu(&e->list, &next->list);
|
||||||
else if (prev)
|
else if (prev)
|
||||||
|
@ -431,6 +429,7 @@ list_set_destroy(struct ip_set *set)
|
||||||
|
|
||||||
if (SET_WITH_TIMEOUT(set))
|
if (SET_WITH_TIMEOUT(set))
|
||||||
del_timer_sync(&map->gc);
|
del_timer_sync(&map->gc);
|
||||||
|
|
||||||
list_for_each_entry_safe(e, n, &map->members, list) {
|
list_for_each_entry_safe(e, n, &map->members, list) {
|
||||||
list_del(&e->list);
|
list_del(&e->list);
|
||||||
ip_set_put_byindex(map->net, e->id);
|
ip_set_put_byindex(map->net, e->id);
|
||||||
|
@ -450,8 +449,10 @@ list_set_head(struct ip_set *set, struct sk_buff *skb)
|
||||||
struct set_elem *e;
|
struct set_elem *e;
|
||||||
u32 n = 0;
|
u32 n = 0;
|
||||||
|
|
||||||
list_for_each_entry(e, &map->members, list)
|
rcu_read_lock();
|
||||||
|
list_for_each_entry_rcu(e, &map->members, list)
|
||||||
n++;
|
n++;
|
||||||
|
rcu_read_unlock();
|
||||||
|
|
||||||
nested = ipset_nest_start(skb, IPSET_ATTR_DATA);
|
nested = ipset_nest_start(skb, IPSET_ATTR_DATA);
|
||||||
if (!nested)
|
if (!nested)
|
||||||
|
@ -483,33 +484,25 @@ list_set_list(const struct ip_set *set,
|
||||||
atd = ipset_nest_start(skb, IPSET_ATTR_ADT);
|
atd = ipset_nest_start(skb, IPSET_ATTR_ADT);
|
||||||
if (!atd)
|
if (!atd)
|
||||||
return -EMSGSIZE;
|
return -EMSGSIZE;
|
||||||
list_for_each_entry(e, &map->members, list) {
|
|
||||||
if (i == first)
|
|
||||||
break;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
list_for_each_entry_from(e, &map->members, list) {
|
list_for_each_entry_rcu(e, &map->members, list) {
|
||||||
|
if (i < first ||
|
||||||
|
(SET_WITH_TIMEOUT(set) &&
|
||||||
|
ip_set_timeout_expired(ext_timeout(e, set)))) {
|
||||||
i++;
|
i++;
|
||||||
if (SET_WITH_TIMEOUT(set) &&
|
|
||||||
ip_set_timeout_expired(ext_timeout(e, set)))
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
nested = ipset_nest_start(skb, IPSET_ATTR_DATA);
|
nested = ipset_nest_start(skb, IPSET_ATTR_DATA);
|
||||||
if (!nested) {
|
if (!nested)
|
||||||
if (i == first) {
|
|
||||||
nla_nest_cancel(skb, atd);
|
|
||||||
ret = -EMSGSIZE;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
goto nla_put_failure;
|
goto nla_put_failure;
|
||||||
}
|
|
||||||
if (nla_put_string(skb, IPSET_ATTR_NAME,
|
if (nla_put_string(skb, IPSET_ATTR_NAME,
|
||||||
ip_set_name_byindex(map->net, e->id)))
|
ip_set_name_byindex(map->net, e->id)))
|
||||||
goto nla_put_failure;
|
goto nla_put_failure;
|
||||||
if (ip_set_put_extensions(skb, set, e, true))
|
if (ip_set_put_extensions(skb, set, e, true))
|
||||||
goto nla_put_failure;
|
goto nla_put_failure;
|
||||||
ipset_nest_end(skb, nested);
|
ipset_nest_end(skb, nested);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ipset_nest_end(skb, atd);
|
ipset_nest_end(skb, atd);
|
||||||
|
@ -520,10 +513,12 @@ list_set_list(const struct ip_set *set,
|
||||||
nla_put_failure:
|
nla_put_failure:
|
||||||
nla_nest_cancel(skb, nested);
|
nla_nest_cancel(skb, nested);
|
||||||
if (unlikely(i == first)) {
|
if (unlikely(i == first)) {
|
||||||
|
nla_nest_cancel(skb, atd);
|
||||||
cb->args[IPSET_CB_ARG0] = 0;
|
cb->args[IPSET_CB_ARG0] = 0;
|
||||||
ret = -EMSGSIZE;
|
ret = -EMSGSIZE;
|
||||||
|
} else {
|
||||||
|
cb->args[IPSET_CB_ARG0] = i;
|
||||||
}
|
}
|
||||||
cb->args[IPSET_CB_ARG0] = i - 1;
|
|
||||||
ipset_nest_end(skb, atd);
|
ipset_nest_end(skb, atd);
|
||||||
out:
|
out:
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
|
|
Loading…
Reference in New Issue