tcp: md5: use sock_kmalloc() to limit md5 keys
There is no limit on number of MD5 keys an application can attach to a tcp socket. This patch adds a per tcp socket limit based on /proc/sys/net/core/optmem_max With current default optmem_max values, this allows about 150 keys on 64bit arches, and 88 keys on 32bit arches. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Родитель
a915da9b69
Коммит
5f3d9cb296
|
@ -943,11 +943,11 @@ int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr,
|
||||||
tp->md5sig_info = md5sig;
|
tp->md5sig_info = md5sig;
|
||||||
}
|
}
|
||||||
|
|
||||||
key = kmalloc(sizeof(*key), gfp);
|
key = sock_kmalloc(sk, sizeof(*key), gfp);
|
||||||
if (!key)
|
if (!key)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
if (hlist_empty(&md5sig->head) && !tcp_alloc_md5sig_pool(sk)) {
|
if (hlist_empty(&md5sig->head) && !tcp_alloc_md5sig_pool(sk)) {
|
||||||
kfree(key);
|
sock_kfree_s(sk, key, sizeof(*key));
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -971,6 +971,7 @@ int tcp_md5_do_del(struct sock *sk, const union tcp_md5_addr *addr, int family)
|
||||||
if (!key)
|
if (!key)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
hlist_del_rcu(&key->node);
|
hlist_del_rcu(&key->node);
|
||||||
|
atomic_sub(sizeof(*key), &sk->sk_omem_alloc);
|
||||||
kfree_rcu(key, rcu);
|
kfree_rcu(key, rcu);
|
||||||
if (hlist_empty(&tp->md5sig_info->head))
|
if (hlist_empty(&tp->md5sig_info->head))
|
||||||
tcp_free_md5sig_pool();
|
tcp_free_md5sig_pool();
|
||||||
|
@ -988,6 +989,7 @@ void tcp_clear_md5_list(struct sock *sk)
|
||||||
tcp_free_md5sig_pool();
|
tcp_free_md5sig_pool();
|
||||||
hlist_for_each_entry_safe(key, pos, n, &tp->md5sig_info->head, node) {
|
hlist_for_each_entry_safe(key, pos, n, &tp->md5sig_info->head, node) {
|
||||||
hlist_del_rcu(&key->node);
|
hlist_del_rcu(&key->node);
|
||||||
|
atomic_sub(sizeof(*key), &sk->sk_omem_alloc);
|
||||||
kfree_rcu(key, rcu);
|
kfree_rcu(key, rcu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче