Intel® Software Guard Extensions (Intel® SGX)
Discussion board focused on hardware-based isolation and memory encryption to provide extended code protection in solutions.

File system sample code - reading data

John_D_4
Beginner
481 Views

Hi there,
I am following the sample code from the file system guide (https://software.intel.com/en-us/articles/overview-of-intel-protected-file-system-library-using-software-guard-extensions).  The edl sets the readData buffer as "[in, out, string]":

public size_t ecall_file_read([user_check]SGX_FILE* fp,[in,out,string]char* readData);

Unfortunately, the app code below only returns part of the data:

//Read from File
size_t sizeOfRead = 0;
char data[100];
ret = ecall_file_read(eid, &sizeOfRead, fp, data);
printf("Size of Read= %d\n", sizeOfRead);
data[sizeOfRead] = '\0';
printf("Read Data= %s\n", data);

Output:
"Size of Read= 14
 Read Data= Hello E"

The data is indeed read in the enclave but only part of it is returned to the app. If I modify the edl to "[out, size=len]" I need to pass the size but at least I get all data over to the app consistenly.

Output: "Read Data= Hello Enclave!"

Any ideas what might be wrong with the sample code or my setup, is it possible to avoid specifying the size upfront and still make this work?

Thanks!

 

 

0 Kudos
1 Reply
Hoang_N_Intel
Employee
481 Views

John,

I just compiled and ran the provided example without modification and the output is correct as follows:

Enclave Secret Value: Hello Enclave!
Size of Write=  14
Size of Read= 14
Read Data= Hello Enclave!

From what you posted, the size value is not the issue.

Output:
"Size of Read= 14
 Read Data= Hello E"

Size of 14 is correct. and "Hello E" string has only the length of 7.

Given that the code shows putting a NULL character at the end of the buffer at 14

ret = ecall_file_read(eid, &sizeOfRead, fp, data);
printf("Size of Read= %d\n", sizeOfRead);
data[sizeOfRead] = '\0';
printf("Read Data= %s\n", data);
 
it should be printing out at least 14 characters unless your data has a NULL character in the middle of that string.
 
Would you please download and run the provided example as is one more time and let us know the result?
Thanks,
 

 

 

0 Kudos
Reply