Skip to contentSkip to conversation

net: sctp: sctp_transport_destroy{,_rcu}: fix potential pointer corruption

PATCH Applied Daniel Borkmann 3 participants 3 messages Aug 9, 2013 – Aug 13, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 net: sctp: sctp_transport_destroy{,_rcu}: fix potential pointer corruption

Probably this one is quite unlikely to be triggered, but it's more safe to do the call_rcu() at the end after we have dropped the reference on the asoc and freed sctp packet chunks. The reason why is because in sctp_transport_destroy_rcu() the transport is being kfree()'d, and if we're unlucky enough we could run into corrupted pointers. Probably that's more of theoretical nature, but it's safer to have this simple fix.

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.

---
 net/sctp/transport.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/sctp/transport.c +2 -2
index bdbbc3f..8fdd160 100644
@@ -181,12 +181,12 @@ static void sctp_transport_destroy(struct sctp_transport *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);
 }
 
 /* Start T3_rtx timer if it is not already running and update the heartbeat
Signature · 1 line
1.7.11.7
Acked-by on v3 1/1
#1 lore raw
Quoted 7 lines · Daniel Borkmann

Probably this one is quite unlikely to be triggered, but it's more safe to do the call_rcu() at the end after we have dropped the reference on the asoc and freed sctp packet chunks. The reason why is because in sctp_transport_destroy_rcu() the transport is being kfree()'d, and if we're unlucky enough we could run into corrupted pointers. Probably that's more of theoretical nature, but it's safer to have this simple fix.

Quoted 5 lines

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.

-vlad

Quoted 24 lines
---
  net/sctp/transport.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
net/sctp/transport.c +2 -2
index bdbbc3f..8fdd160 100644
@@ -181,12 +181,12 @@ static void sctp_transport_destroy(struct sctp_transport *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);
  }
 
  /* Start T3_rtx timer if it is not already running and update the heartbeat
maintainer Applied
#2 lore raw

From: Vlad Yasevich <[email protected]>
Date: Fri, 09 Aug 2013 10:42:37 -0400

Quoted 10 lines · Daniel Borkmann
Quoted 9 lines

Probably this one is quite unlikely to be triggered, but it's more safe
to do the call_rcu() at the end after we have dropped the reference on the asoc and freed sctp packet chunks. The reason why is because in sctp_transport_destroy_rcu() the transport is being kfree()'d, and if we're unlucky enough we could run into corrupted pointers. Probably that's more of theoretical nature, but it's safer to have this simple fix.

Quoted 8 lines
Quoted 6 lines

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.

Applied, thanks everyone.