Bug 173461 - sigaddset/sigdelset may not work as expected with gcc optimizer
sigaddset/sigdelset may not work as expected with gcc optimizer
Status: CLOSED WONTFIX
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: kernel (Show other bugs)
3.0
i386 Linux
medium Severity high
: ---
: ---
Assigned To: Don Howard
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2005-11-17 03:20 EST by Constantine Gavrilov
Modified: 2007-11-30 17:07 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2007-10-19 14:50:54 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
A sample of code using kernel sigaddset that shows the problem with -O2 flags (4.15 KB, text/plain)
2005-11-17 03:20 EST, Constantine Gavrilov
no flags Details
Proposed patch fo sigaddset and sigdelset to constant signal argument case miscompilation. (1.25 KB, patch)
2005-11-17 03:24 EST, Constantine Gavrilov
no flags Details | Diff
fix wrong sigaddset sigdelset for i386 (1.33 KB, patch)
2005-11-17 04:16 EST, Constantine Gavrilov
no flags Details | Diff
fix wrong sigaddset sigdelset for i386 (1.33 KB, patch)
2005-11-17 05:08 EST, Constantine Gavrilov
no flags Details | Diff

  None (edit)
Description Constantine Gavrilov 2005-11-17 03:20:41 EST
I have run into problem using sigaddset() with constant signal argument in
kernel code.

A code like the following gets miscompiled:

sigset_t a;
sigset_t b;
sigset_t c;

...........
sigaddset(&a, const1);
sigaddset(&a,  const2);
................................
b =a;    /* this line causes incorrect code; any 64-bit assignment seems to
cause a problem! */
sigaddset(&c, const2);
sigaddset(&c,  const3);
/* more sigaddset to c */

At some iteration of sigaddset to c, c may get the value of a!

All versions of compilers and all kernel versions are affected. The problem is
also reproducible in user space (with kernel sigaddset definition). Looking at
the dissassembly (or running in the debugger) clearly shows that gcc miscompiled
the code. The problem goes away if optimization is disabled, if just -O flag is
used, or if variables are used instead of constants.

Attached please find a C code (can be compiled into module or executable) that
demonstrates the problem (problem occurs if -O2 flag is used). Attached is also
a patch that fixes the problem (the patch was prepared against 2.6 tree). 

I defined sigaddset a macro (similar to sigismember) that calls one function for
constant argument and another for variable. In addition to fixing the problem,
it also makes sigaddset() faster for constant arguments.

To be on the safe side, I changed sigdelset() in the same way (I think the same
gcc bug may apply).
Comment 1 Constantine Gavrilov 2005-11-17 03:20:41 EST
Created attachment 121167 [details]
A sample of code using kernel sigaddset that shows the problem with -O2 flags
Comment 2 Constantine Gavrilov 2005-11-17 03:24:08 EST
Created attachment 121168 [details]
Proposed patch fo sigaddset and sigdelset to constant signal argument case miscompilation.
Comment 3 Constantine Gavrilov 2005-11-17 04:16:14 EST
Created attachment 121170 [details]
fix wrong sigaddset sigdelset for i386
Comment 4 Constantine Gavrilov 2005-11-17 04:21:39 EST
According to jakub@redhat.com, who closed bug 173460, it is a pure kernel bug
and not gcc problem. Instead of
__asm__("btsl %1,%0" : "=m"(*set) : "Ir"(_sig-1) : "cc");

sigsaddset must use
__asm__("btsl %1,%0" : "+m"(*set) : "Ir"(_sig-1) : "cc");

I have reworked the pacth but kept the constant case optimization.
Comment 5 Constantine Gavrilov 2005-11-17 05:08:30 EST
Created attachment 121174 [details]
 fix wrong sigaddset sigdelset for i386

Previous patch had a typo.
Comment 6 Ernie Petrides 2005-11-18 00:46:53 EST
Removing dependency on bug 173460.
Comment 7 Constantine Gavrilov 2006-02-22 09:32:56 EST
The bug has been fixed in 2.6.15 kernel (Linus accepted my patch). The bug
remains in advanced server 3 release.
Comment 8 RHEL Product and Program Management 2007-10-19 14:50:54 EDT
This bug is filed against RHEL 3, which is in maintenance phase.
During the maintenance phase, only security errata and select mission
critical bug fixes will be released for enterprise products. Since
this bug does not meet that criteria, it is now being closed.
 
For more information of the RHEL errata support policy, please visit:
http://www.redhat.com/security/updates/errata/
 
If you feel this bug is indeed mission critical, please contact your
support representative. You may be asked to provide detailed
information on how this bug is affecting you.

Note You need to log in before you can comment on or make changes to this bug.