public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/9813] New: pselect implementation (when not implemneted by the kernel) agriviates the race
@ 2009-02-04 10:05 shachar at shemesh dot biz
  2009-02-04 10:36 ` [Bug libc/9813] " shachar at shemesh dot biz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: shachar at shemesh dot biz @ 2009-02-04 10:05 UTC (permalink / raw)
  To: glibc-bugs

pselect is an operation that must be performed atomically. As such, the only
race free implementation is one done in the kernel. If the race exists, then it
is possible that "select" will hang until the timeout (or forever), because the
signal that the programmer thought would wake it up happened before "select" was
called. The glibc implementation is only as a stop gap for platforms where the
function is not defined, to encourage people to use it anyways, and is known not
to cover 100% of the cases.

That being said, the current pselect implementation makes the race condition
worse, almost guaranteeing that the race will take place.

The current implementation looks like this:
1: sigprocmask // Enable the signals
2: select // Perform the actual select
3: sigprocmask // Re-disable the signals

A typical use scenario would be:

4: while
5: pselect
6: if( signal happened ) ...
7: Do something not signal related
8: loop over the while

In the current implementation, any signal arriving after the sigprocmask in line
3, and before the "select" in line 2 is GUARANTEED to trigger the race
condition, as the signal will take effect as soon as the sigprocmask in line 1
takes place, necessarily before the select in line 2. This means the chances for
the race are directly proportional to the relative amount of time the program
spends doing something other than waiting on the select.

I am attaching a modified implementation of pselect that greatly reduces the
window in which the race can take effect, limiting it to only within the actual
pselect function.

-- 
           Summary: pselect implementation (when not implemneted by the
                    kernel) agriviates the race
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: shachar at shemesh dot biz
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=9813

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug libc/9813] pselect implementation (when not implemneted by the kernel) agriviates the race
  2009-02-04 10:05 [Bug libc/9813] New: pselect implementation (when not implemneted by the kernel) agriviates the race shachar at shemesh dot biz
@ 2009-02-04 10:36 ` shachar at shemesh dot biz
  2009-02-04 10:42 ` shachar at shemesh dot biz
  2009-02-04 10:52 ` shachar at shemesh dot biz
  2 siblings, 0 replies; 4+ messages in thread
From: shachar at shemesh dot biz @ 2009-02-04 10:36 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From shachar at shemesh dot biz  2009-02-04 10:36 -------
Created an attachment (id=3710)
 --> (http://sourceware.org/bugzilla/attachment.cgi?id=3710&action=view)
Proposed patch to narrow the race window

Proposed patch to the problem

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=9813

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug libc/9813] pselect implementation (when not implemneted by the kernel) agriviates the race
  2009-02-04 10:05 [Bug libc/9813] New: pselect implementation (when not implemneted by the kernel) agriviates the race shachar at shemesh dot biz
  2009-02-04 10:36 ` [Bug libc/9813] " shachar at shemesh dot biz
@ 2009-02-04 10:42 ` shachar at shemesh dot biz
  2009-02-04 10:52 ` shachar at shemesh dot biz
  2 siblings, 0 replies; 4+ messages in thread
From: shachar at shemesh dot biz @ 2009-02-04 10:42 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From shachar at shemesh dot biz  2009-02-04 10:42 -------
Forgot to add - in the above patch, NSIG_LONGS is undefined. Here is its definition:

// Number of __vals in sigset_t that actually contain useful data
#define NSIG_LONGS (_NSIG/(8*sizeof(((sigset_t *)NULL)->__val[0])))

Shachar

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=9813

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug libc/9813] pselect implementation (when not implemneted by the kernel) agriviates the race
  2009-02-04 10:05 [Bug libc/9813] New: pselect implementation (when not implemneted by the kernel) agriviates the race shachar at shemesh dot biz
  2009-02-04 10:36 ` [Bug libc/9813] " shachar at shemesh dot biz
  2009-02-04 10:42 ` shachar at shemesh dot biz
@ 2009-02-04 10:52 ` shachar at shemesh dot biz
  2 siblings, 0 replies; 4+ messages in thread
From: shachar at shemesh dot biz @ 2009-02-04 10:52 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From shachar at shemesh dot biz  2009-02-04 10:52 -------
Created an attachment (id=3712)
 --> (http://sourceware.org/bugzilla/attachment.cgi?id=3712&action=view)
Program demonstrating the problem

This program demonstrate the problem. Under a kernel with pselect support, it
prints:
sig_happened=1
sig_happened=1
sig_happened=1
sig_happened=1
sig_happened=1

And exits almost immediately.

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=9813

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

end of thread, other threads:[~2009-02-04 10:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-04 10:05 [Bug libc/9813] New: pselect implementation (when not implemneted by the kernel) agriviates the race shachar at shemesh dot biz
2009-02-04 10:36 ` [Bug libc/9813] " shachar at shemesh dot biz
2009-02-04 10:42 ` shachar at shemesh dot biz
2009-02-04 10:52 ` shachar at shemesh dot biz

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 read-only IMAP folder(s) and NNTP newsgroup(s).