<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - getgrnam_r interceptor can crash"
   href="http://llvm.org/bugs/show_bug.cgi?id=19734">19734</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>getgrnam_r interceptor can crash
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>compiler-rt
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>compiler-rt
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>davem@iabyn.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This relates to sanitizer_common_interceptors.inc @r208530.

The interceptor for getgrnam_r() (and possibly others, including getgrid_r())
can crash, because it unpoisons the fields of the struct group even when no
matches have been found.

getgrnam_r(...., &result) is documented to return zero on lack of error (even
including no matches), and to set result to a non-NULL value if a match occurs.
The interceptor only checks for !res and not for result before unpoisoning.

On my system, the fields of grp on no-match happen to point to the last entry
in /etc/group, so this is harmless; on another system (which I don't have
access to)
and which has 'group: compat' in nsswitch.conf (which may or may not be
relevant), the fields of grp on no-match contain garbage. Here's what gdb shows
just after the return from the libc getgrnam_r() call on that system:

$3 = {gr_name = 0xbebebebebebebebe <Address 0xbebebebebebebebe out of bounds>,
  gr_passwd = 0xbebebebebebebebe <Address 0xbebebebebebebebe out of bounds>,
  gr_gid = 3200171710, gr_mem = 0xbebebebebebebebe}

So clearly the getgrnam_r interceptor shouldn't call unpoison_group() (and
possibly some other actions too?) unless result is non-NULL.

Also I think the places where it checks for result being non-null should be
checking *result????

This was originally discovered in the test suite for the perl interpreter;
under ASan on one person's test server, it was consistently crashing when doing
a getgrnam on an unknown name on a perl built using getgrnam_r() (i.e. a
threaded interpreter).

The original thread can be seen here:

<a href="http://www.nntp.perl.org/group/perl.perl5.porters/2014/05/msg215176.html">http://www.nntp.perl.org/group/perl.perl5.porters/2014/05/msg215176.html</a></pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>