<?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>sujet Using Global variables and malloc function inside Enclave dans Intel® Software Guard Extensions (Intel® SGX)</title>
    <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Using-Global-variables-and-malloc-function-inside-Enclave/m-p/1151245#M2570</link>
    <description>&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Hi, I have trouble in applying SGX to my application&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;I want to keep an value inside Enclave while I'm using application.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;For example, I define account balance variable inside Enclave and want to keep the value of it while I'm using the application.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;but If I put the account balance variable in the trusted functions inside enclave as a local variable, the value would be gone after using the function and I couldn't keep the value.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;So I tried to define it as a global variable inside Enclave but the global variable was not encrypted unlike the local variables (* I checked it by using Cheat Engine. I couldn't scan local variables but could scan global variables)&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Could I use global variable inside enclave securely?&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;I hope to know how to use the global variables in enclave if I could use them.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;or If there is another way to keep value inside Enclave safely, I hope to know how to do.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;(I'm guessing there could be a way to allocate memory safely using malloc function ..)&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Thanks for reading my question :)&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Best regards&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Suin&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jul 2017 06:37:45 GMT</pubDate>
    <dc:creator>suin_k_</dc:creator>
    <dc:date>2017-07-20T06:37:45Z</dc:date>
    <item>
      <title>Using Global variables and malloc function inside Enclave</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Using-Global-variables-and-malloc-function-inside-Enclave/m-p/1151245#M2570</link>
      <description>&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Hi, I have trouble in applying SGX to my application&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;I want to keep an value inside Enclave while I'm using application.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;For example, I define account balance variable inside Enclave and want to keep the value of it while I'm using the application.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;but If I put the account balance variable in the trusted functions inside enclave as a local variable, the value would be gone after using the function and I couldn't keep the value.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;So I tried to define it as a global variable inside Enclave but the global variable was not encrypted unlike the local variables (* I checked it by using Cheat Engine. I couldn't scan local variables but could scan global variables)&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Could I use global variable inside enclave securely?&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;I hope to know how to use the global variables in enclave if I could use them.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;or If there is another way to keep value inside Enclave safely, I hope to know how to do.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;(I'm guessing there could be a way to allocate memory safely using malloc function ..)&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Thanks for reading my question :)&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Best regards&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Suin&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2017 06:37:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Using-Global-variables-and-malloc-function-inside-Enclave/m-p/1151245#M2570</guid>
      <dc:creator>suin_k_</dc:creator>
      <dc:date>2017-07-20T06:37:45Z</dc:date>
    </item>
    <item>
      <title>Hi：</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Using-Global-variables-and-malloc-function-inside-Enclave/m-p/1151246#M2571</link>
      <description>&lt;P&gt;Hi：&lt;/P&gt;

&lt;P&gt;I think there is something wrong with your code. The enclave global &lt;SPAN style="font-size: 12px;"&gt;variables is encrypted. In your case, you may use the global &amp;nbsp;variables outside the enclave. Did you clear up the secret after you use it ? I mean after you get the global variable via an Ecall function you should clear the utrusted buffer&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px;"&gt;which receives the value.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 12px;"&gt;Regards &lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 12px;"&gt;you&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2017 09:17:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Using-Global-variables-and-malloc-function-inside-Enclave/m-p/1151246#M2571</guid>
      <dc:creator>you_w_</dc:creator>
      <dc:date>2017-07-20T09:17:38Z</dc:date>
    </item>
    <item>
      <title>Hi, you</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Using-Global-variables-and-malloc-function-inside-Enclave/m-p/1151247#M2572</link>
      <description>&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Hi, you&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Thank you for answering my question.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;But I think I followed the SGX format. Maybe I am missing something.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;I wish you could check my sample code.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;*** Enclave2.cpp&lt;/P&gt;

&lt;DIV&gt;
	&lt;PRE class="brush:cpp;"&gt;#include "Enclave2_t.h"

#include "sgx_trts.h"

int balance;

void setBalance(int input) {
	balance = input;
}

void withdraw(int money) {
	balance -= money;
}

int getBalance() {
	return balance;
}&lt;/PRE&gt;
&lt;/DIV&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;***&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;*** Enclave2.edl&lt;/P&gt;

&lt;DIV&gt;
	&lt;PRE class="brush:cpp;"&gt;enclave {
    from "sgx_tstdc.edl" import *;
    trusted {
		public void setBalance(int input);
		public void withdraw(int money);
		public int getBalance(); 
    };
};&lt;/PRE&gt;
&lt;/DIV&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;***&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;***account.cpp&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;tchar.h&amp;gt;
#include "sgx_urts.h"
#include "Enclave2_u.h"

#define ENCLAVE_FILENAME _T("Enclave2.signed.dll")

int main() {
	sgx_enclave_id_t eid;
	sgx_status_t ret = SGX_SUCCESS;
	sgx_launch_token_t token = { 0 };
	int updated = 0;
	int balance;
	ret = sgx_create_enclave(ENCLAVE_FILENAME, SGX_DEBUG_FLAG, &amp;amp;token, &amp;amp;updated, &amp;amp;eid, NULL);

	setBalance(eid, 1000);
	withdraw(eid, 200);

	getchar();	
	//I scanned 800 here for global variable balance in Enclave2.cpp 
	//and found 9 memory address with value 800, I changed them all to 400 by using cheat engine
	
	withdraw(eid, 100); 
	//and here one of them decreased to 300
	//I think the value must be the global variable  

	if (SGX_SUCCESS != sgx_destroy_enclave(eid))
		printf("\nApp: error, failed to destroy enclave.\n");
	return 0;
}&lt;/PRE&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;***&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;If I miss something, please let me know.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Thanks for reading my question.&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Best regards&lt;/P&gt;

&lt;P style="word-wrap: break-word; font-size: 12px;"&gt;Suin&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2017 01:53:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Using-Global-variables-and-malloc-function-inside-Enclave/m-p/1151247#M2572</guid>
      <dc:creator>suin_k_</dc:creator>
      <dc:date>2017-07-21T01:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using Global variables and malloc function inside Enclave</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Using-Global-variables-and-malloc-function-inside-Enclave/m-p/1525251#M5936</link>
      <description>&lt;P&gt;I asked about a similar matter in my recent post, so i think for future reference it will be good to post the answer here too.&lt;/P&gt;&lt;P&gt;There is a detailed &lt;A href="https://github.com/intel/linux-sgx/issues/973" target="_self"&gt;answer&lt;/A&gt; in intel/sgx/issues on github. The PowerTransition sample code demonstrates exactly how to use a global variable to keep valid data inside the enclave till it's destruction.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Sep 2023 08:45:08 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Using-Global-variables-and-malloc-function-inside-Enclave/m-p/1525251#M5936</guid>
      <dc:creator>nyxon</dc:creator>
      <dc:date>2023-09-19T08:45:08Z</dc:date>
    </item>
  </channel>
</rss>

