Greetings!
I have two questions about the NaClSendDatagram and NaClReceiveDatagram functions in Native Client.
First, I've constructed a demo application where the untrusted code can communicate with the trusted code (and vice-versa) via the NaClSendDatagram and NaClReceiveDatagram functions. In our experimentation with this demo we've noticed that Native Client prepends a 16 byte header when communicating from untrusted code to trusted code, but not vice versa.
For example, if we send the int 0x03 via NaClSendDatagram in the untrusted code we can hexdump the 4 bytes in the I/O vector: 0x03 0x00 0x00 0x00:
int
main(int argc, char **argv)
{
int ret;
NaClIOVec iov;
/*
* The NaClMessageHeader is a struct which has these attributes:
*
* NaClIOVec* iov
* size_t iov_length
* NaClHandle* handles
* size_t handle_count
* int flags
*/
NaClMessageHeader hdr = {&iov, 1, NULL, 0, 0};
struct mystruct m = {0x3};
assert(argc == 2);
imcfd = atoi(argv[1]);
iov.base = &m;
iov.length = sizeof(m);
ret = NaClSendDatagram(imcfd, &hdr, 0);
assert(ret != -1);
hexdump(iov.base, iov.length);
return 0;
}
ret = NaClReceiveDatagram(handlepair[1], &hdr, 0);
CHECK(ret != -1);
mystruct = (struct mystruct *) ((char *) iov.base + 16);
printf("Received in trusted code:");
hexdump(iov.base, ret);
#define NACL_SYSCALL_ADDR(syscall_number) \
(NACL_SYSCALL_START_ADDR + (syscall_number << NACL_SYSCALL_BLOCK_SHIFT))
--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to native-client-di...@googlegroups.com.
To post to this group, send email to native-cli...@googlegroups.com.
Visit this group at http://groups.google.com/group/native-client-discuss.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to native-client-discuss+unsub...@googlegroups.com.
int NaClSendDatagram(NaClHandle handle, const NaClMessageHeader* message,
int flags) {
return imc_sendmsg(handle, (const NaClImcMsgHdr *) message,
flags);
}
I see!Our goal is to send a message from trusted code to untrusted code, and then for the trusted code to send a message back to trusted code after doing whatever it needed to do with the message - like a request-response cycle. - all within a SINGLE host-os process. We have no need for IPC.We had at first used imc_sendmsg() in the untrusted code and then SendMsg() in the trusted code - but we were unable to initiate communication from the trusted code to the untrusted code. Rather, we found that we had to call imc_recvmsg() in the untrusted code, which invoked a callback in the trusted code (like in the custom_desc test) upon which the trusted code could then write into untrusted memory. Is this possible? As a result of these difficulties we found we were able to initiate communication from the trusted code to the untrusted code via NaClSendDatagram and NaClReceiveDatagram.
Would you be able to explain what you mean by "because those definitions aren't useful and shouldn't be being used"? Is it that these definitions are unsafe?
If it wouldn't consume too much of your time, a brief tour of the internals of IMC would be great! We're currently reading through the Native Client source to understand how it works - however we've only just reached the system call invocation in the trampoline routine for untrusted code (i.e. how the system call number calculates an offset in service runtime which is called like a function pointer etc).
NaClSend/ReceiveDatagram() are low-level layers of IMC's implementation which are only used in trusted code.