All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Borkmann <dborkman@redhat.com>
To: Vlad Yasevich <vyasevich@gmail.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org, linux-sctp@vger.kernel.org
Subject: Re: [PATCH net v2] net: sctp: sctp_transport_destroy{,_rcu}: fix potential pointer corruption
Date: Fri, 09 Aug 2013 13:59:15 +0000	[thread overview]
Message-ID: <5204F5B3.7020800@redhat.com> (raw)
In-Reply-To: <5204F55B.2040704@gmail.com>

On 08/09/2013 03:57 PM, Vlad Yasevich wrote:
> On 08/09/2013 09:27 AM, Daniel Borkmann wrote:
>> 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);
>
> 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 :)

Ok, that's also a way to go. Will send v3. :-)

> -vlad
>>   }
>>
>>   /* 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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: Daniel Borkmann <dborkman@redhat.com>
To: Vlad Yasevich <vyasevich@gmail.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org, linux-sctp@vger.kernel.org
Subject: Re: [PATCH net v2] net: sctp: sctp_transport_destroy{,_rcu}: fix potential pointer corruption
Date: Fri, 09 Aug 2013 15:59:15 +0200	[thread overview]
Message-ID: <5204F5B3.7020800@redhat.com> (raw)
In-Reply-To: <5204F55B.2040704@gmail.com>

On 08/09/2013 03:57 PM, Vlad Yasevich wrote:
> On 08/09/2013 09:27 AM, Daniel Borkmann wrote:
>> 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);
>
> 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 :)

Ok, that's also a way to go. Will send v3. :-)

> -vlad
>>   }
>>
>>   /* 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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2013-08-09 13:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-09 13:27 [PATCH net v2] net: sctp: sctp_transport_destroy{,_rcu}: fix potential pointer corruption Daniel Borkmann
2013-08-09 13:27 ` Daniel Borkmann
2013-08-09 13:57 ` Vlad Yasevich
2013-08-09 13:57   ` Vlad Yasevich
2013-08-09 13:59   ` Daniel Borkmann [this message]
2013-08-09 13:59     ` Daniel Borkmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5204F5B3.7020800@redhat.com \
    --to=dborkman@redhat.com \
    --cc=davem@davemloft.net \
    --cc=linux-sctp@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=vyasevich@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.