Bug 107932

Summary: segmentation fault in libGL when testing sse exceptions
Product: [Fedora] Fedora Reporter: Linus Torvalds <torvalds>
Component: XFree86Assignee: Mike A. Harris <mharris>
Status: CLOSED ERRATA QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: medium    
Version: rawhideCC: jonsmirl
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: 4.3.0-42 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2003-10-24 18:32:29 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Linus Torvalds 2003-10-24 17:38:31 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031009

Description of problem:
This version of libGL contains a buggy assembler
routine for _mesa_test_os_sse_exception_support.

The end of the assembler routine looks roughly like

   ....
   movups (%esp),%xmm1
   addl $32,%esp
   divps  %xmm0,%xmm1
   ldmxcsr -4(%ebp)
   leave
   ret

and that "addl $32,%esp" is buggy, since it de-allocates
the stack. As a result, the exception that we are testing
for that "divps" results in will _overwrite_ the stack
location that "ldmxcsr" will restore the XCSR from.

So first you get a (correct) SIGFPE from the divps, and
when that returns you will get a (deadly) SIGSEGV from
ldmxcsr and the program dies.

Version-Release number of selected component (if applicable):
XFree86-Mesa-libGL-4.3.0-37

How reproducible:
Always

Steps to Reproduce:
1. Run _just_ the right combination of kernel and stack offsets
   (which will depend on a lot of things, but 2.6.0-test8 generally
   shows it)
2. Run any program using libGL (eg "glxinfo")
3. See it segfault
    

Actual Results:  Program dies with SIGSEGV

Expected Results:  Program should just run

Additional info:

This is most trivially fixed by just _removing_ that one
"addl $32,%esp" entirely from the _mesa_test_os_exception_support
routine. The "leave" instruction will do the right thing
anyway, and the "addl" instruction is simply buggy and has the
wrong constant in it.

This is also fixed in later versions of DRI CVS (and hopefully
later versions of XFree86 too). Which is where I originally
debugged this.

Comment 1 Mike A. Harris 2003-10-24 18:32:29 UTC
Ah yes, that makes a lot of sense.  I must admit I haven't given the problem
much thought until now, been too busy with other critical stuff for our release,
however it's great to get this nasty one squashed.

I've pulled the fix out of XFree86 CVS head by diffing the 4.3.0 vs. HEAD
versions of that file.  The addl is removed now, and should hopefully work.

On a side note, what's odd to me is why ENTER/LEAVE is getting used, as
that is God aweful slow instructions to use in modern code anywhere.  I'm
kindof surprised that is there at all.  I've filed another bug report to
fix that for the future as well.

Thanks a bunch for pointing this out Linus.  I wouldn't have had the time
to allocate to investigate this prior to Fedora Core 1 due to other
priorities, so our users will be very greatful to see this fixed.  A lot
less people will get hit while using 2.6.x.

If only there were 36 hours in a day.  ;o)

Fix applied to 4.3.0-42 in rawhide as:
    XFree86-4.3.0-Mesa-SSE-fixes-from-MesaCVS-v2.patch


Comment 2 Linus Torvalds 2003-10-24 19:04:13 UTC
As to why the routine uses enter/leave at all: I suspect
the original author really didn't know i386 assembly code,
and had just created a C file that he compiled with some
awful compile optimization options into assembler.

And then he edited the assembler directly. The code is
too ugly for words. But at least it should work now.

Comment 3 Mike A. Harris 2003-11-03 10:27:26 UTC
*** Bug 105581 has been marked as a duplicate of this bug. ***

Comment 4 Jay Turner 2004-01-16 16:58:27 UTC
An errata has been issued which should help the problem described in this bug report. 
This report is therefore being closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files, please follow the link below. You may reopen 
this bug report if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2003-406.html