<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Re:Enclave stack overflow and malloc in Intel® Software Guard Extensions (Intel® SGX)</title>
    <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1189963#M3791</link>
    <description>&lt;P&gt;Hi Jesus,&lt;/P&gt;
&lt;P&gt;For the stack reserve memory:&lt;/P&gt;
&lt;P&gt;I selected the untrusted app project and then went to&amp;nbsp;&lt;STRONG&gt;Proprieties-&amp;gt;Configuration Proprieties-&amp;gt;Linker-&amp;gt;System-&amp;gt;Stack Reserve Size&amp;nbsp;&lt;/STRONG&gt;and increased the stack size to 4MB at first at think, and it solved the issue.&lt;/P&gt;
&lt;P&gt;I don't recall having another problem around here after that, my code is compiling and working now (the same code I posted here). The enclave memory settings are: stack - 0x4000, heap 0x2000000.&amp;nbsp;I have been able to copy chunks of 10MB, 20 MB and more back and forth.&lt;/P&gt;
&lt;P&gt;Anna&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jul 2020 18:37:07 GMT</pubDate>
    <dc:creator>Criston__Anna</dc:creator>
    <dc:date>2020-07-06T18:37:07Z</dc:date>
    <item>
      <title>Enclave stack overflow and malloc</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1187834#M3755</link>
      <description>&lt;P&gt;Hi! I am trying to allocate 1.8MB memory on the heap, with malloc, inside the enclave, then make an OCALL where I pass as parameter a [in, out] pointer(*&lt;EM&gt;message_in&lt;/EM&gt;) to this allocated memory(size_t&amp;nbsp;&lt;EM&gt;message_len = 1823577&lt;/EM&gt;&lt;LI-EMOJI id="lia_disappointed-face" title=":disappointed_face:"&gt;&lt;/LI-EMOJI&gt;&amp;nbsp;&lt;LI-EMOJI id="lia_disappointed-face" title=":disappointed_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;	ocall_get_next_message_size(&amp;amp;res_len, message_len);
	free(message_in);
	message_in = (unsigned char*) malloc(*message_len + 2);
    ocall_get_next_message(&amp;amp;res_message, message_in, *message_len + 2, &amp;amp;len_in, &amp;amp;len_out, path, 512);
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(*message_in has been allocated memory in the enclave before).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And in the .edl file:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;[cdecl] int ocall_get_next_message_size([in, out]size_t *message_len);
[cdecl] int ocall_get_next_message([in,out, size=message_len]unsigned char *message_in,size_t message_len,[in,out] size_t *len_in, [in, out]size_t *len_out, [in, out, size=len] char* path, size_t len);
		&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;However, I get stack overflow on ocall_get_next_message:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot (87).png" style="width: 999px;"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/10879iC7BB8549260992C6/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="Screenshot (87).png" alt="Screenshot (87).png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe I have allocated enough memory on the stack:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot (84).png" style="width: 489px;"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/10877i1FBBFB9CF0F5AF9E/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="Screenshot (84).png" alt="Screenshot (84).png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Moreover, trying to increase the stack size(even only to 0x3600000) or the heap size more (still multiple of 4k) makes the program not start anymore:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot (86).png" style="width: 999px;"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/10880iF30B894B42FF6093/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="Screenshot (86).png" alt="Screenshot (86).png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wanted to ask where could be the problem and what are the limitations of an enclave, besides the 128MB size. How much memory can pass a pointer to in an OCALL/ECALL and what is the maximum size my stack and heap can have?&amp;nbsp; I could not find information about this in the developer guide.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Sun, 28 Jun 2020 15:32:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1187834#M3755</guid>
      <dc:creator>Criston__Anna</dc:creator>
      <dc:date>2020-06-28T15:32:44Z</dc:date>
    </item>
    <item>
      <title>Re:Enclave stack overflow and malloc</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1188192#M3764</link>
      <description>&lt;P&gt;Hello Anna,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;We are looking into your issue. Please stay tuned.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Jun 2020 01:28:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1188192#M3764</guid>
      <dc:creator>JesusG_Intel</dc:creator>
      <dc:date>2020-06-30T01:28:05Z</dc:date>
    </item>
    <item>
      <title>Re:Enclave stack overflow and malloc</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1188588#M3770</link>
      <description>&lt;P&gt;Hello Anna,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I was able to reproduce your issue but not solve it. You must have enough space in your EPC for SGX Enclave Control Structure, Thread Control Structure, Save State Area, Stack, Heap, and Code and Data. I noticed that decreasing the size of the allocated buffer to a little more than 1000000 made the allocation successful. I could not find a max stack and heap size config that would allow your size of buffer.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Have you verified in your BIOS how much Processor Reserved Memory you have?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jesus&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Jun 2020 23:54:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1188588#M3770</guid>
      <dc:creator>JesusG_Intel</dc:creator>
      <dc:date>2020-06-30T23:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: Re:Enclave stack overflow and malloc</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1188659#M3775</link>
      <description>Hi Jesus, thank you for your reply. I checked and I had enabled 128 MB of PRM in BIOS.</description>
      <pubDate>Wed, 01 Jul 2020 06:50:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1188659#M3775</guid>
      <dc:creator>Criston__Anna</dc:creator>
      <dc:date>2020-07-01T06:50:57Z</dc:date>
    </item>
    <item>
      <title>Re:Enclave stack overflow and malloc</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1189078#M3782</link>
      <description>&lt;P&gt;Hi Anna, we are still looking into this issue. I apologize for the delay.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 02 Jul 2020 16:49:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1189078#M3782</guid>
      <dc:creator>JesusG_Intel</dc:creator>
      <dc:date>2020-07-02T16:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Re:Enclave stack overflow and malloc</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1189303#M3783</link>
      <description>&lt;P&gt;Hi, Jesus. I've solved the problem. Looks like the stack overflow came from copying the buffer to the untrusted stack. Apparently, Visual Studio set the untrusted stack size to 1MB by default. Increasing the stack reserve size to more than 2MB solved the issue.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jul 2020 09:23:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1189303#M3783</guid>
      <dc:creator>Criston__Anna</dc:creator>
      <dc:date>2020-07-04T09:23:19Z</dc:date>
    </item>
    <item>
      <title>Re:Enclave stack overflow and malloc</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1189928#M3787</link>
      <description>&lt;P&gt;Thanks for sharing the solution, Anna. I'm glad you got it working.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 06 Jul 2020 16:42:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1189928#M3787</guid>
      <dc:creator>JesusG_Intel</dc:creator>
      <dc:date>2020-07-06T16:42:42Z</dc:date>
    </item>
    <item>
      <title>Re:Enclave stack overflow and malloc</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1189940#M3788</link>
      <description>&lt;P&gt;Hi Anna, I have been playing around with the C++ option /F and setting the linker options for stack reserve and commit sizes but I still cannot get the program to work. I got around the stack overflow but run into a different error.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Would you mind telling us what specifically you changed to resolve the issue?&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 06 Jul 2020 17:21:08 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1189940#M3788</guid>
      <dc:creator>JesusG_Intel</dc:creator>
      <dc:date>2020-07-06T17:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: Re:Enclave stack overflow and malloc</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1189963#M3791</link>
      <description>&lt;P&gt;Hi Jesus,&lt;/P&gt;
&lt;P&gt;For the stack reserve memory:&lt;/P&gt;
&lt;P&gt;I selected the untrusted app project and then went to&amp;nbsp;&lt;STRONG&gt;Proprieties-&amp;gt;Configuration Proprieties-&amp;gt;Linker-&amp;gt;System-&amp;gt;Stack Reserve Size&amp;nbsp;&lt;/STRONG&gt;and increased the stack size to 4MB at first at think, and it solved the issue.&lt;/P&gt;
&lt;P&gt;I don't recall having another problem around here after that, my code is compiling and working now (the same code I posted here). The enclave memory settings are: stack - 0x4000, heap 0x2000000.&amp;nbsp;I have been able to copy chunks of 10MB, 20 MB and more back and forth.&lt;/P&gt;
&lt;P&gt;Anna&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 18:37:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Enclave-stack-overflow-and-malloc/m-p/1189963#M3791</guid>
      <dc:creator>Criston__Anna</dc:creator>
      <dc:date>2020-07-06T18:37:07Z</dc:date>
    </item>
  </channel>
</rss>

