sctp: hold transport instead of assoc in sctp_diag
authorXin Long <lucien.xin@gmail.com>
Mon, 31 Oct 2016 12:32:31 +0000 (20:32 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 31 Oct 2016 20:20:32 +0000 (16:20 -0400)
In sctp_transport_lookup_process(), Commit 1cceda784980 ("sctp: fix
the issue sctp_diag uses lock_sock in rcu_read_lock") moved cb() out
of rcu lock, but it put transport and hold assoc instead, and ignore
that cb() still uses transport. It may cause a use-after-free issue.

This patch is to hold transport instead of assoc there.

Fixes: 1cceda784980 ("sctp: fix the issue sctp_diag uses lock_sock in rcu_read_lock")
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sctp/socket.c

index 9fbb6fe..71b75f9 100644 (file)
@@ -4480,12 +4480,9 @@ int sctp_transport_lookup_process(int (*cb)(struct sctp_transport *, void *),
        if (!transport || !sctp_transport_hold(transport))
                goto out;
 
-       sctp_association_hold(transport->asoc);
-       sctp_transport_put(transport);
-
        rcu_read_unlock();
        err = cb(transport, p);
-       sctp_association_put(transport->asoc);
+       sctp_transport_put(transport);
 
 out:
        return err;