<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta content="text/html; charset=US-ASCII" http-equiv="Content-Type">
<title>
GitLab
</title>
<style>img {
max-width: 100%; height: auto;
}
</style>
</head>
<body>
<div class="content">
<p class="details" style="font-style: italic; color: #777;">
<a href="https://gitlab.com/estanglerbm">Edward Stangler</a> created an issue:
</p>
<div></div>
<h2 dir="auto">
<a id="user-content-description-of-problem" class="anchor" href="#description-of-problem" aria-hidden="true"></a>Description of problem:</h2>
<p dir="auto">When compiling on Linux that doesn't have getrandom() at all:</p>
<pre class="code highlight js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code><span id="LC1" class="line" lang="plaintext">/* if defined(__linux__) && !defined(HAVE_GETRANDOM) && !defined(SYS_getrandom) */</span>
<span id="LC2" class="line" lang="plaintext"></span>
<span id="LC3" class="line" lang="plaintext"># define getrandom(dst,s,flags) -1</span></code></pre>
<p dir="auto">Then if this executes (on a Linux with kernel < 3.17, for example) during GNU TLS init:</p>
<pre class="code highlight js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code><span id="LC1" class="line" lang="plaintext">static unsigned have_getrandom(void)</span>
<span id="LC2" class="line" lang="plaintext">{</span>
<span id="LC3" class="line" lang="plaintext"> char c;</span>
<span id="LC4" class="line" lang="plaintext"> int ret;</span>
<span id="LC5" class="line" lang="plaintext"> ret = getrandom(&c, 1, 1/*GRND_NONBLOCK*/);</span>
<span id="LC6" class="line" lang="plaintext"> if (ret == 1 || (ret == -1 && errno == EAGAIN))</span>
<span id="LC7" class="line" lang="plaintext"> return 1;</span>
<span id="LC8" class="line" lang="plaintext"> return 0;</span>
<span id="LC9" class="line" lang="plaintext">}</span></code></pre>
<p dir="auto">Then have_getrandom() = 1 when GNU TLS init is executed right after an API call that sets errno = EAGAIN. This causes TLS failure.</p>
<p dir="auto">This actually happened. At a very bad time.</p>
<p dir="auto">Our patch was to change this line:</p>
<pre class="code highlight js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code><span id="LC1" class="line" lang="plaintext"># define getrandom(dst,s,flags) -1</span></code></pre>
<p dir="auto">to this:</p>
<pre class="code highlight js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code><span id="LC1" class="line" lang="plaintext">static ssize_t _getrandom0(void *buf, size_t buflen, unsigned int flags)</span>
<span id="LC2" class="line" lang="plaintext">{</span>
<span id="LC3" class="line" lang="plaintext"> errno = ENOSYS;</span>
<span id="LC4" class="line" lang="plaintext"> return -1;</span>
<span id="LC5" class="line" lang="plaintext">}</span>
<span id="LC6" class="line" lang="plaintext"># define getrandom(dst,s,flags) _getrandom0(dst,s,flags)</span></code></pre>
<h2 dir="auto">
<a id="user-content-version-of-gnutls-used" class="anchor" href="#version-of-gnutls-used" aria-hidden="true"></a>Version of gnutls used:</h2>
<p dir="auto">3.6.10</p>
<h2 dir="auto">
<a id="user-content-distributor-of-gnutls-eg-ubuntu-fedora-rhel" class="anchor" href="#distributor-of-gnutls-eg-ubuntu-fedora-rhel" aria-hidden="true"></a>Distributor of gnutls (e.g., Ubuntu, Fedora, RHEL)</h2>
<p dir="auto">None</p>
<h2 dir="auto">
<a id="user-content-how-reproducible" class="anchor" href="#how-reproducible" aria-hidden="true"></a>How reproducible:</h2>
<p dir="auto">Always</p>
<p dir="auto">Steps to Reproduce:</p>
<ul dir="auto">
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
<h2 dir="auto">
<a id="user-content-actual-results" class="anchor" href="#actual-results" aria-hidden="true"></a>Actual results:</h2>
<h2 dir="auto">
<a id="user-content-expected-results" class="anchor" href="#expected-results" aria-hidden="true"></a>Expected results:</h2>
</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #777;">
—
<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/gnutls/issues/892">view it on GitLab</a>.
<br>
You're receiving this email because of your account on gitlab.com.
If you'd like to receive fewer emails, you can
<a href="https://gitlab.com/sent_notifications/a043f7a32e09c7a5bc93e16cc7357c80/unsubscribe">unsubscribe</a>
from this thread or
adjust your notification settings.
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Issue","url":"https://gitlab.com/gnutls/gnutls/issues/892"}}</script>
</p>
</div>
</body>
</html>