Bug 107932 - segmentation fault in libGL when testing sse exceptions
Summary: segmentation fault in libGL when testing sse exceptions
Alias: None
Product: Fedora
Classification: Fedora
Component: XFree86   
(Show other bugs)
Version: rawhide
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Mike A. Harris
QA Contact: David Lawrence
: 105581 (view as bug list)
Depends On:
TreeView+ depends on / blocked
Reported: 2003-10-24 17:38 UTC by Linus Torvalds
Modified: 2007-11-30 22:10 UTC (History)
1 user (show)

Fixed In Version: 4.3.0-42
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2003-10-24 18:32:29 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2003:406 normal SHIPPED_LIVE Updated XFree86 packages are available 2003-12-11 05:00:00 UTC

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)

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):

How reproducible:

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:

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.


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