<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://sourceware.org/bugzilla/bugzilla.dtd">

<bugzilla version="4.0.10"
          urlbase="http://sourceware.org/bugzilla/"
          
          maintainer="overseers@sourceware.org"
>

    <bug>
          <bug_id>12492</bug_id>
          
          <creation_ts>2011-02-15 14:44:00 +0000</creation_ts>
          <short_desc>dl: RELRO handling crashes when kernel enforces MPROTECT restrictions</short_desc>
          <delta_ts>2012-03-29 14:56:50 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>glibc</product>
          <component>dynamic-link</component>
          <version>2.11</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>REOPENED</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Pierre Ynard">linkfanel</reporter>
          <assigned_to name="Ulrich Drepper">drepper.fsp</assigned_to>
          <cc>atoth</cc>
    
    <cc>ireopenit</cc>
    
    <cc>kees</cc>
    
    <cc>pageexec</cc>
    
    <cc>thoger</cc>
          <cf_gcchost></cf_gcchost>
          <cf_gcctarget></cf_gcctarget>
          <cf_gccbuild></cf_gccbuild>
          

      

      

      

          <long_desc isprivate="0">
            <commentid>47078</commentid>
              <attachid>5242</attachid>
            <who name="Pierre Ynard">linkfanel</who>
            <bug_when>2011-02-15 14:44:32 +0000</bug_when>
            <thetext>Created attachment 5242
Proposed fix

See Debian bug http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=611195

When dlopen&apos;ing a library that needs to make the stack executable, the RELRO section is made writable again to modify the __stack_prot variable. However, the return value of the mprotect() call is not checked; so if mprotect() fails, instead of gracefully handling the error, the dynamic loader tries to write to __stack_prot anyway, which results in a segmentation fault. And this mprotect() call *will* fail on PaX kernels that enforce restrictions on it.

