mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-23 07:12:09 +00:00
inet_diag: fix access to tcp cc information
Two different problems are fixed here : 1) inet_sk_diag_fill() might be called without socket lock held. icsk->icsk_ca_ops can change under us and module be unloaded. -> Access to freed memory. Fix this using rcu_read_lock() to prevent module unload. 2) Some TCP Congestion Control modules provide information but again this is not safe against icsk->icsk_ca_ops change and nla_put() errors were ignored. Some sockets could not get the additional info if skb was almost full. Fix this by returning a status from get_info() handlers and using rcu protection as well. Signed-off-by: Eric Dumazet <edumazet@google.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
fad9dfefea
commit
521f1cf1db
7 changed files with 36 additions and 18 deletions
|
@ -111,6 +111,7 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
|
|||
const struct nlmsghdr *unlh)
|
||||
{
|
||||
const struct inet_sock *inet = inet_sk(sk);
|
||||
const struct tcp_congestion_ops *ca_ops;
|
||||
const struct inet_diag_handler *handler;
|
||||
int ext = req->idiag_ext;
|
||||
struct inet_diag_msg *r;
|
||||
|
@ -208,16 +209,31 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
|
|||
info = nla_data(attr);
|
||||
}
|
||||
|
||||
if ((ext & (1 << (INET_DIAG_CONG - 1))) && icsk->icsk_ca_ops)
|
||||
if (nla_put_string(skb, INET_DIAG_CONG,
|
||||
icsk->icsk_ca_ops->name) < 0)
|
||||
if (ext & (1 << (INET_DIAG_CONG - 1))) {
|
||||
int err = 0;
|
||||
|
||||
rcu_read_lock();
|
||||
ca_ops = READ_ONCE(icsk->icsk_ca_ops);
|
||||
if (ca_ops)
|
||||
err = nla_put_string(skb, INET_DIAG_CONG, ca_ops->name);
|
||||
rcu_read_unlock();
|
||||
if (err < 0)
|
||||
goto errout;
|
||||
}
|
||||
|
||||
handler->idiag_get_info(sk, r, info);
|
||||
|
||||
if (sk->sk_state < TCP_TIME_WAIT &&
|
||||
icsk->icsk_ca_ops && icsk->icsk_ca_ops->get_info)
|
||||
icsk->icsk_ca_ops->get_info(sk, ext, skb);
|
||||
if (sk->sk_state < TCP_TIME_WAIT) {
|
||||
int err = 0;
|
||||
|
||||
rcu_read_lock();
|
||||
ca_ops = READ_ONCE(icsk->icsk_ca_ops);
|
||||
if (ca_ops && ca_ops->get_info)
|
||||
err = ca_ops->get_info(sk, ext, skb);
|
||||
rcu_read_unlock();
|
||||
if (err < 0)
|
||||
goto errout;
|
||||
}
|
||||
|
||||
out:
|
||||
nlmsg_end(skb, nlh);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue