This is the mail archive of the
mailing list for the glibc project.
[Bug libc/9813] New: pselect implementation (when not implemneted by the kernel) agriviates the race
- From: "shachar at shemesh dot biz" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 4 Feb 2009 10:05:34 -0000
- Subject: [Bug libc/9813] New: pselect implementation (when not implemneted by the kernel) agriviates the race
- Reply-to: sourceware-bugzilla at sourceware dot org
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:
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
Summary: pselect implementation (when not implemneted by the
kernel) agriviates the race
AssignedTo: drepper at redhat dot com
ReportedBy: shachar at shemesh dot biz
CC: glibc-bugs at sources dot redhat dot com
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.