提交 86fdb344 编写于 作者: X Xin Long 提交者: David S. Miller

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: NMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: NXin Long <lucien.xin@gmail.com>
Acked-by: NNeil Horman <nhorman@tuxdrver.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 7fe5b914
...@@ -275,6 +275,7 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep) ...@@ -275,6 +275,7 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
if (sctp_sk(sk)->bind_hash) if (sctp_sk(sk)->bind_hash)
sctp_put_port(sk); sctp_put_port(sk);
sctp_sk(sk)->ep = NULL;
sock_put(sk); sock_put(sk);
} }
......
...@@ -278,7 +278,6 @@ static int sctp_tsp_dump_one(struct sctp_transport *tsp, void *p) ...@@ -278,7 +278,6 @@ static int sctp_tsp_dump_one(struct sctp_transport *tsp, void *p)
static int sctp_sock_dump(struct sock *sk, void *p) static int sctp_sock_dump(struct sock *sk, void *p)
{ {
struct sctp_endpoint *ep = sctp_sk(sk)->ep;
struct sctp_comm_param *commp = p; struct sctp_comm_param *commp = p;
struct sk_buff *skb = commp->skb; struct sk_buff *skb = commp->skb;
struct netlink_callback *cb = commp->cb; struct netlink_callback *cb = commp->cb;
...@@ -287,7 +286,9 @@ static int sctp_sock_dump(struct sock *sk, void *p) ...@@ -287,7 +286,9 @@ static int sctp_sock_dump(struct sock *sk, void *p)
int err = 0; int err = 0;
lock_sock(sk); lock_sock(sk);
list_for_each_entry(assoc, &ep->asocs, asocs) { if (!sctp_sk(sk)->ep)
goto release;
list_for_each_entry(assoc, &sctp_sk(sk)->ep->asocs, asocs) {
if (cb->args[4] < cb->args[1]) if (cb->args[4] < cb->args[1])
goto next; goto next;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册