Commit 45122ca2 authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller

sctp: Add RCU protection to assoc->transport_addr_list

peer.transport_addr_list is currently only protected by sk_sock
which is inpractical to acquire for procfs dumping purposes.

This patch adds RCU protection allowing for the procfs readers to
enter RCU read-side critical sections.

Modification of the list continues to be serialized via sk_lock.

V2: Use list_del_rcu() in sctp_association_free() to be safe
    Skip transports marked dead when dumping for procfs

Cc: Vlad Yasevich <vyasevich@gmail.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Acked-by: default avatarVlad Yasevich <vyasevich@gmail.com>
Acked-by: default avatarNeil Horman <nhorman@tuxdriver.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0b0fe913
...@@ -949,6 +949,8 @@ struct sctp_transport { ...@@ -949,6 +949,8 @@ struct sctp_transport {
/* 64-bit random number sent with heartbeat. */ /* 64-bit random number sent with heartbeat. */
__u64 hb_nonce; __u64 hb_nonce;
struct rcu_head rcu;
}; };
struct sctp_transport *sctp_transport_new(struct net *, const union sctp_addr *, struct sctp_transport *sctp_transport_new(struct net *, const union sctp_addr *,
......
...@@ -448,7 +448,7 @@ void sctp_association_free(struct sctp_association *asoc) ...@@ -448,7 +448,7 @@ void sctp_association_free(struct sctp_association *asoc)
/* Release the transport structures. */ /* Release the transport structures. */
list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) { list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
transport = list_entry(pos, struct sctp_transport, transports); transport = list_entry(pos, struct sctp_transport, transports);
list_del(pos); list_del_rcu(pos);
sctp_transport_free(transport); sctp_transport_free(transport);
} }
...@@ -568,7 +568,7 @@ void sctp_assoc_rm_peer(struct sctp_association *asoc, ...@@ -568,7 +568,7 @@ void sctp_assoc_rm_peer(struct sctp_association *asoc,
sctp_assoc_update_retran_path(asoc); sctp_assoc_update_retran_path(asoc);
/* Remove this peer from the list. */ /* Remove this peer from the list. */
list_del(&peer->transports); list_del_rcu(&peer->transports);
/* Get the first transport of asoc. */ /* Get the first transport of asoc. */
pos = asoc->peer.transport_addr_list.next; pos = asoc->peer.transport_addr_list.next;
...@@ -769,7 +769,7 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc, ...@@ -769,7 +769,7 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
peer->state = peer_state; peer->state = peer_state;
/* Attach the remote transport to our asoc. */ /* Attach the remote transport to our asoc. */
list_add_tail(&peer->transports, &asoc->peer.transport_addr_list); list_add_tail_rcu(&peer->transports, &asoc->peer.transport_addr_list);
asoc->peer.transport_count++; asoc->peer.transport_count++;
/* If we do not yet have a primary path, set one. */ /* If we do not yet have a primary path, set one. */
......
...@@ -162,15 +162,20 @@ static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_associa ...@@ -162,15 +162,20 @@ static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_associa
struct sctp_af *af; struct sctp_af *af;
primary = &assoc->peer.primary_addr; primary = &assoc->peer.primary_addr;
list_for_each_entry(transport, &assoc->peer.transport_addr_list, rcu_read_lock();
list_for_each_entry_rcu(transport, &assoc->peer.transport_addr_list,
transports) { transports) {
addr = &transport->ipaddr; addr = &transport->ipaddr;
if (transport->dead)
continue;
af = sctp_get_af_specific(addr->sa.sa_family); af = sctp_get_af_specific(addr->sa.sa_family);
if (af->cmp_addr(addr, primary)) { if (af->cmp_addr(addr, primary)) {
seq_printf(seq, "*"); seq_printf(seq, "*");
} }
af->seq_dump_addr(seq, addr); af->seq_dump_addr(seq, addr);
} }
rcu_read_unlock();
} }
static void * sctp_eps_seq_start(struct seq_file *seq, loff_t *pos) static void * sctp_eps_seq_start(struct seq_file *seq, loff_t *pos)
...@@ -441,12 +446,16 @@ static int sctp_remaddr_seq_show(struct seq_file *seq, void *v) ...@@ -441,12 +446,16 @@ static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
head = &sctp_assoc_hashtable[hash]; head = &sctp_assoc_hashtable[hash];
sctp_local_bh_disable(); sctp_local_bh_disable();
read_lock(&head->lock); read_lock(&head->lock);
rcu_read_lock();
sctp_for_each_hentry(epb, node, &head->chain) { sctp_for_each_hentry(epb, node, &head->chain) {
if (!net_eq(sock_net(epb->sk), seq_file_net(seq))) if (!net_eq(sock_net(epb->sk), seq_file_net(seq)))
continue; continue;
assoc = sctp_assoc(epb); assoc = sctp_assoc(epb);
list_for_each_entry(tsp, &assoc->peer.transport_addr_list, list_for_each_entry_rcu(tsp, &assoc->peer.transport_addr_list,
transports) { transports) {
if (tsp->dead)
continue;
/* /*
* The remote address (ADDR) * The remote address (ADDR)
*/ */
...@@ -492,6 +501,7 @@ static int sctp_remaddr_seq_show(struct seq_file *seq, void *v) ...@@ -492,6 +501,7 @@ static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
} }
} }
rcu_read_unlock();
read_unlock(&head->lock); read_unlock(&head->lock);
sctp_local_bh_enable(); sctp_local_bh_enable();
......
...@@ -163,13 +163,11 @@ void sctp_transport_free(struct sctp_transport *transport) ...@@ -163,13 +163,11 @@ void sctp_transport_free(struct sctp_transport *transport)
sctp_transport_put(transport); sctp_transport_put(transport);
} }
/* Destroy the transport data structure. static void sctp_transport_destroy_rcu(struct rcu_head *head)
* Assumes there are no more users of this structure.
*/
static void sctp_transport_destroy(struct sctp_transport *transport)
{ {
SCTP_ASSERT(transport->dead, "Transport is not dead", return); struct sctp_transport *transport;
transport = container_of(head, struct sctp_transport, rcu);
if (transport->asoc) if (transport->asoc)
sctp_association_put(transport->asoc); sctp_association_put(transport->asoc);
...@@ -180,6 +178,16 @@ static void sctp_transport_destroy(struct sctp_transport *transport) ...@@ -180,6 +178,16 @@ static void sctp_transport_destroy(struct sctp_transport *transport)
SCTP_DBG_OBJCNT_DEC(transport); SCTP_DBG_OBJCNT_DEC(transport);
} }
/* Destroy the transport data structure.
* Assumes there are no more users of this structure.
*/
static void sctp_transport_destroy(struct sctp_transport *transport)
{
SCTP_ASSERT(transport->dead, "Transport is not dead", return);
call_rcu(&transport->rcu, sctp_transport_destroy_rcu);
}
/* Start T3_rtx timer if it is not already running and update the heartbeat /* Start T3_rtx timer if it is not already running and update the heartbeat
* timer. This routine is called every time a DATA chunk is sent. * timer. This routine is called every time a DATA chunk is sent.
*/ */
......
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