<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        text-align:justify;
        text-justify:inter-ideograph;
        font-size:10.5pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {mso-style-priority:99;
        mso-style-link:"Plain Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.5pt;
        font-family:"Calibri","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.PlainTextChar
        {mso-style-name:"Plain Text Char";
        mso-style-priority:99;
        mso-style-link:"Plain Text";
        font-family:"Calibri","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
/* Page Definitions */
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="ZH-CN" link="blue" vlink="purple" style="text-justify-trim:punctuation">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hi:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I am a software engineer of Alcatel-Lucent. In our product we use dropbear v071 under the OS: Linux version 3.4.24. At most time it works perfectly, but recently we got a problem: sometimes a child-process of
 dropbear occupied nearly 100% CPU (we use ARM1176, single-core). After I investigated it ,I found it is cause by a misuse of KEX_REKEY_TIMEOUT.<o:p></o:p></span></p>
<p class="MsoPlainText" style="text-indent:21.0pt"><span lang="EN-US">KEX_REKEY_TIMEOUT is defined as 8hours. that means when a session lasts more than 8 hours, the server and client will re-exchange their KEY for security reason. The timestamp of last-time
 KEY-EXCHANGED is recorded in variable &quot;ses.kexstate.lastkextime&quot;. <o:p></o:p></span></p>
<p class="MsoPlainText" style="text-indent:21.0pt"><span lang="EN-US">&nbsp;The child dropbear process decides the &quot;timeout&quot; parameter of &quot;select&quot; function by calling &quot;select_timeout&quot;. we can see it checks the timeout-events like KEX_REKEY_TIMEOUT, AUTH_TIMEOUT,
 keepalive_secs. If there is a timeout occurs, the &quot;update_timeout&quot; function returns a negative value, then &quot;select_timeout&quot; modifies it to ZREO by this:<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">/* clamp negative timeouts to zero - event has already triggered */<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return MAX(timeout, 0);<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">&nbsp;&nbsp; if &quot;select_timeout&quot; returns ZERO, the next &quot;select&quot; call (in &quot;session_loop&quot;) will return immediately. Then it will check timeout events by this:<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">/* check for auth timeout, rekeying required etc */<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; checktimeouts();<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">&nbsp;&nbsp; in the function &quot; checktimeouts &quot;, when it find the timeout is reached or to many data has been sent, it will send a SSH_MSG_KEXINIT message to peer. Normally this message will trigger a new KEY-EXCHANGE. However,
 when there is a network problem that the peer can't receive the message , this bug occurs: the timestamp ses.kexstate.lastkextime is only updated by calling&nbsp; &quot;switch_keys&quot;--&gt;&quot; kexinitialise &quot;, unfortunately this calling sequence is driven by ssh-messages,
 either SSH_MSG_KEXDH_INIT or SSH_MSG_NEWKEYS. When there is no ssh-message received , the child dropbear process enters dead-loop &quot;select&quot; with ZERO-timeout parameter caused by KEX_REKEY_TIMEOUT.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">&gt; &nbsp;&nbsp;&nbsp;&nbsp; So there is a very simple way to reproduce this bug: first define the KEX_REKEY_TIMEOUT as small as possible( I set it to 8 seconds), then start a ssh-session , the child dropbear process is forked. then plug
 out the network wire, after 8 seconds the child dropbear thread will occupy 100% CPU. Could you kindly check it? thanks.<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoPlainText" style="text-indent:21.0pt"><span lang="EN-US">Best regards<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
</div>
</body>
</html>