<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/107881>107881</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            pthread interceptors for ASAN/MSAN
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ccotter
      </td>
    </tr>
</table>

<pre>
    Common pthread APIs like `pthread_mutex_lock` do not seem to have ASAN or MSAN interceptors. The following program is not caught by ASAN, though it is caught by TSAN with a `ThreadSanitizer: heap-use-after-free` diagnostic.

ASAN and MSAN intercept other libc names and check for the validity of the input parameters. Are the pthread APIs intentionally left out , or should they be added to `sanitizer_common_interceptors.inc` to catch such errors.

```
#include <pthread.h>

int main() {
 pthread_mutex_t* m = new pthread_mutex_t;
  delete m;
 pthread_mutex_lock(m); // No ASAN or MSAN diagnostic. TSAN catches this with heap-use-after-free.
  return 0;
}
```

Stack use after free are not caught by any of the sanitizers.

```
#include <pthread.h>

int main() {
  pthread_mutex_t* m;
  {
 pthread_mutex_t mtx;
    m = &mtx;
  }
  pthread_mutex_lock(m); // ASAN/MSAN hang on my system (but do not give any sanitizer diagnostic). The TSAN program runs without any error.
  return 0;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VE1v6zYQ_DX0ZWGDpvylgw5OUgM99KFAcg8oai2yoUiDXDrP_fUFKduxU_fQwwMECeJyl7Mzw5Uxmt4hNmz5xJYvE5lI-9Ao5YkwTFrfnZpnPwzewYF0QNnB9s_fI1jzgcBW_Lz4PiTCn-_Wqw-24tB5cJ4gIg5AHrQ8Imxftz_AB_gjf40jDAoP5EOcwZtG2Htr_adxPRyC74McwMRSRMnUa4L2VCow8Qykfeo1GMpbvsJvufCnIQ0yI3srwF6lM2T-xsCqLWiUh2mKOJV7wjDdB8SC1sje-UhGzRh_YXw7vgtg6bpviMGTxgDWtAqcHDCWPUqj-oC9D0Aa4Sit6QydwO_Lv3GHRHCQQQ5ImFveBiyRO1LzGY6Md9LaE1jcE_hEkHv2AaL2yXY56wQtguw67DK7bMXjpct3VbR6v-PXOJXbJA9KktIQk9KAIeTYbcNsxc_P-Csq45RNHQKrns9AZ5pVv90mGUcwSOOY2DBRA1s_jetw7wxiYgsDsOoFHH7-K1hdsqBDi4QwfC09sJjYDEzUrHoCJnZM7OCHv_fXjaSjL0rnGIG0iaNJHphhdgERkFJwwK8g2PrlMUfl_UpSfUCKCKUW5FogA37zr3RXQ1wF-5UKPJTghur_1AoG-nmzD87CMbG6D1xZ-X7UY5HG-7srAmnpevAOhhPEUyQcgIlNm-gyOnpzxELYlakbTZmox6FRpL3Mi5DcKG2-Mzm1WPz_aDrpmqqrq1pOsJmvxXJTryvOJ7pBIeebVnTVWnaCI672rVxy5FWL85a39cQ0gosFr3k9Xy6XnM_mnVys5XK-2K-43MyXbMFxkMbOrD0OMx_6iYkxYTPn681mPrGyRRvLEBYiX5ASZULkmRyanDRtUx_ZglsTKX6VIUMWm8sYub33ZRrdcD5JwTaa6BBZtR0l6Q3p1M6UH5jY5ZLnz_QQ_F-oiIldARKZ2J2RHhvxTwAAAP__dw_2KQ">