All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-core] Race in rpi_clear_remote?
@ 2010-04-26 13:43 Jan Kiszka
  2010-04-26 13:51 ` Jan Kiszka
  0 siblings, 1 reply; 18+ messages in thread
From: Jan Kiszka @ 2010-04-26 13:43 UTC (permalink / raw)
  To: xenomai-core

Hi,

I'm meditating over an oops in rpi_clear_remote. NULL pointer deref, it
/seems/ like thread->rpi is invalid. Looking at the code, I wonder if
this could explain the bug:


static void rpi_clear_remote(struct xnthread *thread)
{
...
        rpi = thread->rpi;
        if (unlikely(rpi == NULL))
                return;

        xnlock_get_irqsave(&rpi->rpilock, s);

        /*
         * The RPI slot - if present - is always valid, and won't
         * change since the thread is resuming on this CPU and cannot
         * migrate under our feet. We may grab the remote slot lock
         * now.
         */
        xnsched_pop_rpi(thread);
        thread->rpi = NULL;

...

So we deref (xnsched_pop_rpi) and clear thread->rpi under rpilock, but
we check for it without any protection? Sounds racy. I think 'thread' is
not only pointing to the current thread but could refer to a foreign one
as well, right? Don't we need this:

diff --git a/ksrc/nucleus/shadow.c b/ksrc/nucleus/shadow.c
index 872c37f..1f995d6 100644
--- a/ksrc/nucleus/shadow.c
+++ b/ksrc/nucleus/shadow.c
@@ -331,6 +331,12 @@ static void rpi_clear_remote(struct xnthread *thread)
 
 	xnlock_get_irqsave(&rpi->rpilock, s);
 
+	/* Re-check under lock, someone may have cleared rpi by now. */
+	if (unlikely(thread->rpi == NULL)) {
+		xnlock_put_irqrestore(&rpi->rpilock, s);
+		return;
+	}
+
 	/*
 	 * The RPI slot - if present - is always valid, and won't
 	 * change since the thread is resuming on this CPU and cannot


Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2010-05-02  9:08 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-26 13:43 [Xenomai-core] Race in rpi_clear_remote? Jan Kiszka
2010-04-26 13:51 ` Jan Kiszka
2010-04-26 16:06   ` [Xenomai-core] [PATCH] nucleus: Plug race between rpi_clear_remote and rpi_next Jan Kiszka
2010-04-26 16:11     ` Jan Kiszka
2010-04-27  1:19     ` Philippe Gerum
2010-04-27  6:46       ` Jan Kiszka
2010-04-27  8:13         ` Philippe Gerum
2010-04-27  8:25           ` Jan Kiszka
2010-04-27  9:12             ` Philippe Gerum
2010-04-27  9:27               ` Jan Kiszka
2010-04-27  9:32                 ` Philippe Gerum
2010-04-27  9:34                   ` Jan Kiszka
2010-04-27  9:51                     ` Philippe Gerum
2010-04-27 10:40                       ` Jan Kiszka
2010-05-01 17:26                         ` Philippe Gerum
2010-05-01 17:47                           ` Jan Kiszka
2010-05-01 18:59                             ` Philippe Gerum
2010-05-02  9:08                               ` Jan Kiszka

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.