forked from gramineproject/gramine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Xun's patch to add ioctl support (gramineproject#7)
- Loading branch information
Showing
18 changed files
with
1,266 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <sys/ioctl.h> | ||
#include <string.h> | ||
#include <malloc.h> | ||
#include <stddef.h> | ||
|
||
#include <sys/socket.h> | ||
#include <netinet/in.h> | ||
#include <net/if.h> | ||
#include <arpa/inet.h> | ||
#include <unistd.h> | ||
#include <stdio.h> | ||
#define MAX_IFS 64 | ||
int main(int argc, char **argv) { | ||
struct ifreq *ifr, *ifend; | ||
struct ifreq ifreq; | ||
struct ifconf ifc; | ||
int SockFD; | ||
SockFD = socket(AF_INET, SOCK_DGRAM, 0); | ||
memset(&ifc, 1, sizeof(ifc)); | ||
ifc.ifc_req = NULL; | ||
if (ioctl(SockFD, SIOCGIFCONF, &ifc) < 0) { | ||
printf("ioctl(SIOCGIFCONF): %m\n"); | ||
return 0; | ||
} | ||
//ifc.ifc_len = sizeof(ifs); | ||
ifc.ifc_req =(struct ifreq*) malloc(ifc.ifc_len); | ||
struct ifreq *ifs = ifc.ifc_req; | ||
if (ioctl(SockFD, SIOCGIFCONF, &ifc) < 0) { | ||
printf("ioctl(SIOCGIFCONF): %m\n"); | ||
return 0; | ||
} | ||
ifend = ifs + (ifc.ifc_len / sizeof(struct ifreq)); | ||
for (ifr = ifc.ifc_req; ifr < ifend; ifr++) { | ||
if (ifr->ifr_addr.sa_family == AF_INET) { | ||
strncpy(ifreq.ifr_name, ifr->ifr_name,sizeof(ifreq.ifr_name)); | ||
if (ioctl (SockFD, SIOCGIFHWADDR, &ifreq) < 0) { | ||
printf("SIOCGIFHWADDR(%s): %m\n", ifreq.ifr_name); | ||
return 0; | ||
} | ||
printf("Ip Address %s\n", inet_ntoa( ( (struct sockaddr_in *) &ifr->ifr_addr)->sin_addr)); | ||
printf("Device %s -> Ethernet %02x:%02x:%02x:%02x:%02x:%02x\n", ifreq.ifr_name, | ||
(int) ((unsigned char *) &ifreq.ifr_hwaddr.sa_data)[0], | ||
(int) ((unsigned char *) &ifreq.ifr_hwaddr.sa_data)[1], | ||
(int) ((unsigned char *) &ifreq.ifr_hwaddr.sa_data)[2], | ||
(int) ((unsigned char *) &ifreq.ifr_hwaddr.sa_data)[3], | ||
(int) ((unsigned char *) &ifreq.ifr_hwaddr.sa_data)[4], | ||
(int) ((unsigned char *) &ifreq.ifr_hwaddr.sa_data)[5]); | ||
} | ||
} | ||
free(ifc.ifc_req); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
loader.entrypoint = "file:{{ gramine.libos }}" | ||
libos.entrypoint = "{{ entrypoint }}" | ||
loader.argv0_override = "{{ entrypoint }}" | ||
|
||
loader.env.LD_LIBRARY_PATH = "/lib:{{ arch_libdir }}:/usr/{{ arch_libdir }}" | ||
loader.insecure__use_cmdline_argv = true | ||
|
||
# for eventfd test | ||
sys.insecure__allow_eventfd = true | ||
|
||
fs.mounts = [ | ||
{ path = "/lib", uri = "file:{{ gramine.runtimedir(libc) }}" }, | ||
{ path = "/{{ entrypoint }}", uri = "file:{{ binary_dir }}/{{ entrypoint }}" }, | ||
{ path = "/exec_victim", uri = "file:{{ binary_dir }}/exec_victim" }, | ||
{ path = "{{ arch_libdir }}", uri = "file:{{ arch_libdir }}" }, | ||
{ path = "/usr/{{ arch_libdir }}", uri = "file:/usr/{{ arch_libdir }}" }, | ||
{ path = "/bin", uri = "file:/bin" }, | ||
|
||
{ type = "tmpfs", path = "/mnt/tmpfs" }, | ||
{ type = "encrypted", path = "/tmp_enc", uri = "file:tmp_enc", key_name = "my_custom_key" }, | ||
{ type = "encrypted", path = "/encrypted_file_mrenclave.dat", uri = "file:encrypted_file_mrenclave.dat", key_name = "_sgx_mrenclave" }, | ||
{ type = "encrypted", path = "/encrypted_file_mrsigner.dat", uri = "file:encrypted_file_mrsigner.dat", key_name = "_sgx_mrsigner" }, | ||
] | ||
|
||
#sgx.ioctl_structs.ifconf = [ {name = "ifc_len",size = 8, align = 8, type= "out" }, { ptr=[ {name="ifcu_req", size= "ifc_len", type="inout"} ] } ] | ||
sgx.ioctl_structs.ifconf = [ {name = "ifc_len",size = 4, align = 4, type= "inout" }, {size = 4, type= "inout"}, { ptr=[ {name="ifcu_req", size= "ifc_len", type="in"} ] } ] | ||
sgx.allowed_ioctls.io1.request = 0x8912 | ||
sgx.allowed_ioctls.io1.struct = "ifconf" | ||
|
||
sgx.ioctl_structs.ifreq = [ { name ="ifreq", size=40, type="inout"} ] | ||
sgx.allowed_ioctls.io2.request = 0x8927 | ||
sgx.allowed_ioctls.io2.struct = "ifreq" | ||
|
||
sgx.thread_num = 16 | ||
sgx.nonpie_binary = true | ||
sgx.debug = true | ||
|
||
sgx.allowed_files = [ | ||
"file:tmp/", | ||
"file:root", # for getdents test | ||
"file:testfile", # for mmap_file test | ||
"file:scripts/", # for exec_script test | ||
] | ||
|
||
sgx.trusted_files = [ | ||
"file:{{ gramine.libos }}", | ||
"file:{{ gramine.runtimedir(libc) }}/", | ||
"file:{{ arch_libdir }}/libgcc_s.so.1", | ||
"file:/usr{{ arch_libdir }}/libstdc++.so.6", | ||
"file:{{ binary_dir }}/{{ entrypoint }}", | ||
"file:{{ binary_dir }}/exec_victim", | ||
"file:/bin/sh", | ||
] | ||
|
||
sgx.insecure__protected_files_key = "ffeeddccbbaa99887766554433221100" | ||
sgx.protected_files = [ | ||
"file:tmp/pf/", | ||
] | ||
|
||
# See the `keys.c` test. | ||
fs.insecure__keys.default = "ffeeddccbbaa99887766554433221100" | ||
fs.insecure__keys.my_custom_key = "00112233445566778899aabbccddeeff" | ||
|
||
# for sealed_file_mrenclave* tests | ||
sgx.protected_mrenclave_files = [ | ||
"file:sealed_file_mrenclave.dat", | ||
] | ||
|
||
# for sealed_file_mrsigner test | ||
sgx.protected_mrsigner_files = [ | ||
"file:sealed_file_mrsigner.dat", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,7 @@ manifests = [ | |
"debug_regs_x86_64", | ||
"rdtsc", | ||
"bootstrap_cpp", | ||
"ioctl", | ||
"sighandler_divbyzero", | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.