net: sctp: sctp_transport_destroy{,_rcu}: fix potential pointer corruption
Subsystems (3)
PATCH v2 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 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.
---
v1->v2: do sctp_packet_free before call_rcu
net/sctp/transport.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
net/sctp/transport.c +6 -4
@@ -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
Signature · 1 line
1.7.11.7
Quoted 30 lines · Daniel Borkmann
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 commit8c98653f("sctp:sctp_close: fix release of bindings for deferred call_rcu's"). I also did the8c98653fregression test and it's fine that way.Signed-off-by Daniel Borkmann <[email protected]>---
v1->v2: dosctp_packet_freebeforecall_rcunet/sctp/transport.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)net/sctp/transport.c +2
-0@@ -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 ; }
net/sctp/transport.c static void sctp_transport_destroy_rcu(struct rcu_head *head) · line 191
Quoted 10 lines
net/sctp/transport.c +4
-4-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);
I think it is safe to move call_rcu to be the last call in this function. This should never be a last ref on the association. If by some chance it is, we'll get the same warning.
And if you move call_rcu(), this becomes an ever smaller patch :) -vlad
Quoted 4 lines
net/sctp/transport.c +0
-0}/* Start T3_rtx timer if it is not already running and update the heartbeat
Quoted 45 lines · Vlad Yasevich
Quoted 30 lines · Daniel Borkmann
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 commit8c98653f("sctp:sctp_close: fix release of bindings for deferred call_rcu's"). I also did the8c98653fregression test and it's fine that way.Signed-off-by Daniel Borkmann <[email protected]>---
v1->v2: dosctp_packet_freebeforecall_rcunet/sctp/transport.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)net/sctp/transport.c +2
-0@@ -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 ; }net/sctp/transport.c static void sctp_transport_destroy_rcu(struct rcu_head *head) · line 191
Quoted 10 lines
net/sctp/transport.c +4
-4-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);I think it is safe to move
call_rcuto be the last call in this function. This should never be a last ref on the association. If by some chance it is, we'll get the same warning.
Quoted 1 line
And if you move
call_rcu(), this becomes an ever smaller patch :)
Ok, that's also a way to go. Will send v3. :-)
Quoted 10 lines
-vlad
net/sctp/transport.c static void sctp_transport_destroy_rcu(struct rcu_head *head) · line 194
Quoted 4 lines
net/sctp/transport.c +0
-0}/* Start T3_rtx timer if it is not already running and update the heartbeat --
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html