linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stanislaw Gruszka <sgruszka@redhat.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	LKML <linux-kernel@vger.kernel.org>,
	Dave Jones <davej@redhat.com>,
	John Stultz <john.stultz@linaro.org>,
	Tommi Rantala <tt.rantala@gmail.com>
Subject: Re: [PATCH] posix-cpu-timers: fix nanosleep task_struct leak
Date: Thu, 7 Feb 2013 13:22:13 +0100	[thread overview]
Message-ID: <20130207122212.GA2668@redhat.com> (raw)
In-Reply-To: <20130206161011.GA11161@redhat.com>

On Wed, Feb 06, 2013 at 05:10:11PM +0100, Oleg Nesterov wrote:
> First of all, thank you so much. I knew it was a good idea to cc you ;)

:-)

> On 02/06, Stanislaw Gruszka wrote:
> >
> > In do_cpu_nanosleep() we do posix_cpu_timer_create(), but forgot
> > corresponding posix_cpu_timer_del(), what lead to task_struct leak.
> 
> Plus, it seems we can leave the timer on ->cpu_timers list...
> 
> > @@ -1403,6 +1403,7 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags,
> >  				/*
> >  				 * Our timer fired and was reset.
> >  				 */
> > +				posix_cpu_timer_del(&timer);
> >  				spin_unlock_irq(&timer.it_lock);
> >  				return 0;
> >  			}
> > @@ -1420,9 +1421,17 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags,
> >  		 * We were interrupted by a signal.
> >  		 */
> >  		sample_to_timespec(which_clock, timer.it.cpu.expires, rqtp);
> > -		posix_cpu_timer_set(&timer, 0, &zero_it, it);
> > +		error = posix_cpu_timer_set(&timer, 0, &zero_it, it);
> > +		if (!error)
> > +			posix_cpu_timer_del(&timer);
> >  		spin_unlock_irq(&timer.it_lock);
> >
> > +		while (error == TIMER_RETRY) {
> > +			spin_lock_irq(&timer.it_lock);
> > +			error = posix_cpu_timer_del(&timer);
> 
> It is not clear to me why other posix_cpu_timer_del's above can't fail..
> May be you can add a comment.

Sure, I'll add more comments.

Once posix_cpu_timer_set(..., &zero_it, it) succeed with 0 return value,
it's not possible to fire timer, so posix_cpu_timer_del() will not fail.
Similar assumption is with first posix_cpu_timer_del() call I added
in the patch.

> And I am not sure that TIMER_RETRY is the only error we should worry.
> And perhaps we need even more posix_cpu_timer_del's?
>
> For example. Suppose that posix_cpu_timer_create() succeeds and does
> get_task_struct(p). But than p dies, and the first posix_cpu_timer_set()
> fails with -ESRCH. No?

On second -ESRCH case posix_cpu_timer_set() internally call
put_task_struct(). It does not remove from cpu_timers list, but
that is done at exit(). First -ESRCH case, i.e. calling
posix_cpu_timer_set() with timer->it.cpu.task == NULL, is not possible
in our case.

BTW: I don't think we handle correctly case when traced process -
- timer->it.cpu.task will die. Tracing process - timer->it_process will
probably not be woken up.

Stanislaw

  reply	other threads:[~2013-02-07 12:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-01 13:39 clock_nanosleep() task_struct leak Tommi Rantala
2013-02-01 13:52 ` Thomas Gleixner
2013-02-04 19:32   ` Oleg Nesterov
2013-02-05 10:34     ` Stanislaw Gruszka
2013-02-05 10:55       ` Thomas Gleixner
2013-02-06 11:23         ` Stanislaw Gruszka
2013-02-06 12:01           ` Tommi Rantala
2013-02-06 15:15             ` [PATCH] posix-cpu-timers: fix nanosleep " Stanislaw Gruszka
2013-02-06 16:10               ` Oleg Nesterov
2013-02-07 12:22                 ` Stanislaw Gruszka [this message]
2013-02-07 13:24                   ` Oleg Nesterov
2013-02-07 16:04                     ` [PATCH v2] " Stanislaw Gruszka
2013-02-07 18:37                       ` Oleg Nesterov

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=20130207122212.GA2668@redhat.com \
    --to=sgruszka@redhat.com \
    --cc=davej@redhat.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=tt.rantala@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 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).