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

    <tr>
        <th>Summary</th>
        <td>
            [libfuzzer] Usage of getpid() causes non-unique merge-control file names on some Linux distributions, causing errors if several Fuzzers run in parallel
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    The default value for `CFPath` (control file path) is using `TempPath`: 

```
std::string TempPath(const char *Prefix, const char *Extension) {
  return DirPlusFile(TmpDir(), std::string("libFuzzerTemp.") + Prefix +
 std::to_string(GetPid()) + Extension);
}
```
[source](https://github.com/llvm/llvm-project/blob/23a09b99313edb67d267a974be6cebfdfd97c7c8/compiler-rt/lib/fuzzer/FuzzerIO.cpp#L215)

This can cause issues on some Linux distributions if several fuzzers are running at the same time, spawned by the same process. The reasons is, that `getpid()` returns the same ID for all threads of the same process on distributions using Native POSIX Thread Library (NPTL). Examples are Red Hat 9.0 or SUSE Linux Enterprise Server 9. Other versions of Linux using LinuxThreads instead of NPTL are not affected, as they return unique IDs for all threads. See [this paper](http://comet.lehman.cuny.edu/jung/cmp426697/NPTL.pdf) from IBM as reference.

So if a process on a RHEL9 distribution spawns several threads to run libfuzzer they will try to read and write to the same merge-control file. This causes the following error:

```
MERGE: failed to parse the control file (unexpected error)
```

I guess a good way to fix this is to use a combination of `getpid()` and `gettid()`. I am open to contribute this fix, but I'd love to get some feedback on the idea before jumping on it. 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU1v2zgQ_TX0ZRBBpmzJOviQ1FZrIG2DxgX2tqCkocQuRWr54ST99QtSsuOk3QUWMGSJ5Hy9efPIrBWdQtyS9R1Z7xbMu16bLXtG6XspukWt25ftsUdokTMvHZyY9AhcGyB5-qF6YK4neQqE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