netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] net: sctp: sctp_transport_destroy{,_rcu}: fix potential pointer corruption
@ 2013-08-09 13:27 Daniel Borkmann
  2013-08-09 13:57 ` Vlad Yasevich
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Borkmann @ 2013-08-09 13:27 UTC (permalink / raw)
  To: davem; +Cc: netdev, linux-sctp

Probably this one is quite unlikely to be triggered, but it's more safe
to hold a pointer to asoc (instead of dereferencing), free the packet
chunks first, and access asoc though the pointer after we have called
sctp_transport_destroy_rcu() where the transport is being kfree()'d.
Introduced by commit 8c98653f ("sctp: sctp_close: fix release of bindings
for deferred call_rcu's"). I also did the 8c98653f regression test and
it's fine that way.

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
---
 v1->v2: do sctp_packet_free before call_rcu

 net/sctp/transport.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/net/sctp/transport.c b/net/sctp/transport.c
index bdbbc3f..c691455 100644
--- a/net/sctp/transport.c
+++ b/net/sctp/transport.c
@@ -176,17 +176,19 @@ static void sctp_transport_destroy_rcu(struct rcu_head *head)
  */
 static void sctp_transport_destroy(struct sctp_transport *transport)
 {
+	struct sctp_association *asoc = transport->asoc;
+
 	if (unlikely(!transport->dead)) {
 		WARN(1, "Attempt to destroy undead transport %p!\n", transport);
 		return;
 	}
 
-	call_rcu(&transport->rcu, sctp_transport_destroy_rcu);
-
 	sctp_packet_free(&transport->packet);
 
-	if (transport->asoc)
-		sctp_association_put(transport->asoc);
+	call_rcu(&transport->rcu, sctp_transport_destroy_rcu);
+
+	if (asoc != NULL)
+		sctp_association_put(asoc);
 }
 
 /* Start T3_rtx timer if it is not already running and update the heartbeat
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-09 13:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-09 13:27 [PATCH net v2] net: sctp: sctp_transport_destroy{,_rcu}: fix potential pointer corruption Daniel Borkmann
2013-08-09 13:57 ` Vlad Yasevich
2013-08-09 13:59   ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).