The simple fix is to check the return value and simply fail to load the problematic library, instead of crashing the whole process. And it&apos;s just good programming practice.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47081</commentid>
            <who name="Ulrich Drepper">drepper.fsp</who>
            <bug_when>2011-02-15 19:30:30 +0000</bug_when>
            <thetext>Just use a supported kernel.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47084</commentid>
            <who name="PaX Team">pageexec</who>
            <bug_when>2011-02-15 20:03:46 +0000</bug_when>
            <thetext>mprotect() can fail on supported kernels (what are they anyway?), so it is simply bad programming practice to not check the return value.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47097</commentid>
            <who name="Ulrich Drepper">drepper.fsp</who>
            <bug_when>2011-02-17 05:45:00 +0000</bug_when>
            <thetext>No, it cannot fail in these situations.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47098</commentid>
            <who name="PaX Team">pageexec</who>
            <bug_when>2011-02-17 10:02:59 +0000</bug_when>
            <thetext>merging and splitting vma structures require memory allocation that can fail.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47099</commentid>
            <who name="PaX Team">pageexec</who>
            <bug_when>2011-02-17 10:25:43 +0000</bug_when>
            <thetext>i almost forgot, you didn&apos;t answer my question: what is your definition of a supported kernel?</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47114</commentid>
            <who name="Ulrich Drepper">drepper.fsp</who>
            <bug_when>2011-02-18 16:40:41 +0000</bug_when>
            <thetext>Stop reopening the bug.  If you have to redefine what your own OS does then maintain your own version of everything else as well.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47115</commentid>
            <who name="">ireopenit</who>
            <bug_when>2011-02-18 16:53:35 +0000</bug_when>
            <thetext>Do you have any real reason not to apply the submitted patch? Childish spite doesn&apos;t count.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47116</commentid>
            <who name="Kees Cook">kees</who>
            <bug_when>2011-02-18 17:08:11 +0000</bug_when>
            <thetext>The stock Linux kernel can fail the mprotect call. The LSM mediates this routine. Even SELinux has hooks to reject certain calls. It seems prudent to check the return code since LSMs are being improved/changed all the time.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47119</commentid>
            <who name="PaX Team">pageexec</who>
            <bug_when>2011-02-18 19:43:01 +0000</bug_when>
            <thetext>since this bug affects any kernel, including those of your own employer, it will stay open until it gets fixed. it&apos;s also obvious that failing the second mprotect in the same block of code means you&apos;ve left ld.so&apos;s RELRO region writable and that&apos;s a security bug itself so you&apos;d better check its return value as well and ask for a CVE.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47132</commentid>
            <who name="Pierre Ynard">linkfanel</who>
            <bug_when>2011-02-21 04:05:59 +0000</bug_when>
            <thetext>First of all, I&apos;m sorry for all of this that I started :( I&apos;m sorry to
use up so much of your time, I imagine that dealing with bug reports and
trivial issues must be boring and sometimes frustrating. I&apos;m just trying
to help by taking care some of the dull janitor job like checking return
values: a patch is all ready and it only needs someone to commit it.

glibc is a great piece of software and I&apos;m sure people look at it as a
coding model, so it would be a shame to leave examples that could look
like bad practice, even if that part of the code is not so important in
itself.

I&apos;d love to see this matter just resolved. If you don&apos;t mind. Please
please accept my humble apology along with this patch.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47294</commentid>
            <who name="Pierre Ynard">linkfanel</who>
            <bug_when>2011-03-02 22:12:09 +0000</bug_when>
            <thetext>The patch was merged into eglibc (http://www.eglibc.org/archives/commits/msg01710.html). I guess than rather than &quot;just use a supported kernel&quot;, I&apos;ll have to just use a supported libc :(
Pax Team, any suggestion about what should be done if the second mprotect() fails?</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47295</commentid>
            <who name="PaX Team">pageexec</who>
            <bug_when>2011-03-02 22:30:32 +0000</bug_when>
            <thetext>probably the same as with the first mprotect failure.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47297</commentid>
            <who name="Pierre Ynard">linkfanel</who>
            <bug_when>2011-03-03 02:09:51 +0000</bug_when>
            <thetext>But it still leaves the RELRO region writable, and I doubt the calling application is going to do anything about it</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47298</commentid>
            <who name="PaX Team">pageexec</who>
            <bug_when>2011-03-03 08:40:54 +0000</bug_when>
            <thetext>by default the code after call_lose_errno won&apos;t return to the application ;).</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>47502</commentid>
            <who name="Charlie Sheen">charliesheen</who>
            <bug_when>2011-03-15 15:54:27 +0000</bug_when>
            <thetext>__stack_prot |= PROT_READ|PROT_WRITE|PROT_EXEC;

Whoever wrote this, you are rwx-winning. You win at reads, you win at writes and you win at execution. I couldn&apos;t have done it better even if I banged a seven gram text-relocating rock.</thetext>
          </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
              isurl="0"
          >
            <attachid>5242</attachid>
            <date>2011-02-15 14:44:00 +0000</date>
            <delta_ts>2011-02-15 14:44:32 +0000</delta_ts>
            <desc>Proposed fix</desc>
            <filename>dl.patch</filename>
            <type>text/plain</type>
            <size>585</size>
            <attacher>linkfanel</attacher>
            
              <data encoding="base64">LS0tIGVsZi9kbC1sb2FkLmMJMjAxMS0wMS0yNiAyMjowMjowMi4wMDAwMDAwMDAgKzAxMDAKKysr
IGVsZi9kbC1sb2FkLmMJMjAxMS0wMS0yNiAyMjozMDoyMi4wMDAwMDAwMDAgKzAxMDAKQEAgLTEz
OTgsNyArMTM5OCwxMSBAQAogCSAgaWYgKF9fYnVpbHRpbl9leHBlY3QgKHAgKyBzIDw9IHJlbHJv
X2VuZCwgMSkpCiAJICAgIHsKIAkgICAgICAvKiBUaGUgdmFyaWFibGUgbGllcyBpbiB0aGUgcmVn
aW9uIHByb3RlY3RlZCBieSBSRUxSTy4gICovCi0JICAgICAgX19tcHJvdGVjdCAoKHZvaWQgKikg
cCwgcywgUFJPVF9SRUFEfFBST1RfV1JJVEUpOworCSAgICAgIGlmIChfX21wcm90ZWN0ICgodm9p
ZCAqKSBwLCBzLCBQUk9UX1JFQUR8UFJPVF9XUklURSkgPCAwKQorCQl7CisJCSAgZXJyc3RyaW5n
ID0gTl8oImNhbm5vdCBjaGFuZ2UgbWVtb3J5IHByb3RlY3Rpb25zIik7CisJCSAgZ290byBjYWxs
X2xvc2VfZXJybm87CisJCX0KIAkgICAgICBfX3N0YWNrX3Byb3QgfD0gUFJPVF9SRUFEfFBST1Rf
V1JJVEV8UFJPVF9FWEVDOwogCSAgICAgIF9fbXByb3RlY3QgKCh2b2lkICopIHAsIHMsIFBST1Rf
UkVBRCk7CiAJICAgIH0K
</data>

          </attachment>
      

    </bug>

</bugzilla>