From: Ove Kaaven <ovek@transgaming.com>
To: linux-kernel@vger.kernel.org
Subject: PATCH: SysV semaphore race vs SIGSTOP
Date: Mon, 31 Jan 2005 22:52:22 -0500 [thread overview]
Message-ID: <1107229942.2371.13.camel@renegade> (raw)
In-Reply-To: <1106952950.15901.47.camel@renegade>
As I mentioned in an earlier mail, there is a race when SIGSTOP-ing a
process waiting for a SysV semaphore, where if a process holding a
semaphore suspends another process waiting on the semaphore and then
releases the semaphore, the suspended process might still get the
semaphore, resulting in a deadlock. My sample test program is at
http://www.ping.uio.no/~ovehk/sembug.c
Now I've written a patch for this which seems to work for me. It is
against 2.4.27, but the semaphore code doesn't seem to change often. And
please Cc me on any questions or comments, since I'm not subscribed.
Here is the patch:
--- ipc/sem.c.original 2005-01-31 18:17:17.000000000 -0500
+++ ipc/sem.c 2005-01-31 18:17:34.000000000 -0500
@@ -307,6 +307,18 @@
return result;
}
+static int is_stopping(struct task_struct *t)
+{
+ if (t->state == TASK_STOPPED) {
+ /* shouldn't happen */
+ return 1;
+ }
+ if (sigismember(&t->pending.signal, SIGSTOP)) {
+ return 1;
+ }
+ return 0;
+}
+
/* Go through the pending queue for the indicated semaphore
* looking for tasks that can be completed.
*/
@@ -961,6 +973,12 @@
error = -EIDRM;
goto out_free;
}
+
+ if (is_stopping(current))
+ /* Could either EINTR out or continue.
+ * Currently I've chosen to continue */
+ continue;
+
/*
* If queue.status == 1 we where woken up and
* have to retry else we simply return.
next prev parent reply other threads:[~2005-02-01 3:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-28 22:55 PROBLEM: SysV semaphore race vs SIGSTOP Ove Kaaven
2005-02-01 3:52 ` Ove Kaaven [this message]
-- strict thread matches above, loose matches on Subject: below --
2005-02-05 8:37 PATCH: " Manfred Spraul
2005-02-06 7:42 ` Ove Kaaven
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=1107229942.2371.13.camel@renegade \
--to=ovek@transgaming.com \
--cc=linux-kernel@vger.kernel.org \
/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