Skip to content

Commit 86fdb34

Browse files
lxindavem330
authored andcommitted
sctp: ensure ep is not destroyed before doing the dump
Now before dumping a sock in sctp_diag, it only holds the sock while the ep may be already destroyed. It can cause a use-after-free panic when accessing ep->asocs. This patch is to set sctp_sk(sk)->ep NULL in sctp_endpoint_destroy, and check if this ep is already destroyed before dumping this ep. Suggested-by: Marcelo Ricardo Leitner <[email protected]> Signed-off-by: Xin Long <[email protected]> Acked-by: Neil Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7fe5b91 commit 86fdb34

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

net/sctp/endpointola.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
275275
if (sctp_sk(sk)->bind_hash)
276276
sctp_put_port(sk);
277277

278+
sctp_sk(sk)->ep = NULL;
278279
sock_put(sk);
279280
}
280281

net/sctp/sctp_diag.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ static int sctp_tsp_dump_one(struct sctp_transport *tsp, void *p)
278278

279279
static int sctp_sock_dump(struct sock *sk, void *p)
280280
{
281-
struct sctp_endpoint *ep = sctp_sk(sk)->ep;
282281
struct sctp_comm_param *commp = p;
283282
struct sk_buff *skb = commp->skb;
284283
struct netlink_callback *cb = commp->cb;
@@ -287,7 +286,9 @@ static int sctp_sock_dump(struct sock *sk, void *p)
287286
int err = 0;
288287

289288
lock_sock(sk);
290-
list_for_each_entry(assoc, &ep->asocs, asocs) {
289+
if (!sctp_sk(sk)->ep)
290+
goto release;
291+
list_for_each_entry(assoc, &sctp_sk(sk)->ep->asocs, asocs) {
291292
if (cb->args[4] < cb->args[1])
292293
goto next;
293294

0 commit comments

Comments
 (0)