Module: xenomai-jki
Branch: for-forge
Commit: 6fa0c3fff47375b7a4af8c16b27014b611cff188
URL:    
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=6fa0c3fff47375b7a4af8c16b27014b611cff188

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Fri Jun 26 15:11:42 2015 +0200

cobalt/kernel: Fix locking for xnthread info manipulations

nklock must be held when manipulating bits of xnthread::info. Not all
callsites of xnthread_set/clear_info follow this rule so far, directly
or indirectly, fix them (and possibly some other races along this).

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 kernel/cobalt/posix/syscall.c |    5 +++++
 kernel/cobalt/synch.c         |    2 ++
 kernel/cobalt/thread.c        |    3 +++
 3 files changed, 10 insertions(+)

diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index 74b8c18..2d7ab1e 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -82,6 +82,9 @@ static void prepare_for_signal(struct task_struct *p,
                               int sysflags)
 {
        int notify = 0;
+       spl_t s;
+
+       xnlock_get_irqsave(&nklock, s);
 
        if (xnthread_test_info(thread, XNKICKED)) {
                if (signal_pending(p)) {
@@ -94,6 +97,8 @@ static void prepare_for_signal(struct task_struct *p,
                xnthread_clear_info(thread, XNKICKED);
        }
 
+       xnlock_put_irqrestore(&nklock, s);
+
        xnthread_test_cancel();
 
        xnthread_relax(notify, SIGDEBUG_MIGRATE_SIGNAL);
diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index 7142fd2..ae4ceef 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -443,7 +443,9 @@ redo:
        if (likely(h == XN_NO_HANDLE)) {
                xnsynch_set_owner(synch, curr);
                xnthread_get_resource(curr);
+               xnlock_get_irqsave(&nklock, s);
                xnthread_clear_info(curr, XNRMID | XNTIMEO | XNBREAK);
+               xnlock_put_irqrestore(&nklock, s);
                return 0;
        }
 
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 4cec6e7..7c8cb3a 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -1989,6 +1989,7 @@ void xnthread_relax(int notify, int reason)
        struct task_struct *p = current;
        int cpu __maybe_unused;
        siginfo_t si;
+       spl_t s;
 
        primary_mode_only();
 
@@ -2045,7 +2046,9 @@ void xnthread_relax(int notify, int reason)
                        si.si_int = reason | sigdebug_marker;
                        send_sig_info(SIGDEBUG, &si, p);
                }
+               xnlock_get_irqsave(&nklock, s);
                xnsynch_detect_claimed_relax(thread);
+               xnlock_put_irqrestore(&nklock, s);
        }
 
        /*


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to