Skip to content

Commit fba4c33

Browse files
lxindavem330
authored andcommitted
sctp: hold transport before we access t->asoc in sctp proc
Previously, before rhashtable, /proc assoc listing was done by read-locking the entire hash entry and dumping all assocs at once, so we were sure that the assoc wasn't freed because it wouldn't be possible to remove it from the hash meanwhile. Now we use rhashtable to list transports, and dump entries one by one. That is, now we have to check if the assoc is still a good one, as the transport we got may be being freed. Signed-off-by: Xin Long <lucien.xin@gmail.com> Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1eed677 commit fba4c33

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

net/sctp/proc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
380380
}
381381

382382
transport = (struct sctp_transport *)v;
383+
if (!sctp_transport_hold(transport))
384+
return 0;
383385
assoc = transport->asoc;
384386
epb = &assoc->base;
385387
sk = epb->sk;
@@ -412,6 +414,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
412414
sk->sk_rcvbuf);
413415
seq_printf(seq, "\n");
414416

417+
sctp_transport_put(transport);
418+
415419
return 0;
416420
}
417421

@@ -489,6 +493,8 @@ static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
489493
}
490494

491495
tsp = (struct sctp_transport *)v;
496+
if (!sctp_transport_hold(tsp))
497+
return 0;
492498
assoc = tsp->asoc;
493499

494500
list_for_each_entry_rcu(tsp, &assoc->peer.transport_addr_list,
@@ -544,6 +550,8 @@ static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
544550
seq_printf(seq, "\n");
545551
}
546552

553+
sctp_transport_put(tsp);
554+
547555
return 0;
548556
}
549557

0 commit comments

Comments
 (0)