* Re: [Lksctp-developers] [PATCH 1/3] sctp: fix autoclose timer race
@ 2009-11-12 16:24 Vlad Yasevich
2009-11-12 18:14 ` Vlad Yasevich
0 siblings, 1 reply; 2+ messages in thread
From: Vlad Yasevich @ 2009-11-12 16:24 UTC (permalink / raw)
To: linux-sctp
Andrei Pelinescu-Onciul wrote:
> For very small autoclose timeouts (e.g. 0 or close to 0 due to
> overflows) it's possible that the timer is executed immediately
> after is set, before there is a chance to increase the association
> reference counter. To avoid this race, always reference the
> association before calling mod_timer() and dereference it back if
> the timer was already active.
>
Actually, I don't think this can happen. At worst, you'd trigger
a soft lock-up, since the code modifying the timer is already holding
a socket lock. But that would only happen if that code is pre-empted,
which would mean that a user version of the lock is held, then the
autoclose would get rescheduled anyway.
-vlad
> Signed-off-by: Andrei Pelinescu-Onciul <andrei@iptel.org>
> ---
> net/sctp/output.c | 5 +++--
> 1 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/net/sctp/output.c b/net/sctp/output.c
> index b94c211..8c39bd2 100644
> --- a/net/sctp/output.c
> +++ b/net/sctp/output.c
> @@ -586,8 +586,9 @@ int sctp_packet_transmit(struct sctp_packet *packet)
> timer = &asoc->timers[SCTP_EVENT_TIMEOUT_AUTOCLOSE];
> timeout = asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE];
>
> - if (!mod_timer(timer, jiffies + timeout))
> - sctp_association_hold(asoc);
> + sctp_association_hold(asoc);
> + if (mod_timer(timer, jiffies + timeout))
> + sctp_association_put(asoc); /* already active, deref */
> }
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Lksctp-developers] [PATCH 1/3] sctp: fix autoclose timer race
2009-11-12 16:24 [Lksctp-developers] [PATCH 1/3] sctp: fix autoclose timer race Vlad Yasevich
@ 2009-11-12 18:14 ` Vlad Yasevich
0 siblings, 0 replies; 2+ messages in thread
From: Vlad Yasevich @ 2009-11-12 18:14 UTC (permalink / raw)
To: linux-sctp
Vlad Yasevich wrote:
>
> Andrei Pelinescu-Onciul wrote:
>> For very small autoclose timeouts (e.g. 0 or close to 0 due to
>> overflows) it's possible that the timer is executed immediately
>> after is set, before there is a chance to increase the association
>> reference counter. To avoid this race, always reference the
>> association before calling mod_timer() and dereference it back if
>> the timer was already active.
>>
>
> Actually, I don't think this can happen. At worst, you'd trigger
> a soft lock-up, since the code modifying the timer is already holding
> a socket lock. But that would only happen if that code is pre-empted,
> which would mean that a user version of the lock is held, then the
> autoclose would get rescheduled anyway.
>
Even if the timer ends up running on a different CPU, the socket lock
guarantees that only 1 instance of the state machine is running per
socket. The timer handler will spin on the lock until it's released,
so there doesn't appear to be a race.
-vlad
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-11-12 18:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-12 16:24 [Lksctp-developers] [PATCH 1/3] sctp: fix autoclose timer race Vlad Yasevich
2009-11-12 18:14 ` Vlad Yasevich
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.